コード例 #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]")
コード例 #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))
コード例 #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
コード例 #4
0
ファイル: user.py プロジェクト: sylwekb/python-fuelclient
    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)
コード例 #5
0
ファイル: user.py プロジェクト: gdyuldin/python-fuelclient
    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)
コード例 #6
0
ファイル: base.py プロジェクト: enchantner/fuel-web
 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
コード例 #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
コード例 #8
0
ファイル: base.py プロジェクト: Zipfer/fuel-web
    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
コード例 #9
0
ファイル: arguments.py プロジェクト: CGenie/fuel-web
 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))
コード例 #10
0
ファイル: __init__.py プロジェクト: xglhjk6/eayunstack-tools
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)
コード例 #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
コード例 #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))
コード例 #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
コード例 #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
コード例 #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
コード例 #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
コード例 #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
コード例 #18
0
ファイル: base.py プロジェクト: tinyxiao/python-fuelclient
    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
コード例 #19
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
コード例 #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)
コード例 #21
0
ファイル: list.py プロジェクト: zeus911/eayunstack-tools
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
コード例 #22
0
ファイル: list.py プロジェクト: zeus911/eayunstack-tools
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
コード例 #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)
コード例 #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
コード例 #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
コード例 #26
0
ファイル: __init__.py プロジェクト: masterpy/eayunstack-tools
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)
コード例 #27
0
ファイル: __init__.py プロジェクト: caisan/eayunstack-tools
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)
コード例 #28
0
ファイル: __init__.py プロジェクト: taicai/eayunstack-tools
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) 
コード例 #29
0
ファイル: __init__.py プロジェクト: masterpy/eayunstack-tools
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)
コード例 #30
0
ファイル: __init__.py プロジェクト: taicai/eayunstack-tools
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)
コード例 #31
0
ファイル: fsclient.py プロジェクト: Mirantis/f2s
 def graph(self, uid):
     from fuelclient.client import APIClient as nailgun
     return nailgun.get_request('clusters/{}/serialized_tasks'.format(uid))
コード例 #32
0
ファイル: arguments.py プロジェクト: CGenie/fuel-web
 def __call__(self, parser, namespace, values, option_string=None):
     parser.exit(message=APIClient.get_fuel_version())
コード例 #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
コード例 #34
0
 def __call__(self, parser, namespace, values, option_string=None):
     parser.exit(message=APIClient.get_fuel_version())
コード例 #35
0
ファイル: fsclient.py プロジェクト: Mirantis/f2s
 def graph(self, uid):
     from fuelclient.client import APIClient as nailgun
     return nailgun.get_request('clusters/{}/serialized_tasks'.format(uid))
コード例 #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
コード例 #37
0
ファイル: go.py プロジェクト: xglhjk6/eayunstack-tools
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)
コード例 #38
0
ファイル: user.py プロジェクト: iberezovskiy/fuel-web
 def change_password(self, params):
     """To change user password:
             fuel user change-password
     """
     APIClient.update_own_password(params.newpass)