Exemplo n.º 1
0
 def change_password(self, params):
     """To change user password:
             fuel user change-password
     """
     if params.newpass:
         APIClient.update_own_password(params.newpass)
     else:
         raise ArgumentException(
             "Expect password [--newpass NEWPASS]")
Exemplo n.º 2
0
 def delete_dashboard_link(self, link_id):
     """
     Delete a registered link by its ID
     :param link_id: ID of the link
     :type link_id: str, int
     """
     print('Remove the registered link ID: %s using the url: "%s"' %
           (link_id, self.cluster.plugin_links_url)
           )
     APIClient.delete_request(self.cluster.plugin_links_url + '/' + str(link_id))
Exemplo n.º 3
0
 def action_func(self, params):
     """Entry point for all actions subclasses
     """
     APIClient.debug_mode(debug=params.debug)
     self.serializer = Serializer.from_params(params)
     if self.flag_func_map is not None:
         for flag, method in self.flag_func_map:
             if flag is None or getattr(params, flag):
                 method(params)
                 break
Exemplo n.º 4
0
    def change_password(self, params):
        """To change user password:
                fuel user change-password
        """
        if params.newpass:
            password = params.newpass
        else:
            password = self._get_password_from_prompt()

        APIClient.update_own_password(password)
Exemplo n.º 5
0
    def change_password(self, params):
        """To change user password:
                fuel user change-password
        """
        if params.newpass:
            password = params.newpass
        else:
            password = self._get_password_from_prompt()

        APIClient.update_own_password(password)
Exemplo n.º 6
0
 def action_func(self, params):
     """Entry point for all actions subclasses
     """
     APIClient.debug_mode(debug=params.debug)
     self.serializer = Serializer.from_params(params)
     if self.flag_func_map is not None:
         for flag, method in self.flag_func_map:
             if flag is None or getattr(params, flag):
                 method(params)
                 break
Exemplo n.º 7
0
    def action_func(self, params):
        """Entry point for all actions subclasses
        """
        APIClient.debug_mode(debug=params.debug)
        if getattr(params, 'user') and getattr(params, 'password'):
            APIClient.user = params.user
            APIClient.password = params.password
            APIClient.initialize_keystone_client()

        self.serializer = Serializer.from_params(params)
        if self.flag_func_map is not None:
            for flag, method in self.flag_func_map:
                if flag is None or getattr(params, flag):
                    method(params)
                    break
Exemplo n.º 8
0
    def action_func(self, params):
        """Entry point for all actions subclasses
        """
        APIClient.debug_mode(debug=params.debug)
        if getattr(params, 'user') and getattr(params, 'password'):
            APIClient.user = params.user
            APIClient.password = params.password
            APIClient.initialize_keystone_client()

        self.serializer = Serializer.from_params(params)
        if self.flag_func_map is not None:
            for flag, method in self.flag_func_map:
                if flag is None or getattr(params, flag):
                    method(params)
                    break
Exemplo n.º 9
0
 def __call__(self, parser, namespace, values, option_string=None):
     if values:
         node_identities = set(chain(*values))
         input_macs = set(n for n in node_identities if ":" in n)
         only_ids = set()
         for _id in (node_identities - input_macs):
             try:
                 only_ids.add(int(_id))
             except ValueError:
                 raise ArgumentException(
                     "'{0}' is not valid node id.".format(_id))
         if input_macs:
             nodes_mac_to_id_map = dict(
                 (n["mac"], n["id"])
                 for n in APIClient.get_request("nodes/")
             )
             for short_mac in input_macs:
                 target_node = None
                 for mac in nodes_mac_to_id_map:
                     if mac.endswith(short_mac):
                         target_node = mac
                         break
                 if target_node:
                     only_ids.add(nodes_mac_to_id_map[target_node])
                 else:
                     raise ArgumentException(
                         'Node with mac endfix "{0}" was not found.'
                         .format(short_mac)
                     )
         setattr(namespace, self.dest, map(int, only_ids))
Exemplo n.º 10
0
def init_node_list_file():
    # generate node-list file
    LOG.info('Generate node-list file ...')
    file_path = '/.eayunstack/node-list'
    if not os.path.exists(os.path.dirname(file_path)):
        os.mkdir(os.path.dirname(file_path))
    if os.path.exists(file_path):
        os.remove(file_path)
    logging.disable(logging.CRITICAL)
    rep = APIClient.get_request("nodes/")
    logging.disable(logging.NOTSET)
    ips = []
    for node in rep:
        fqdn = node['fqdn']
        ip = node['ip']
        ips.append(ip)
        roles = ','.join(node['roles'])
        if not roles:
            continue
        host = fqdn.split('.')[0]
        mac = node['mac'].replace(':', '.')
        idrac_addr = get_idrac_addr(ip)
        entry = fqdn + ':' + host + ':' + ip + ':' + roles + ':' + mac + ':' + idrac_addr + '\n'
        output = open(file_path, 'a')
        output.write(entry)
        output.close()
    # scp node-list file to all nodes
    LOG.info('Copy node-list file to all nodes ...')
    for ip in ips:
        LOG.info('   To node %s ...' % ip)
        scp_connect(ip, file_path, file_path)
Exemplo n.º 11
0
 def registered_plugin_links(self):
     registered_links = APIClient.get_request(self.cluster.plugin_links_url)
     if not isinstance(registered_links, list):
         raise StandardError('Could not get the list of the plugin links from the url: "%s"!' %
                             self.cluster.plugin_links_url
                             )
     return registered_links
Exemplo n.º 12
0
 def __call__(self, parser, namespace, values, option_string=None):
     if values:
         node_identities = set(chain(*values))
         input_macs = set(n for n in node_identities if ":" in n)
         only_ids = set()
         for _id in (node_identities - input_macs):
             try:
                 only_ids.add(int(_id))
             except ValueError:
                 raise ArgumentException(
                     "'{0}' is not valid node id.".format(_id))
         if input_macs:
             nodes_mac_to_id_map = dict(
                 (n["mac"], n["id"])
                 for n in APIClient.get_request("nodes/"))
             for short_mac in input_macs:
                 target_node = None
                 for mac in nodes_mac_to_id_map:
                     if mac.endswith(short_mac):
                         target_node = mac
                         break
                 if target_node:
                     only_ids.add(nodes_mac_to_id_map[target_node])
                 else:
                     raise ArgumentException(
                         'Node with mac endfix "{0}" was not found.'.format(
                             short_mac))
         setattr(namespace, self.dest, map(int, only_ids))
Exemplo n.º 13
0
 def take_action(self, parsed_args):
     args = parsed_args.__dict__
     data = APIClient.get_request(API_URI.format(args['node']))
     data['node'] = args['node']
     data['vrouter_cores'] = data.get('vrouter_cores', [])
     data['nova_cores'] = data.get('nova_cores', [])
     data = data_utils.get_display_data_single(self.columns, data)
     return self.columns, data
Exemplo n.º 14
0
def get_plugin_version(plugin_name):
    plugin_version = None
    from fuelclient.client import APIClient
    plugins = APIClient.get_request("plugins")
    for plugin in plugins:
        if plugin['name'] == plugin_name:
            plugin_version = plugin['version']
    return plugin_version
Exemplo n.º 15
0
    def take_action(self, parsed_args):
        args = parsed_args.__dict__
        nova_cores = [s for s in args['nova_cores'].split(',') if s]
        vrouter_cores = [s for s in args['vrouter_cores'].split(',') if s]
        data = {'nova_cores': nova_cores, 'vrouter_cores': vrouter_cores}
        result = APIClient.put_request(API_URI.format(args['node']), data)

        return self.columns, data
Exemplo n.º 16
0
    def take_action(self, parsed_args):
        args = parsed_args.__dict__
        nova_cores = [s for s in args['nova_cores'].split(',') if s]
        vrouter_cores = [s for s in args['vrouter_cores'].split(',') if s]
        data = {'nova_cores': nova_cores, 'vrouter_cores': vrouter_cores}
        result = APIClient.put_request(API_URI.format(args['node']), data)

        return self.columns, data
Exemplo n.º 17
0
 def take_action(self, parsed_args):
     args = parsed_args.__dict__
     data = APIClient.get_request(API_URI.format(args['node']))
     data['node'] = args['node']
     data['vrouter_cores'] = data.get('vrouter_cores', [])
     data['nova_cores'] = data.get('nova_cores', [])
     data = data_utils.get_display_data_single(self.columns, data)
     return self.columns, data
Exemplo n.º 18
0
    def action_func(self, params):
        """Entry point for all actions subclasses
        """
        APIClient.debug_mode(debug=params.debug)
        if getattr(params, "user") and getattr(params, "password"):
            APIClient.user = params.user
            APIClient.password = params.password
            # tenant is set by default to 'admin' in parser.add_argument
            APIClient.tenant = params.tenant
            APIClient.initialize_keystone_client()

        self.serializer = Serializer.from_params(params)
        if self.flag_func_map is not None:
            for flag, method in self.flag_func_map:
                if flag is None or getattr(params, flag):
                    method(params)
                    break
def get_plugin_version(plugin_name):
    plugin_version = None
    from fuelclient.client import APIClient
    plugins = APIClient.get_request("plugins")
    for plugin in plugins:
        if plugin['name'] == plugin_name:
            plugin_version = plugin['version']
    return plugin_version
Exemplo n.º 20
0
 def create_dashboard_link(self, link_title, link_description, link_url):
     """
     Create a new plugin link
     :param link_title:
     :param link_description:
     :param link_url:
     :type link_title: str
     :type link_description: str
     :type link_url: str
     """
     link_data = {
         'title': link_title,
         'description': link_description,
         'url': link_url,
     }
     print('Creating the link: "%s" to "%s" using the url: "%s"' %
           (link_title, link_url, self.cluster.plugin_links_url)
           )
     APIClient.post_request(self.cluster.plugin_links_url, link_data)
Exemplo n.º 21
0
def node_list(parser):
    logger.setLevel(logging.CRITICAL)
    # TODO: get fuel host from config file?
    rep = APIClient.get_request("nodes/")
    t = PrettyTable(['Roles', 'Hosts', 'IP', 'MAC'], sortby='Roles')
    for node in rep:
        roles = ' '.join(i for i in node['roles'])
        if not roles:
            roles = 'unused'
        host = node['fqdn']
        ip = node['ip']
        mac = node['mac']
        t.add_row([roles, host, ip, mac])
    print t
Exemplo n.º 22
0
def node_list(parser):
    logger.setLevel(logging.CRITICAL)
    # TODO: get fuel host from config file?
    rep = APIClient.get_request("nodes/")
    t = PrettyTable(['Roles', 'Hosts', 'IP', 'MAC'], sortby='Roles')
    for node in rep:
        roles = ' '.join(i for i in node['roles'])
        if not roles:
            roles = 'unused'
        host = node['fqdn']
        ip = node['ip']
        mac = node['mac']
        t.add_row([roles, host, ip, mac])
    print t
Exemplo n.º 23
0
    def _node_list(self):
        from fuelclient.client import APIClient
        LOG.setLevel(logging.CRITICAL)
        nodes = []
        rep = APIClient.get_request("nodes/")
        for n in rep:
            roles = ' '.join(i for i in n['roles'])
            if not roles:
                roles = 'unused'
            host = n['fqdn']
            ip = n['ip']
            mac = n['mac']
            nodes.append({'roles': roles, 'host': host, 'ip': ip, 'mac': mac})
        # FIXME: our log level is DEBUG?
        LOG.setLevel(logging.DEBUG)

        def _cmp(s):
            return s['roles']
        return sorted(nodes, key=_cmp)
Exemplo n.º 24
0
def fuel_inventory():
    inventory = defaultdict(list)
    inventory['_meta'] = {
        'hostvars': {},
    }

    nodes = APIClient.get_request(NODES_URL)
    ready_nodes = [node for node in nodes if
                   (node['status'] == 'ready' and
                    node['online'])]

    for node in ready_nodes:
        node_fqdn = node['fqdn']
        node_cluster = node['cluster']
        node_roles = node['roles']

        inventory['cluster-%d' % node_cluster].append(node_fqdn)

        for role in node_roles:
            inventory[role].append(node_fqdn)

    return inventory
Exemplo n.º 25
0
def fuel_inventory():
    inventory = defaultdict(list)
    inventory['_meta'] = {
        'hostvars': {},
    }

    nodes = APIClient.get_request(NODES_URL)
    ready_nodes = [
        node for node in nodes
        if (node['status'] == 'ready' and node['online'])
    ]

    for node in ready_nodes:
        node_fqdn = node['fqdn']
        node_cluster = node['cluster']
        node_roles = node['roles']

        inventory['cluster-%d' % node_cluster].append(node_fqdn)

        for role in node_roles:
            inventory[role].append(node_fqdn)

    return inventory
Exemplo n.º 26
0
def init_node_role_file():
    file_path = "/.eayunstack/node-role"
    tmp_path = "/tmp/node-role"
    # init local node-role file
    LOG.info("Generate node-role file for fuel node ...")
    output = open(file_path, "w")
    output.write("fuel\n")
    output.close()
    # init openstack node node-role file
    LOG.info("Generate node-role file for openstack node ...")
    logging.disable(logging.CRITICAL)
    rep = APIClient.get_request("nodes/")
    logging.disable(logging.NOTSET)
    for node in rep:
        ip = node["ip"]
        if os.path.exists(tmp_path):
            os.remove(tmp_path)
        output = open(tmp_path, "a")
        for role in node["roles"]:
            output.write(role + "\n")
        output.close()
        LOG.info("   To node %s ..." % ip)
        scp_connect(ip, tmp_path, file_path)
Exemplo n.º 27
0
def init_node_role_file():
    file_path = '/.eayunstack/node-role'
    tmp_path = ('/tmp/node-role')
    # init local node-role file
    LOG.info('Generate node-role file for fuel node ...')
    output = open(file_path, 'w')
    output.write('fuel\n')
    output.close()
    # init openstack node node-role file
    LOG.info('Generate node-role file for openstack node ...')
    logging.disable(logging.CRITICAL)
    rep = APIClient.get_request("nodes/")
    logging.disable(logging.NOTSET)
    for node in rep:
        ip = node['ip']
        if os.path.exists(tmp_path):
            os.remove(tmp_path)
        output = open(tmp_path, 'a')
        for role in node['roles']:
            output.write(role + '\n')
        output.close()
        LOG.info('   To node %s ...' % ip)
        scp_connect(ip, tmp_path, file_path)
Exemplo n.º 28
0
def init_node_role_file():
    file_path = '/.eayunstack/node-role'
    tmp_path = ('/tmp/node-role')
    # init local node-role file
    LOG.info('Generate node-role file for fuel node ...')
    output = open(file_path,'w')
    output.write('fuel\n')
    output.close()
    # init openstack node node-role file
    LOG.info('Generate node-role file for openstack node ...')
    logging.disable(logging.CRITICAL)
    rep = APIClient.get_request("nodes/")
    logging.disable(logging.NOTSET)
    for node in rep:
        ip = node['ip']
        if os.path.exists(tmp_path):
            os.remove(tmp_path)
        output = open(tmp_path,'a')
        for role in node['roles']:
            output.write(role + '\n')
        output.close()
        LOG.info('   To node %s ...' % ip)
        scp_connect(ip, tmp_path, file_path) 
Exemplo n.º 29
0
def init_node_list_file():
    # generate node-list file
    LOG.info("Generate node-list file ...")
    file_path = "/.eayunstack/node-list"
    if not os.path.exists(os.path.dirname(file_path)):
        os.mkdir(os.path.dirname(file_path))
    if os.path.exists(file_path):
        os.remove(file_path)
    logging.disable(logging.CRITICAL)
    rep = APIClient.get_request("nodes/")
    logging.disable(logging.NOTSET)
    ips = []
    for node in rep:
        fqdn = node["fqdn"]
        ip = node["ip"]
        ips.append(ip)
        roles = ""
        if len(node["roles"]) > 1:
            for n in node["roles"]:
                if not roles:
                    roles = roles + n
                else:
                    roles = roles + "," + n
        else:
            roles = node["roles"][0]
        host = fqdn.split(".")[0]
        mac = node["mac"].replace(":", ".")
        idrac_addr = get_idrac_addr(ip)
        entry = fqdn + ":" + host + ":" + ip + ":" + roles + ":" + mac + ":" + idrac_addr + "\n"
        output = open(file_path, "a")
        output.write(entry)
        output.close()
    # scp node-list file to all nodes
    LOG.info("Copy node-list file to all nodes ...")
    for ip in ips:
        LOG.info("   To node %s ..." % ip)
        scp_connect(ip, file_path, file_path)
Exemplo n.º 30
0
def init_node_list_file():
    # generate node-list file
    LOG.info('Generate node-list file ...')
    file_path = '/.eayunstack/node-list'
    if not os.path.exists(os.path.dirname(file_path)):
        os.mkdir(os.path.dirname(file_path))
    if os.path.exists(file_path):
        os.remove(file_path)
    logging.disable(logging.CRITICAL)
    rep = APIClient.get_request("nodes/")
    logging.disable(logging.NOTSET)
    ips = []
    for node in rep:
        fqdn = node['fqdn']
        ip = node['ip']
        ips.append(ip)
        roles = ''
        if len(node['roles']) > 1:
            for n in node['roles']: 
                if not roles:
                    roles = roles + n
                else:
                    roles = roles + ',' + n
        else:
            roles = node['roles'][0]
        host = fqdn.split('.')[0]
        mac = node['mac'].replace(':', '.')
        idrac_addr = get_idrac_addr(ip)
        entry = fqdn + ':' + host + ':' + ip + ':' + roles + ':' + mac + ':' + idrac_addr + '\n'
        output = open(file_path,'a')
        output.write(entry)
        output.close()
    # scp node-list file to all nodes
    LOG.info('Copy node-list file to all nodes ...')
    for ip in ips:
        LOG.info('   To node %s ...' % ip)
        scp_connect(ip, file_path, file_path)
Exemplo n.º 31
0
 def graph(self, uid):
     from fuelclient.client import APIClient as nailgun
     return nailgun.get_request('clusters/{}/serialized_tasks'.format(uid))
Exemplo n.º 32
0
 def __call__(self, parser, namespace, values, option_string=None):
     parser.exit(message=APIClient.get_fuel_version())
Exemplo n.º 33
0
 def take_action(self, parsed_args):
     args = parsed_args.__dict__
     data = {'node': args['node']}
     result = APIClient.delete_request(API_URI.format(args['node']))
     return self.columns, data
Exemplo n.º 34
0
 def __call__(self, parser, namespace, values, option_string=None):
     parser.exit(message=APIClient.get_fuel_version())
Exemplo n.º 35
0
 def graph(self, uid):
     from fuelclient.client import APIClient as nailgun
     return nailgun.get_request('clusters/{}/serialized_tasks'.format(uid))
Exemplo n.º 36
0
 def take_action(self, parsed_args):
     args = parsed_args.__dict__
     data = {'node': args['node']}
     result = APIClient.delete_request(API_URI.format(args['node']))
     return self.columns, data
Exemplo n.º 37
0
def go_upgrade(myip):
    MODULES_SOURCE = 'rsync://%s:/eayunstack/puppet/modules' % myip
    MANIFESTS_SOURCE = 'rsync://%s:/eayunstack/puppet/manifests' % myip

    CWD = '/var/lib/eayunstack'

    RELATIVE_MODULES_PATH = 'puppet/modules'
    MODULES_PATH = os.path.join(CWD, RELATIVE_MODULES_PATH)
    MANIFESTS_PATH = os.path.join(CWD, 'puppet/manifests')

    MANIFEST = os.path.join(MANIFESTS_PATH, 'site.pp')
    MODULES = ':'.join([RELATIVE_MODULES_PATH, '/etc/puppet/modules'])

    SYNC_COMMAND = ' '.join([MCO_COMMAND_PREFIX, 'puppetsync rsync',
                             'modules_source=%s' % MODULES_SOURCE,
                             'manifests_source=%s' % MANIFESTS_SOURCE,
                             'modules_path=%s' % MODULES_PATH,
                             'manifests_path=%s' % MANIFESTS_PATH])
    RUN_COMMAND = ' '.join([MCO_COMMAND_PREFIX, 'puppetd runonce',
                            'manifest=%s' % MANIFEST,
                            'cwd=%s' % CWD,
                            'modules=%s' % MODULES])

    if not os.path.isdir(RUNDIR):
        os.makedirs(RUNDIR)

    nodes = APIClient.get_request('nodes/')
    if not os.path.isfile(FIRST_CONTROLLER):
        for n in nodes:
            if n['online'] and 'controller' in n['roles']:
                first_controller = str(n['id'])
                break
        with open(FIRST_CONTROLLER, 'wb') as first_controller_file:
            first_controller_file.write(first_controller)
        nodes = [first_controller]
    else:
        current_running = check_upgrade_process()
        if current_running > 0:
            return
        with open(FIRST_CONTROLLER, 'r') as first_controller_file:
            first_controller = first_controller_file.readline()
        nodes = [
            str(n['id']) for n in nodes
            if n['online'] and str(n['id']) != first_controller
        ]
        with open(OTHER_NODES, 'wb') as other_nodes_file:
            other_nodes_file.write(' '.join(nodes))

    nodes_in_command = ' '.join(['-I %s' % n for n in nodes])

    errors = 0
    (s, o) = commands.getstatusoutput(
        SYNC_COMMAND.format(nodes=nodes_in_command))
    if s == 0:
        ret = json.loads(o)
        for node_info in ret:
            sender = node_info['sender']
            data = node_info['data']
            if node_info['statuscode'] == 0:
                LOG.info('node %s: %s' % (sender, data['msg']))
            else:
                LOG.error('node %s: %s' % (sender, node_info['statusmsg']))
                errors += 1
    else:
        LOG.error('Failed to sync puppet modules to nodes %s.' % nodes)
        errors += 1

    if errors:
        return

    (s, o) = commands.getstatusoutput(
        RUN_COMMAND.format(nodes=nodes_in_command))
    if s == 0:
        ret = json.loads(o)
        for node_info in ret:
            sender = node_info['sender']
            data = node_info['data']
            if node_info['statuscode'] == 0:
                LOG.info('node %s: %s' % (sender, data['output']))
            else:
                LOG.error('node %s: %s' % (sender, data['output']))
    else:
        LOG.error('Failed to run puppet on nodes %s.' % nodes)
Exemplo n.º 38
0
 def change_password(self, params):
     """To change user password:
             fuel user change-password
     """
     APIClient.update_own_password(params.newpass)