def take_action(self, parsed_args): self.log.debug('take_action(%s)', parsed_args) client = self.app.client_manager.warre if parsed_args.private and parsed_args.public: raise exceptions.CommandError( "Can't specify --private and --public") if parsed_args.active and parsed_args.disable: raise exceptions.CommandError( "Can't specify --active and --disable") flavor = self._get_flavor(parsed_args.id) data = {} if parsed_args.description: data['description'] = parsed_args.description if parsed_args.max_length_hours: data['max_length_hours'] = parsed_args.max_length_hours if parsed_args.slots: data['slots'] = parsed_args.slots if parsed_args.public: data['is_public'] = True if parsed_args.private: data['is_public'] = False if parsed_args.active: data['active'] = True if parsed_args.disable: data['active'] = False flavor = client.flavors.update(flavor_id=parsed_args.id, **data) flavor_dict = flavor.to_dict() return self.dict2columns(flavor_dict)
def _get_flavor(self, id): client = self.app.client_manager.warre try: flavor = client.flavors.get(id) except exceptions.NotFound as ex: raise exceptions.CommandError(str(ex)) return flavor
def take_action(self, parsed_args): self.log.debug('take_action(%s)', parsed_args) client = self.app.client_manager.warre is_public = not parsed_args.private active = not parsed_args.disable try: extra_specs = json.loads(parsed_args.extra_specs) \ if parsed_args.extra_specs else parsed_args.extra_specs except json.JSONDecodeError: raise exceptions.CommandError("Extra specs not valid json") fields = { 'name': parsed_args.name, 'vcpu': parsed_args.vcpu, 'memory_mb': parsed_args.memory, 'disk_gb': parsed_args.disk, 'description': parsed_args.description, 'active': active, 'properties': parsed_args.properties, 'max_length_hours': parsed_args.max_length_hours, 'slots': parsed_args.slots, 'is_public': is_public, 'extra_specs': extra_specs } flavor = client.flavors.create(**fields) flavor_dict = flavor.to_dict() return self.dict2columns(flavor_dict)
def format_parameters(params, parse_semicolon=True): '''Reformat parameters into dict of format expected by the API.''' if not params: return {} if parse_semicolon: # expect multiple invocations of --parameters but fall back # to ; delimited if only one --parameters is specified if len(params) == 1: params = params[0].split(';') parameters = {} for p in params: try: (n, v) = p.split(('='), 1) except ValueError: msg = 'Malformed parameter(%s). Use the key=value format.' % p raise exceptions.CommandError(msg) if n not in parameters: parameters[n] = v else: if not isinstance(parameters[n], list): parameters[n] = [parameters[n]] parameters[n].append(v) return parameters
def take_action(self, parsed_args): self.log.debug('take_action(%s)', parsed_args) client = self.app.client_manager.warre try: client.flavorprojects.delete(parsed_args.id) except exceptions.NotFound as ex: raise exceptions.CommandError(str(ex)) return [], []
def take_action(self, parsed_args): self.log.debug('take_action(%s)', parsed_args) client = self.app.client_manager.warre try: reservation = client.reservations.get(parsed_args.id) except exceptions.NotFound as ex: raise exceptions.CommandError(str(ex)) return self.dict2columns(reservation.to_dict())