modules.opnfv: fuel adapter: Switch to MCP
[releng.git] / modules / opnfv / deployment / manager.py
index efa28ce..2b5aedb 100644 (file)
@@ -95,6 +95,7 @@ class Deployment(object):
 
 
 class Role():
+    INSTALLER = 'installer'
     CONTROLLER = 'controller'
     COMPUTE = 'compute'
     ODL = 'opendaylight'
@@ -107,6 +108,7 @@ class NodeStatus():
     STATUS_OFFLINE = 'offline'
     STATUS_ERROR = 'error'
     STATUS_UNUSED = 'unused'
+    STATUS_UNKNOWN = 'unknown'
 
 
 class Node(object):
@@ -131,7 +133,7 @@ class Node(object):
         self.memory = 'unknown'
         self.ovs = 'unknown'
 
-        if ssh_client:
+        if ssh_client and Role.INSTALLER not in self.roles:
             sys_info = self.get_system_info()
             self.cpu_info = sys_info['cpu_info']
             self.memory = sys_info['memory']
@@ -174,13 +176,15 @@ class Node(object):
         Run command remotely on a node
         '''
         if self.status is not NodeStatus.STATUS_OK:
-            logger.error("The node %s is not active" % self.ip)
+            logger.error(
+                "Error running command %s. The node %s is not active"
+                % (cmd, self.ip))
             return None
         _, stdout, stderr = (self.ssh_client.exec_command(cmd))
         error = stderr.readlines()
         if len(error) > 0:
             logger.error("error %s" % ''.join(error))
-            return error
+            return None
         output = ''.join(stdout.readlines()).rstrip()
         return output
 
@@ -200,6 +204,14 @@ class Node(object):
             'info': self.info
         }
 
+    def is_active(self):
+        '''
+        Returns if the node is active
+        '''
+        if self.status == NodeStatus.STATUS_OK:
+            return True
+        return False
+
     def is_controller(self):
         '''
         Returns if the node is a controller
@@ -218,16 +230,24 @@ class Node(object):
         '''
         return Role.ODL in self.roles
 
+    def is_onos(self):
+        '''
+        Returns if the node is an ONOS
+        '''
+        return Role.ONOS in self.roles
+
     def get_ovs_info(self):
         '''
         Returns the ovs version installed
         '''
-        cmd = "ovs-vsctl --version|head -1| sed 's/^.*) //'"
-        return self.run_cmd(cmd)
+        if self.is_active():
+            cmd = "ovs-vsctl --version 2>/dev/null|head -1| sed 's/^.*) //'"
+            return self.run_cmd(cmd) or None
+        return None
 
     def get_system_info(self):
         '''
-        Returns the ovs version installed
+        Returns system information
         '''
         cmd = 'grep MemTotal /proc/meminfo'
         memory = self.run_cmd(cmd).partition('MemTotal:')[-1].strip().encode()
@@ -306,7 +326,7 @@ class DeploymentHandler(object):
                                        name=installer,
                                        status=NodeStatus.STATUS_OK,
                                        ssh_client=self.installer_connection,
-                                       roles='installer node')
+                                       roles=Role.INSTALLER)
         else:
             raise Exception(
                 'Cannot establish connection to the installer node!')
@@ -347,6 +367,18 @@ class DeploymentHandler(object):
         '''
         return self.installer_node
 
+    def get_arch(self):
+        '''
+            Returns the architecture of the first compute node found
+        '''
+        arch = None
+        for node in self.nodes:
+            if node.is_compute():
+                arch = node.cpu_info.get('arch', None)
+                if arch:
+                    break
+        return arch
+
     def get_deployment_info(self):
         '''
             Returns an object of type Deployment
@@ -358,4 +390,4 @@ class DeploymentHandler(object):
                           pod=os.getenv('NODE_NAME', 'Unknown'),
                           openstack_version=self.get_openstack_version(),
                           sdn_controller=self.get_sdn_version(),
-                          nodes=self.get_nodes())
+                          nodes=self.nodes)