Exemplo n.º 1
0
 def _get_roles(self):
     """Get roles which node represents"""
     roles = []
     try:
         with open(self._role_file_path, 'r') as f:
             for i in f:
                 r = i.strip().split('\n')
                 if r[0].lower() == 'fuel':
                     roles.append(ROLES.FUEL)
                 elif r[0].lower() == 'controller':
                     roles.append(ROLES.CONTROLLER)
                 elif r[0].lower() == 'compute':
                     roles.append(ROLES.COMPUTE)
                 elif r[0].lower() == 'ceph-osd':
                     roles.append(ROLES.CEPH_OSD)
                 elif r[0].lower() == 'mongo':
                     roles.append(ROLES.MONGO)
                 else:
                     print 'Unknow node, please fix it'
                     roles.append(ROLES.UNKNOWN)
     except Exception as e:
         # If the file not exists, or something wrong happens, we consume
         # the node is unknow, and fire a warn message
         print 'Unknow node, please fix the issue: %s'\
             % logger.fmt_excep_msg(e)
         roles.append(ROLES.UNKNOWN)
     if not roles:
         print 'Unknow node, please fix it'
         roles.append(ROLES.UNKNOWN)
     return roles
Exemplo n.º 2
0
    def _node_list(self):
        nodes = []
        try:
            with open(self._role_list_file_path, 'r') as f:
                for i in f:
                    # i: "node-6.eayun.com:node-6:172.16.100.10:ceph-osd:52.a8.3b.dc.c9.47:192.168.1.239"
                    r = i.strip().split('\n')[0].split(':')
                    if len(r) != 6:
                        continue
                    nodes.append({'roles': r[3], 'host': r[0],
                                  'ip': r[2], 'mac': r[4].replace('.', ':'),
                                  'idrac_addr': r[5]})
        except Exception as e:
            print 'failed to open file: %s: %s' % (self._role_list_file_path,
                                                   logger.fmt_excep_msg(e))

        def _cmp(s):
            return s['roles']
        return sorted(nodes, key=_cmp)