From 6b3e7cdec66603ab1596ec02b137a854bf758bd3 Mon Sep 17 00:00:00 2001 From: "jose.lausuch" Date: Fri, 10 Feb 2017 17:10:18 +0100 Subject: [deployment handler] Add Roles and Status classes By doing this, we can handle roles and status as a list in the node object. Output: http://pastebin.com/raw/PAMrWRJi Change-Id: I0e3c7f375b19548a7e424e3257b84424c8fe4725 Signed-off-by: jose.lausuch --- modules/opnfv/deployment/manager.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'modules/opnfv/deployment/manager.py') diff --git a/modules/opnfv/deployment/manager.py b/modules/opnfv/deployment/manager.py index 8c9599b6e..9be516660 100644 --- a/modules/opnfv/deployment/manager.py +++ b/modules/opnfv/deployment/manager.py @@ -94,20 +94,30 @@ class Deployment(object): return s -class Node(object): +class Role(): + CONTROLLER = 'controller' + COMPUTE = 'compute' + ODL = 'opendaylight' + ONOS = 'onos' + +class NodeStatus(): STATUS_OK = 'active' STATUS_INACTIVE = 'inactive' STATUS_OFFLINE = 'offline' - STATUS_FAILED = 'failed' + STATUS_ERROR = 'error' + STATUS_UNUSED = 'unused' + + +class Node(object): def __init__(self, id, ip, name, status, - roles, - ssh_client, + roles=[], + ssh_client=None, info={}): self.id = id self.ip = ip @@ -121,7 +131,7 @@ class Node(object): ''' SCP file from a node ''' - if self.status is not Node.STATUS_OK: + if self.status is not NodeStatus.STATUS_OK: logger.info("The node %s is not active" % self.ip) return 1 logger.info("Fetching %s from %s" % (src, self.ip)) @@ -137,7 +147,7 @@ class Node(object): ''' SCP file to a node ''' - if self.status is not Node.STATUS_OK: + if self.status is not NodeStatus.STATUS_OK: logger.info("The node %s is not active" % self.ip) return 1 logger.info("Copying %s to %s" % (src, self.ip)) @@ -153,7 +163,7 @@ class Node(object): ''' Run command remotely on a node ''' - if self.status is not Node.STATUS_OK: + if self.status is not NodeStatus.STATUS_OK: logger.info("The node %s is not active" % self.ip) return 1 _, stdout, stderr = (self.ssh_client.exec_command(cmd)) @@ -187,7 +197,7 @@ class Node(object): ''' Returns if the node is a controller ''' - if 'controller' in self.get_attribute('roles'): + if 'controller' in self.roles: return True return False @@ -195,7 +205,7 @@ class Node(object): ''' Returns if the node is a compute ''' - if 'compute' in self.get_attribute('roles'): + if 'compute' in self.roles: return True return False @@ -236,7 +246,7 @@ class DeploymentHandler(object): self.installer_node = Node(id='', ip=installer_ip, name=installer, - status='active', + status=NodeStatus.STATUS_OK, ssh_client=self.installer_connection, roles='installer node') else: -- cgit 1.2.3-korg