def get_parser(self, prog_name): parser = super(ListBackupDownloadLinks, self).get_parser(prog_name) parser.add_argument('backup_id', metavar='<backup_id>', help=_('ID of the backup')) return parser
class ListMetrics(command.Lister): _description = _('List CES Metrics') columns = ( 'namespace', 'dimensions', 'metric_name', 'unit', ) table_columns = ( 'namespace', 'dimensions.name', 'dimensions.value', 'metric_name', 'unit', ) def get_parser(self, prog_name): parser = super(ListMetrics, self).get_parser(prog_name) parser.add_argument('--namespace', metavar='<namespace>', help=_('Namespace of the monitored object, e.g.\n' 'SYS.ECS, SYS.VPC')) parser.add_argument('--metric-name', metavar='<metric_name>', help=_('Name of the metrics object.')) parser.add_argument('--unit', metavar='<unit>', help=_('Unit which is measured.')) return parser def take_action(self, parsed_args): client = self.app.client_manager.ces query = {} if parsed_args.namespace: query['namespace'] = parsed_args.namespace if parsed_args.metric_name: query['metric_name'] = parsed_args.metric_name if parsed_args.unit: query['unit'] = parsed_args.unit data = client.metrics(**query) # Modify table output to provide a better metric overview. # Given data set is taken, splitted and flattened to build the table. table = () temp_list = [] big_list = [] for s in data: for item in utils.get_dict_properties(s, self.columns): if isinstance(item, (list)): temp_list.append(item[0].name) temp_list.append(item[0].value) else: temp_list.append(item) big_list.append(tuple(temp_list)) temp_list = [] table = (self.table_columns, big_list) return table
class CreateDMSInstanceTopic(command.ShowOne): _description = _('Create DMS Instance Topic') def get_parser(self, prog_name): parser = super(CreateDMSInstanceTopic, self).get_parser(prog_name) parser.add_argument( 'instance', metavar='<instance>', help=_('Instance ID or Name.') ) parser.add_argument( 'id', metavar='<id>', help=_('Name/ID of the topic.') ) parser.add_argument( '--partition', metavar='<part>', type=int, choices=range(1, 21), help=_( 'The number of topic partitions, which is used to set the ' 'number of concurrently consumed messages. ' 'Value range: 1–20. Default value: 3.') ) parser.add_argument( '--replication', metavar='<repl>', type=int, choices=range(1, 4), help=_( 'The number of replicas, which is configured to ensure data ' 'reliability. Value range: 1–3. Default value: 3.') ) parser.add_argument( '--retention-time', metavar='<hours>', type=int, choices=range(1, 169), default=72, help=_( 'The retention period of a message. Its default value is ' '72. Value range: 1–168. Default value: 72. Unit: hour.') ) parser.add_argument( '--enable-sync-flush', action='store_true', help=_( 'Whether to enable synchronous flushing. ' 'Default value: false. Synchronous flushing compromises ' 'performance.') ) parser.add_argument( '--enable-sync-replication', action='store_true', help=_( 'Whether to enable synchronous replication. After this ' 'function is enabled, the acks parameter on the producer ' 'client must be set to –1. Otherwise, this parameter does ' 'not take effect.') ) return parser def take_action(self, parsed_args): attrs = {} attrs['id'] = parsed_args.id for attr in ['partition', 'replication', 'retention_time']: val = getattr(parsed_args, attr) if val is not None: attrs[attr] = val if parsed_args.enable_sync_flush: attrs['is_sync_flush'] = True if parsed_args.enable_sync_replication: attrs['is_sync_replication'] = True client = self.app.client_manager.dms instance = client.find_instance(parsed_args.instance, ignore_missing=False) obj = client.create_topic(instance=instance, **attrs) display_columns, columns = _get_columns(obj) data = utils.get_item_properties(obj, columns) return (display_columns, data)
def get_parser(self, prog_name): parser = super(ListDnatRules, self).get_parser(prog_name) parser.add_argument( '--id', metavar='<id>', help=_("Specifies the ID of the SNAT rule."), ) parser.add_argument( '--limit', metavar='<limit>', type=int, help=_("Limit to fetch number of records."), ) parser.add_argument( '--project-id', metavar='<project_id>', help=_("Specifies the project ID."), ) parser.add_argument( '--nat-gateway-id', metavar='<nat_gateway_id>', help=_("Specifies the NAT gateway ID."), ) parser.add_argument( '--port-id', metavar='<port_id>', help=_("Specifies the port ID of an ECS or a BMS."), ) parser.add_argument( '--private-ip', metavar='<private_ip>', help=_("Specifies the private IP address, for example, " "the IP address of a Direct Connect connection."), ) parser.add_argument( '--internal-service-port', metavar='<internal_service_port>', help=_("Specifies port used by ECSs or BMSs to provide " "services for external systems."), ) parser.add_argument( '--floating-ip-id', metavar='<floating_ip_id>', help=_("Specifies the Floating IP ID."), ) parser.add_argument( '--floating-ip-address', metavar='<floating_ip_address>', help=_("Specifies the Floating IP."), ) parser.add_argument( '--external-service-port', metavar='<external_service_port>', help=_("Specifies the port for providing external services."), ) parser.add_argument( '--protocol', metavar='<protocol>', help=_("Specifies the protocol type." "Currently, TCP, UDP, and ANY are supported."), ) parser.add_argument( '--status', metavar='<status>', help=_("Specifies the status of the DNAT rule.\n" "ACTIVE: The resource status is normal.\n" "PENDING_CREATE: The resource is being created.\n" "PENDING_UPDATE: The resource is being updated.\n" "PENDING_DELETE: The resource is being deleted.\n" "EIP_FREEZED: The EIP of the resource is frozen.\n" "INACTIVE: The resource status is abnormal."), ) parser.add_argument( '--admin-state-up', metavar='<admin_state_up>', help=_("Specifies whether the DNAT rule is enabled or " "disabled. The value can be:\n" "true: The DNAT rule is enabled.\n" "false: The DNAT rule is disabled."), ) parser.add_argument( '--created-at', metavar='<created_at>', help=_("Specifies when the DNAT rule is created (UTC time). " "Its value rounds to 6 decimal places forseconds. " "The format is yyyy-mm-ddhh:mm:ss."), ) return parser
class SetListener(command.ShowOne): _description = _('Update a listener') def get_parser(self, prog_name): parser = super(SetListener, self).get_parser(prog_name) parser.add_argument('listener', metavar='<listener>', help=_('Listener to modify (ID).')) parser.add_argument('--name', metavar='<name>', help=_('Set the listener name.')) parser.add_argument('--description', metavar='<description>', help=_('Set the description of this listener.')) parser.add_argument( '--connection_limit', metavar='<connection_limit>', type=int, help=_('The maximum number of connections permitted for this ' 'listener. Default value is -1 which represents infinite ' 'connections.')) parser.add_argument( '--default_pool', metavar='<pool>', help=_('The ID of the pool used by the listener if no L7 policies ' 'match.')) parser.add_argument( '--default_tls_container_ref', metavar='<default_tls_container_ref>', help=_('The URI of the key manager service secret containing a ' 'PKCS12 format certificate/key bundle for TERMINATED_TLS ' 'listeners. DEPRECATED: A secret container of type ' '\"certificate\" containing the certificate and key ' 'for TERMINATED_TLS listeners.')) admin_group = parser.add_mutually_exclusive_group() admin_group.add_argument('--enable', action='store_true', default=True, help=_('Enable load balancer (default).')) admin_group.add_argument('--disable', action='store_true', default=None, help=_('Disable load balancer.')) return parser def take_action(self, parsed_args): args = {} if parsed_args.disable: args['is_admin_state_up'] = False if parsed_args.connection_limit: args['connection_limit'] = parsed_args.connection_limit if parsed_args.default_pool: args['default_pool_id'] = parsed_args.default_pool if parsed_args.default_tls_container_ref: args['default_tls_container_ref'] = \ parsed_args.default_tls_container_ref if parsed_args.description: args['description'] = parsed_args.description if parsed_args.name: args['name'] = parsed_args.name client = self.app.client_manager.network obj = client.update_listener(listener=parsed_args.listener, **args) display_columns, columns = _get_columns(obj) data = utils.get_item_properties(obj, columns, formatters=_formatters) return (display_columns, data)
class SetHealthMonitor(command.ShowOne): _description = _('Update a health monitor') def get_parser(self, prog_name): parser = super(SetHealthMonitor, self).get_parser(prog_name) parser.add_argument('health_monitor', metavar='<health_monitor>', help=_('Health monitor to update (name or ID).')) parser.add_argument('--name', metavar='<name>', help=_('Human-readable name of the resource.')) parser.add_argument( '--delay', metavar='<delay>', type=int, help=_('The time, in seconds, between sending probes to members.')) parser.add_argument( '--expected_codes', metavar='<expected_codes>', help=_('The list of HTTP status codes expected in response ' 'from the member to declare it healthy. Specify one ' 'of the following values:\n' '* A single value, such as 200\n' '* A list, such as 200, 202\n' '* A range, such as 200-204\n' 'The default is 200.')) parser.add_argument( '--http_method', metavar='{' + ','.join(HTTP_METHODS) + '}', choices=HTTP_METHODS, type=lambda s: s.upper(), # case insensitive help=_('The HTTP method that the health monitor uses for requests.' 'One of [`GET`, `HEAD`, `POST`, `PUT`, `DELETE`,' '`TRACE`, `OPTIONS`, `CONNECT`, `PATCH`]\n' 'Default is `GET`')) parser.add_argument( '--timeout', metavar='<timeout>', type=int, help=_('The maximum time, in seconds, that a monitor waits to ' 'connect before it times out. This value must be less ' 'than the delay value.')) parser.add_argument( '--max_retries', metavar='<max_retries>', type=int, required=True, choices=range(1, 10), help=_('The number of successful checks before changing the ' 'operating status of the member to `ONLINE`. ' 'A valid value is from 1 to 10.')) parser.add_argument( '--url_path', metavar='<url_path>', help=_('The HTTP URL path of the request sent by the monitor ' 'to test the health of a backend member. Must be a string ' 'that begins with a forward slash (/).' 'The default URL path is /.')) admin_group = parser.add_mutually_exclusive_group() admin_group.add_argument('--enable', action='store_true', default=True, help=_('Enable health monitor (default).')) admin_group.add_argument('--disable', action='store_true', default=None, help=_('Disable health monitor.')) return parser def take_action(self, parsed_args): args = {} if parsed_args.delay: args['delay'] = parsed_args.delay if parsed_args.expected_codes: args['expected_codes'] = parsed_args.expected_codes if parsed_args.max_retries: args['max_retries'] = parsed_args.max_retries if parsed_args.timeout: args['timeout'] = parsed_args.timeout if parsed_args.url_path: args['url_path'] = parsed_args.url_path if parsed_args.http_method: args['http_method'] = parsed_args.http_method if parsed_args.name: args['name'] = parsed_args.name if parsed_args.disable: args['is_admin_state_up'] = False client = self.app.client_manager.network hm = client.find_health_monitor(name_or_id=parsed_args.health_monitor, ignore_missing=False) obj = client.update_health_monitor(health_monitor=hm.id, **args) display_columns, columns = _get_columns(obj) data = utils.get_item_properties(obj, columns, formatters=_formatters) return (display_columns, data)
class CreateDnatRule(command.ShowOne): _description = _("Create new DNAT Rule") def get_parser(self, prog_name): parser = super(CreateDnatRule, self).get_parser(prog_name) parser.add_argument( '--nat-gateway-id', metavar='<nat_gateway_id>', required=True, help=_("Specifies the ID of the NAT Gateway."), ) parser.add_argument( '--port-id', metavar='<port_id>', help=_("Specifies the port ID of an ECS or a BMS."), ) parser.add_argument( '--private-ip', metavar='<private_ip>', help=_("Specifies the private IP address, for example, " "the IP address of a Direct Connect connection."), ) parser.add_argument( '--internal-service-port', metavar='<internal_service_port>', required=True, help=_("Specifies port used by ECSs or BMSs to provide " "services for external systems."), ) parser.add_argument( '--floating-ip-id', metavar="<floating_ip_id>", required=True, help=_("Specifies the Floating IP ID. Multiple " "Floating IPs are separated using commas."), ) parser.add_argument( '--external-service-port', metavar='<external_service_port>', required=True, help=_("Specifies the port for providing external services."), ) parser.add_argument( '--protocol', metavar='<protocol>', required=True, help=_("Specifies the protocol type."), ) return parser def take_action(self, parsed_args): client = self.app.client_manager.nat args_list = [ 'nat_gateway_id', 'port_id', 'private_ip', 'internal_service_port', 'floating_ip_id', 'external_service_port', 'protocol' ] attrs = {} for arg in args_list: val = getattr(parsed_args, arg) if val: attrs[arg] = val obj = client.create_dnat_rule(**attrs) display_columns, columns = _get_columns(obj) data = utils.get_item_properties(obj, columns) return (display_columns, data)
def get_parser(self, prog_name): parser = super(_OperationInstance, self).get_parser(prog_name) parser.add_argument('instance', metavar='<instance>', help=_('ID or Name of the instance to modify')) return parser
def get_parser(self, prog_name): parser = super(Snapshots, self).get_parser(prog_name) parser.add_argument('cluster_id', metavar='<cluster_id>', help=_('Cluster id')) return parser
def get_parser(self, prog_name): parser = super(CreateInstance, self).get_parser(prog_name) parser.add_argument( '--name', metavar='<name>', required=True, help=_('DCS instance name. An instance name is a string of ' '4-64 characters that contain letters, digits, underscores ' '(_), and hyphens (-). An instance name must start ' 'with letters.')) parser.add_argument( '--description', metavar='<description>', help=_('Brief description of the DCS instance. A brief ' 'description supports up to 1024 characters. NOTE "\\" ' 'is defined as an escape character in the queue ' 'description. If you need to enter a backward slash (\\) ' 'or a double quotation mark (") in the queue description, ' 'enter \\ or \\\"')) parser.add_argument('--engine', metavar='<engine>', default='redis', help=_('Cache engine, which is Redis.')) parser.add_argument('--engine_version', metavar='<version>', default='3.0.7', help=_('Cache engine version, which is 3.0.7.')) parser.add_argument( '--capacity', metavar='<size>', type=int, required=True, choices=[1, 2, 4, 8, 16, 32, 64, 128, 256, 512], help=_('Cache capacity. Unit: GB. For a single-node DCS instance ' 'and master/standby DCS instance, the cache capacity can ' 'be: 1, 2, 4, 8, 16, 32, or 64 GB. For a DCS instance in ' 'cluster mode, the cache capacity can be 64, 128, 256, ' 'or 512 GB.')) parser.add_argument( '--password', metavar='<password>', required=True, help=_('Password of a DCS instance. Password complexity ' 'requirements:\n' '* A string of 8-32 characters.\n' '* Contains at least three types of the following ' 'characters:\n' '* Uppercase letters\n' '* Lowercase letters\n' '* Digits\n' '* Special characters, such as ' '~!@#$%%^&*()-_=+\\|[{}]:\'",<.>/?')) parser.add_argument( '--vpc_id', metavar='<id>', required=True, help=_('Tenant\'s Virtual Private Cloud (VPC) ID.')) parser.add_argument('--security_group_id', metavar='<id>', required=True, help=_('Tenant\'s security group ID.')) parser.add_argument('--subnet_id', metavar='<id>', required=True, help=_('Subnet ID.')) parser.add_argument('--az', metavar='<az>', required=True, help=_('Availability zone.')) parser.add_argument( '--product_id', metavar='{' + ','.join(PRODUCT_ID_VALUES) + '}', type=lambda s: s.upper(), choices=PRODUCT_ID_VALUES, required=True, help=_('Product ID used to differentiate DCS instance types. ' 'Values:\n' '* OTC_DCS_SINGLE: indicates a single-node DCS instance.\n' '* OTC_DCS_MS: indicates a master/standby DCS instance.\n' '* OTC_DCS_CL: indicates a DCS instance in cluster mode.')) parser.add_argument('--backup_policy', metavar='<json>', help=_('Backup policy JSON.\n' '{\n' '"save_days" - retention time [1-7]\n' '"backup_type" - [auto,manual]\n' '"periodical_backup_plan": {\n' '"begin_at" - time when backup starts\n' '"period_type" - [weekly]\n' '"backup_at" - array of days [1-7]\n' '}\n' '}')) parser.add_argument( '--maintain_begin', metavar='<HH:mm:ss>', help=_('Time at which the maintenance time window starts.\n' 'The start time must be set to 22:00:00, 02:00:00,' '06:00:00, 10:00:00, 14:00:00, or 18:00:00.\n' 'Parameters maintain_begin and maintain_end must be ' 'set in pairs. If parameter maintain_start is left blank, ' 'parameter maintain_end is also blank. In this case, the ' 'system automatically allocates the default start time ' '02:00:00.')) parser.add_argument( '--maintain_end', metavar='<HH:mm:ss>', help=_('Time at which the maintenance time window starts.\n' 'The end time is four hours later than the start time. ' 'For example, if the start time is 22:00:00, the end time ' 'is 02:00:00.\n' 'Parameters maintain_begin and maintain_end must be ' 'set in pairs. If parameter maintain_end is left blank, ' 'parameter maintain_start is also blank. In this case, the ' 'system automatically allocates the default end time ' '06:00:00.')) return parser
class SetInstance(command.ShowOne): _description = _('Update a single DCS instance') def get_parser(self, prog_name): parser = super(SetInstance, self).get_parser(prog_name) parser.add_argument('instance', metavar='<instance>', help=_('ID or Name of the instance to modify')) parser.add_argument( '--name', metavar='<name>', help=_('DCS instance name. An instance name is a string of ' '4-64 characters that contain letters, digits, underscores ' '(_), and hyphens (-). An instance name must start ' 'with letters.')) parser.add_argument( '--description', metavar='<description>', help=_('Brief description of the DCS instance. A brief ' 'description supports up to 1024 characters. NOTE "\\" ' 'is defined as an escape character in the queue ' 'description. If you need to enter a backward slash (\\) ' 'or a double quotation mark (") in the queue description, ' 'enter \\ or \\\"')) parser.add_argument('--security_group_id', metavar='<id>', help=_('Tenant\'s security group ID.')) parser.add_argument('--backup_policy', metavar='<json>', help=_('Backup policy JSON.\n' '{\n' '"save_days" - retention time [1-7]\n' '"backup_type" - [auto,manual]\n' '"periodical_backup_plan": {\n' '"begin_at" - time when backup starts\n' '"period_type" - [weekly]\n' '"backup_at" - array of days [1-7]\n' '}\n' '}')) parser.add_argument( '--maintain_begin', metavar='<HH:mm:ss>', help=_('Time at which the maintenance time window starts.\n' 'The start time must be set to 22:00:00, 02:00:00,' '06:00:00, 10:00:00, 14:00:00, or 18:00:00.\n' 'Parameters `maintain_begin` and `maintain_end` must be ' 'set in pairs. If parameter `maintain_start` is left ' 'blank, parameter `maintain_end` is also blank. In this ' 'case, the system automatically allocates the default ' 'start time 02:00:00.')) parser.add_argument( '--maintain_end', metavar='<HH:mm:ss>', help=_('Time at which the maintenance time window starts.\n' 'The end time is four hours later than the start time. ' 'For example, if the start time is 22:00:00, the end time ' 'is 02:00:00.\n' 'Parameters `maintain_begin` and `maintain_end` must be ' 'set in pairs. If parameter `maintain_end` is left blank, ' 'parameter `maintain_start` is also blank. In this case, ' 'the system automatically allocates the default end time ' '06:00:00.')) return parser def take_action(self, parsed_args): client = self.app.client_manager.dcs attrs = {} if parsed_args.name: attrs['name'] = parsed_args.name if parsed_args.description: attrs['description'] = parsed_args.description if parsed_args.security_group_id: attrs['security_group_id'] = parsed_args.security_group_id if parsed_args.backup_policy: attrs['backup_policy'] = parsed_args.backup_policy if parsed_args.maintain_begin and parsed_args.maintain_end: attrs['maintain_begin'] = parsed_args.maintain_begin attrs['maintain_end'] = parsed_args.maintain_end obj = client.update_instance(instance=parsed_args.instance, **attrs) display_columns, columns = _get_columns(obj) data = utils.get_item_properties(obj, columns, formatters=_formatters) return (display_columns, data)
def get_parser(self, prog_name): parser = super(UpdateAutoScalingPolicy, self).get_parser(prog_name) parser.add_argument( 'policy', metavar='<policy>', help=_('AS Policy ID') ) parser.add_argument( '--group', metavar='<group>', required=True, help=_('AS Group ID or Name for the AS Policy') ) parser.add_argument( '--type', metavar='<type>', help=_('AS Policy type [`ALARM`, `SCHEDULED`, `RECURRENCE`]') ) parser.add_argument( '--cool-down-time', metavar='<cool_down_time>', type=int, help=_('Specifies the cooling time in seconds for the policy') ) parser.add_argument( '--alarm-id', metavar='<alarm_id>', help=_('Specifies the alarm_id for the policy') ) parser.add_argument( '--action-operation', metavar='<action_operation>', help=_('Specifies the policy operation ' 'Can be [`ADD`, `REMOVE`, `SET`]') ) parser.add_argument( '--action-instance-number', metavar='<action_instance_number>', type=int, help=_('Specifies number of instances to be operated') ) parser.add_argument( '--launch-time', metavar='<launch_time>', help=_('Specifies the time when the scaling action is triggered. ' 'The time format must comply with UTC.\n' '* when type=`SCHEDULED`, then `YYYY-MM-DDThh:mmZ`\n' '* when type=`RECURRENCE`, then `hh:mm`\n') ) parser.add_argument( '--recurrence-type', metavar='<recurrence_type>', help=_( 'Specifies the periodic triggering type\n' 'This parameter is mandatory when type=`RECURRENCE`\n' 'Can be [`Daily`, `Weekly`, `Monthly`]' ) ) parser.add_argument( '--recurrence-value', metavar='<recurrence_value>', help=_( 'Specifies the frequency, at which actions are triggered\n' 'When recurrente_type=`Daily` it is Null\n' 'When recurrente_type=`Weekly` it is a week day number ' '[1..7], where 1 is for Sunday\n' 'When recurrente_type=`Monthly` it is a day number [1..31]\n' ) ) parser.add_argument( '--start-time', metavar='<start_time>', help=_('Specifies the start time in of the action in the ' '`YYYY-MM-DDThh:mmZ` format') ) parser.add_argument( '--end-time', metavar='<end_time>', help=_('Specifies the end time in of the action in the ' '`YYYY-MM-DDThh:mmZ` format\n' 'Mandatory when type=`RECURRENCE`') ) return parser
class UpdateAutoScalingPolicy(command.ShowOne): _description = _('Updates AutoScalinig Policy') columns = ['ID', 'Name', 'scaling_group_id', 'status', 'type', 'alarm_id', 'scheduled_policy', 'scaling_policy_action', 'cool_down_time' ] # columns = ['ID', 'Name', 'instance_id', 'instance_name', # 'flavor_id', 'image_id', 'disk', # 'key_name', 'public_ip', 'user_data', 'metadata' # ] # POLICY_TYPES = ['ALARM', 'SCHEDULED', 'RECURRENCE'] def get_parser(self, prog_name): parser = super(UpdateAutoScalingPolicy, self).get_parser(prog_name) parser.add_argument( 'policy', metavar='<policy>', help=_('AS Policy ID') ) parser.add_argument( '--group', metavar='<group>', required=True, help=_('AS Group ID or Name for the AS Policy') ) parser.add_argument( '--type', metavar='<type>', help=_('AS Policy type [`ALARM`, `SCHEDULED`, `RECURRENCE`]') ) parser.add_argument( '--cool-down-time', metavar='<cool_down_time>', type=int, help=_('Specifies the cooling time in seconds for the policy') ) parser.add_argument( '--alarm-id', metavar='<alarm_id>', help=_('Specifies the alarm_id for the policy') ) parser.add_argument( '--action-operation', metavar='<action_operation>', help=_('Specifies the policy operation ' 'Can be [`ADD`, `REMOVE`, `SET`]') ) parser.add_argument( '--action-instance-number', metavar='<action_instance_number>', type=int, help=_('Specifies number of instances to be operated') ) parser.add_argument( '--launch-time', metavar='<launch_time>', help=_('Specifies the time when the scaling action is triggered. ' 'The time format must comply with UTC.\n' '* when type=`SCHEDULED`, then `YYYY-MM-DDThh:mmZ`\n' '* when type=`RECURRENCE`, then `hh:mm`\n') ) parser.add_argument( '--recurrence-type', metavar='<recurrence_type>', help=_( 'Specifies the periodic triggering type\n' 'This parameter is mandatory when type=`RECURRENCE`\n' 'Can be [`Daily`, `Weekly`, `Monthly`]' ) ) parser.add_argument( '--recurrence-value', metavar='<recurrence_value>', help=_( 'Specifies the frequency, at which actions are triggered\n' 'When recurrente_type=`Daily` it is Null\n' 'When recurrente_type=`Weekly` it is a week day number ' '[1..7], where 1 is for Sunday\n' 'When recurrente_type=`Monthly` it is a day number [1..31]\n' ) ) parser.add_argument( '--start-time', metavar='<start_time>', help=_('Specifies the start time in of the action in the ' '`YYYY-MM-DDThh:mmZ` format') ) parser.add_argument( '--end-time', metavar='<end_time>', help=_('Specifies the end time in of the action in the ' '`YYYY-MM-DDThh:mmZ` format\n' 'Mandatory when type=`RECURRENCE`') ) return parser def take_action(self, parsed_args): policy_attrs = {} # policy_attrs['name'] = parsed_args.name policy_attrs['scaling_group_id'] = parsed_args.group if parsed_args.type: policy_type = parsed_args.type.upper() if policy_type not in self.POLICY_TYPES: msg = (_('Unsupported policy type. Should be one of %s') % self.POLICY_TYPES) raise argparse.ArgumentTypeError(msg) else: policy_attrs['type'] = policy_type if parsed_args.alarm_id: policy_attrs['alarm_id'] = parsed_args.alarm_id if parsed_args.cool_down_time: policy_attrs['cool_down_time'] = parsed_args.cool_down_time policy_action = {} if parsed_args.action_operation: policy_action['operation'] = parsed_args.action_operation if parsed_args.action_instance_number: policy_action['instance_number'] = \ parsed_args.action_instance_number if policy_action.keys(): policy_attrs['scaling_policy_action'] = policy_action scheduled_policy = {} if parsed_args.launch_time: scheduled_policy['launch_time'] = parsed_args.launch_time if parsed_args.recurrence_type: # TODO(agoncharov) validate input scheduled_policy['recurrence_type'] = parsed_args.recurrence_type if parsed_args.recurrence_value: scheduled_policy['recurrence_value'] = parsed_args.recurrence_value if parsed_args.launch_time: scheduled_policy['start_time'] = parsed_args.start_time if parsed_args.launch_time: scheduled_policy['end_time'] = parsed_args.end_time if scheduled_policy.keys(): policy_attrs['scheduled_policy'] = scheduled_policy client = self.app.client_manager.auto_scaling policy = client.get_policy(parsed_args.policy) policy = client.update_policy( policy, **policy_attrs) fmt = set_attributes_for_print_detail(policy) # display_columns, columns = _get_columns(obj) data = utils.get_dict_properties( fmt, self.columns, formatters={}) return (self.columns, data)
class ListBackup(command.Lister): _description = _("List database backups") column_headers = ('ID', 'Name', 'Type', 'Instance Id', 'Size (KB)', 'Begin time', 'End time') columns = ('id', 'name', 'type', 'instance_id', 'size', 'begin_time', 'end_time') def get_parser(self, prog_name): parser = super(ListBackup, self).get_parser(prog_name) parser.add_argument( 'instance', metavar='<instance>', help=_('Specify instance ID or Name to get backup list'), ) parser.add_argument( '--backup-id', metavar='<backup_id>', help=_('Specify the backup ID.'), ) parser.add_argument( '--backup-type', metavar='{' + ','.join(BACKUP_TYPE_CHOICES) + '}', choices=BACKUP_TYPE_CHOICES, type=lambda s: s.lower(), help=_('Specify the backup type.'), ) parser.add_argument( '--offset', metavar='<offset>', type=int, help=_('Specify the index position.'), ) parser.add_argument( '--limit', metavar='<limit>', type=int, help=_('Specify the limit of resources to be queried.'), ) parser.add_argument( '--begin-time', metavar='<begin_time>', help=_('Specify the start time for obtaining the backup list.'), ) parser.add_argument( '--end-time', metavar='<end_time>', help=_('Specify the end time for obtaining the backup list.'), ) return parser def take_action(self, parsed_args): client = self.app.client_manager.rds attrs = {} args_list = [ 'backup_id', 'backup_type', 'offset', 'limit', 'begin_time', 'end_time' ] must_be_together_group = [parsed_args.begin_time, parsed_args.end_time] if any(must_be_together_group) and not all(must_be_together_group): raise exceptions.CommandError( _('`--begin-time` and `--end-time` must be given together')) for arg in args_list: if getattr(parsed_args, arg): attrs[arg] = getattr(parsed_args, arg) if parsed_args.limit: attrs['paginated'] = False instance = client.find_instance(parsed_args.instance, ignore_missing=False) data = client.backups(instance=instance, **attrs) return (self.column_headers, (utils.get_item_properties( s, self.columns, ) for s in data))
def get_parser(self, prog_name): parser = super(CreateCCECluster, self).get_parser(prog_name) parser.add_argument('name', metavar='<name>', help=_('Name of the cluster.')) parser.add_argument('router', metavar='<router>', help=_('ID or name the Neutron Router.')) parser.add_argument('network', metavar='<network>', help=_('ID or name of the Neutron network.')) parser.add_argument('--description', metavar='<description>', help=_('Text description of the cluster.')) parser.add_argument('--multi-az', action='store_true', help=_('Support for multi-AZ cluster')) parser.add_argument('--version', metavar='<version>', help=_('Cluster version.')) parser.add_argument('--flavor', metavar='<flavor>', required=True, help=_('Cluster flavor.')) parser.add_argument('--type', metavar='{' + ','.join(CLUSTER_TYPES) + '}', choices=CLUSTER_TYPES, default='VirtualMachine', help=_('Cluster type.')) parser.add_argument('--container-network-mode', metavar='{' + ','.join(CONTAINER_NET_MODE_CHOICES) + '}', type=lambda s: s.lower(), choices=CONTAINER_NET_MODE_CHOICES, default='overlay_l2', help=_('Container network mode.')) parser.add_argument( '--container-network-cidr', metavar='<CIDR>', help=_('Network segment of the container network.')) parser.add_argument('--wait', action='store_true', help=('Wait for the instance to become active')) parser.add_argument('--wait-interval', type=int, help=_('Interval for checking status')) parser.add_argument('--wait-timeout', type=int, help=_('Wait timeout')) return parser
class SetRS(command.ShowOne): _description = _('Update a Recordset') def get_parser(self, prog_name): parser = super(SetRS, self).get_parser(prog_name) parser.add_argument('zone', metavar='<zone>', help=_('UUID or name of the zone.')) parser.add_argument('--zone-type', help=_('DNS Zone type (private/public)')) parser.add_argument('recordset', metavar='<rs>', help=_('UUID or name of the recordset.')) parser.add_argument('--description', metavar='<description>', help=_('Description for this zone.')) parser.add_argument( '--ttl', metavar='<300-2147483647>', type=int, # NOTE: py2 does not support such big int, skip unless py3-only # choices=range(300, 2147483647), help=_('TTL (Time to Live) for the zone.')) parser.add_argument( '--record', metavar='<value>', action='append', help=_('Record set value, which varies depending on the record ' 'set type. For example, the value of an `AAAA` record set ' 'is the IPv6 address list mapped to the domain name. ')) return parser def take_action(self, parsed_args): client = self.app.client_manager.dns attrs = {'records': []} if parsed_args.description: attrs['description'] = parsed_args.description if parsed_args.ttl: attrs['ttl'] = parsed_args.ttl zone = client.find_zone(parsed_args.zone, ignore_missing=False, zone_type=parsed_args.zone_type) if parsed_args.ttl: attrs['zone_id'] = zone.id for rec in parsed_args.record: attrs['records'].append(rec) recordset = client.find_recordset(zone=zone, name_or_id=parsed_args.recordset) obj = client.update_recordset(recordset=recordset, **attrs) display_columns, columns = _get_columns(obj) data = utils.get_item_properties(obj, columns) return (display_columns, data)
def get_parser(self, prog_name): parser = super(ShowCCECluster, self).get_parser(prog_name) parser.add_argument('cluster', metavar='<cluster>', help=_('ID of the cluster')) return parser
class CreateCCEClusterNode(command.Command): _description = _('Create CCE Cluster Node') columns = ('ID', 'name', 'cluster_uuid', 'flavor', 'cpu', 'memory', 'volumes', 'cpu_max', 'mem_max', 'pods_max', 'cpu_allocatable', 'mem_allocatable', 'pods_allocatable', 'conditions', 'private_ip', 'public_ip', 'availability_zone', 'ssh_key', 'status', 'replica_count') def get_parser(self, prog_name): parser = super(CreateCCEClusterNode, self).get_parser(prog_name) parser.add_argument('cluster', metavar='<cluster>', help=_('Name or ID of the cluster.')) parser.add_argument('--flavor', metavar='<flavor>', required=True, help=_('The flavor for the server.')) parser.add_argument('--label', metavar='<label>', help=_('The label attached to the node.')) parser.add_argument( '--volume', metavar='<volume>', action='append', required=True, help=_( 'Disk information to attach to the instance.\n' 'format = `DISK_TYPE`,`VOLUME_TYPE`,`SIZE`\n' '`DISK_TYPE` can be in [SYS, DATA] and identifies ' 'whether disk should be a system or data disk\n' '`VOLUME_TYPE` can be in: \n' '* `SATA` = Common I/O \n' '* `SAS` = High I/O \n' '* `SSD` = Ultra-High I/O \n' '`SIZE` is size in Gb (40 hardcoded for root, [100..32768])\n' '(Repeat multiple times for multiple disks).')) parser.add_argument('--ssh_key', metavar='<ssh_key>', required=True, help=_('SSH Key used to create the node.')) parser.add_argument( '--assign_floating_ip', required=True, action='store_true', help=_('Whether to assign floating IP to the server or not.')) parser.add_argument('--availability_zone', metavar='<availability_zone>', help=_('Availability zone to place server in.')) parser.add_argument( '--tag', metavar='<tag>', action='append', help=_('Tag to assign to the server in KEY=VALUE format. ' 'Repeat for multiple values.')) parser.add_argument('--replica_count', metavar='[1..15]', type=int, choices=range(1, 15), default=1, help=_('Number of node instances to create ' '(max 15 in the cluster).')) return parser def take_action(self, parsed_args): attrs = {} spec = {} spec['flavor'] = parsed_args.flavor spec['ssh_key'] = parsed_args.ssh_key spec['availability_zone'] = parsed_args.availability_zone if parsed_args.label: spec['label'] = parsed_args.label if parsed_args.assign_floating_ip: spec['assign_floating_ip'] = parsed_args.assign_floating_ip attrs['replica_count'] = parsed_args.replica_count spec['volume'] = [] for disk in parsed_args.volume: disk_parts = disk.split(',') disk_data = {} if 3 == len(disk_parts): dt = disk_parts[0].upper() # Disk type: SYS->root; DATA->data if dt in ('SYS', 'DATA'): disk_data['disk_type'] = 'data' if dt == 'DATA' else 'root' else: msg = _('Disk Type is not in (SYS, DATA)') raise argparse.ArgumentTypeError(msg) vt = disk_parts[1].upper() if vt in ('SATA', 'SAS', 'SSD'): disk_data['volume_type'] = vt else: msg = _('Volume Type is not in (SATA, SAS, SSD)') raise argparse.ArgumentTypeError(msg) if dt == 'DATA': # Size only relevant for data disk if disk_parts[2].isdigit: disk_data['disk_size'] = disk_parts[2] else: msg = _('Volume SIZE is not a digit') raise argparse.ArgumentTypeError(msg) spec['volume'].append(disk_data) else: msg = _('Cannot parse disk information') raise argparse.ArgumentTypeError(msg) if parsed_args.tag: tags = [] for tag in parsed_args.tag: (k, v) = tag.split('=') tags.append(k + '.' + v) spec['tags'] = tags attrs['spec'] = spec client = self.app.client_manager.cce obj = client.add_node(cluster=parsed_args.cluster, **attrs) data = utils.get_dict_properties(_flatten_cluster_node(obj), self.columns) return (self.columns, data)
def get_parser(self, prog_name): parser = super(SetHealthMonitor, self).get_parser(prog_name) parser.add_argument('health_monitor', metavar='<health_monitor>', help=_('Health monitor to update (name or ID).')) parser.add_argument('--name', metavar='<name>', help=_('Human-readable name of the resource.')) parser.add_argument( '--delay', metavar='<delay>', type=int, help=_('The time, in seconds, between sending probes to members.')) parser.add_argument( '--expected_codes', metavar='<expected_codes>', help=_('The list of HTTP status codes expected in response ' 'from the member to declare it healthy. Specify one ' 'of the following values:\n' '* A single value, such as 200\n' '* A list, such as 200, 202\n' '* A range, such as 200-204\n' 'The default is 200.')) parser.add_argument( '--http_method', metavar='{' + ','.join(HTTP_METHODS) + '}', choices=HTTP_METHODS, type=lambda s: s.upper(), # case insensitive help=_('The HTTP method that the health monitor uses for requests.' 'One of [`GET`, `HEAD`, `POST`, `PUT`, `DELETE`,' '`TRACE`, `OPTIONS`, `CONNECT`, `PATCH`]\n' 'Default is `GET`')) parser.add_argument( '--timeout', metavar='<timeout>', type=int, help=_('The maximum time, in seconds, that a monitor waits to ' 'connect before it times out. This value must be less ' 'than the delay value.')) parser.add_argument( '--max_retries', metavar='<max_retries>', type=int, required=True, choices=range(1, 10), help=_('The number of successful checks before changing the ' 'operating status of the member to `ONLINE`. ' 'A valid value is from 1 to 10.')) parser.add_argument( '--url_path', metavar='<url_path>', help=_('The HTTP URL path of the request sent by the monitor ' 'to test the health of a backend member. Must be a string ' 'that begins with a forward slash (/).' 'The default URL path is /.')) admin_group = parser.add_mutually_exclusive_group() admin_group.add_argument('--enable', action='store_true', default=True, help=_('Enable health monitor (default).')) admin_group.add_argument('--disable', action='store_true', default=None, help=_('Disable health monitor.')) return parser
class CreateZone(command.ShowOne): _description = _('Create zone') def get_parser(self, prog_name): parser = super(CreateZone, self).get_parser(prog_name) parser.add_argument( 'name', metavar='<name>', help=_('DNS Name for the zone.') ) parser.add_argument( '--email', metavar='<email>', help=_('E-mail for the zone. Used in SOA records for the zone.') ) parser.add_argument( '--description', metavar='<description>', help=_('Description for this zone.') ) parser.add_argument( '--type', metavar='{' + ','.join(ZONE_TYPES) + '}', type=lambda s: s.lower(), choices=ZONE_TYPES, help=_('Domain name type, the value of which can be ' '`public` or `private` .') ) parser.add_argument( '--ttl', metavar='<300-2147483647>', type=int, # NOTE: py2 does not support such big int, skip unless py3-only # choices=range(300, 2147483647), help=_('TTL (Time to Live) for the zone.') ) parser.add_argument( '--router_id', metavar='<router_id>', help=_('Router ID (VPC ID) for the private zone.') ) parser.add_argument( '--router_region', metavar='<router_region>', help=_('Router region for the private zone.') ) return parser def take_action(self, parsed_args): client = self.app.client_manager.dns attrs = {} if parsed_args.name: attrs['name'] = parsed_args.name if parsed_args.email: attrs['email'] = parsed_args.email if parsed_args.description: attrs['description'] = parsed_args.description if parsed_args.type: attrs['zone_type'] = parsed_args.type if parsed_args.ttl: attrs['ttl'] = parsed_args.ttl if parsed_args.type and parsed_args.type == 'private': if not parsed_args.router_id: msg = _('router_id is required for a private zone') raise argparse.ArgumentTypeError(msg) router = { 'router_id': parsed_args.router_id } if parsed_args.router_region: router['router_region'] = parsed_args.router_region attrs['router'] = router obj = client.create_zone( **attrs ) display_columns, columns = _get_columns(obj) data = utils.get_item_properties(obj, columns) return (display_columns, data)
class ListDnatRules(command.Lister): _description = _("List DNAT Rules.") columns = ( 'Id', 'Nat Gateway Id', 'Port Id', 'Private IP', 'Floating Ip Address', 'Protocol', 'Status' ) def get_parser(self, prog_name): parser = super(ListDnatRules, self).get_parser(prog_name) parser.add_argument( '--id', metavar='<id>', help=_("Specifies the ID of the SNAT rule."), ) parser.add_argument( '--limit', metavar='<limit>', type=int, help=_("Limit to fetch number of records."), ) parser.add_argument( '--project-id', metavar='<project_id>', help=_("Specifies the project ID."), ) parser.add_argument( '--nat-gateway-id', metavar='<nat_gateway_id>', help=_("Specifies the NAT gateway ID."), ) parser.add_argument( '--port-id', metavar='<port_id>', help=_("Specifies the port ID of an ECS or a BMS."), ) parser.add_argument( '--private-ip', metavar='<private_ip>', help=_("Specifies the private IP address, for example, " "the IP address of a Direct Connect connection."), ) parser.add_argument( '--internal-service-port', metavar='<internal_service_port>', help=_("Specifies port used by ECSs or BMSs to provide " "services for external systems."), ) parser.add_argument( '--floating-ip-id', metavar='<floating_ip_id>', help=_("Specifies the Floating IP ID."), ) parser.add_argument( '--floating-ip-address', metavar='<floating_ip_address>', help=_("Specifies the Floating IP."), ) parser.add_argument( '--external-service-port', metavar='<external_service_port>', help=_("Specifies the port for providing external services."), ) parser.add_argument( '--protocol', metavar='<protocol>', help=_("Specifies the protocol type." "Currently, TCP, UDP, and ANY are supported."), ) parser.add_argument( '--status', metavar='<status>', help=_("Specifies the status of the DNAT rule.\n" "ACTIVE: The resource status is normal.\n" "PENDING_CREATE: The resource is being created.\n" "PENDING_UPDATE: The resource is being updated.\n" "PENDING_DELETE: The resource is being deleted.\n" "EIP_FREEZED: The EIP of the resource is frozen.\n" "INACTIVE: The resource status is abnormal."), ) parser.add_argument( '--admin-state-up', metavar='<admin_state_up>', help=_("Specifies whether the DNAT rule is enabled or " "disabled. The value can be:\n" "true: The DNAT rule is enabled.\n" "false: The DNAT rule is disabled."), ) parser.add_argument( '--created-at', metavar='<created_at>', help=_("Specifies when the DNAT rule is created (UTC time). " "Its value rounds to 6 decimal places forseconds. " "The format is yyyy-mm-ddhh:mm:ss."), ) return parser def take_action(self, parsed_args): client = self.app.client_manager.nat args_list = [ 'id', 'limit', 'project_id', 'nat_gateway_id', 'port_id', 'private_ip', 'internal_service_port', 'floating_ip_id', 'floating_ip_address', 'external_service_port', 'protocol', 'status', 'admin_state_up', 'created_at' ] attrs = {} for arg in args_list: val = getattr(parsed_args, arg) if val: attrs[arg] = val data = client.dnat_rules(**attrs) return ( self.columns, (utils.get_item_properties( s, self.columns, ) for s in data) )
class CreateSnapshot(command.ShowOne): _description = _('Create a single CSS snapshot') columns = ('clusterid', 'name', 'clustername', 'status', 'created') def get_parser(self, prog_name): parser = super(CreateSnapshot, self).get_parser(prog_name) parser.add_argument( 'cluster_id', metavar='<cluster_id>', # required=True, help=_('Specifies the DWS Cluster name. The value is a string of ' '0 to 64 characters and can contain uppercase and ' 'lowercase letters (a to z and A to Z), digits (0 to ' '9), hyphens (-), underscores (_), and periods (.). ' 'In addition, it must start and end with a letter.')) parser.add_argument( '--name', metavar='<name>', required=True, help=_( 'Specifies the CSS Cluster name OBS bucket name. The value is a string of ' '0 to 64 characters and can contain uppercase and ' 'lowercase letters (a to z and A to Z), digits (0 to ' '9), hyphens (-), underscores (_), and periods (.). ' 'In addition, it must start and end with a letter.')) parser.add_argument( '--description', metavar='<description>', help=_('Specifies the prefix of a log that needs to be stored ' 'in an OBS bucket. The value is a string of 0 to 64 ' 'characters and can contain uppercase and lowercase ' 'letters (a to z and A to Z), digits (0 to 9), ' 'hyphens (-), underscores (_), and periods (.)')) parser.add_argument( '--indices', metavar='<indices>', help=_('Specifies whether SMN is supported. When the value is ' '`false`, `topic_id` and `operations` can be left empty.')) return parser def take_action(self, parsed_args): client = self.app.client_manager.dws attrs = {} if parsed_args.name: attrs['name'] = parsed_args.name if parsed_args.cluster_id: attrs['cluster_id'] = parsed_args.cluster_id if parsed_args.description: attrs['description'] = parsed_args.description if parsed_args.indices: attrs['indices'] = parsed_args.indices obj = client.create_snapshot(**attrs) display_columns, columns = _get_columns(obj) data = utils.get_item_properties(obj, columns) return display_columns, data
class CreateListener(command.ShowOne): _description = _('Create LoadBalancer Listener') def get_parser(self, prog_name): parser = super(CreateListener, self).get_parser(prog_name) parser.add_argument( 'load_balancer', metavar='<load_balancer>', help=_('Load balancer for the listener (name or ID).')) parser.add_argument('--name', metavar='<name>', help=_('Set the listener name.')) parser.add_argument('--description', metavar='<description>', help=_('Set the description of this listener.')) parser.add_argument('--protocol', metavar='{' + ','.join(SUPPORTED_PROTOCOLS) + '}', type=lambda s: s.upper(), choices=SUPPORTED_PROTOCOLS, required=True, help=_('The protocol for the listener. ' 'One of [`TCP`, `HTTP`, `HTTPS`]')) parser.add_argument( '--protocol_port', type=int, metavar='<port>', required=True, help=_('Set the protocol port number for the listener.')) parser.add_argument( '--connection_limit', metavar='<limit>', type=int, help=_('The maximum number of connections permitted for this ' 'listener. Default value is -1 which represents infinite ' 'connections.')) parser.add_argument( '--default_pool', metavar='<pool>', help=_('The ID of the pool used by the listener if no L7 policies ' 'match.')) parser.add_argument( '--default_tls_container_ref', metavar='<default_tls_container_ref>', help=_('The URI of the key manager service secret containing a ' 'PKCS12 format certificate/key bundle for TERMINATED_TLS ' 'listeners. DEPRECATED: A secret container of type ' '\"certificate\" containing the certificate and key ' 'for TERMINATED_TLS listeners.')) admin_group = parser.add_mutually_exclusive_group() admin_group.add_argument('--enable', action='store_true', default=True, help=_('Enable listener (default).')) admin_group.add_argument('--disable', action='store_true', default=None, help=_('Disable listener.')) return parser def take_action(self, parsed_args): args = {} if parsed_args.load_balancer: args['load_balancer_id'] = parsed_args.load_balancer if parsed_args.protocol: args['protocol'] = parsed_args.protocol if parsed_args.protocol_port: args['protocol_port'] = parsed_args.protocol_port if parsed_args.disable: args['is_admin_state_up'] = False if parsed_args.connection_limit: args['connection_limit'] = parsed_args.connection_limit if parsed_args.default_pool: args['default_pool_id'] = parsed_args.default_pool if parsed_args.default_tls_container_ref: args['default_tls_container_ref'] = \ parsed_args.default_tls_container_ref if parsed_args.description: args['description'] = parsed_args.description if parsed_args.name: args['name'] = parsed_args.name client = self.app.client_manager.network obj = client.create_listener(**args) display_columns, columns = _get_columns(obj) data = utils.get_item_properties(obj, columns, formatters=_formatters) return (display_columns, data)
class RestoreSnapshot(command.ShowOne): _description = _("Restore Snapshot of a database instance.") columns = ('id', ) def get_parser(self, prog_name): parser = super(RestoreSnapshot, self).get_parser(prog_name) parser.add_argument( 'snapshot', metavar='<snapshot>', # default='system', help=_('Snapshot id')) parser.add_argument('--name', required=True, metavar='<name>', help=_("Name of the instance.")) parser.add_argument( '--availability-zone', metavar='<availability_zone>', # required=True, default="eu-de-01", help=_("The Zone hint to give to Nova.")) parser.add_argument('--port', metavar='<port>', type=int, default=8000, help=_("Database Port")) parser.add_argument('--eip-id', metavar='<eip_id>', dest='eip_id', default=None, help=_("EIP ID for instance.")) parser.add_argument('--public-bind-type', metavar='<public_bind_type>', dest='public_bind_type', default="auto_assign", help=_("EIP public bind type for instance.")) parser.add_argument( '--vpc-id', metavar='<vpc_id>', dest='vpc_id', help=_('ID of a VPC the DB should be connected to')) parser.add_argument( '--subnet-id', required=True, metavar='<subnet_id>', help=_('ID of a network the DB should be connected to.')) parser.add_argument('--security-group-id', dest='security_group_id', required=True, metavar='<security_group_id>', help=_('Security group ID.')) return parser def take_action(self, parsed_args): client = self.app.client_manager.dws attrs = {} for attr in [ # 'snapshot', 'name', 'availability_zone', 'subnet_id', 'vpc_id', 'port', 'security_group_id', ]: if getattr(parsed_args, attr): attrs[attr] = getattr(parsed_args, attr) snapshot = parsed_args.snapshot obj = client.restore_snapshot(snapshot, **attrs) obj = list(obj) columns = ('id', ) table = (columns, (utils.get_dict_properties(_flatten_output(s), columns) for s in obj)) return table
def get_parser(self, prog_name): parser = super(CreateCCENodePool, self).get_parser(prog_name) parser.add_argument('cluster', metavar='<cluster>', help=_('ID or name of the CCE cluster.')) parser.add_argument('name', metavar='<name>', help=_('Name of the CCE Node Pool.')) parser.add_argument( '--autoscaling-enabled', metavar='<autoscaling_enabled>', default=False, type=bool, help=_('Enables or disables Autoscaling for cluster nodes.')) parser.add_argument('--az', metavar='<availability_zone>', default='random', help=_('Availability zone for cluster nodes.\n' 'Default: random')) parser.add_argument( '--data-volume', metavar='volumetype=<volumetype>,size=<disksize>,' 'encrypted=<True|False>,cmk_id=<cmk_id>', action=parseractions.MultiKeyValueAction, dest='data_volumes', required_keys=['volumetype', 'size'], optional_keys=['encrypted', 'cmk_id'], help=_('Example: ' '--data-volume volumetype=SATA,size=100,encrypted=True,' 'cmk_id=12345qwertz \n' 'Repeat option for multiple data volumes.\n' 'Default: --data-volume volumetype=SATA,size=100')) parser.add_argument( '--ecs-group', metavar='<ecs_group>', help=_('ECS group id of the ECS group to which nodes belong ' 'after creation.')) parser.add_argument('--flavor', metavar='<flavor>', required=True, help=_('CCE cluster node flavor.')) parser.add_argument('--initial-node-count', metavar='<initial_node_count>', default=0, type=int, help=_('Node count after Node pool creation.')) parser.add_argument( '--k8s-tag', metavar='<key_name>=<value_name>', action=parseractions.KeyValueAction, dest='k8s_tags', help=_('Kubernetes tags in form of key, value pairs. Repeat ' 'option for multiple tags.\n' 'Example: ' '--k8s-tag keyname1=valuename1 ' '--k8s-tag keyname2=valuename2')) parser.add_argument('--lvm-config', metavar='<lvm_config>', help=_('Config Map of the Docker data disk.')) parser.add_argument( '--min-node-count', metavar='<min_node_count>', type=int, help=_('If auto-scaling is enabled, the value describes the ' 'minimum number of nodes of the cluster.')) parser.add_argument( '--max-node-count', metavar='<max_node_count>', type=int, help=_('If auto-scaling is enabled, the value describes the ' 'maximum number of nodes of the cluster. The value ' 'must be equal or greater as the min_node_count.')) parser.add_argument('--max-pods', metavar='<max_pods>', type=int, help=_('Maximum number of pods on the node.')) parser.add_argument('--node-image-id', metavar='<node_image_id>', help=_( 'Mandatory if custom image is used on a bare ' 'metall node.')) parser.add_argument( '--node-pool-type', metavar='<node_pool_type>', help=_('Node pool type, currently only vm is supported.')) parser.add_argument('--os', metavar='<operating_system>', required=True, help=_('CCE cluster node operating system.')) parser.add_argument('--preinstall-script', metavar='<preinstall_script>', help=_('Script required before installation. ' 'Input must be Base64 encoded.')) parser.add_argument('--postinstall-script', metavar='<postinstall_script>', help=_('Script required after installation. ' 'Input must be Base64 encoded.')) parser.add_argument( '--priority', metavar='<priority>', type=int, help=_('If auto-scaling is enabled, the value describes the ' 'priority of the scale up functionality between ' 'several Node Pools. A higher priority number ' 'indicates a higher priority starting from 1.')) parser.add_argument( '--public-key', metavar='<public_key>', help=_('Additional public key to be added to for login.')) parser.add_argument('--network-id', metavar='<network_id>', required=True, help=_( 'ID of the network to which the cluster node ' 'will belong to.')) parser.add_argument('--root-volume-size', metavar='<root_volume_size>', type=int, default=40, help=_('Root volume size in GB.')) parser.add_argument( '--root-volume-type', metavar='<root_volume_type>', choices=['SAS', 'SATA', 'SSD'], default='SATA', help=_('Root volume type.\nOptions: SAS, SATA, SSD.')) parser.add_argument('--scale-down-cooldown-time', metavar='<time in minutes>', type=int, help=_( 'Interval in minutes during which nodes added ' 'after a scale-up will not be deleted.')) parser.add_argument('--ssh-key', metavar='<ssh-key>', required=True, help=_('Name of the SSH public key.')) parser.add_argument('--tag', metavar='key=<keyname1>,value=<value1>', action=parseractions.MultiKeyValueAction, dest='tags', required_keys=['key', 'value'], help=_('Example: ' '--tag key=mykey1,value=myvalue1\n' 'Repeat option for multiple tags.')) parser.add_argument( '--taint', metavar='key=<keyname1>,value=<value1>,\n' 'effect=<NoSchedule|PreferNoSchedule|NoExecute', action=parseractions.MultiKeyValueAction, dest='taints', required_keys=['key', 'value', 'effect'], help=_('Example: ' '--taint key=mykey1,value=myvalue1,effect=NoSchedule\n' 'Repeat option for multiple taints.')) return parser
class ListVpcPeerings(command.Lister): _description = _("List Vpc Peerings.") columns = ('Id', 'Name', 'Status', 'Local Router Id', 'Peer Router Id', 'Peer Project Id') def get_parser(self, prog_name): parser = super(ListVpcPeerings, self).get_parser(prog_name) parser.add_argument( '--id', metavar='<id>', help=_("Specifies the ID of the VPC peering connection."), ) parser.add_argument( '--limit', metavar='<limit>', type=int, help=_("Limit to fetch number of records."), ) parser.add_argument( '--marker', metavar='<marker>', help=_("Specifies the start resource ID of pagination query."), ) parser.add_argument( '--project-id', metavar='<project_id>', help=_("Specifies the project ID."), ) parser.add_argument( '--name', metavar='<name>', help=_("Specifies the Name of the VPC peering connection."), ) parser.add_argument( '--router-id', metavar='<router_id>', help=_("Specifies the router/vpc ID of requester/accepter " "of vpc peering."), ) parser.add_argument( '--status', metavar='{' + ','.join(STATUS_CHOICES) + '}', type=lambda s: s.upper(), choices=STATUS_CHOICES, help=_("Specifies the status of the VPC peering connection."), ) return parser def take_action(self, parsed_args): client = self.app.client_manager.vpc args_list = [ 'id', 'name', 'limit', 'marker', 'project_id', 'router_id', 'status' ] attrs = {} for arg in args_list: val = getattr(parsed_args, arg) if val: attrs[arg] = val data = client.peerings(**attrs) if data: data = set_attributes_for_print(data) return (self.columns, (utils.get_item_properties(s, self.columns) for s in data))
class ListVpcRoutes(command.Lister): _description = _("List Vpc Routes.") columns = ( 'Id', 'Type', 'Router Id', 'Project Id', 'NextHop', 'Destination' ) def get_parser(self, prog_name): parser = super(ListVpcRoutes, self).get_parser(prog_name) parser.add_argument( '--id', metavar='<id>', help=_("Specifies the ID of the VPC route."), ) parser.add_argument( '--limit', metavar='<limit>', type=int, help=_("Limit to fetch number of records."), ) parser.add_argument( '--marker', metavar='<marker>', help=_("Specifies the start resource ID of pagination query."), ) parser.add_argument( '--project-id', metavar='<project_id>', help=_("Specifies the project ID."), ) parser.add_argument( '--router-id', metavar='<router_id>', help=_("Specifies the router/vpc ID."), ) parser.add_argument( '--destination', metavar='<destination>', help=_("Specifies that the route destination address (CIDR) " "is used as the filtering condition."), ) parser.add_argument( '--type', metavar='<type>', help=_("Specifies that the type is used as the filtering " "condition. Currently, the value can only be peering."), ) return parser def take_action(self, parsed_args): client = self.app.client_manager.vpc args_list = [ 'id', 'type', 'limit', 'marker', 'project_id', 'router_id', 'destination'] attrs = {} for arg in args_list: val = getattr(parsed_args, arg) if val: attrs[arg] = val data = client.routes(**attrs) if data: data = set_attributes_for_print(data) return (self.columns, (utils.get_item_properties(s, self.columns) for s in data))
class CreateCCECluster(command.ShowOne): _description = _('Create CCE Cluster') columns = ('ID', 'name', 'version', 'endpoint') def get_parser(self, prog_name): parser = super(CreateCCECluster, self).get_parser(prog_name) parser.add_argument('name', metavar='<name>', help=_('Name of the cluster.')) parser.add_argument('router', metavar='<router>', help=_('ID or name the Neutron Router.')) parser.add_argument('network', metavar='<network>', help=_('ID or name of the Neutron network.')) parser.add_argument('--description', metavar='<description>', help=_('Text description of the cluster.')) parser.add_argument('--multi-az', action='store_true', help=_('Support for multi-AZ cluster')) parser.add_argument('--version', metavar='<version>', help=_('Cluster version.')) parser.add_argument('--flavor', metavar='<flavor>', required=True, help=_('Cluster flavor.')) parser.add_argument('--type', metavar='{' + ','.join(CLUSTER_TYPES) + '}', choices=CLUSTER_TYPES, default='VirtualMachine', help=_('Cluster type.')) parser.add_argument('--container-network-mode', metavar='{' + ','.join(CONTAINER_NET_MODE_CHOICES) + '}', type=lambda s: s.lower(), choices=CONTAINER_NET_MODE_CHOICES, default='overlay_l2', help=_('Container network mode.')) parser.add_argument( '--container-network-cidr', metavar='<CIDR>', help=_('Network segment of the container network.')) parser.add_argument('--wait', action='store_true', help=('Wait for the instance to become active')) parser.add_argument('--wait-interval', type=int, help=_('Interval for checking status')) parser.add_argument('--wait-timeout', type=int, help=_('Wait timeout')) return parser def take_action(self, parsed_args): attrs = {} for attr in [ 'name', 'type', 'flavor', 'router', 'network', 'container_network_mode', 'annotations', 'authentication_proxy_ca', 'authentication_mode', 'container_network_cidr', 'cpu_manager_policy', 'dss_master_volumes', 'description', 'external_ip', 'fix_pool_mask', 'labels', 'service_ip_range', 'kube_proxy_mode', 'upgrade_from', 'version', 'wait', 'wait_timeout', 'wait_interval' ]: if hasattr(parsed_args, attr) and getattr(parsed_args, attr): attrs[attr] = getattr(parsed_args, attr) if not parsed_args.wait: attrs['wait'] = False if parsed_args.multi_az: attrs['az'] = 'multi_az' # initialize sdk_connection with cce methods _ = self.app.client_manager.cce obj = self.app.client_manager.sdk_connection.create_cce_cluster( **attrs) data = utils.get_dict_properties(_flatten_cluster(obj), self.columns) return (self.columns, data)
def get_parser(self, prog_name): parser = super(CreateDataset, self).get_parser(prog_name) parser.add_argument( '--dataset_name', metavar='<dataset_name>', required=True, help=_('Dataset name.' ' The value is a string of 1 to 100 characters' ' consisting of only digits, letters, underscores (_), ' 'and hyphens (-). Example value: dataset-9f3b') ) parser.add_argument( '--dataset_type', metavar='<dataset_type>', required=True, help=_('Dataset type. Possible values: ' '0: image classification' '1: object detection' '100: text classification' '101: named entity recognition' '102: text triplet' '200: sound classification' '201: speech content' '202: speech start and end points' '900: custom format ') ) parser.add_argument( '--data_sources', metavar='<data_sources>', required=True, help=_( 'Quantity of the partitions into which data records in the newly created DIS stream ' 'will be distributed ' 'Partitions are the base throughput unit of a DIS stream ' 'The value range varies depending on the value of stream_type ') ) parser.add_argument( '--work_path', metavar='<work_path>', required=True, help=_('Type of the source data. ') ) parser.add_argument( '--work_path_type', metavar='<work_path_type>', action='append', help=_('Source data structure that defines JOSN and CSV formats. It is ' 'described in the syntax of Avro. For details about Avro, ' 'see http://avro.apache.org/docs/current/#schemas. ') ) parser.add_argument( '--labels', metavar='<labels>', help=_('Period of time for which data is retained in the DIS stream. ' 'Value range: N x 24, where N is an integer from 1 to 7. ' 'Unit: hour' 'Default value: 24' 'If this parameter is left unspecified, the default value will be used.') ) parser.add_argument( '--description', metavar='<description>', help=_('Dataset description. The value is a string of 0 to 256 characters. ' 'Special characters !<>=&"\' are not allowed. By default, this parameter is left blank.') ) parser.add_argument( '--import_annotations', metavar='<import_annotations>', help=_('Whether to synchronize the labels in the input path when creating an object' 'detection or image classification dataset. The default value is true.' 'true: Import labels. false: Do not import labels. ') ) parser.add_argument( '--label_format', metavar='<label_format>', help=_('Label format information.' 'This parameter is used only when a text classification dataset is created.') ) parser.add_argument( '--workspace_id', metavar='<workspace_id>', help=_('Workspace ID. If no workspace is created, ' 'the default value is 0. If a workspace is created and used, use the actual value. ') ) parser.add_argument( '--data_type', metavar='<data_type>', help=_('Data source type. Possible values are as follows: OBS ') ) parser.add_argument( '--data_path', metavar='<data_path>', required=True, help=_('Path of the data source. The value is a string of 3 to 1,024 characters.') ) parser.add_argument( '--name', metavar='<name>', required=True, help=_('Label name The value can contain 1 to 32 characters, ' 'including Chinese characters, digits, letters, underscores (_), and hyphens (-). ') ) parser.add_argument( '--type', metavar='<type>', help=_('Label type. The value range is the same as that of the dataset type. ' 'If this parameter is not passed, the current dataset type is used by default. ') ) parser.add_argument( '--property', metavar='<property>', help=_('Label attributes. For details, see Table 5. If no built-in or custom attribute needs to be set ' 'for labels, this field can be omitted or left blank (the parameter value is {}). ') ) parser.add_argument( '--label_type', metavar='<label_type>', help=_('Label format. The default value is 1. ') ) parser.add_argument( '--text_sample_separator', metavar='<text_sample_separator>', help=_('Separator between the text and label. By default, the Tab key is used as the separator. ' 'The separator needs to be escaped.') ) parser.add_argument( '--text_label_separator', metavar='<text_label_separator>', help=_('Separator between labels. By default, the comma (,) is used as the separator. ' 'The separator needs to be escaped. ') ) parser.add_argument( '--dataset_id', metavar='<dataset_id>', help=_('Dataset ID ') ) parser.add_argument( '--error_code', metavar='<text_label_separator>', help=_('Error code of a failed API call. For details, see Error Code.' 'This parameter is not included when the API call succeeds. ') ) parser.add_argument( '--error_msg', metavar='<error_msg>', help=_('Error message of a failed API call. ' 'This parameter is not included when the API call succeeds. ') ) return parser
class CreateBackup(command.ShowOne): _description = _('Create Database backup') def get_parser(self, prog_name): parser = super(CreateBackup, self).get_parser(prog_name) parser.add_argument('name', metavar='<name>', help=_('Name for the backup')) parser.add_argument( 'instance', metavar='<instance>', help=_('ID or Name of the instance to create backup from')) parser.add_argument('--description', metavar='<description>', help=_('Description for the backup')) parser.add_argument('--databases', metavar='<databases>', help=_( 'Specifies a CSV list of self-built SQL Server' 'databases that are partially backed up' '(Only SQL Server support partial backups.)')) parser.add_argument('--wait', action='store_true', help=('Wait for the instance to become active')) parser.add_argument('--wait-interval', type=int, help=_('Interval for checking status')) return parser def take_action(self, parsed_args): client = self.app.client_manager.rds attrs = {'name': parsed_args.name} if parsed_args.description: attrs['description'] = parsed_args.description instance = client.find_instance(parsed_args.instance, ignore_missing=False) if (parsed_args.databases and instance.datastore['type'].lower() == 'sqlserver'): attrs['databases'] = [] databases = parsed_args.databases databases = databases.split(",") for db_name in databases: attrs['databases'].append({'name': db_name}) else: # Do we want to raise error otherwise? pass obj = client.create_backup(instance=instance, **attrs) if parsed_args.wait: wait_args = {} if parsed_args.wait_interval: wait_args['interval'] = parsed_args.wait_interval obj = client.wait_for_backup(obj, **wait_args) display_columns, columns = _get_columns(obj) data = utils.get_item_properties(obj, columns, formatters=_formatters) return (display_columns, data)