container status report
This commit is contained in:
parent
785e8c2054
commit
8ec8bd1f29
3 changed files with 42 additions and 2 deletions
19
cloud_node_statistics.py
Normal file
19
cloud_node_statistics.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
# coding: utf-8
|
||||
|
||||
import requests
|
||||
import config
|
||||
import ConfigParser
|
||||
import lxc
|
||||
import node
|
||||
|
||||
clslxc = lxc.lxc()
|
||||
clsnode = node.NodeClient()
|
||||
|
||||
containers = clslxc.list()
|
||||
|
||||
for container in containers:
|
||||
# print container
|
||||
info = clslxc.info(container)
|
||||
info['container_id'] = info['name']
|
||||
print clsnode.report_container_status(info['container_id'], info)
|
||||
# print info
|
|
@ -78,7 +78,7 @@ class lxc():
|
|||
else:
|
||||
path = ""
|
||||
|
||||
cmd = ['lxc-ls', path]
|
||||
cmd = ['/usr/bin/lxc-ls', path]
|
||||
out = subprocess.check_output(cmd).splitlines()
|
||||
# print out
|
||||
return out
|
||||
|
@ -145,7 +145,7 @@ class lxc():
|
|||
if not self.exists(name):
|
||||
raise ContainerNotExists("The container (%s) does not exist!" % name)
|
||||
|
||||
cmd = ['lxc-info', '-n', name, "-H"]
|
||||
cmd = ['/usr/bin/lxc-info', '-n', name, "-H"]
|
||||
out = subprocess.check_output(cmd).splitlines()
|
||||
clean = []
|
||||
info = {}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
# coding: utf-8
|
||||
|
||||
import config
|
||||
import os
|
||||
|
@ -22,6 +23,26 @@ class NodeClient():
|
|||
response = requests.get('http://%s/server_api/task_status_update?node_id=%s&node_secret=%s&task_id=%s&status=%s' % (config.server, config.node_id, config.node_secret, task_id, status))
|
||||
return response.json()
|
||||
|
||||
def report_container_status(self, container_id, statistics):
|
||||
data = {
|
||||
'node_id': config.node_id,
|
||||
'node_secret': config.node_secret,
|
||||
'status': json.dumps(statistics)
|
||||
}
|
||||
|
||||
print statistics
|
||||
# for i in statistics:
|
||||
# data[i] = statistics[i]
|
||||
|
||||
response = requests.post(
|
||||
'http://%s/server_api/report/container_status' % config.server,
|
||||
data=data
|
||||
)
|
||||
if response.status_code == 200:
|
||||
return response.json()
|
||||
# print response.text
|
||||
return False
|
||||
|
||||
|
||||
def __container_config_create(container_id, link, ipv4, ipv6):
|
||||
cfg = []
|
||||
|
|
Loading…
Add table
Reference in a new issue