class TestServerGroup(compute_fakes.TestComputev2): fake_server_group = compute_fakes.FakeServerGroup.create_one_server_group() columns = ( 'id', 'members', 'name', 'policies', 'project_id', 'user_id', ) data = ( fake_server_group.id, utils.format_list(fake_server_group.members), fake_server_group.name, utils.format_list(fake_server_group.policies), fake_server_group.project_id, fake_server_group.user_id, ) def setUp(self): super(TestServerGroup, self).setUp() # Get a shortcut to the ServerGroupsManager Mock self.server_groups_mock = self.app.client_manager.compute.server_groups self.server_groups_mock.reset_mock()
def take_action(self, parsed_args): self.log.debug("take_action(%s)" % parsed_args) client = self.app.client_manager.data_processing if parsed_args.plugin_version: data = client.plugins.get_version_details( parsed_args.plugin, parsed_args.plugin_version).to_dict() processes = data.pop('node_processes') for k, v in processes.items(): processes[k] = osc_utils.format_list(v) data['required_image_tags'] = osc_utils.format_list( data['required_image_tags']) label_items = _serialize_label_items(data) data = utils.prepare_data( data, ['required_image_tags', 'name', 'description', 'title']) data = self.dict2columns(data) data = utils.extend_columns(data, label_items) data = utils.extend_columns( data, [('Service:', 'Available processes:')]) data = utils.extend_columns( data, sorted(processes.items())) else: data = client.plugins.get(parsed_args.plugin).to_dict() data['versions'] = osc_utils.format_list(data['versions']) items = _serialize_label_items(data) data = utils.prepare_data( data, ['versions', 'name', 'description', 'title']) data = utils.extend_columns(self.dict2columns(data), items) return data
class TestServerGroup(test_base.TestBaremetalComputeV1): fake_server_group = fakes.FakeServerGroup.create_one_server_group() columns = ( 'uuid', 'name', 'user_id', 'project_id', 'members', 'policies', ) data = ( fake_server_group.uuid, fake_server_group.name, fake_server_group.user_id, fake_server_group.project_id, utils.format_list(fake_server_group.members), utils.format_list(fake_server_group.policies), ) def setUp(self): self.server_group_mock = mock.Mock() self.useFixture( fixtures.MockPatch( 'moganclient.v1.server_group.ServerGroupManager', return_value=self.server_group_mock)) super(TestServerGroup, self).setUp()
def test_type_show_with_access(self): arglist = [ self.volume_type.id ] verifylist = [ ("volume_type", self.volume_type.id) ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) private_type = volume_fakes.FakeType.create_one_type( attrs={'is_public': False}) type_access_list = volume_fakes.FakeTypeAccess.create_one_type_access() with mock.patch.object(self.types_mock, 'get', return_value=private_type): with mock.patch.object(self.types_access_mock, 'list', return_value=[type_access_list]): columns, data = self.cmd.take_action(parsed_args) self.types_mock.get.assert_called_once_with( self.volume_type.id) self.types_access_mock.list.assert_called_once_with( private_type.id) self.assertEqual(self.columns, columns) private_type_data = ( utils.format_list([type_access_list.project_id]), private_type.description, private_type.id, private_type.is_public, private_type.name, utils.format_dict(private_type.extra_specs) ) self.assertEqual(private_type_data, data)
def get_parser(self, prog_name): parser = super(CreateQos, self).get_parser(prog_name) parser.add_argument( 'name', metavar='<name>', help=_('New QoS specification name'), ) consumer_choices = ['front-end', 'back-end', 'both'] parser.add_argument( '--consumer', metavar='<consumer>', choices=consumer_choices, default='both', help=(_('Consumer of the QoS. Valid consumers: %s ' "(defaults to 'both')") % utils.format_list(consumer_choices)) ) parser.add_argument( '--property', metavar='<key=value>', action=parseractions.KeyValueAction, help=_('Set a QoS specification property ' '(repeat option to set multiple properties)'), ) return parser
def take_action(self, parsed_args): compute_client = self.app.client_manager.compute resource_flavor = _find_flavor(compute_client, parsed_args.flavor) access_projects = None # get access projects list of this flavor if not resource_flavor.is_public: try: flavor_access = compute_client.flavor_access.list( flavor=resource_flavor.id) projects = [ utils.get_field(access, 'tenant_id') for access in flavor_access ] # TODO(Huanxuan Ao): This format case can be removed after # patch https://review.openstack.org/#/c/330223/ merged. access_projects = utils.format_list(projects) except Exception as e: msg = _("Failed to get access projects list " "for flavor '%(flavor)s': %(e)s") LOG.error(msg, {'flavor': parsed_args.flavor, 'e': e}) flavor = resource_flavor._info.copy() flavor.update({'access_project_ids': access_projects}) flavor.pop("links", None) flavor['properties'] = utils.format_dict(resource_flavor.get_keys()) return zip(*sorted(six.iteritems(flavor)))
def take_action(self, parsed_args): identity_client = self.app.client_manager.identity if parsed_args.remote_id_file: file_content = utils.read_blob_file_contents( parsed_args.remote_id_file) remote_ids = file_content.splitlines() remote_ids = list(map(str.strip, remote_ids)) else: remote_ids = (parsed_args.remote_id if parsed_args.remote_id else None) domain_id = None if parsed_args.domain: domain_id = common.find_domain(identity_client, parsed_args.domain).id idp = identity_client.federation.identity_providers.create( id=parsed_args.identity_provider_id, remote_ids=remote_ids, description=parsed_args.description, domain_id=domain_id, enabled=parsed_args.enabled) idp._info.pop('links', None) remote_ids = utils.format_list(idp._info.pop('remote_ids', [])) idp._info['remote_ids'] = remote_ids return zip(*sorted(six.iteritems(idp._info)))
def _format_image(image): """Format an image to make it more consistent with OSC operations.""" info = {} properties = {} # the only fields we're not including is "links", "tags" and the properties fields_to_show = [ 'status', 'name', 'container_format', 'created_at', 'size', 'disk_format', 'updated_at', 'visibility', 'min_disk', 'protected', 'id', 'file', 'checksum', 'owner', 'virtual_size', 'min_ram', 'schema' ] # split out the usual key and the properties which are top-level for key in six.iterkeys(image): if key in fields_to_show: info[key] = image.get(key) elif key == 'tags': continue # handle this later else: properties[key] = image.get(key) # format the tags if they are there info['tags'] = utils.format_list(image.get('tags')) # add properties back into the dictionary as a top-level key if properties: info['properties'] = utils.format_dict(properties) return info
def take_action(self, parsed_args): volume_client = self.app.client_manager.volume volume_type = utils.find_resource(volume_client.volume_types, parsed_args.volume_type) properties = utils.format_dict(volume_type._info.pop( 'extra_specs', {})) volume_type._info.update({'properties': properties}) access_project_ids = None if not volume_type.is_public: try: volume_type_access = volume_client.volume_type_access.list( volume_type.id) project_ids = [ utils.get_field(item, 'project_id') for item in volume_type_access ] # TODO(Rui Chen): This format list case can be removed after # patch https://review.openstack.org/#/c/330223/ merged. access_project_ids = utils.format_list(project_ids) except Exception as e: msg = _('Failed to get access project list for volume type ' '%(type)s: %(e)s') LOG.error(msg % {'type': volume_type.id, 'e': e}) volume_type._info.update({'access_project_ids': access_project_ids}) return zip(*sorted(six.iteritems(volume_type._info)))
def test_assert_item_formattable_columns_vs_legacy_formatter(self): expected = [format_columns.DictColumn({'a': 1, 'b': 2}), format_columns.ListColumn(['x', 'y', 'z'])] actual = [utils.format_dict({'a': 1, 'b': 2}), utils.format_list(['x', 'y', 'z'])] self.assertRaises(AssertionError, self.assertItemEqual, expected, actual)
def get_parser(self, prog_name): parser = super(PassthruCallBaremetalNode, self).get_parser( prog_name) parser.add_argument( 'node', metavar='<node>', help="Name or UUID of the node" ) parser.add_argument( 'method', metavar='<method>', help="Vendor passthru method to be executed" ) parser.add_argument( '--arg', metavar='<key=value>', action='append', help="Argument to pass to the passthru method (repeat option " "to specify multiple arguments)" ) parser.add_argument( '--http-method', metavar='<http-method>', choices=v1_utils.HTTP_METHODS, default='POST', help="The HTTP method to use in the passthru request. One of " "%s. Defaults to POST." % oscutils.format_list(v1_utils.HTTP_METHODS) ) return parser
def take_action(self, parsed_args): network = self._create_network( parsed_args.name, project=parsed_args.project, zone=parsed_args.zone, ttl=parsed_args.ttl, ) return zip( *{ 'name': parsed_args.name, 'network_id': network['network'].id, 'v6_subnet_id': network['subnetv6'].id, 'v4_subnet_id': network['subnetv4'].id, 'dhcp_port_id': network['dhcp'].id, 'gateway_port_id': network['gateway'].id, 'zone_id': network['zone']['id'], 'dns_domain': network['network'].dns_domain, 'cidr': format_list( [network['subnetv6'].cidr, network['subnetv4'].cidr]), }.items())
class TestServerGroupV264(TestServerGroup): fake_server_group = \ compute_fakes.FakeServerGroupV264.create_one_server_group() columns = ( 'id', 'members', 'name', 'policy', 'project_id', 'user_id', ) data = ( fake_server_group.id, utils.format_list(fake_server_group.members), fake_server_group.name, fake_server_group.policy, fake_server_group.project_id, fake_server_group.user_id, ) def setUp(self): super(TestServerGroupV264, self).setUp()
def get_parser(self, prog_name): parser = super(PassthruCallBaremetalDriver, self).get_parser(prog_name) parser.add_argument( 'driver', metavar='<driver>', help=_('Name of the driver.') ) parser.add_argument( 'method', metavar='<method>', help=_("Vendor passthru method to be called.") ) parser.add_argument( '--arg', metavar='<key=value>', action='append', help=_("Argument to pass to the passthru method (repeat option " "to specify multiple arguments).") ) parser.add_argument( '--http-method', dest='http_method', metavar='<http-method>', choices=v1_utils.HTTP_METHODS, default='POST', help=_("The HTTP method to use in the passthru request. One of " "%s. Defaults to 'POST'.") % oscutils.format_list(v1_utils.HTTP_METHODS) ) return parser
def take_action(self, parsed_args): compute_client = self.app.client_manager.compute resource_flavor = _find_flavor(compute_client, parsed_args.flavor) access_projects = None # get access projects list of this flavor if not resource_flavor.is_public: try: flavor_access = compute_client.flavor_access.list( flavor=resource_flavor.id) projects = [utils.get_field(access, 'tenant_id') for access in flavor_access] # TODO(Huanxuan Ao): This format case can be removed after # patch https://review.openstack.org/#/c/330223/ merged. access_projects = utils.format_list(projects) except Exception as e: msg = _("Failed to get access projects list " "for flavor '%(flavor)s': %(e)s") LOG.error(msg % {'flavor': parsed_args.flavor, 'e': e}) flavor = resource_flavor._info.copy() flavor.update({ 'access_project_ids': access_projects }) flavor.pop("links", None) flavor['properties'] = utils.format_dict(resource_flavor.get_keys()) return zip(*sorted(six.iteritems(flavor)))
def _format_image(image): """Format an image to make it more consistent with OSC operations.""" info = {} properties = {} # the only fields we're not including is "links", "tags" and the properties fields_to_show = ['status', 'name', 'container_format', 'created_at', 'size', 'disk_format', 'updated_at', 'visibility', 'min_disk', 'protected', 'id', 'file', 'checksum', 'owner', 'virtual_size', 'min_ram', 'schema'] # split out the usual key and the properties which are top-level for key in six.iterkeys(image): if key in fields_to_show: info[key] = image.get(key) elif key == 'tags': continue # handle this later else: properties[key] = image.get(key) # format the tags if they are there info['tags'] = utils.format_list(image.get('tags')) # add properties back into the dictionary as a top-level key if properties: info['properties'] = utils.format_dict(properties) return info
def test_type_show_with_access(self): arglist = [self.volume_type.id] verifylist = [("volume_type", self.volume_type.id)] parsed_args = self.check_parser(self.cmd, arglist, verifylist) private_type = volume_fakes.FakeType.create_one_type( attrs={'is_public': False}) type_access_list = volume_fakes.FakeTypeAccess.create_one_type_access() with mock.patch.object(self.types_mock, 'get', return_value=private_type): with mock.patch.object(self.types_access_mock, 'list', return_value=[type_access_list]): columns, data = self.cmd.take_action(parsed_args) self.types_mock.get.assert_called_once_with( self.volume_type.id) self.types_access_mock.list.assert_called_once_with( private_type.id) self.assertEqual(self.columns, columns) private_type_data = (utils.format_list([type_access_list.project_id]), private_type.description, private_type.id, private_type.is_public, private_type.name, utils.format_dict(private_type.extra_specs)) self.assertEqual(private_type_data, data)
def _format_ngt_output(data): data['node_processes'] = osc_utils.format_list(data['node_processes']) data['plugin_version'] = data.pop('hadoop_version') if data['volumes_per_node'] == 0: del data['volume_local_to_instance'] del data['volume_mount_prefix'] del data['volume_type'], del data['volumes_availability_zone'] del data['volumes_size']
def take_action(self, parsed_args): self.log.debug("take_action(%s)", parsed_args) client = self.app.client_manager.data_processing data = utils.get_resource(client.images, parsed_args.image).to_dict() data['tags'] = osc_utils.format_list(data['tags']) data = utils.prepare_data(data, IMAGE_FIELDS) return self.dict2columns(data)
def take_action(self, parsed_args): self.log.debug("take_action(%s)", parsed_args) client = self.app.client_manager.data_processing data = utils.get_resource( client.images, parsed_args.image).to_dict() data['tags'] = osc_utils.format_list(data['tags']) data = utils.prepare_data(data, IMAGE_FIELDS) return self.dict2columns(data)
def image_data(self, image): datalist = ( image["id"], image["name"], image["owner"], image["protected"], "active", common_utils.format_list(image.get("tags")), image["visibility"], ) return datalist
def take_action(self, parsed_args): volume_client = self.app.client_manager.volume qos_spec = utils.find_resource(volume_client.qos_specs, parsed_args.qos_spec) qos_associations = volume_client.qos_specs.get_associations(qos_spec) if qos_associations: associations = [association.name for association in qos_associations] qos_spec._info.update({"associations": utils.format_list(associations)}) qos_spec._info.update({"specs": utils.format_dict(qos_spec.specs)}) return zip(*sorted(six.iteritems(qos_spec._info)))
def image_data(self, image): datalist = ( image['id'], image['name'], image['owner'], image['protected'], 'active', common_utils.format_list(image.get('tags')), image['visibility'], ) return datalist
def take_action(self, parsed_args): identity_client = self.app.client_manager.identity idp = utils.find_resource( identity_client.federation.identity_providers, parsed_args.identity_provider, id=parsed_args.identity_provider) idp._info.pop('links', None) remote_ids = utils.format_list(idp._info.pop('remote_ids', [])) idp._info['remote_ids'] = remote_ids return zip(*sorted(six.iteritems(idp._info)))
def _format_ngt_output(data): data['node_processes'] = osc_utils.format_list(data['node_processes']) if data['volumes_per_node'] == 0: del data['volume_local_to_instance'] del data['volume_mount_prefix'] del data['volume_type'], del data['volumes_availability_zone'] del data['volumes_size'] if not data['boot_from_volume']: del data['boot_volume_type'] del data['boot_volume_availability_zone'] del data['boot_volume_local_to_instance']
def _get_common_cols_data(self, fake_port): columns = ( "admin_state_up", "allowed_address_pairs", "binding_host_id", "binding_profile", "binding_vif_details", "binding_vif_type", "binding_vnic_type", "description", "device_id", "device_owner", "dns_assignment", "dns_name", "extra_dhcp_opts", "fixed_ips", "id", "mac_address", "name", "network_id", "port_security_enabled", "project_id", "security_groups", "status", ) data = ( port._format_admin_state(fake_port.admin_state_up), utils.format_list_of_dicts(fake_port.allowed_address_pairs), fake_port.binding_host_id, utils.format_dict(fake_port.binding_profile), utils.format_dict(fake_port.binding_vif_details), fake_port.binding_vif_type, fake_port.binding_vnic_type, fake_port.description, fake_port.device_id, fake_port.device_owner, utils.format_list_of_dicts(fake_port.dns_assignment), fake_port.dns_name, utils.format_list_of_dicts(fake_port.extra_dhcp_opts), utils.format_list_of_dicts(fake_port.fixed_ips), fake_port.id, fake_port.mac_address, fake_port.name, fake_port.network_id, fake_port.port_security_enabled, fake_port.project_id, utils.format_list(fake_port.security_groups), fake_port.status, ) return columns, data
def _get_common_cols_data(self, fake_port): columns = ( 'admin_state_up', 'allowed_address_pairs', 'binding_host_id', 'binding_profile', 'binding_vif_details', 'binding_vif_type', 'binding_vnic_type', 'description', 'device_id', 'device_owner', 'dns_assignment', 'dns_name', 'extra_dhcp_opts', 'fixed_ips', 'id', 'mac_address', 'name', 'network_id', 'port_security_enabled', 'project_id', 'security_groups', 'status', ) data = ( port._format_admin_state(fake_port.admin_state_up), utils.format_list_of_dicts(fake_port.allowed_address_pairs), fake_port.binding_host_id, utils.format_dict(fake_port.binding_profile), utils.format_dict(fake_port.binding_vif_details), fake_port.binding_vif_type, fake_port.binding_vnic_type, fake_port.description, fake_port.device_id, fake_port.device_owner, utils.format_list_of_dicts(fake_port.dns_assignment), fake_port.dns_name, utils.format_list_of_dicts(fake_port.extra_dhcp_opts), utils.format_list_of_dicts(fake_port.fixed_ips), fake_port.id, fake_port.mac_address, fake_port.name, fake_port.network_id, fake_port.port_security_enabled, fake_port.project_id, utils.format_list(fake_port.security_groups), fake_port.status, ) return columns, data
def take_action(self, parsed_args): user = self._create_user(parsed_args.name, ) return zip( *{ 'name': parsed_args.name, 'user_id': user['user'].id, 'project_id': user['project'].id, 'network_id': user['network'].id, 'dns_domain': user['network'].dns_domain, 'cidr': format_list( [user['subnetv6'].cidr, user['subnetv4'].cidr]), 'password': user['password'], }.items())
class TestShowIPAvailability(TestIPAvailability): _ip_availability = \ network_fakes.FakeIPAvailability.create_one_ip_availability() columns = ( 'network_id', 'network_name', 'project_id', 'subnet_ip_availability', 'total_ips', 'used_ips', ) data = ( _ip_availability.network_id, _ip_availability.network_name, _ip_availability.tenant_id, common_utils.format_list(_ip_availability.subnet_ip_availability), _ip_availability.total_ips, _ip_availability.used_ips, ) def setUp(self): super(TestShowIPAvailability, self).setUp() self.network.find_network_ip_availability = mock.Mock( return_value=self._ip_availability) # Get the command object to test self.cmd = ip_availability.ShowIPAvailability(self.app, self.namespace) def test_show_no_option(self): arglist = [] verifylist = [] self.assertRaises(tests_utils.ParserException, self.check_parser, self.cmd, arglist, verifylist) def test_show_all_options(self): arglist = [ self._ip_availability.network_name, ] verifylist = [('network', self._ip_availability.network_name)] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) self.network.find_network_ip_availability.assert_called_once_with( self._ip_availability.network_name, ignore_missing=False) self.assertEqual(self.columns, columns) self.assertEqual(self.data, data)
def take_action(self, parsed_args): self.log.debug("take_action(%s)" % parsed_args) client = self.app.client_manager.data_processing image = utils.get_resource(client.images, parsed_args.image) parsed_args.tags.extend(image.tags) data = client.images.update_tags( image.id, list(set(parsed_args.tags))).to_dict() data['tags'] = osc_utils.format_list(data['tags']) data = utils.prepare_data(data, IMAGE_FIELDS) return self.dict2columns(data)
def _get_common_cols_data(self, fake_port): columns = ( 'admin_state_up', 'allowed_address_pairs', 'binding_host_id', 'binding_profile', 'binding_vif_details', 'binding_vif_type', 'binding_vnic_type', 'device_id', 'device_owner', 'dns_assignment', 'dns_name', 'extra_dhcp_opts', 'fixed_ips', 'id', 'mac_address', 'name', 'network_id', 'port_security_enabled', 'project_id', 'security_groups', 'status', ) data = ( port._format_admin_state(fake_port.admin_state_up), utils.format_list_of_dicts(fake_port.allowed_address_pairs), fake_port.binding_host_id, utils.format_dict(fake_port.binding_profile), utils.format_dict(fake_port.binding_vif_details), fake_port.binding_vif_type, fake_port.binding_vnic_type, fake_port.device_id, fake_port.device_owner, utils.format_list_of_dicts(fake_port.dns_assignment), fake_port.dns_name, utils.format_list_of_dicts(fake_port.extra_dhcp_opts), utils.format_list_of_dicts(fake_port.fixed_ips), fake_port.id, fake_port.mac_address, fake_port.name, fake_port.network_id, fake_port.port_security_enabled, fake_port.project_id, utils.format_list(fake_port.security_groups), fake_port.status, ) return columns, data
def take_action(self, parsed_args): self.log.debug("take_action(%s)" % parsed_args) client = self.app.client_manager.data_processing image = utils.get_resource(client.images, parsed_args.image) parsed_args.tags.extend(image.tags) data = client.images.update_tags(image.id, list(set( parsed_args.tags))).to_dict() data['tags'] = osc_utils.format_list(data['tags']) data = utils.prepare_data(data, IMAGE_FIELDS) return self.dict2columns(data)
def verify_long_form(self, expected_rt, observed_rt, expected_ports=None): self.assertIsNotNone(observed_rt) self.assertEqual(expected=expected_rt.id, observed=observed_rt['ID']) self.assertEqual(expected=expected_rt.name, observed=observed_rt['Name']) self.assertEqual(expected=expected_rt.end_point_type, observed=observed_rt['Insertion Mode']) self.assertEqual(expected=expected_rt.redundancy_enabled, observed=observed_rt['Redundancy Enabled']) self.assertEqual(expected=expected_rt.description, observed=observed_rt['Description']) self.assertEqual( expected=format_list(expected_ports if expected_ports else []), observed=observed_rt['Ports'])
def take_action(self, parsed_args): volume_client = self.app.client_manager.volume qos_spec = utils.find_resource(volume_client.qos_specs, parsed_args.qos_spec) qos_associations = volume_client.qos_specs.get_associations(qos_spec) if qos_associations: associations = [association.name for association in qos_associations] qos_spec._info.update({ 'associations': utils.format_list(associations) }) qos_spec._info.update({'specs': utils.format_dict(qos_spec.specs)}) return zip(*sorted(six.iteritems(qos_spec._info)))
def take_action(self, parsed_args): self.log.debug("take_action(%s)", parsed_args) client = self.app.client_manager.data_processing image_client = self.app.client_manager.image image_id = osc_utils.find_resource(image_client.images, parsed_args.image).id data = client.images.update_image(image_id, user_name=parsed_args.username, desc=parsed_args.description).image data['tags'] = osc_utils.format_list(data['tags']) data = utils.prepare_data(data, IMAGE_FIELDS) return self.dict2columns(data)
def take_action(self, parsed_args): self.log.debug("take_action(%s)", parsed_args) client = self.app.client_manager.data_processing image_client = self.app.client_manager.image image_id = osc_utils.find_resource( image_client.images, parsed_args.image).id data = client.images.update_image( image_id, user_name=parsed_args.username, desc=parsed_args.description).image data['tags'] = osc_utils.format_list(data['tags']) data = utils.prepare_data(data, IMAGE_FIELDS) return self.dict2columns(data)
def take_action(self, parsed_args): self.log.debug("take_action(%s)", parsed_args) baremetal_client = self.app.client_manager.baremetal methods = baremetal_client.node.get_vendor_passthru_methods( parsed_args.node) data = [] for method, response in methods.items(): response['name'] = method response['http_methods'] = oscutils.format_list( response['http_methods']) data.append(response) return (res_fields.VENDOR_PASSTHRU_METHOD_RESOURCE.labels, (oscutils.get_dict_properties( s, res_fields.VENDOR_PASSTHRU_METHOD_RESOURCE.fields) for s in data))
def test_image_list_long_option(self): arglist = [ '--long', ] verifylist = [ ('long', True), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) # In base command class Lister in cliff, abstract method take_action() # returns a tuple containing the column names and an iterable # containing the data to be listed. columns, data = self.cmd.take_action(parsed_args) self.api_mock.image_list.assert_called_with( marker=self._image.id, ) collist = ( 'ID', 'Name', 'Disk Format', 'Container Format', 'Size', 'Checksum', 'Status', 'Visibility', 'Protected', 'Project', 'Tags', ) self.assertEqual(collist, columns) datalist = (( self._image.id, self._image.name, '', '', '', '', '', self._image.visibility, self._image.protected, self._image.owner, common_utils.format_list(self._image.tags), ), ) self.assertEqual(datalist, tuple(data))
def take_action(self, parsed_args): self.log.debug("take_action(%s)", parsed_args) baremetal_client = self.app.client_manager.baremetal methods = baremetal_client.node.get_vendor_passthru_methods( parsed_args.node) data = [] for method, response in methods.items(): response['name'] = method response['http_methods'] = oscutils.format_list( response['http_methods']) data.append(response) return ( res_fields.VENDOR_PASSTHRU_METHOD_RESOURCE.labels, (oscutils.get_dict_properties( s, res_fields.VENDOR_PASSTHRU_METHOD_RESOURCE.fields) for s in data))
def take_action(self, parsed_args): self.log.debug("take_action(%s)", parsed_args) client = self.app.client_manager.data_processing image = utils.get_resource(client.images, parsed_args.image) if parsed_args.all: data = client.images.update_tags(image.id, []).to_dict() else: parsed_args.tags = parsed_args.tags or [] new_tags = list(set(image.tags) - set(parsed_args.tags)) data = client.images.update_tags(image.id, new_tags).to_dict() data['tags'] = osc_utils.format_list(data['tags']) data = utils.prepare_data(data, IMAGE_FIELDS) return self.dict2columns(data)
def get_parser(self, prog_name): parser = super(BootdeviceSetBaremetalNode, self).get_parser(prog_name) parser.add_argument('node', metavar='<node>', help="Name or UUID of the node") parser.add_argument('device', metavar='<device>', choices=v1_utils.BOOT_DEVICES, help="One of %s" % (oscutils.format_list(v1_utils.BOOT_DEVICES))) parser.add_argument( '--persistent', dest='persistent', action='store_true', default=False, help="Make changes persistent for all future boots") return parser
def take_action(self, parsed_args): self.log.debug("take_action(%s)" % parsed_args) client = self.app.client_manager.data_processing blob = osc_utils.read_blob_file_contents(parsed_args.json) try: update_dict = json.loads(blob) except ValueError as e: raise exceptions.CommandError( 'An error occurred when reading ' 'update dict from file %s: %s' % (parsed_args.json, e)) plugin = client.plugins.update(parsed_args.plugin, update_dict) data = plugin.to_dict() data['versions'] = osc_utils.format_list(data['versions']) items = _serialize_label_items(data) data = utils.prepare_data( data, ['versions', 'name', 'description', 'title']) data = utils.extend_columns(self.dict2columns(data), items) return data
def get_image_data(image=None): """Get the image data from a faked image object. :param image: A FakeResource objects faking image :return A tuple which may include the following values: ('image-123', 'image-foo', 'admin', False, 'public', 'bar, baz') """ data_list = [] if image is not None: for x in sorted(image.keys()): if x == 'tags': # The 'tags' should be format_list data_list.append( common_utils.format_list(getattr(image, x))) else: data_list.append(getattr(image, x)) return tuple(data_list)
def get_volume_data(volume=None): """Get the volume data from a faked volume object. :param volume: A FakeResource objects faking volume :return A tuple which may include the following values: ('ce26708d', 'fake_volume', 'fake description', 'available', 20, 'fake_lvmdriver-1', "Alpha='a', Beta='b', Gamma='g'", 1, 'nova', [{'device': '/dev/ice', 'server_id': '1233'}]) """ data_list = [] if volume is not None: for x in sorted(volume.keys()): if x == 'tags': # The 'tags' should be format_list data_list.append( common_utils.format_list(volume.info.get(x))) else: data_list.append(volume.info.get(x)) return tuple(data_list)
def take_action(self, parsed_args): cm = self.app.command_manager groups = cm.get_command_groups() groups = sorted(groups) columns = ('Command Group', 'Commands') commands = [] for group in groups: command_names = cm.get_command_names(group) command_names = sorted(command_names) if command_names != []: # TODO(bapalm): Fix this when cliff properly supports # handling the detection rather than using the hard-code below. if parsed_args.formatter == 'table': command_names = utils.format_list(command_names, "\n") commands.append((group, command_names)) return (columns, commands)
def get_parser(self, prog_name): parser = super(CreateQos, self).get_parser(prog_name) parser.add_argument("name", metavar="<name>", help=_("New QoS specification name")) consumer_choices = ["front-end", "back-end", "both"] parser.add_argument( "--consumer", metavar="<consumer>", choices=consumer_choices, default="both", help=( _("Consumer of the QoS. Valid consumers: %s " "(defaults to 'both')") % utils.format_list(consumer_choices) ), ) parser.add_argument( "--property", metavar="<key=value>", action=parseractions.KeyValueAction, help=_("Set a QoS specification property " "(repeat option to set multiple properties)"), ) return parser
def get_parser(self, prog_name): parser = super(BootdeviceSetBaremetalNode, self).get_parser(prog_name) parser.add_argument( 'node', metavar='<node>', help="Name or UUID of the node" ) parser.add_argument( 'device', metavar='<device>', choices=v1_utils.BOOT_DEVICES, help="One of %s" % (oscutils.format_list(v1_utils.BOOT_DEVICES)) ) parser.add_argument( '--persistent', dest='persistent', action='store_true', default=False, help="Make changes persistent for all future boots" ) return parser
def take_action(self, parsed_args): volume_client = self.app.client_manager.volume volume_type = utils.find_resource( volume_client.volume_types, parsed_args.volume_type) properties = utils.format_dict( volume_type._info.pop('extra_specs', {})) volume_type._info.update({'properties': properties}) access_project_ids = None if not volume_type.is_public: try: volume_type_access = volume_client.volume_type_access.list( volume_type.id) project_ids = [utils.get_field(item, 'project_id') for item in volume_type_access] # TODO(Rui Chen): This format list case can be removed after # patch https://review.openstack.org/#/c/330223/ merged. access_project_ids = utils.format_list(project_ids) except Exception as e: msg = _('Failed to get access project list for volume type ' '%(type)s: %(e)s') LOG.error(msg % {'type': volume_type.id, 'e': e}) volume_type._info.update({'access_project_ids': access_project_ids}) return zip(*sorted(six.iteritems(volume_type._info)))