Loading bin/cc-node +6 −3 Changes for bin/cc-node: 6 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ DEFAULT_CONFIGURATION = { 'verbosity': '0', 'detect_hypervisor': 'yes', #'ssl_cert': '', 'command_execution' : 'yes', } MAX_AUTH_TIMEOUT = 10 Loading Loading @@ -62,7 +63,8 @@ def run_node(options): try: node = CCNode(options['address'], int(options['port']), options['detect_hypervisor'] == 'yes') options['detect_hypervisor'] == 'yes', options['command_execution'] == 'yes') except Exception as err: logging.critical('Starting fail: %s' % err) return Loading Loading @@ -104,6 +106,7 @@ def run_node(options): logging.critical('Node failed: %s' % err) return if __name__ == '__main__': usage = 'usage: %prog [OPTION...]' Loading @@ -117,7 +120,7 @@ if __name__ == '__main__': cliopts, args = op.parse_args() # Reading the config file: # read the config file config = ConfigParser.SafeConfigParser() config.read(cliopts.config) try: Loading @@ -127,7 +130,7 @@ if __name__ == '__main__': "in '%s'\n" % cliopts.config) sys.exit(1) # Applying default config file options: # applying default config file options for opt, default in DEFAULT_CONFIGURATION.iteritems(): if opt not in options or not options[opt]: if default is None: Loading ccnode/__init__.py +2 −58 Changes for ccnode/__init__.py: 2 added lines, 58 removed lines. Original line number Diff line number Diff line Loading @@ -2,65 +2,9 @@ #coding:utf-8 """ This API abstracts all calls to any hypervisor type. This API is split in four parts: * Global Interface * Libvirt Wrapper * KVM, XEN, ... hypervisor interface * Exceptions Every entity in the hypervisor library has a common ancestor :class:`interface.Host`. The inheritance diagram shown below reflects the relationship between each class. .. graphviz:: digraph { subgraph cluster_interface { "Host" [shape=box]; "Hypervisor" [shape=box]; "VM" [shape=box]; "Host" -> "Hypervisor"; "Host" -> "VM"; label = "interface"; style = filled; color = "#e6fbff"; } subgraph cluster_libvirt { "LibvirtHypervisor" [shape=box]; "LibvirtVm" [shape=box]; "Hypervisor" -> "LibvirtHypervisor"; "VM" -> "LibvirtVm"; style=filled; color="#ffe6ea"; label = "libvirt"; } subgraph cluster_hypervisor_calls { "KvmHypervisor" [shape=box]; "XenHypervisor" [shape=box]; "LibvirtHypervisor" -> "KvmHypervisor"; "LibvirtHypervisor" -> "XenHypervisor"; label = "Hypervisor Calls"; labelloc = "b"; style = filled; color = "#fffcc9"; } subgraph cluster_vm_calls { "KvmVm" [shape=box]; "XenVm" [shape=box]; "LibvirtVm" -> "KvmVm"; "LibvirtVm" -> "XenVm"; label = "Virtual Machine Calls"; labelloc = "b"; style = filled; color = "#fffcc9"; } } TODO : rewrite based on older doc """ __version__ = 7 No newline at end of file __version__ = '8~dev+revamp' ccnode/ccnode.py +6 −4 Changes for ccnode/ccnode.py: 6 added lines, 4 removed lines. Original line number Diff line number Diff line import socket import threading import ssl Loading @@ -5,16 +6,17 @@ import logging from sjrpc.client import SimpleRpcClient from sjrpc.utils import ConnectionProxy from sjrpc.core import RpcError from ccnodehandlers import * import handlers class CCNode(object): ''' This class handles node initialization and connection and authentication Handle node initialization, connection to server, and authentication ''' def __init__(self, server, port, hypervisor, cert=None): def __init__(self, server, port, hypervisor, exec_cmd, cert=None): self.manager = SimpleRpcClient.from_addr(server, port, enable_ssl=True, default_handler=NodeHandler(self, hypervisor)) default_handler=handlers.NodeHandler(self, hypervisor, exec_cmd)) self.server = ConnectionProxy(self.manager) def run(self): Loading ccnode/ccnodehandlers.py −386 File deleted. Show changes ccnode/common.py +217 Changes for ccnode/common.py: 217 added lines, 0 removed lines. Original line number Diff line number Diff line import os import re import psutil from subprocess import Popen, PIPE from multiprocessing import cpu_count from platform import platform, machine from socket import gethostbyaddr, gethostname class Host(object): ''' ''' class LocalHost(Host): ''' ''' ARCH = { 'i386' : 'x86', 'i486' : 'x86', 'i586' : 'x86', 'i686' : 'x86', 'x86_64' : 'x64', } def get_hw_serial(self): serial = None try: data = open('/sys/class/dmi/id/product_serial').read().strip() if data: serial = data except: pass return serial def get_hw_vendor(self): vendor = None try: data = open('/sys/class/dmi/id/sys_vendor').read().strip() if data: vendor = data except: pass return vendor def get_hw_product(self): product = None try: data = open('/sys/class/dmi/id/product_name').read().strip() if data: product = data except: pass return product def get_hw_bios(self): bios = '' try: bios_ver = open('/sys/class/dmi/id/bios_version').read().strip() bios_date = open('/sys/class/dmi/id/bios_date').read().strip() if bios_ver: bios += bios_ver if bios_date: bios += ' (%s)' % bios_date if not bios: bios = None except: pass return bios def get_name(self): result = None try: hostname = gethostname() fqdn = gethostbyaddr(hostname)[0] result = fqdn if fqdn else hostname except: pass return result def get_uname(self): uname = None try: data = ' '.join(os.uname()) if data: uname = data except: pass return uname def get_platform(self): result = None try: p = platform() if p: result = p except: pass return result def get_uptime(self): uptime = None try: data = open("/proc/uptime").read().split() if data: uptime = int(float(data[0])) except: pass return uptime def get_loadavg(self): return ' '.join('%.2f' % load for load in os.getloadavg()) def get_arch(self): arch = None try: a = machine() if a in self.ARCH: arch = ARCH[a] except: pass return arch def get_cpu(self): return cpu_count() def get_cpu_usage(self): return '%.1f' % psutil.cpu_percent() def get_mem(self): return psutil.avail_phymem() + psutil.used_phymem() def get_mem_free(self): return psutil.avail_phymem() def get_mem_used(self): return psutil.used_phymem() def get_disks(self): disks = {} try: re_pattern = re.compile(r'([sh]d[a-z]+)') found = [bd for bd in os.listdir('/sys/block/') if re_pattern.match(bd)] for disk in found: fullname = os.path.join('/sys/block', disk, 'size') size = int(open(fullname).read()) if size > 0: disks[disk] = size * 512 except: pass return disks def power_shutdown(self): return self.execute('/sbin/shutdown -h -P 0') def power_off(self): return self.execute('/sbin/shutdown -h -P -n 0') def power_reboot(self): return self.execute('/sbin/shutdown -r -f 0') def power_force_reboot(self): return self.execute('/sbin/shutdown -r -n 0') def execute(self, command): #FIXME: stop using shell=true and parse arguments with shlex.split() return Popen(command, shell=True, bufsize=-1, stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate() class Hypervisor(LocalHost): ''' ''' def storage(self): raise NotImplemented def vm_list(self): raise NotImplemented def vm_list_running(self): raise NotImplemented def vm_list_stopped(self): raise NotImplemented def vm_list_paused(self): raise NotImplemented def vm_get(self, name): raise NotImplemented class VM(Host): ''' ''' class Storage(object): ''' ''' class StoragePool(object): ''' ''' class StorageVolume(object): ''' ''' Loading
bin/cc-node +6 −3 Changes for bin/cc-node: 6 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ DEFAULT_CONFIGURATION = { 'verbosity': '0', 'detect_hypervisor': 'yes', #'ssl_cert': '', 'command_execution' : 'yes', } MAX_AUTH_TIMEOUT = 10 Loading Loading @@ -62,7 +63,8 @@ def run_node(options): try: node = CCNode(options['address'], int(options['port']), options['detect_hypervisor'] == 'yes') options['detect_hypervisor'] == 'yes', options['command_execution'] == 'yes') except Exception as err: logging.critical('Starting fail: %s' % err) return Loading Loading @@ -104,6 +106,7 @@ def run_node(options): logging.critical('Node failed: %s' % err) return if __name__ == '__main__': usage = 'usage: %prog [OPTION...]' Loading @@ -117,7 +120,7 @@ if __name__ == '__main__': cliopts, args = op.parse_args() # Reading the config file: # read the config file config = ConfigParser.SafeConfigParser() config.read(cliopts.config) try: Loading @@ -127,7 +130,7 @@ if __name__ == '__main__': "in '%s'\n" % cliopts.config) sys.exit(1) # Applying default config file options: # applying default config file options for opt, default in DEFAULT_CONFIGURATION.iteritems(): if opt not in options or not options[opt]: if default is None: Loading
ccnode/__init__.py +2 −58 Changes for ccnode/__init__.py: 2 added lines, 58 removed lines. Original line number Diff line number Diff line Loading @@ -2,65 +2,9 @@ #coding:utf-8 """ This API abstracts all calls to any hypervisor type. This API is split in four parts: * Global Interface * Libvirt Wrapper * KVM, XEN, ... hypervisor interface * Exceptions Every entity in the hypervisor library has a common ancestor :class:`interface.Host`. The inheritance diagram shown below reflects the relationship between each class. .. graphviz:: digraph { subgraph cluster_interface { "Host" [shape=box]; "Hypervisor" [shape=box]; "VM" [shape=box]; "Host" -> "Hypervisor"; "Host" -> "VM"; label = "interface"; style = filled; color = "#e6fbff"; } subgraph cluster_libvirt { "LibvirtHypervisor" [shape=box]; "LibvirtVm" [shape=box]; "Hypervisor" -> "LibvirtHypervisor"; "VM" -> "LibvirtVm"; style=filled; color="#ffe6ea"; label = "libvirt"; } subgraph cluster_hypervisor_calls { "KvmHypervisor" [shape=box]; "XenHypervisor" [shape=box]; "LibvirtHypervisor" -> "KvmHypervisor"; "LibvirtHypervisor" -> "XenHypervisor"; label = "Hypervisor Calls"; labelloc = "b"; style = filled; color = "#fffcc9"; } subgraph cluster_vm_calls { "KvmVm" [shape=box]; "XenVm" [shape=box]; "LibvirtVm" -> "KvmVm"; "LibvirtVm" -> "XenVm"; label = "Virtual Machine Calls"; labelloc = "b"; style = filled; color = "#fffcc9"; } } TODO : rewrite based on older doc """ __version__ = 7 No newline at end of file __version__ = '8~dev+revamp'
ccnode/ccnode.py +6 −4 Changes for ccnode/ccnode.py: 6 added lines, 4 removed lines. Original line number Diff line number Diff line import socket import threading import ssl Loading @@ -5,16 +6,17 @@ import logging from sjrpc.client import SimpleRpcClient from sjrpc.utils import ConnectionProxy from sjrpc.core import RpcError from ccnodehandlers import * import handlers class CCNode(object): ''' This class handles node initialization and connection and authentication Handle node initialization, connection to server, and authentication ''' def __init__(self, server, port, hypervisor, cert=None): def __init__(self, server, port, hypervisor, exec_cmd, cert=None): self.manager = SimpleRpcClient.from_addr(server, port, enable_ssl=True, default_handler=NodeHandler(self, hypervisor)) default_handler=handlers.NodeHandler(self, hypervisor, exec_cmd)) self.server = ConnectionProxy(self.manager) def run(self): Loading
ccnode/common.py +217 Changes for ccnode/common.py: 217 added lines, 0 removed lines. Original line number Diff line number Diff line import os import re import psutil from subprocess import Popen, PIPE from multiprocessing import cpu_count from platform import platform, machine from socket import gethostbyaddr, gethostname class Host(object): ''' ''' class LocalHost(Host): ''' ''' ARCH = { 'i386' : 'x86', 'i486' : 'x86', 'i586' : 'x86', 'i686' : 'x86', 'x86_64' : 'x64', } def get_hw_serial(self): serial = None try: data = open('/sys/class/dmi/id/product_serial').read().strip() if data: serial = data except: pass return serial def get_hw_vendor(self): vendor = None try: data = open('/sys/class/dmi/id/sys_vendor').read().strip() if data: vendor = data except: pass return vendor def get_hw_product(self): product = None try: data = open('/sys/class/dmi/id/product_name').read().strip() if data: product = data except: pass return product def get_hw_bios(self): bios = '' try: bios_ver = open('/sys/class/dmi/id/bios_version').read().strip() bios_date = open('/sys/class/dmi/id/bios_date').read().strip() if bios_ver: bios += bios_ver if bios_date: bios += ' (%s)' % bios_date if not bios: bios = None except: pass return bios def get_name(self): result = None try: hostname = gethostname() fqdn = gethostbyaddr(hostname)[0] result = fqdn if fqdn else hostname except: pass return result def get_uname(self): uname = None try: data = ' '.join(os.uname()) if data: uname = data except: pass return uname def get_platform(self): result = None try: p = platform() if p: result = p except: pass return result def get_uptime(self): uptime = None try: data = open("/proc/uptime").read().split() if data: uptime = int(float(data[0])) except: pass return uptime def get_loadavg(self): return ' '.join('%.2f' % load for load in os.getloadavg()) def get_arch(self): arch = None try: a = machine() if a in self.ARCH: arch = ARCH[a] except: pass return arch def get_cpu(self): return cpu_count() def get_cpu_usage(self): return '%.1f' % psutil.cpu_percent() def get_mem(self): return psutil.avail_phymem() + psutil.used_phymem() def get_mem_free(self): return psutil.avail_phymem() def get_mem_used(self): return psutil.used_phymem() def get_disks(self): disks = {} try: re_pattern = re.compile(r'([sh]d[a-z]+)') found = [bd for bd in os.listdir('/sys/block/') if re_pattern.match(bd)] for disk in found: fullname = os.path.join('/sys/block', disk, 'size') size = int(open(fullname).read()) if size > 0: disks[disk] = size * 512 except: pass return disks def power_shutdown(self): return self.execute('/sbin/shutdown -h -P 0') def power_off(self): return self.execute('/sbin/shutdown -h -P -n 0') def power_reboot(self): return self.execute('/sbin/shutdown -r -f 0') def power_force_reboot(self): return self.execute('/sbin/shutdown -r -n 0') def execute(self, command): #FIXME: stop using shell=true and parse arguments with shlex.split() return Popen(command, shell=True, bufsize=-1, stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate() class Hypervisor(LocalHost): ''' ''' def storage(self): raise NotImplemented def vm_list(self): raise NotImplemented def vm_list_running(self): raise NotImplemented def vm_list_stopped(self): raise NotImplemented def vm_list_paused(self): raise NotImplemented def vm_get(self, name): raise NotImplemented class VM(Host): ''' ''' class Storage(object): ''' ''' class StoragePool(object): ''' ''' class StorageVolume(object): ''' '''