Commit 87f8b7de authored by Thibault VINCENT's avatar Thibault VINCENT
Browse files

fixed sphynx api doc, added empty docstrings to be filled

parent 5d122bb2
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -37,7 +37,8 @@ DEFAULT_CONFIGURATION = {
MAX_AUTH_TIMEOUT = 10

def run_node(options):

    '''
    '''
    # Setup logging facility:
    level = logging.ERROR
    verb = int(options['verbosity'])
@@ -72,6 +73,8 @@ def run_node(options):
        logging.info('Connected to server %s' % options['address'])

    def authentication():
        '''
        '''
        timeout = 1
        while node.manager.is_running():
            result = node.authentify(options['login'], options['password'])
@@ -90,13 +93,11 @@ def run_node(options):
        '''
        Handler called when SIGINT emited
        '''
        
        node.manager.shutdown()
        logging.info('Node properly exited by SIGINT')
        sys.exit(0)

    signal.signal(signal.SIGINT, shutdown_handler)

    threading.Thread(target=authentication).start()

    try:
+6 −0
Original line number Diff line number Diff line
@@ -15,15 +15,21 @@ class CCNode(object):
    Handle node initialization, connection to server, and authentication
    '''
    def __init__(self, server, port, hypervisor, exec_cmd, cert=None):
        '''
        '''
        self.manager = SimpleRpcClient.from_addr(server, port, enable_ssl=True,
                default_handler=handlers.NodeHandler(self, hypervisor,
                                                                    exec_cmd))
        self.server = ConnectionProxy(self.manager)
    
    def run(self):
        '''
        '''
        self.manager.run()
    
    def authentify(self, login, password):
        '''
        '''
        logging.debug('Authenticating user %s with password <%s>' % (login,
                      password))
        try:
+58 −0
Original line number Diff line number Diff line
@@ -11,11 +11,15 @@ from socket import gethostbyaddr, gethostname

class Host(object):
    '''
    Root class for all physical or virtual machines that CloudControl Node may
    run on, or manage. It is not intended for direct usage by NodeHandler.
    '''


class LocalHost(Host):
    '''
    Regular host with no hypervisor support, all methods defined here are
    expected to provide information to the NodeHandler.
    '''
    
    ARCH = {
@@ -27,6 +31,8 @@ class LocalHost(Host):
    }
    
    def get_hw_serial(self):
        '''
        '''
        serial = None
        try:
            data = open('/sys/class/dmi/id/product_serial').read().strip()
@@ -37,6 +43,8 @@ class LocalHost(Host):
        return serial
    
    def get_hw_vendor(self):
        '''
        '''
        vendor = None
        try:
            data = open('/sys/class/dmi/id/sys_vendor').read().strip()
@@ -47,6 +55,8 @@ class LocalHost(Host):
        return vendor
    
    def get_hw_product(self):
        '''
        '''
        product = None
        try:
            data = open('/sys/class/dmi/id/product_name').read().strip()
@@ -57,6 +67,8 @@ class LocalHost(Host):
        return product
    
    def get_hw_bios(self):
        '''
        '''
        bios = ''
        try:
            bios_ver = open('/sys/class/dmi/id/bios_version').read().strip()
@@ -72,6 +84,8 @@ class LocalHost(Host):
        return bios
    
    def get_name(self):
        '''
        '''
        result = None
        try:
            hostname = gethostname()
@@ -82,6 +96,8 @@ class LocalHost(Host):
        return result
    
    def get_uname(self):
        '''
        '''
        uname = None
        try:
            data = ' '.join(os.uname())
@@ -92,6 +108,8 @@ class LocalHost(Host):
        return uname
    
    def get_platform(self):
        '''
        '''
        result = None
        try:
            p = platform()
@@ -102,6 +120,8 @@ class LocalHost(Host):
        return result
    
    def get_uptime(self):
        '''
        '''
        uptime = None
        try:
            data = open("/proc/uptime").read().split()
@@ -112,9 +132,13 @@ class LocalHost(Host):
        return uptime
    
    def get_loadavg(self):
        '''
        '''
        return ' '.join('%.2f' % load for load in os.getloadavg())
    
    def get_arch(self):
        '''
        '''
        arch = None
        try:
            a = machine()
@@ -125,21 +149,33 @@ class LocalHost(Host):
        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]+)')
@@ -155,18 +191,28 @@ class LocalHost(Host):
        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,
@@ -180,21 +226,33 @@ 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


+23 −6
Original line number Diff line number Diff line
# -*- coding: utf-8 -*-

class CCException(Exception):
    '''
    '''
    
    def __init__(self, message, exception=None):
        '''
        '''
        self._exception = exception
        self._message = message
    
    def __str__(self):
        '''
        '''
        if self._exception is not None:
            return '[%s] %s' % (self._exception, self._message)
        else:
            return '%s' % self._message

class FeatureNotImplemented(CCException):
    pass

    '''
    Hosts
    '''
    pass


# host

class HostError(CCException):
    '''
    '''
    pass


class HypervisorError(HostError):
    '''
    '''
    pass


class VMError(HostError):
    '''
    '''
    pass


'''
    Storage
'''
# storage

class StorageError(CCException):
    '''
    '''
    pass


class StoragePoolError(StorageError):
    '''
    '''
    pass


class StorageVolumeError(StorageError):
    '''
    '''
    pass
+2 −0
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ class NodeHandler(RpcHandler):
    '''   
    
    def __init__(self, connection, detect_hv, allow_exec):
        '''
        '''
        super(RpcHandler, self).__init__()
        self._connection = connection
        self._allow_cmd_exec = allow_exec
Loading