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 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): 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']: formatted_rule = _xform_and_trim_security_group_rule(r) rules.append(utils.format_dict(formatted_rule)) # Format rules into a list of strings info.update({'rules': utils.format_list(rules, separator='\n')}) # Map 'tenant_id' column to 'project_id' info.update({'project_id': info.pop('tenant_id')}) return zip(*sorted(six.iteritems(info)))
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