def GetAutoscalerResource(self, igm_ref, args): if _IsZonalGroup(igm_ref): scope_name = igm_ref.zone scope_type = 'zone' zones, regions = [scope_name], None else: scope_name = igm_ref.region scope_type = 'region' zones, regions = None, [scope_name] autoscaler = managed_instance_groups_utils.AutoscalerForMig( mig_name=args.name, autoscalers=managed_instance_groups_utils.AutoscalersForLocations( regions=regions, zones=zones, project=self.project, compute=self.compute, http=self.http, batch_url=self.batch_url), project=self.project, scope_name=scope_name, scope_type=scope_type) if autoscaler is None: raise managed_instance_groups_utils.ResourceNotFoundException( 'The managed instance group is not autoscaled.') return autoscaler
def CreateRequests(self, args): igm_ref = self.CreateZonalReference( args.name, args.zone, resource_type='instanceGroupManagers') # We need the zone name, which might have been passed after prompting. # In that case, we get it from the reference. zone = args.zone or igm_ref.zone managed_instance_groups_utils.AssertInstanceGroupManagerExists( igm_ref, self.project, self.messages, self.compute, self.http, self.batch_url) autoscaler = managed_instance_groups_utils.AutoscalerForMig( mig_name=args.name, autoscalers=managed_instance_groups_utils.AutoscalersForZones( zones=[zone], project=self.project, compute=self.compute, http=self.http, batch_url=self.batch_url), project=self.project, zone=zone) if autoscaler is None: raise managed_instance_groups_utils.ResourceNotFoundException( 'The managed instance group is not autoscaled.') as_ref = self.CreateZonalReference(autoscaler.name, zone) request = self.messages.ComputeAutoscalersDeleteRequest( project=self.project) request.zone = zone request.autoscaler = as_ref.Name() return (request, )
def check_if_instance_config_exists(self, igm_ref, instance_ref, should_exist=True): """Checks if instance config exists for given instance reference.""" per_instance_config = self.get_instance_config( igm_ref=igm_ref, instance_ref=instance_ref) if should_exist: if per_instance_config is None: raise managed_instance_groups_utils.ResourceNotFoundException( 'Instance config for {instance} does not exist'.format( instance=instance_ref.SelfLink())) else: if per_instance_config is not None: raise managed_instance_groups_utils.ResourceAlreadyExistsException( 'Instance config for {instance} already exists'.format( instance=instance_ref.SelfLink()))
def GetAutoscalerResource(self, client, resources, igm_ref, args): if _IsZonalGroup(igm_ref): scope_type = 'zone' location = managed_instance_groups_utils.CreateZoneRef( resources, igm_ref) zones, regions = [location], None else: scope_type = 'region' location = managed_instance_groups_utils.CreateRegionRef( resources, igm_ref) zones, regions = None, [location] autoscaler = managed_instance_groups_utils.AutoscalerForMig( mig_name=args.name, autoscalers=managed_instance_groups_utils.AutoscalersForLocations( regions=regions, zones=zones, client=client), location=location, scope_type=scope_type) if autoscaler is None: raise managed_instance_groups_utils.ResourceNotFoundException( 'The managed instance group is not autoscaled.') return autoscaler