コード例 #1
0
ファイル: manager.py プロジェクト: opnfv/releng-utils
    def __init__(self,
                 installer,
                 installer_ip,
                 installer_user,
                 installer_pwd=None,
                 pkey_file=None):

        self.installer = installer.lower()
        self.installer_ip = installer_ip
        self.installer_user = installer_user
        self.installer_pwd = installer_pwd
        self.pkey_file = pkey_file

        if pkey_file is not None and not os.path.isfile(pkey_file):
            raise Exception('The private key file %s does not exist!' %
                            pkey_file)

        self.installer_connection = ssh_utils.get_ssh_client(
            hostname=self.installer_ip,
            username=self.installer_user,
            password=self.installer_pwd,
            pkey_file=self.pkey_file)

        if self.installer_connection:
            self.installer_node = Node(id='',
                                       ip=installer_ip,
                                       name=installer,
                                       status=NodeStatus.STATUS_OK,
                                       ssh_client=self.installer_connection,
                                       roles=Role.INSTALLER)
        else:
            raise Exception(
                'Cannot establish connection to the installer node!')

        self.nodes = self.get_nodes()
コード例 #2
0
    def get_nodes(self):
        nodes = []
        cmd = "source /home/stack/stackrc;openstack server list"
        output = self.installer_node.run_cmd(cmd)
        lines = output.rsplit('\n')
        if len(lines) < 4:
            logger.info("No nodes found in the deployment.")
            return None

        for line in lines:
            roles = []
            if any(x in line for x in ['-----', 'Networks']):
                continue
            if 'controller' in line:
                roles.append(manager.Role.CONTROLLER)
            if 'compute' in line:
                roles.append(manager.Role.COMPUTE)
            if 'opendaylight' in line.lower():
                roles.append(manager.Role.ODL)

            fields = line.split('|')
            id = re.sub('[!| ]', '', fields[1]).encode()
            name = re.sub('[!| ]', '', fields[2]).encode()
            status_node = re.sub('[!| ]', '', fields[3]).encode().lower()
            ip = re.sub('[!| ctlplane=]', '', fields[4]).encode()

            ssh_client = None
            if 'active' in status_node:
                status = manager.NodeStatus.STATUS_OK
                ssh_client = ssh_utils.get_ssh_client(hostname=ip,
                                                      username='******',
                                                      pkey_file=self.pkey_file)
            elif 'error' in status_node:
                status = manager.NodeStatus.STATUS_ERROR
            elif 'off' in status_node:
                status = manager.NodeStatus.STATUS_OFFLINE
            else:
                status = manager.NodeStatus.STATUS_INACTIVE

            node = manager.Node(id, ip, name, status, roles, ssh_client)
            nodes.append(node)

        return nodes
コード例 #3
0
    def _process_nodes(self, raw_nodes):
        nodes = []

        for node in raw_nodes:
            name = node
            ip = raw_nodes[node]['ip']
            status = 'active'
            id = None
            if self.ROLES[node] == 'controller':
                roles = 'controller'
            elif self.ROLES[node] == 'compute':
                roles = 'compute'
            ssh_client = ssh_utils.get_ssh_client(hostname=ip,
                                                  username=self.installer_user,
                                                  pkey_file=self.pkey_file)
            node = manager.Node(id, ip, name, status, roles, ssh_client)
            nodes.append(node)

        return nodes
コード例 #4
0
ファイル: adapter.py プロジェクト: deliamadalina/releng
    def _process_nodes(self, raw_nodes):
        nodes = []

        for node in raw_nodes:
            name = node
            ip = raw_nodes[node]['ip']
            # TODO when xci provides status and id of nodes add logic
            status = 'active'
            id = None
            if 'controller' in node:
                roles = 'controller'
            elif 'compute' in node:
                roles = 'compute'
            ssh_client = ssh_utils.get_ssh_client(hostname=ip,
                                                  username=self.installer_user,
                                                  pkey_file=self.pkey_file)
            node = manager.Node(id, ip, name, status, roles, ssh_client)
            nodes.append(node)

        return nodes
コード例 #5
0
ファイル: adapter.py プロジェクト: xudan2189/releng
    def get_nodes(self, options=None):

        if options and options['cluster'] and len(self.nodes) > 0:
            n = []
            for node in self.nodes:
                if str(node.info['cluster']) == str(options['cluster']):
                    n.append(node)
            return n

        try:
            # if we have retrieved previously all the nodes, don't do it again
            # This fails the first time when the constructor calls this method
            # therefore the try/except
            if len(self.nodes) > 0:
                return self.nodes
        except:
            pass

        nodes = []
        cmd = 'fuel node'
        output = self.installer_node.run_cmd(cmd)
        lines = output.rsplit('\n')
        if len(lines) < 2:
            logger.info("No nodes found in the deployment.")
            return nodes

        # get fields indexes
        fields = lines[0].rsplit(' | ')

        index_id = -1
        index_status = -1
        index_name = -1
        index_cluster = -1
        index_ip = -1
        index_mac = -1
        index_roles = -1
        index_online = -1

        for i in range(len(fields)):
            if "group_id" in fields[i]:
                break
            elif "id" in fields[i]:
                index_id = i
            elif "status" in fields[i]:
                index_status = i
            elif "name" in fields[i]:
                index_name = i
            elif "cluster" in fields[i]:
                index_cluster = i
            elif "ip" in fields[i]:
                index_ip = i
            elif "mac" in fields[i]:
                index_mac = i
            elif "roles " in fields[i] and "pending_roles" not in fields[i]:
                index_roles = i
            elif "online" in fields[i]:
                index_online = i

        # order nodes info
        for i in range(2, len(lines)):
            fields = lines[i].rsplit(' | ')
            id = fields[index_id].strip().encode()
            ip = fields[index_ip].strip().encode()
            status_node = fields[index_status].strip().encode().lower()
            name = fields[index_name].strip().encode()
            roles_all = fields[index_roles].strip().encode().lower()

            roles = [
                x for x in [
                    manager.Role.CONTROLLER, manager.Role.COMPUTE,
                    manager.Role.ODL
                ] if x in roles_all
            ]

            dict = {
                "cluster": fields[index_cluster].strip().encode(),
                "mac": fields[index_mac].strip().encode(),
                "status_node": status_node,
                "online": fields[index_online].strip().encode()
            }

            ssh_client = None
            if status_node == 'ready':
                status = manager.NodeStatus.STATUS_OK
                proxy = {
                    'ip': self.installer_ip,
                    'username': self.installer_user,
                    'password': self.installer_pwd
                }
                ssh_client = ssh_utils.get_ssh_client(hostname=ip,
                                                      username='******',
                                                      proxy=proxy)
            elif 'error' in status_node:
                status = manager.NodeStatus.STATUS_ERROR
            elif 'off' in status_node:
                status = manager.NodeStatus.STATUS_OFFLINE
            elif 'discover' in status_node:
                status = manager.NodeStatus.STATUS_UNUSED
            else:
                status = manager.NodeStatus.STATUS_INACTIVE

            node = manager.Node(id, ip, name, status, roles, ssh_client, dict)
            if options and options['cluster']:
                if fields[index_cluster].strip() == options['cluster']:
                    nodes.append(node)
            else:
                nodes.append(node)

        self.get_nodes_called = True
        return nodes
コード例 #6
0
    def _get_deployment_nodes(self):
        sql_query = ('select host.host_id, host.roles, '
                     'network.ip_int, machine.mac from clusterhost as host, '
                     'host_network as network, machine as machine '
                     'where host.host_id=network.host_id '
                     'and host.id=machine.id;')
        cmd = 'mysql -uroot -Dcompass -e "{0}"'.format(sql_query)
        logger.debug('mysql command: %s', cmd)
        output = self.installer_node.run_cmd(cmd)
        '''
        host_id roles   ip_int  mac
        1 ["controller", "ha", "odl", "ceph-adm", "ceph-mon"]
        167837746 00:00:e3:ee:a8:63
        2 ["controller", "ha", "odl", "ceph-mon"]
        167837747 00:00:31:1d:16:7a
        3 ["controller", "ha", "odl", "ceph-mon"]
        167837748 00:00:0c:bf:eb:01
        4 ["compute", "ceph-osd"] 167837749 00:00:d8:22:6f:59
        5 ["compute", "ceph-osd"] 167837750 00:00:75:d5:6b:9e
        '''
        lines = output.encode().rsplit('\n')
        nodes_dict = {}
        if (not lines or len(lines) < 2):
            logger.error('No nodes are found in the deployment.')
            return nodes_dict

        proxy = {
            'ip': self.installer_ip,
            'username': self.installer_user,
            'password': self.installer_pwd
        }
        for i in range(1, len(lines)):
            fields = lines[i].strip().encode().rsplit('\t')
            host_id = fields[0].strip().encode()
            name = 'host{0}'.format(host_id)
            node_roles_str = fields[1].strip().encode().lower()
            node_roles_list = json.loads(node_roles_str)
            node_roles = [
                manager.Role.ODL if x == 'odl' else x for x in node_roles_list
            ]
            roles = [
                x for x in [
                    manager.Role.CONTROLLER, manager.Role.COMPUTE,
                    manager.Role.ODL, manager.Role.ONOS
                ] if x in node_roles
            ]
            ip = fields[2].strip().encode()
            ip = str(netaddr.IPAddress(ip))
            mac = fields[3].strip().encode()

            nodes_dict[name] = {}
            nodes_dict[name]['id'] = host_id
            nodes_dict[name]['roles'] = roles
            nodes_dict[name]['ip'] = ip
            nodes_dict[name]['mac'] = mac
            ssh_client = ssh_utils.get_ssh_client(hostname=ip,
                                                  username='******',
                                                  proxy=proxy)
            nodes_dict[name]['ssh_client'] = ssh_client
            nodes_dict[name]['status'] = manager.NodeStatus.STATUS_UNKNOWN
        return nodes_dict
コード例 #7
0
    def get_nodes(self, options=None):
        if hasattr(self, 'nodes') and len(self.nodes) > 0:
            if options and 'cluster' in options and options['cluster']:
                nodes = []
                for node in self.nodes:
                    if str(node.info['cluster']) == str(options['cluster']):
                        nodes.append(node)
                return nodes
            else:
                return self.nodes

        clusters = self._get_clusters()
        nodes = []
        for cluster in clusters:
            if options and 'cluster' in options and options['cluster']:
                if cluster["id"] != options['cluster']:
                    continue
            cmd = 'source /root/daisyrc_admin; daisy host-list ' \
                  '--cluster-id {} | grep -v "+--"'.format(cluster["id"])
            output = self.installer_node.run_cmd(cmd)
            lines = output.rsplit('\n')
            if len(lines) < 2:
                logger.info("No nodes found in the cluster {}".format(
                    cluster["id"]))
                continue

            fields = lines[0].rsplit('|')
            index_id = -1
            index_status = -1
            index_name = -1

            for i in range(len(fields)):
                if "ID" in fields[i]:
                    index_id = i
                elif "Role_status" in fields[i]:
                    index_status = i
                elif "Name" in fields[i]:
                    index_name = i

            for i in range(1, len(lines)):
                fields = lines[i].rsplit('|')
                id = fields[index_id].strip().encode()
                status_node = fields[index_status].strip().encode().lower()
                name = fields[index_name].strip().encode()
                ip = ".".join(name.split("-")[1:])

                cmd_role = 'source /root/daisyrc_admin; ' \
                           'daisy host-detail {} | grep "^| role"'.format(id)
                output_role = self.installer_node.run_cmd(cmd_role)
                role_all = output_role.rsplit('|')[2].strip().encode()
                roles = []
                if 'COMPUTER' in role_all:
                    roles.append(manager.Role.COMPUTE)
                if 'CONTROLLER_LB' in role_all or 'CONTROLLER_HA' in role_all:
                    roles.append(manager.Role.CONTROLLER)

                ssh_client = None
                if status_node == 'active':
                    status = manager.NodeStatus.STATUS_OK
                    proxy = {
                        'ip': self.installer_ip,
                        'username': self.installer_user,
                        'password': self.installer_pwd,
                        'pkey_file': '/root/.ssh/id_dsa'
                    }
                    ssh_client = ssh_utils.get_ssh_client(hostname=ip,
                                                          username='******',
                                                          proxy=proxy)
                else:
                    status = manager.NodeStatus.STATUS_INACTIVE

                node = DaisyNode(id, ip, name, status, roles, ssh_client)
                nodes.append(node)
        return nodes