def handle(self, args): """ Handle the launch command """ # Load the regions for the launch command regions = Regions(region for region in Regions.load() if str(region) in args.regions) # Get the templates associated with each region self.templates = regions.launch_templates() # Launch the instances with the specified template instances = Instances.collect( wait( (partial(self.launch_in_region, region) for region in regions), args=(args, ))) # Rename the instances given wait((partial(self.tag_instance, instance, idx) for idx, instance in enumerate(instances)), args=(args, )) # Update the instances under management manager = ManagedInstances.load() for instance in instances: manager.add(str(instance), instance.region) manager.dump() # Report what went down print( color.format("created {} instances in {} regions", color.LIGHT_GREEN, len(instances), len(regions)))
def handle(self, args): """ Handle the template command """ regions = Regions.load_active() wait((partial(self.handle_region, region) for region in regions), args=(args, ))
def instances(self, status=False, **kwargs): """ Returns a collection of instances across all regions. If status is True then the status for all instances are also collected. """ instances = wait((region.instances for region in self), kwargs=kwargs) if status: wait((instance.update_statuses for instance in instances)) return Instances.collect(instances)
def images(self, **kwargs): """ Returns the images associated with the region. By default this filters the images that belong to the owner id set in the configuration file, otherwise this will take a really long time and return many results. """ return Images.collect( wait((region.images for region in self), kwargs=kwargs))
def handle(self, args): """ Handle the sg:destroy command """ args.regions = set(args.regions) regions = Regions( region for region in Regions.load() if str(region) in args.regions ) results = wait( (partial(self.handle_region, region) for region in regions), args=(args,)) table = [['', 'Region', 'Notes']] + results print(tabulate(table, tablefmt=args.tablefmt, headers='firstrow'))
def handle(self, args): """ Handle the security group create command """ # Load the regions for the sg command regions = Regions.load() # Filter regions specified args.regions = set(args.regions) if "all" not in args.regions: regions = Regions( region for region in regions if str(region) in args.regions ) results = wait( (partial(self.handle_region, region) for region in regions), args=(args,)) table = [['', 'Region', 'Notes']] + results print(tabulate(table, tablefmt=args.tablefmt, headers='firstrow'))
def placement_groups(self, **kwargs): """ Returns the placement groups associated with the region. """ return PlacementGroups.collect( wait((region.placement_groups for region in self), kwargs=kwargs))
def security_groups(self, **kwargs): """ Returns the security groups associated with the region. """ return SecurityGroups.collect( wait((region.security_groups for region in self), kwargs=kwargs))
def launch_templates(self, **kwargs): """ Returns the launch templates associated with the region. """ return LaunchTemplates.collect( wait((region.launch_templates for region in self), kwargs=kwargs))
def key_pairs(self, **kwargs): """ Returns the keys associated with the region. """ return KeyPairs.collect( wait((region.key_pairs for region in self), kwargs=kwargs))
def volumes(self, **kwargs): """ Returns a collection of volumes across all regions. """ return Volumes.collect( wait((region.volumes for region in self), kwargs=kwargs))
def zones(self, **kwargs): """ Returns a collection ofa vailability zones across all regions. """ return AvailabilityZones.collect( wait((region.zones for region in self), kwargs=kwargs))