def add_public_ip_option(parser): parser.add_argument( '--ip-type', required=False, choices=['5_bgp', '5_lxbgp', '5_telcom', '5_union'], help=_( 'IP type of EIP to be assigned, (Your zone may only support ' 'part of the ip type list)'), ) parser.add_argument( '--bandwidth-size', required=False, metavar='<size(Mbit/s)>', type=parsetypes.int_range_type(1, 300), help=_('Bandwidth size, available size range is 1-300 Mbit/s'), ) parser.add_argument( '--bandwidth-share-type', required=False, choices=['PER'], help=_('Bandwidth share type, ' 'PER is the only&default option for now.'), ) parser.add_argument( '--bandwidth-charging-mode', required=False, choices=['bandwidth', 'traffic'], help=_('Bandwidth charging mode (Your zone may only support part ' 'of the charging mode list)'), )
def get_parser(self, prog_name): parser = super(ListAutoScalingConfig, self).get_parser(prog_name) help_name = _("list auto scaling instance configs with name") pb.Config.add_name_opt(parser, help_name, required=False) help_image = _("list auto scaling instance configs with image" "(ID or Name)") pb.Config.add_image_opt(parser, help_image, required=False) bpb.Base.add_offset_opt(parser) bpb.Base.add_limit_opt(parser) return parser
def add_authentication_opt(parser): group = parser.add_mutually_exclusive_group() group.add_argument('--key-name', metavar='<key-name>', help=_( "SSH key name, Not support for Window Server " "(Either key-name or admin-pass is required)")) group.add_argument('--admin-pass', metavar='<admin-pass>', help=_( "SSH key name " "(Either key-name or admin-pass is required)"))
def take_action(self, args): compute = self.app.client_manager.compute mgr = self.app.client_manager.auto_scaling.configs image = None flavor = None disk = [] if not args.instance_id: if not all((args.image, args.flavor, args.root_volume,)): msg = ("All Flavor/Image/Root-Volume is required when " "instance-id is not provided") raise exceptions.CommandError(_(msg)) image = utils.find_resource(compute.images, args.image).id flavor = utils.find_resource(compute.flavors, args.flavor).id args.root_volume.update(dict(disk_type='SYS')) disk.append(args.root_volume) for v in args.data_volumes: v.update(dict(disk_type='DATA')) disk.append(v) files = {} for f in args.file: dst, src = f.split('=', 1) try: files[dst] = io.open(src, 'rb') except IOError as e: msg = _("Can't open file '%(source)s': %(exception)s") raise exceptions.CommandError( msg % dict(source=src, exception=e) ) kwargs = { "instance_id": args.instance_id, "flavor_id": flavor, "image_id": image, "disk": disk, "files": files, "metadata": args.metadata, "key_name": args.key_name, "admin_pwd": args.admin_pass, "ip_type": args.ip_type, "bandwidth_size": args.bandwidth_size, "bandwidth_share_type": args.bandwidth_share_type, "bandwidth_charging_mode": args.bandwidth_charging_mode, "user_data": args.userdata, } config = mgr.create(args.name, **kwargs) return "Configuration %s created" % config.id
class ListAutoScalingPolicy(command.Lister): _description = _("List Auto Scaling Policies") def get_parser(self, prog_name): parser = super(ListAutoScalingPolicy, self).get_parser(prog_name) pb.Policy.add_group_opt(parser, required=True) pb.Policy.add_policy_name_opt(parser) pb.Policy.add_policy_type_opt(parser) bpb.Base.add_limit_opt(parser) bpb.Base.add_offset_opt(parser) return parser def take_action(self, args): group_mgr = self.app.client_manager.auto_scaling.groups group_id = group_mgr.find(args.group).id policy_mgr = self.app.client_manager.auto_scaling.policies policies = policy_mgr.list(group_id, name=args.name, type_=args.type, offset=args.offset, limit=args.limit) columns = resource.AutoScalingPolicy.list_column_names data = [p.get_display_data(columns) for p in policies] return columns, data
class ListAutoScalingInstance(command.Lister): _description = _("List Auto Scaling instances") def get_parser(self, prog_name): parser = super(ListAutoScalingInstance, self).get_parser(prog_name) pb.Instance.add_group_opt(parser) pb.Instance.add_lifecycle_status_opt(parser) pb.Instance.add_health_status_opt(parser) bpb.Base.add_limit_opt(parser) bpb.Base.add_offset_opt(parser) return parser def take_action(self, args): mgr = self.app.client_manager.auto_scaling.instances as_groups_mgr = self.app.client_manager.auto_scaling.groups group_id = as_groups_mgr.find(args.group).id instances = mgr.list(group_id, lifecycle_status=args.lifecycle_status, health_status=args.health_status, limit=args.limit, offset=args.offset) # return columns, output columns = resource.AutoScalingInstance.list_column_names data = [i.get_display_data(columns) for i in instances] return columns, data
class ListAutoScalingLog(command.Lister): _description = _("List Auto Scaling instances") def get_parser(self, prog_name): parser = super(ListAutoScalingLog, self).get_parser(prog_name) pb.Instance.add_group_opt(parser) pb.Log.add_start_time_option(parser) pb.Log.add_end_time_opt(parser) bpb.Base.add_limit_opt(parser) bpb.Base.add_offset_opt(parser) return parser def take_action(self, args): as_groups_mgr = self.app.client_manager.auto_scaling.groups group_id = as_groups_mgr.find(args.group).id mgr = self.app.client_manager.auto_scaling.logs logs = mgr.list(group_id, start_time=args.start_time, end_time=args.end_time, limit=args.limit, offset=args.offset) columns = resource.AutoScalingLog.list_column_names data = [log.get_display_data(columns) for log in logs] return columns, data
class ListAutoScalingConfig(command.Lister): _description = _("List Auto Scaling instance configuration") def get_parser(self, prog_name): parser = super(ListAutoScalingConfig, self).get_parser(prog_name) help_name = _("list auto scaling instance configs with name") pb.Config.add_name_opt(parser, help_name, required=False) help_image = _("list auto scaling instance configs with image" "(ID or Name)") pb.Config.add_image_opt(parser, help_image, required=False) bpb.Base.add_offset_opt(parser) bpb.Base.add_limit_opt(parser) return parser def take_action(self, args): mgr = self.app.client_manager.auto_scaling.configs image_id = None if args.image: image_client = self.app.client_manager.image image_id = utils.find_resource(image_client.images, args.image).id configs = mgr.list(name=args.name, image_id=image_id, offset=args.offset, limit=args.limit) columns = resource.AutoScalingConfig.list_column_names output = [c.get_display_data(columns) for c in configs] return columns, output
def add_cool_down_opt(parser, required=False): parser.add_argument( '--cool-down', required=required, metavar='<seconds>', type=int, help=_("Auto-Scaling group cool down time (second)"))
def add_del_public_ip_opt(parser, required=False): parser.add_argument('--delete-public-ip', required=required, action="store_true", default=False, help=_("Delete public-ip when terminate instance " "(False by default)"))
def add_group_opt(parser): parser.add_argument( '--group', metavar="<group>", required=True, help=_("Group which the instances belong to (ID or name)"), )
class CreateAutoScalingGroup(command.Command): _description = _("Create Auto Scaling group") def get_parser(self, prog_name): parser = super(CreateAutoScalingGroup, self).get_parser(prog_name) pb.Group.add_group_name_arg(parser) pb.Group.add_vpc_opt(parser) pb.Group.add_subnet_opt(parser) pb.Group.add_security_group_opt(parser) pb.Group.add_config_id_opt(parser, required=False) pb.Group.add_desired_instance_opt(parser, required=False) pb.Group.add_max_instance_opt(parser, required=False) pb.Group.add_min_instance_opt(parser, required=False) pb.Group.add_cool_down_opt(parser, required=False) pb.Group.add_lb_listener_opt(parser, required=False) pb.Group.add_health_periodic_audit_method_arg(parser) pb.Group.add_health_periodic_audit_time_arg(parser) pb.Group.add_instance_terminate_policy_opt(parser) pb.Group.add_del_public_ip_opt(parser) pb.Group.add_az_opt(parser) # TODO availability_zones return parser def take_action(self, args): network = self.app.client_manager.network auto_scaling = self.app.client_manager.auto_scaling # manager groups = auto_scaling.groups configs = auto_scaling.configs vpc_id = network.find_router(args.vpc, ignore_missing=False).id subnets = [ network.find_subnet(subnet, ignore_missing=False).network_id for subnet in args.subnets ] security_groups = [ network.find_security_group(sg, ignore_missing=False).id for sg in args.security_groups ] config_id = configs.find(args.config).id if args.config else None kwargs = { "as_config_id": config_id, "desire_instance_number": args.desire_instance, "max_instance_number": args.max_instance, "min_instance_number": args.min_instance, "cool_down_time": args.cool_down, "lb_listener_id": args.lb_listener, "health_periodic_audit_time": args.health_periodic_audit_time, "health_periodic_audit_method": args.health_periodic_audit_method, "instance_terminate_policy": args.instance_terminate_policy, "delete_public_ip": args.delete_public_ip, "available_zones": args.available_zones } created = groups.create(args.name, vpc_id, subnets, security_groups, **kwargs) return "Group %s created" % created.id
def add_instance_opt(parser, required=False): parser.add_argument( '--instance-id', required=required, metavar='<instance-id>', help=_("template server instance id (Either instance-id or " "flavor + image + disk is required)"))
def add_config_id_opt(parser, required=False): parser.add_argument( '--config', required=required, metavar='<config>', help=_("Auto-Scaling config to assign to the instance " "(ID or name)"))
def add_desired_instance_opt(parser, required=False): parser.add_argument( '--desire-instance', required=required, metavar='<number>', type=int, help=_("Auto-Scaling group desired instance number"))
def add_sortdir_option(parser): parser.add_argument( "--sort-dir", choices=['desc', 'asc'], default='desc', help=_("Sort desc|asc") )
def add_vpc_opt(parser, required=True): parser.add_argument( '--vpc', metavar='<vpc>', required=required, help=_("VPC(Router) to assign to the instance (ID or name, " "use openstack router list to get it)"))
def add_end_time_opt(parser): parser.add_argument( '--end-time', metavar="<yyyy-MM-ddTHH:mm:ss>", type=parsetypes.date_type('%Y-%m-%dT%H:%M:%S'), help=_("list group activity logs after this time"), )
def add_group_opt(parser, required=False): parser.add_argument( '--group', metavar="<group>", required=required, help=_("Group (ID or name) which the policies belong to"), )
def add_metadata_opt(parser): parser.add_argument( '--metadata', metavar='<key=value>', action=parseractions.KeyValueAction, help=_('Set a metadata on this server ' '(repeat option to set multiple values)'), )
def add_group_name_opt(parser, help_=None, required=False): help_txt = _(help_ if help_ else "Search by group name") parser.add_argument( '--name', required=required, metavar='<group-name>', help=help_txt, )
def add_cool_down_opt(parser, required=False): parser.add_argument( '--cool-down', required=required, metavar='<seconds>', type=int, help=_("Auto-Scaling policy schedule period (second), " "900 seconds by default"))
def add_alarm_id_opt(parser, required=False): parser.add_argument( '--alarm-id', required=required, metavar="<alarm-id>", help=_("Alarm Id to assign to the policy " "(Only effect when policy-type is ALARM)"), )
def add_policy_type_opt(parser, help_=None, required=False): help_ = _(help_ if help_ else "search by policy type") parser.add_argument( '--type', required=required, choices=["ALARM", "SCHEDULED", "RECURRENCE"], help=help_, )
def add_policy_name_opt(parser, help_=None, required=False): help_ = _(help_ if help_ else "search by policy name") parser.add_argument( '--name', metavar="<policy-name>", required=required, help=help_, )
def add_health_periodic_audit_time_arg(parser, required=False): parser.add_argument( '--health-periodic-audit-time', required=required, metavar='<minute>', choices=[5, 15, 60, 180], type=int, help=_("Auto-Scaling group health periodic audit time (min), " "5 minutes by default."))
def add_file_opt(parser): parser.add_argument( '--file', metavar='<dest-filename=source-filename>', action='append', default=[], help=_('File to inject into instance (repeat option to ' 'set multiple files, max file number is 5)'), )
def add_health_periodic_audit_method_arg(parser, required=False): parser.add_argument( '--health-periodic-audit-method', required=required, metavar='<audit-method>', choices=['ELB_AUDIT', 'NOVA_AUDIT'], help=_("Auto-Scaling group health periodic audit method, " "NOVA_AUDIT by default, if lb-listen-id present, " "ELB_AUDIT will be used."))
def add_end_time_opt(parser, required=False): parser.add_argument( '--end-time', required=required, metavar="<yyyy-MM-ddTHH:mm>", type=parsetypes.date_type('%Y-%m-%dT%H:%M'), help=_("Recurrence end UTC time " "(Effect only when policy-type is RECURRENCE)"), )
def add_instance_terminate_policy_opt(parser, required=False): parser.add_argument( '--instance-terminate-policy', required=required, choices=[ 'OLD_CONFIG_OLD_INSTANCE', 'OLD_CONFIG_NEW_INSTANCE', 'OLD_INSTANCE', 'NEW_INSTANCE' ], help=_("Auto-Scaling group instance terminate policy"))