def test_format_dict(self):
     expected = "a='b', c='d', e='f'"
     self.assertEqual(expected,
                      utils.format_dict({
                          'a': 'b',
                          'c': 'd',
                          'e': 'f'
                      }))
     self.assertEqual(expected,
                      utils.format_dict({
                          'e': 'f',
                          'c': 'd',
                          'a': 'b'
                      }))
예제 #2
0
    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
예제 #3
0
    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):
     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})
     return zip(*sorted(six.iteritems(volume_type._info)))
예제 #5
0
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
예제 #6
0
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
예제 #7
0
 def take_action(self, parsed_args):
     self.log.debug("take_action: (%s)", 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})
     return zip(*sorted(six.iteritems(volume_type._info)))
예제 #8
0
    def test_qos_show(self):
        arglist = [
            volume_fakes.qos_id
        ]
        verifylist = [
            ('qos_spec', volume_fakes.qos_id)
        ]

        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        columns, data = self.cmd.take_action(parsed_args)
        self.qos_mock.get.assert_called_with(
            volume_fakes.qos_id
        )

        collist = (
            'associations',
            'consumer',
            'id',
            'name',
            'specs'
        )
        self.assertEqual(collist, columns)
        datalist = (
            volume_fakes.type_name,
            volume_fakes.qos_consumer,
            volume_fakes.qos_id,
            volume_fakes.qos_name,
            utils.format_dict(volume_fakes.qos_specs),
        )
        self.assertEqual(datalist, tuple(data))
    def take_action(self, parsed_args):
        self.log.debug('take_action(%s)' % parsed_args)

        volume_client = self.app.client_manager.volume

        source_volume = None
        if parsed_args.source:
            source_volume = utils.find_resource(
                volume_client.volumes,
                parsed_args.source,
            ).id

        volume = volume_client.volumes.create(
            parsed_args.size,
            parsed_args.snapshot_id,
            source_volume,
            parsed_args.name,
            parsed_args.description,
            parsed_args.volume_type,
            parsed_args.user_id,
            parsed_args.project_id,
            parsed_args.availability_zone,
            parsed_args.property,
            parsed_args.image
        )
        # Map 'metadata' column to 'properties'
        volume._info.update(
            {'properties': utils.format_dict(volume._info.pop('metadata'))}
        )

        return zip(*sorted(six.iteritems(volume._info)))
예제 #10
0
    def test_qos_list(self):
        arglist = []
        verifylist = []

        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        columns, data = self.cmd.take_action(parsed_args)
        self.qos_mock.list.assert_called_with()

        collist = (
            'ID',
            'Name',
            'Consumer',
            'Associations',
            'Specs',
        )
        self.assertEqual(collist, columns)
        datalist = ((
            volume_fakes.qos_id,
            volume_fakes.qos_name,
            volume_fakes.qos_consumer,
            volume_fakes.type_name,
            utils.format_dict(volume_fakes.qos_specs),
        ), )
        self.assertEqual(datalist, tuple(data))
    def test_qos_list(self):
        arglist = []
        verifylist = []

        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        columns, data = self.cmd.take_action(parsed_args)
        self.qos_mock.list.assert_called_with()

        collist = (
            'ID',
            'Name',
            'Consumer',
            'Associations',
            'Specs',
        )
        self.assertEqual(collist, columns)
        datalist = ((
            volume_fakes.qos_id,
            volume_fakes.qos_name,
            volume_fakes.qos_consumer,
            volume_fakes.type_name,
            utils.format_dict(volume_fakes.qos_specs),
        ), )
        self.assertEqual(datalist, tuple(data))
예제 #12
0
 def take_action(self, parsed_args):
     volume_client = self.app.client_manager.volume
     snapshot = utils.find_resource(volume_client.volume_snapshots,
                                    parsed_args.snapshot)
     snapshot._info.update(
         {'properties': utils.format_dict(snapshot._info.pop('metadata'))})
     return zip(*sorted(six.iteritems(snapshot._info)))
    def test_qos_show(self):
        arglist = [
            volume_fakes.qos_id
        ]
        verifylist = [
            ('qos_spec', volume_fakes.qos_id)
        ]

        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        columns, data = self.cmd.take_action(parsed_args)
        self.qos_mock.get.assert_called_with(
            volume_fakes.qos_id
        )

        collist = (
            'associations',
            'consumer',
            'id',
            'name',
            'specs'
        )
        self.assertEqual(collist, columns)
        datalist = (
            volume_fakes.type_name,
            volume_fakes.qos_consumer,
            volume_fakes.qos_id,
            volume_fakes.qos_name,
            utils.format_dict(volume_fakes.qos_specs),
        )
        self.assertEqual(datalist, tuple(data))
예제 #14
0
class TestQosShow(TestQos):

    qos_spec = volume_fakes.FakeQos.create_one_qos()
    qos_association = volume_fakes.FakeQos.create_one_qos_association()

    columns = ('associations', 'consumer', 'id', 'name', 'specs')
    data = (
        qos_association.name,
        qos_spec.consumer,
        qos_spec.id,
        qos_spec.name,
        utils.format_dict(qos_spec.specs),
    )

    def setUp(self):
        super(TestQosShow, self).setUp()

        self.qos_mock.get.return_value = self.qos_spec
        self.qos_mock.get_associations.return_value = [self.qos_association]

        # Get the command object to test
        self.cmd = qos_specs.ShowQos(self.app, None)

    def test_qos_show(self):
        arglist = [self.qos_spec.id]
        verifylist = [('qos_spec', self.qos_spec.id)]

        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        columns, data = self.cmd.take_action(parsed_args)
        self.qos_mock.get.assert_called_with(self.qos_spec.id)

        self.assertEqual(self.columns, columns)
        self.assertEqual(self.data, tuple(data))
예제 #15
0
 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})
     return zip(*sorted(six.iteritems(volume_type._info)))
예제 #16
0
    def take_action(self, parsed_args):
        self.log.debug('take_action(%s)', parsed_args)

        identity_client = self.app.client_manager.identity
        image_client = self.app.client_manager.image
        volume_client = self.app.client_manager.volume

        source_volume = None
        if parsed_args.source:
            source_volume = utils.find_resource(
                volume_client.volumes,
                parsed_args.source,
            ).id

        project = None
        if parsed_args.project:
            project = utils.find_resource(
                identity_client.tenants,
                parsed_args.project,
            ).id

        user = None
        if parsed_args.user:
            user = utils.find_resource(
                identity_client.users,
                parsed_args.user,
            ).id

        image = None
        if parsed_args.image:
            image = utils.find_resource(
                image_client.images,
                parsed_args.image,
            ).id

        snapshot = parsed_args.snapshot or parsed_args.snapshot_id

        volume = volume_client.volumes.create(
            parsed_args.size,
            snapshot,
            source_volume,
            parsed_args.name,
            parsed_args.description,
            parsed_args.type,
            user,
            project,
            parsed_args.availability_zone,
            parsed_args.property,
            image,
        )
        # Map 'metadata' column to 'properties'
        volume._info.update(
            {
                'properties': utils.format_dict(volume._info.pop('metadata')),
                'type': volume._info.pop('volume_type'),
            },
        )

        return zip(*sorted(six.iteritems(volume._info)))
예제 #17
0
    def take_action(self, parsed_args):
        self.log.debug("take_action: (%s)", parsed_args)

        identity_client = self.app.client_manager.identity
        volume_client = self.app.client_manager.volume
        image_client = self.app.client_manager.image

        source_volume = None
        if parsed_args.source:
            source_volume = utils.find_resource(
                volume_client.volumes,
                parsed_args.source).id

        image = None
        if parsed_args.image:
            image = utils.find_resource(
                image_client.images,
                parsed_args.image).id

        snapshot = None
        if parsed_args.snapshot:
            snapshot = utils.find_resource(
                volume_client.snapshots,
                parsed_args.snapshot).id

        project = None
        if parsed_args.project:
            project = utils.find_resource(
                identity_client.projects,
                parsed_args.project).id

        user = None
        if parsed_args.user:
            user = utils.find_resource(
                identity_client.users,
                parsed_args.user).id

        volume = volume_client.volumes.create(
            size=parsed_args.size,
            snapshot_id=snapshot,
            name=parsed_args.name,
            description=parsed_args.description,
            volume_type=parsed_args.type,
            user_id=user,
            project_id=project,
            availability_zone=parsed_args.availability_zone,
            metadata=parsed_args.property,
            imageRef=image,
            source_volid=source_volume
        )
        # Remove key links from being displayed
        volume._info.update(
            {
                'properties': utils.format_dict(volume._info.pop('metadata')),
                'type': volume._info.pop('volume_type')
            }
        )
        volume._info.pop("links", None)
        return zip(*sorted(six.iteritems(volume._info)))
예제 #18
0
    def take_action(self, parsed_args):
        self.log.debug("take_action: (%s)", parsed_args)

        identity_client = self.app.client_manager.identity
        volume_client = self.app.client_manager.volume
        image_client = self.app.client_manager.image

        source_volume = None
        if parsed_args.source:
            source_volume = utils.find_resource(
                volume_client.volumes,
                parsed_args.source).id

        image = None
        if parsed_args.image:
            image = utils.find_resource(
                image_client.images,
                parsed_args.image).id

        snapshot = None
        if parsed_args.snapshot:
            snapshot = utils.find_resource(
                volume_client.snapshots,
                parsed_args.snapshot).id

        project = None
        if parsed_args.project:
            project = utils.find_resource(
                identity_client.projects,
                parsed_args.project).id

        user = None
        if parsed_args.user:
            user = utils.find_resource(
                identity_client.users,
                parsed_args.user).id

        volume = volume_client.volumes.create(
            size=parsed_args.size,
            snapshot_id=snapshot,
            name=parsed_args.name,
            description=parsed_args.description,
            volume_type=parsed_args.type,
            user_id=user,
            project_id=project,
            availability_zone=parsed_args.availability_zone,
            metadata=parsed_args.property,
            imageRef=image,
            source_volid=source_volume
        )
        # Remove key links from being displayed
        volume._info.update(
            {
                'properties': utils.format_dict(volume._info.pop('metadata')),
                'type': volume._info.pop('volume_type')
            }
        )
        volume._info.pop("links", None)
        return zip(*sorted(six.iteritems(volume._info)))
예제 #19
0
    def take_action(self, parsed_args):

        data = self.app.client_manager.object_store.container_show(
            container=parsed_args.container, )
        if 'properties' in data:
            data['properties'] = utils.format_dict(data.pop('properties'))

        return zip(*sorted(six.iteritems(data)))
예제 #20
0
 def take_action(self, parsed_args):
     volume_client = self.app.client_manager.volume
     snapshot = utils.find_resource(
         volume_client.volume_snapshots, parsed_args.snapshot)
     snapshot._info.update(
         {'properties': utils.format_dict(snapshot._info.pop('metadata'))}
     )
     return zip(*sorted(six.iteritems(snapshot._info)))
예제 #21
0
    def take_action(self, parsed_args):
        image_client = self.app.client_manager.image
        image = utils.find_resource(image_client.images, parsed_args.image)

        info = {}
        info.update(image._info)
        info["properties"] = utils.format_dict(info.get("properties", {}))
        return zip(*sorted(six.iteritems(info)))
예제 #22
0
    def take_action(self, parsed_args):

        identity_client = self.app.client_manager.identity
        image_client = self.app.client_manager.image
        volume_client = self.app.client_manager.volume

        source_volume = None
        if parsed_args.source:
            source_volume = utils.find_resource(
                volume_client.volumes,
                parsed_args.source,
            ).id

        project = None
        if parsed_args.project:
            project = utils.find_resource(
                identity_client.tenants,
                parsed_args.project,
            ).id

        user = None
        if parsed_args.user:
            user = utils.find_resource(
                identity_client.users,
                parsed_args.user,
            ).id

        image = None
        if parsed_args.image:
            image = utils.find_resource(
                image_client.images,
                parsed_args.image,
            ).id

        snapshot = parsed_args.snapshot or parsed_args.snapshot_id

        volume = volume_client.volumes.create(
            parsed_args.size,
            snapshot,
            source_volume,
            parsed_args.name,
            parsed_args.description,
            parsed_args.type,
            user,
            project,
            parsed_args.availability_zone,
            parsed_args.property,
            image,
        )
        # Map 'metadata' column to 'properties'
        volume._info.update(
            {
                'properties': utils.format_dict(volume._info.pop('metadata')),
                'type': volume._info.pop('volume_type'),
            },
        )

        return zip(*sorted(six.iteritems(volume._info)))
예제 #23
0
    def take_action(self, parsed_args):
        compute_client = self.app.client_manager.compute
        resource_flavor = _find_flavor(compute_client, parsed_args.flavor)
        flavor = resource_flavor._info.copy()
        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):

        data = self.app.client_manager.object_store.container_show(
            container=parsed_args.container,
        )
        if 'properties' in data:
            data['properties'] = utils.format_dict(data.pop('properties'))

        return zip(*sorted(six.iteritems(data)))
예제 #25
0
    def take_action(self, parsed_args):
        compute_client = self.app.client_manager.compute
        resource_flavor = _find_flavor(compute_client, parsed_args.flavor)
        flavor = resource_flavor._info.copy()
        flavor.pop("links", None)

        flavor['properties'] = utils.format_dict(resource_flavor.get_keys())

        return zip(*sorted(six.iteritems(flavor)))
예제 #26
0
    def take_action(self, parsed_args):
        compute_client = self.app.client_manager.compute

        server = utils.find_resource(
            compute_client.servers,
            parsed_args.server,
        )

        # Set sane defaults as this API wants all mouths to be fed
        if parsed_args.name is None:
            backup_name = server.name
        else:
            backup_name = parsed_args.name
        if parsed_args.type is None:
            backup_type = ""
        else:
            backup_type = parsed_args.type
        if parsed_args.rotate is None:
            backup_rotation = 1
        else:
            backup_rotation = parsed_args.rotate

        compute_client.servers.backup(
            server.id,
            backup_name,
            backup_type,
            backup_rotation,
        )

        image_client = self.app.client_manager.image
        image = utils.find_resource(
            image_client.images,
            backup_name,
        )

        if parsed_args.wait:
            if utils.wait_for_status(
                    image_client.images.get,
                    image.id,
                    callback=_show_progress,
            ):
                sys.stdout.write('\n')
            else:
                msg = _('Error creating server backup: %s') % parsed_args.name
                raise exceptions.CommandError(msg)

        if self.app.client_manager._api_version['image'] == '1':
            info = {}
            info.update(image._info)
            info['properties'] = utils.format_dict(info.get('properties', {}))
        else:
            # Get the right image module to format the output
            image_module = importutils.import_module(self.IMAGE_API_VERSIONS[
                self.app.client_manager._api_version['image']])
            info = image_module._format_image(image)
        return zip(*sorted(six.iteritems(info)))
예제 #27
0
    def take_action(self, parsed_args):
        self.log.debug('take_action(%s)' % parsed_args)
        volume_client = self.app.client_manager.volume
        volume = utils.find_resource(volume_client.volumes, parsed_args.volume)
        # Map 'metadata' column to 'properties'
        volume._info.update(
            {'properties': utils.format_dict(volume._info.pop('metadata'))}
        )

        return zip(*sorted(volume._info.iteritems()))
예제 #28
0
    def take_action(self, parsed_args):
        volume_client = self.app.client_manager.volume
        volume_type = volume_client.volume_types.create(parsed_args.name)
        volume_type._info.pop('extra_specs')
        if parsed_args.property:
            result = volume_type.set_keys(parsed_args.property)
            volume_type._info.update({'properties': utils.format_dict(result)})

        info = {}
        info.update(volume_type._info)
        return zip(*sorted(six.iteritems(info)))
예제 #29
0
    def take_action(self, parsed_args):
        volume_client = self.app.client_manager.volume
        volume_type = volume_client.volume_types.create(parsed_args.name)
        volume_type._info.pop('extra_specs')
        if parsed_args.property:
            result = volume_type.set_keys(parsed_args.property)
            volume_type._info.update({'properties': utils.format_dict(result)})

        info = {}
        info.update(volume_type._info)
        return zip(*sorted(six.iteritems(info)))
예제 #30
0
    def take_action(self, parsed_args):
        image_client = self.app.client_manager.image
        image = utils.find_resource(
            image_client.images,
            parsed_args.image,
        )

        info = {}
        info.update(image._info)
        info['properties'] = utils.format_dict(info.get('properties', {}))
        return zip(*sorted(six.iteritems(info)))
예제 #31
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)", parsed_args)
        compute_client = self.app.client_manager.compute
        resource_flavor = compute_client.flavors.find(name=parsed_args.flavor)

        resource_flavor.unset_keys(parsed_args.property)

        flavor = resource_flavor._info.copy()
        flavor['properties'] = utils.format_dict(resource_flavor.get_keys())
        flavor.pop("links", None)
        return zip(*sorted(six.iteritems(flavor)))
예제 #32
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)", parsed_args)
        compute_client = self.app.client_manager.compute
        resource_flavor = compute_client.flavors.find(name=parsed_args.flavor)

        resource_flavor.unset_keys(parsed_args.property)

        flavor = resource_flavor._info.copy()
        flavor['properties'] = utils.format_dict(resource_flavor.get_keys())
        flavor.pop("links", None)
        return zip(*sorted(six.iteritems(flavor)))
예제 #33
0
    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)))
예제 #34
0
    def take_action(self, parsed_args):
        volume_client = self.app.client_manager.volume
        volume_id = utils.find_resource(volume_client.volumes,
                                        parsed_args.volume).id
        snapshot = volume_client.volume_snapshots.create(
            volume_id, parsed_args.force, parsed_args.name,
            parsed_args.description)

        snapshot._info.update(
            {'properties': utils.format_dict(snapshot._info.pop('metadata'))})

        return zip(*sorted(six.iteritems(snapshot._info)))
예제 #35
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)" % parsed_args)
        volume_client = self.app.client_manager.volume
        volume_type = volume_client.volume_types.create(parsed_args.name)
        if parsed_args.property:
            volume_type.set_keys(parsed_args.property)
        # Map 'extra_specs' column to 'properties'
        volume_type._info.update({"properties": utils.format_dict(volume_type._info.pop("extra_specs"))})

        info = {}
        info.update(volume_type._info)
        return zip(*sorted(six.iteritems(info)))
예제 #36
0
    def setUp(self):
        super(TestTypeShow, self).setUp()

        self.volume_type = volume_fakes.FakeType.create_one_type()
        self.data = (self.volume_type.description, self.volume_type.id,
                     self.volume_type.name,
                     utils.format_dict(self.volume_type.extra_specs))

        self.types_mock.get.return_value = self.volume_type

        # Get the command object to test
        self.cmd = volume_type.ShowVolumeType(self.app, None)
예제 #37
0
 def take_action(self, parsed_args):
     self.log.debug('take_action(%s)' % parsed_args)
     volume_client = self.app.client_manager.volume
     volume = utils.find_resource(volume_client.volumes, parsed_args.volume)
     # Map 'metadata' column to 'properties'
     volume._info.update(
         {'properties': utils.format_dict(volume._info.pop('metadata'))})
     if 'os-vol-tenant-attr:tenant_id' in volume._info:
         volume._info.update({
             'project_id':
             volume._info.pop('os-vol-tenant-attr:tenant_id')
         })
     return zip(*sorted(six.iteritems(volume._info)))
예제 #38
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)", parsed_args)

        image_client = self.app.client_manager.image
        image = utils.find_resource(
            image_client.images,
            parsed_args.image,
        )

        info = {}
        info.update(image._info)
        info['properties'] = utils.format_dict(info.get('properties', {}))
        return zip(*sorted(six.iteritems(info)))
예제 #39
0
def _prep_server_detail(compute_client, server):
    """Prepare the detailed server dict for printing

    :param compute_client: a compute client instance
    :param server: a Server resource
    :rtype: a dict of server details
    """
    info = server._info.copy()

    # Call .get() to retrieve all of the server information
    # as findall(name=blah) and REST /details are not the same
    # and do not return flavor and image information.
    server = compute_client.servers.get(info['id'])
    info.update(server._info)

    # Convert the image blob to a name
    image_info = info.get('image', {})
    if image_info:
        image_id = image_info.get('id', '')
        try:
            image = utils.find_resource(compute_client.images, image_id)
            info['image'] = "%s (%s)" % (image.name, image_id)
        except Exception:
            info['image'] = image_id

    # Convert the flavor blob to a name
    flavor_info = info.get('flavor', {})
    flavor_id = flavor_info.get('id', '')
    try:
        flavor = utils.find_resource(compute_client.flavors, flavor_id)
        info['flavor'] = "%s (%s)" % (flavor.name, flavor_id)
    except Exception:
        info['flavor'] = flavor_id

    # NOTE(dtroyer): novaclient splits these into separate entries...
    # Format addresses in a useful way
    info['addresses'] = _format_servers_list_networks(server.networks)

    # Map 'metadata' field to 'properties'
    info.update(
        {'properties': utils.format_dict(info.pop('metadata'))}
    )

    # Migrate tenant_id to project_id naming
    if 'tenant_id' in info:
        info['project_id'] = info.pop('tenant_id')

    # Remove values that are long and not too useful
    info.pop('links', None)

    return info
    def take_action(self, parsed_args):
        self.log.debug('take_action(%s)', parsed_args)

        identity_client = self.app.client_manager.identity
        image_client = self.app.client_manager.image
        volume_client = self.app.client_manager.volume

        source_volume = None
        if parsed_args.source_volid:
            source_volume = utils.find_resource(
                volume_client.volumes,
                parsed_args.source_volid,
            ).id

        project = None
        if parsed_args.project:
            project = utils.find_resource(
                identity_client.projects,
                parsed_args.project,
            ).id

        image = None
        if parsed_args.imageRef:
            image = image_client.images.get(parsed_args.imageRef)

        volume = volume_client.volumes.create(
            size=parsed_args.size,
            consistencygroup_id=None, 
            snapshot_id=parsed_args.snapshot_id,
            source_volid=source_volume,
            name=parsed_args.name,
            description=parsed_args.description,
            volume_type=parsed_args.volume_type,
            user_id=parsed_args.user,
            project_id=project,
            availability_zone=parsed_args.availability_zone,
            metadata=parsed_args.metadata,
            imageRef=image.id,
            scheduler_hints=None,
            source_replica=None, 
            multiattach=False
        )
        # Map 'metadata' column to 'properties'
        volume._info.update(
            {
                'properties': utils.format_dict(volume._info.pop('metadata')),
                'type': volume._info.pop('volume_type'),
            },
        )

        return zip(*sorted(six.iteritems(volume._info)))
예제 #41
0
 def take_action(self, parsed_args):
     volume_client = self.app.client_manager.volume
     volume_id = utils.find_resource(
         volume_client.volumes, parsed_args.volume).id
     snapshot = volume_client.volume_snapshots.create(
         volume_id,
         force=parsed_args.force,
         name=parsed_args.name,
         description=parsed_args.description
     )
     snapshot._info.update(
         {'properties': utils.format_dict(snapshot._info.pop('metadata'))}
     )
     return zip(*sorted(six.iteritems(snapshot._info)))
예제 #42
0
    def take_action(self, parsed_args):
        volume_client = self.app.client_manager.volume
        volume = utils.find_resource(volume_client.volumes, parsed_args.volume)

        # Special mapping for columns to make the output easier to read:
        # 'metadata' --> 'properties'
        # 'volume_type' --> 'type'
        volume._info.update(
            {"properties": utils.format_dict(volume._info.pop("metadata")), "type": volume._info.pop("volume_type")}
        )

        # Remove key links from being displayed
        volume._info.pop("links", None)
        return zip(*sorted(six.iteritems(volume._info)))
    def take_action(self, parsed_args):

        compute_client = self.app.client_manager.compute
        info = {}
        info.update(utils.find_resource(compute_client.security_groups, parsed_args.group)._info)
        rules = []
        for r in info["rules"]:
            rules.append(utils.format_dict(_xform_security_group_rule(r)))

        # Format rules into a list of strings
        info.update({"rules": rules})
        # Map 'tenant_id' column to 'project_id'
        info.update({"project_id": info.pop("tenant_id")})

        return zip(*sorted(six.iteritems(info)))
def _format_compute_security_group_rule(sg_rule):
    info = network_utils.transform_compute_security_group_rule(sg_rule)
    # Trim parent security group ID since caller has this information.
    info.pop('parent_group_id', None)
    # Trim keys with empty string values.
    keys_to_trim = [
        'ip_protocol',
        'ip_range',
        'port_range',
        'remote_security_group',
    ]
    for key in keys_to_trim:
        if key in info and not info[key]:
            info.pop(key)
    return utils.format_dict(info)
예제 #45
0
    def take_action(self, parsed_args):
        self.log.debug('take_action(%s)' % parsed_args)
        volume_client = self.app.client_manager.volume
        volume_type = volume_client.volume_types.create(parsed_args.name)
        if parsed_args.property:
            volume_type.set_keys(parsed_args.property)
        # Map 'extra_specs' column to 'properties'
        volume_type._info.update({
            'properties':
            utils.format_dict(volume_type._info.pop('extra_specs'))
        })

        info = {}
        info.update(volume_type._info)
        return zip(*sorted(six.iteritems(info)))
    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 _format_compute_security_group_rule(sg_rule):
    info = network_utils.transform_compute_security_group_rule(sg_rule)
    # Trim parent security group ID since caller has this information.
    info.pop('parent_group_id', None)
    # Trim keys with empty string values.
    keys_to_trim = [
        'ip_protocol',
        'ip_range',
        'port_range',
        'remote_security_group',
    ]
    for key in keys_to_trim:
        if key in info and not info[key]:
            info.pop(key)
    return utils.format_dict(info)
    def take_action(self, parsed_args):
        self.log.debug('take_action(%s)', parsed_args)
        volume_client = self.app.client_manager.volume
        qos_specs = utils.find_resource(volume_client.qos_specs,
                                        parsed_args.qos_specs)

        qos_associations = volume_client.qos_specs.get_associations(qos_specs)
        if qos_associations:
            associations = [association.name
                            for association in qos_associations]
            qos_specs._info.update({
                'associations': utils.format_list(associations)
            })
        qos_specs._info.update({'specs': utils.format_dict(qos_specs.specs)})

        return zip(*sorted(six.iteritems(qos_specs._info)))
예제 #49
0
    def take_action(self, parsed_args):
        volume_client = self.app.client_manager.volume
        volume = utils.find_resource(volume_client.volumes, parsed_args.volume)

        # Special mapping for columns to make the output easier to read:
        # 'metadata' --> 'properties'
        # 'volume_type' --> 'type'
        volume._info.update(
            {
                'properties': utils.format_dict(volume._info.pop('metadata')),
                'type': volume._info.pop('volume_type'),
            }, )

        # Remove key links from being displayed
        volume._info.pop("links", None)
        return zip(*sorted(six.iteritems(volume._info)))
예제 #50
0
 def take_action(self, parsed_args):
     volume_client = self.app.client_manager.volume
     volume = utils.find_resource(volume_client.volumes, parsed_args.volume)
     # Map 'metadata' column to 'properties'
     volume._info.update(
         {
             'properties': utils.format_dict(volume._info.pop('metadata')),
             'type': volume._info.pop('volume_type'),
         },
     )
     if 'os-vol-tenant-attr:tenant_id' in volume._info:
         volume._info.update(
             {'project_id': volume._info.pop(
                 'os-vol-tenant-attr:tenant_id')}
         )
     return zip(*sorted(six.iteritems(volume._info)))
예제 #51
0
class TestTypeList(TestType):

    volume_types = volume_fakes.FakeType.create_types()

    columns = ["ID", "Name"]
    columns_long = columns + ["Description", "Properties"]

    data = []
    for t in volume_types:
        data.append((
            t.id,
            t.name,
        ))
    data_long = []
    for t in volume_types:
        data_long.append((
            t.id,
            t.name,
            t.description,
            utils.format_dict(t.extra_specs),
        ))

    def setUp(self):
        super(TestTypeList, self).setUp()

        self.types_mock.list.return_value = self.volume_types
        # get the command to test
        self.cmd = volume_type.ListVolumeType(self.app, None)

    def test_type_list_without_options(self):
        arglist = []
        verifylist = [("long", False)]
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        columns, data = self.cmd.take_action(parsed_args)
        self.assertEqual(self.columns, columns)
        self.assertEqual(self.data, list(data))

    def test_type_list_with_options(self):
        arglist = ["--long"]
        verifylist = [("long", True)]
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        columns, data = self.cmd.take_action(parsed_args)
        self.assertEqual(self.columns_long, columns)
        self.assertEqual(self.data_long, list(data))
예제 #52
0
    def take_action(self, parsed_args):

        volume_client = self.app.client_manager.volume

        kwargs = {}
        if parsed_args.public:
            kwargs["is_public"] = True
        if parsed_args.private:
            kwargs["is_public"] = False

        volume_type = volume_client.volume_types.create(parsed_args.name, description=parsed_args.description, **kwargs)
        volume_type._info.pop("extra_specs")
        if parsed_args.property:
            result = volume_type.set_keys(parsed_args.property)
            volume_type._info.update({"properties": utils.format_dict(result)})

        return zip(*sorted(six.iteritems(volume_type._info)))
예제 #53
0
    def take_action(self, parsed_args):

        volume_client = self.app.client_manager.volume

        kwargs = {}
        if parsed_args.public:
            kwargs['is_public'] = True
        if parsed_args.private:
            kwargs['is_public'] = False

        volume_type = volume_client.volume_types.create(
            parsed_args.name, description=parsed_args.description, **kwargs)
        volume_type._info.pop('extra_specs')
        if parsed_args.property:
            result = volume_type.set_keys(parsed_args.property)
            volume_type._info.update({'properties': utils.format_dict(result)})

        return zip(*sorted(six.iteritems(volume_type._info)))
예제 #54
0
    def take_action(self, parsed_args):
        identity_client = self.app.client_manager.identity

        info = {}
        try:
            project = utils.find_resource(
                identity_client.tenants,
                parsed_args.project,
            )
            info.update(project._info)
        except ks_exc.Forbidden as e:
            auth_ref = self.app.client_manager.auth_ref
            if (
                parsed_args.project == auth_ref.project_id or
                parsed_args.project == auth_ref.project_name
            ):
                # Ask for currently auth'ed project so return it
                info = {
                    'id': auth_ref.project_id,
                    'name': auth_ref.project_name,
                    # True because we don't get this far if it is disabled
                    'enabled': True,
                }
            else:
                raise e

        # TODO(stevemar): Remove the line below when we support multitenancy
        info.pop('parent_id', None)

        # NOTE(stevemar): Property handling isn't really supported in Keystone
        # and needs a lot of extra handling. Let's reserve the properties that
        # the API has and handle the extra top level properties.
        reserved = ('name', 'id', 'enabled', 'description')
        properties = {}
        for k, v in info.items():
            if k not in reserved:
                # If a key is not in `reserved` it's a property, pop it
                info.pop(k)
                # If a property has been "unset" it's `None`, so don't show it
                if v is not None:
                    properties[k] = v

        info['properties'] = utils.format_dict(properties)
        return zip(*sorted(six.iteritems(info)))
예제 #55
0
def _prep_server_detail(compute_client, server):
    """Prepare the detailed server dict for printing

    :param compute_client: a compute client instance
    :param server: a Server resource
    :rtype: a dict of server details
    """
    info = server._info.copy()

    # Call .get() to retrieve all of the server information
    # as findall(name=blah) and REST /details are not the same
    # and do not return flavor and image information.
    server = compute_client.servers.get(info['id'])
    info.update(server._info)

    # Convert the image blob to a name
    image_info = info.get('image', {})
    if image_info:
        image_id = image_info.get('id', '')
        image = utils.find_resource(compute_client.images, image_id)
        info['image'] = "%s (%s)" % (image.name, image_id)

    # Convert the flavor blob to a name
    flavor_info = info.get('flavor', {})
    flavor_id = flavor_info.get('id', '')
    flavor = utils.find_resource(compute_client.flavors, flavor_id)
    info['flavor'] = "%s (%s)" % (flavor.name, flavor_id)

    # NOTE(dtroyer): novaclient splits these into separate entries...
    # Format addresses in a useful way
    info['addresses'] = _format_servers_list_networks(server.networks)

    # Map 'metadata' field to 'properties'
    info.update({'properties': utils.format_dict(info.pop('metadata'))})

    # Migrate tenant_id to project_id naming
    if 'tenant_id' in info:
        info['project_id'] = info.pop('tenant_id')

    # Remove values that are long and not too useful
    info.pop('links', None)

    return info
    def setUp(self):
        super(TestSnapshotShow, self).setUp()

        self.snapshot = volume_fakes.FakeSnapshot.create_one_snapshot()

        self.data = (
            self.snapshot.created_at,
            self.snapshot.description,
            self.snapshot.id,
            self.snapshot.name,
            utils.format_dict(self.snapshot.metadata),
            self.snapshot.size,
            self.snapshot.status,
            self.snapshot.volume_id,
        )

        self.snapshots_mock.get.return_value = self.snapshot
        # Get the command object to test
        self.cmd = snapshot.ShowSnapshot(self.app, None)
예제 #57
0
    def take_action(self, parsed_args):

        compute_client = self.app.client_manager.compute
        info = {}
        info.update(
            utils.find_resource(
                compute_client.security_groups,
                parsed_args.group,
            )._info)
        rules = []
        for r in info['rules']:
            rules.append(utils.format_dict(_xform_security_group_rule(r)))

        # Format rules into a list of strings
        info.update({'rules': rules})
        # Map 'tenant_id' column to 'project_id'
        info.update({'project_id': info.pop('tenant_id')})

        return zip(*sorted(six.iteritems(info)))
예제 #58
0
class TestQosList(TestQos):

    qos_specs = volume_fakes.FakeQos.create_qoses(count=2)
    qos_association = volume_fakes.FakeQos.create_one_qos_association()

    columns = (
        'ID',
        'Name',
        'Consumer',
        'Associations',
        'Specs',
    )
    data = []
    for q in qos_specs:
        data.append((
            q.id,
            q.name,
            q.consumer,
            qos_association.name,
            utils.format_dict(q.specs),
        ))

    def setUp(self):
        super(TestQosList, self).setUp()

        self.qos_mock.list.return_value = self.qos_specs
        self.qos_mock.get_associations.return_value = [self.qos_association]

        # Get the command object to test
        self.cmd = qos_specs.ListQos(self.app, None)

    def test_qos_list(self):
        arglist = []
        verifylist = []

        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        columns, data = self.cmd.take_action(parsed_args)
        self.qos_mock.list.assert_called_with()

        self.assertEqual(self.columns, columns)
        self.assertEqual(self.data, list(data))
    def test_volume_list_long(self):
        arglist = [
            '--long',
        ]
        verifylist = [
            ('long', True),
            ('all_projects', False),
            ('name', None),
            ('status', None),
        ]

        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        columns, data = self.cmd.take_action(parsed_args)

        collist = [
            'ID',
            'Display Name',
            'Status',
            'Size',
            'Type',
            'Bootable',
            'Attached to',
            'Properties',
        ]
        self.assertEqual(collist, columns)

        server = self.mock_volume.attachments[0]['server_id']
        device = self.mock_volume.attachments[0]['device']
        msg = 'Attached to %s on %s ' % (server, device)
        datalist = ((
            self.mock_volume.id,
            self.mock_volume.name,
            self.mock_volume.status,
            self.mock_volume.size,
            self.mock_volume.volume_type,
            self.mock_volume.bootable,
            msg,
            utils.format_dict(self.mock_volume.metadata),
        ), )
        self.assertEqual(datalist, tuple(data))