def get_all_tags(self, filters=None, max_records=None, next_token=None, callback=None): if self.tags.isCacheStale(): params = {'filters':filters, 'max_records':max_records, 'next_token':next_token} Threads.instance().runThread(self.__get_all_tags_cb__, (params, callback)) else: callback(Response(data=self.tags.values))
def revoke_security_group(self, name=None, src_security_group_name=[], src_security_group_owner_id=[], ip_protocol=[], from_port=[], to_port=[], cidr_ip=[], group_id=[], src_security_group_group_id=[], callback=None): self.caches['groups'].expireCache() Threads.instance().runThread( self.__revoke_security_group_cb__, ({ 'name': name, 'src_security_group_name': src_security_group_name, 'src_security_group_owner_id': src_security_group_owner_id, 'ip_protocol': ip_protocol, 'from_port': from_port, 'to_port': to_port, 'cidr_ip': cidr_ip, 'group_id': group_id, 'src_security_group_group_id': src_security_group_group_id }, callback))
def __modify_snapshot_attribute_cb__(self, kwargs, callback): try: ret = self.clc.modify_snapshot_attribute(kwargs['snapshot_id'], kwargs['attribute'], kwargs['operation'], kwargs['user'], kwargs['groups']) Threads.instance().invokeCallback(callback, Response(data=ret)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def __stop_instances_cb__(self, kwargs, callback): try: ret = self.clc.stop_instances(kwargs['instance_ids'], kwargs['force']) Threads.instance().invokeCallback(callback, Response(data=ret)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def reset_image_attribute(self, image_id, attribute): self.caches['images'].expireCache() Threads.instance().runThread(self.__reset_image_attribute_cb__, ({ 'image_id': image_id, 'attribute': attribute }, callback))
def stop_instances(self, instance_ids, force=False, callback=None): self.caches['instances'].expireCache() Threads.instance().runThread(self.__stop_instances_cb__, ({ 'instance_ids': instance_ids, 'force': force }, callback))
def __get_all_tags_cb__(self, kwargs, callback): try: ret = self.clc.get_all_tags(kwargs['filters']) self.caches['tags'].values = ret Threads.instance().invokeCallback(callback, Response(data=ret)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def __delete_auto_scaling_group_cb__(self, kwargs, callback): try: ret = self.scaling.delete_auto_scaling_group( kwargs['name'], kwargs['force_delete']) Threads.instance().invokeCallback(callback, Response(data=ret)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def __import_key_pair_cb__(self, kwargs, callback): try: ret = self.clc.import_key_pair(kwargs['key_name'], kwargs['public_key_material']) Threads.instance().invokeCallback(callback, Response(data=ret)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def __delete_security_group_cb__(self, kwargs, callback): try: ret = self.clc.delete_security_group(kwargs['name'], kwargs['group_id']) Threads.instance().invokeCallback(callback, Response(data=ret)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def __get_all_instances_cb__(self, kwargs, callback): try: self.instances.values = self.clc.get_all_instances() Threads.instance().invokeCallback(callback, Response(data=self.__normalize_instances__(self.instances.values))) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def __get_all_groups_cb__(self, kwargs, callback): try: self.groups.values = self.scaling.get_all_groups(kwargs['names'], kwargs['max_records'], kwargs['next_token']) Threads.instance().invokeCallback(callback, Response(data=self.groups.values)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def __delete_policy_cb__(self, kwargs, callback): try: ret = self.scaling.delete_policy(kwargs['policy_name'], kwargs['autoscale_group']) Threads.instance().invokeCallback(callback, Response(data=ret)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def __get_all_regions_cb__(self, kwargs, callback): try: ret = self.clc.get_all_regions(kwargs['filters']) logging.info("regions = "+str(ret)) Threads.instance().invokeCallback(callback, Response(data=ret)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def __get_all_regions_cb__(self, kwargs, callback): try: ret = self.clc.get_all_regions(kwargs['filters']) logging.info("regions = " + str(ret)) Threads.instance().invokeCallback(callback, Response(data=ret)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def __list_metrics_cb__(self, kwargs, callback): try: self.caches['metrics'].values = self.cw.list_metrics(kwargs['next_token'], kwargs['dimensions'], kwargs['metric_name'], kwargs['namespace']) Threads.instance().invokeCallback(callback, Response(data=self.caches['metrics'].values)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def __describe_alarms_cb__(self, kwargs, callback): try: self.caches['alarms'].values = self.cw.describe_alarms(kwargs['action_prefix'], kwargs['alarm_name_prefix'], kwargs['alarm_names'], kwargs['max_records'], kwargs['state_value'], kwargs['next_token']) Threads.instance().invokeCallback(callback, Response(data=self.caches['alarms'].values)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def associate_address(self, publicip, instanceid, callback): self.caches['addresses'].expireCache() Threads.instance().runThread(self.__associate_address_cb__, ({ 'publicip': publicip, 'instanceid': instanceid }, callback))
def terminate_instance(self, instance_id, decrement_capacity=True): params = { 'instance_id': instance_id, 'decrement_capacity': decrement_capacity } Threads.instance().runThread(self.__terminate_instance_cb__, (params, callback))
def __associate_address_cb__(self, kwargs, callback): try: ret = self.clc.associate_address(kwargs['publicip'], kwargs['instanceid']) Threads.instance().invokeCallback(callback, Response(data=ret)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def __terminate_instance_cb__(self, kwargs, callback): try: ret = self.scaling.set_instance_health( kwargs['instance_id'], kwargs['decrement_capacity']) Threads.instance().invokeCallback(callback, Response(data=ret)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def create_security_group(self, name, description, callback): self.caches['groups'].expireCache() Threads.instance().runThread(self.__create_security_group_cb__, ({ 'name': name, 'description': description }, callback))
def __delete_launch_configuration_cb__(self, kwargs, callback): try: ret = self.scaling.delete_launch_configuration( kwargs['launch_config_name']) Threads.instance().invokeCallback(callback, Response(data=ret)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def register_image(self, name, image_location=None, description=None, architecture=None, kernel_id=None, ramdisk_id=None, root_dev_name=None, block_device_map=None, callback=None): self.caches['images'].expireCache() Threads.instance().runThread(self.__register_image_cb__, ({'name':name, 'image_location':image_location, 'description':description, 'architecture':architecture, 'kernel_id':kernel_id, 'ramdisk_id':ramdisk_id, 'root_dev_name':root_dev_name, 'block_device_map':block_device_map}, callback))
def __create_snapshot_cb__(self, kwargs, callback): try: ret = self.clc.create_snapshot(kwargs['volume_id'], kwargs['description']) Threads.instance().invokeCallback(callback, Response(data=ret)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def create_snapshot(self, volume_id, description, callback): self.caches['snapshots'].expireCache() Threads.instance().runThread(self.__create_snapshot_cb__, ({ 'volume_id': volume_id, 'description': description }, callback))
def get_all_policies(self, as_group=None, policy_names=None, max_records=None, next_token=None, callback=None): if self.caches['policies'].isCacheStale(): params = {'as_group':as_group, 'policy_names':policy_names, 'max_records':max_records, 'next_token':next_token} Threads.instance().runThread(self.__get_all_policies_cb__, (params, callback)) else: callback(Response(data=self.caches['policies'].values))
def __list_metrics_cb__(self, kwargs, callback): try: self.metrics.values = self.cw.list_metrics(kwargs['next_token'], kwargs['dimensions'], kwargs['metric_name'], kwargs['namespace']) Threads.instance().invokeCallback(callback, Response(data=self.metrics.values)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def __reset_snapshot_attribute_cb__(self, kwargs, callback): try: ret = self.clc.reset_snapshot_attribute(kwargs['snapshot_id'], kwargs['attribute']) Threads.instance().invokeCallback(callback, Response(data=ret)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def __get_all_buckets_cb__(self, kwargs, callback): try: self.caches['buckets'].values = self.walrus.get_all_buckets() Threads.instance().invokeCallback( callback, Response(data=self.caches['buckets'].values)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def get_all_load_balancers(self, load_balancer_names=None, callback=None): if self.balancers.isCacheStale(): params = {'load_balancer_names': load_balancer_names} Threads.instance().runThread(self.__get_all_load_balancers_cb__, (params, callback)) else: callback(Response(data=self.balancers.values))
def run_instances(self, image_id, min_count=1, max_count=1, key_name=None, security_groups=None, user_data=None, addressing_type=None, instance_type='m1.small', placement=None, kernel_id=None, ramdisk_id=None, monitoring_enabled=False, subnet_id=None, block_device_map=None, disable_api_termination=False, instance_initiated_shutdown_behavior=None, private_ip_address=None, placement_group=None, client_token=None, security_group_ids=None, additional_info=None, instance_profile_name=None, instance_profile_arn=None, tenancy=None, callback=None): self.caches['instances'].expireCache() Threads.instance().runThread(self.__run_instances_cb__, ({'image_id':image_id, 'min_count':min_count, 'max_count':max_count, 'key_name':key_name, 'security_groups':security_groups, 'user_data':user_data, 'addressing_type':addressing_type, 'instance_type':instance_type, 'placement':placement, 'kernel_id':kernel_id, 'ramdisk_id':ramdisk_id, 'monitoring_enabled':monitoring_enabled, 'subnet_id':subnet_id, 'block_device_map':block_device_map, 'disable_api_termination':disable_api_termination, 'instance_initiated_shutdown_behavior':instance_initiated_shutdown_behavior, 'private_ip_address':private_ip_address, 'placement_group':placement_group, 'client_token':client_token, 'security_group_ids':security_group_ids, 'additional_info':additional_info, 'instance_profile_name':instance_profile_name, 'instance_profile_arn':instance_profile_arn, 'tenancy':tenancy}, callback))
def __create_load_balancer_cb__(self, kwargs, callback): try: ret = self.bal.create_load_balancer(kwargs['name'], kwargs['zones'], kwargs['listeners'], kwargs['subnets'], kwargs['security_groups'], kwargs['scheme']) Threads.instance().invokeCallback(callback, Response(data=ret)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def __describe_instance_health_cb__(self, kwargs, callback): try: ret = self.bal.describe_instance_health( kwargs['load_balancer_name'], kwargs['instances']) Threads.instance().invokeCallback(callback, Response(data=ret)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def get_all_zones(self, filters, callback): # if cache stale, update it if self.caches['zones'].isCacheStale(filters): Threads.instance().runThread(self.__get_all_zones_cb__, ({'filters':filters}, callback)) self.caches['zones'].filters = filters else: callback(Response(data=self.caches['zones'].values))
def __delete_load_balancer_listeners_cb__(self, kwargs, callback): try: ret = self.bal.delete_load_balancer_listeners( kwargs['name'], kwargs['ports']) Threads.instance().invokeCallback(callback, Response(data=ret)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def __configure_health_check_cb__(self, kwargs, callback): try: ret = self.bal.configure_health_check(kwargs['name'], kwargs['health_check']) Threads.instance().invokeCallback(callback, Response(data=ret)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def register_instances(self, load_balancer_name, instances, callback=None): params = { 'load_balancer_name': load_balancer_name, 'instances': instances } Threads.instance().runThread(self.__register_instances_cb__, (params, callback))
def __register_instances_cb__(self, kwargs, callback): try: ret = self.bal.register_instances(kwargs['load_balancer_name'], kwargs['instances']) Threads.instance().invokeCallback(callback, Response(data=ret)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def get_all_buckets(self, callback): # if cache stale, update it if self.caches['buckets'].isCacheStale(): Threads.instance().runThread(self.__get_all_buckets_cb__, ({}, callback)) else: callback(Response(data=self.caches['buckets'].values))
def reset_snapshot_attribute(self, snapshot_id, attribute, callback): self.caches['snapshots'].expireCache() Threads.instance().runThread(self.__reset_snapshot_attribute_cb__, ({ 'snapshot_id': snapshot_id, 'attribute': attribute }, callback))
def __get_all_launch_configurations_cb__(self, kwargs, callback): try: self.caches['launchconfigs'].values = self.scaling.get_all_launch_configurations( kwargs['names'], kwargs['max_records'], kwargs['next_token']) Threads.instance().invokeCallback(callback, Response(data=self.caches['launchconfigs'].values)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def __terminate_instance_cb__(self, kwargs, callback): try: ret = self.scaling.terminate_instance(kwargs['instance_id'], kwargs['decrement_capacity']) Threads.instance().invokeCallback(callback, Response(data=ret)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def __set_instance_health_cb__(self, kwargs, callback): try: ret = self.scaling.set_instance_health(kwargs['instance_id'], kwargs['health_status'], kwargs['should_respect_grace_period']) Threads.instance().invokeCallback(callback, Response(data=ret)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def __set_desired_capacity_cb__(self, kwargs, callback): try: ret = self.scaling.set_desired_capacity(kwargs['group_name'], kwargs['desired_capacity'], kwargs['honor_cooldown']) Threads.instance().invokeCallback(callback, Response(data=ret)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def __get_metric_statistics_cb__(self, kwargs, callback): try: ret = self.cw.get_metric_statistics(kwargs['period'], kwargs['start_time'], kwargs['end_time'], kwargs['metric_name'], kwargs['namespace'], kwargs['statistics'], kwargs['dimensions'], kwargs['unit']) Threads.instance().invokeCallback(callback, Response(data=ret)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def __put_metric_data_cb__(self, kwargs, callback): try: ret = self.cw.put_metric_data(kwargs['namespace'], kwargs['name'], kwargs['value'], kwargs['timestamp'], kwargs['unit'], kwargs['dimensions'], kwargs['statistics']) Threads.instance().invokeCallback(callback, Response(data=ret)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def get_all_autoscaling_instances(self, instance_ids=None, max_records=None, next_token=None, callback=None): if self.instances.isCacheStale(): params = {'instance_ids':instance_ids, 'max_records':max_records, 'next_token':next_token} Threads.instance().runThread(self.__get_all_autoscaling_instances_cb__, (params, callback)) else: callback(Response(data=self.instances.values))
def describe_alarms(self, action_prefix=None, alarm_name_prefix=None, alarm_names=None, max_records=None, state_value=None, next_token=None, callback=None): if self.caches['alarms'].isCacheStale(): params = {'action_prefix':action_prefix, 'alarm_name_prefix':alarm_name_prefix, 'alarm_names':alarm_names, 'max_records':max_records, 'state_value':state_value, 'next_token':next_token} Threads.instance().runThread(self.__describe_alarms_cb__, (params, callback)) else: callback(Response(data=self.caches['alarms'].values))
def __register_image_cb__(self, kwargs, callback): try: ret = self.clc.register_image(kwargs['name'], kwargs['image_location'], kwargs['description'], kwargs['architecture'], kwargs['kernel_id'], kwargs['ramdisk_id'], kwargs['root_dev_name'], kwargs['block_device_map']) Threads.instance().invokeCallback(callback, Response(data=ret)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def __get_all_autoscaling_instances_cb__(self, kwargs, callback): try: self.caches['scalinginsts'].values = self.scaling.get_all_autoscaling_instances( kwargs['instance_ids'], kwargs['max_records'], kwargs['next_token']) Threads.instance().invokeCallback(callback, Response(data=self.caches['scalinginsts'].values)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def __get_password_cb__(self, kwargs, callback): try: passwd_data = self.user_session.clc.get_password_data(kwargs['instanceid']) priv_key_file = self.request.files['priv_key'] user_priv_key = RSA.load_key_string(priv_key_file[0].body) string_to_decrypt = base64.b64decode(passwd_data) ret = user_priv_key.private_decrypt(string_to_decrypt, RSA.pkcs1_padding) ret = {'instance':kwargs['instanceid'], 'password': ret} Threads.instance().invokeCallback(callback, eucaconsole.cachingclcinterface.Response(data=ret)) except Exception as ex: traceback.print_exc(file=sys.stdout) Threads.instance().invokeCallback(callback, eucaconsole.cachingclcinterface.Response(error=ex))
def revoke_security_group(self, name=None, src_security_group_name=[], src_security_group_owner_id=[], ip_protocol=[], from_port=[], to_port=[], cidr_ip=[], group_id=[], src_security_group_group_id=[], callback=None): self.caches['groups'].expireCache() Threads.instance().runThread(self.__revoke_security_group_cb__, ({'name':name, 'src_security_group_name':src_security_group_name, 'src_security_group_owner_id':src_security_group_owner_id, 'ip_protocol':ip_protocol, 'from_port':from_port, 'to_port':to_port, 'cidr_ip':cidr_ip, 'group_id':group_id, 'src_security_group_group_id':src_security_group_group_id}, callback))
def __revoke_security_group_cb__(self, kwargs, callback): try: ret = [] for i in range(len(kwargs['ip_protocol'])): ret.append(self.clc.revoke_security_group(kwargs['name'], kwargs['src_security_group_name'][i] if kwargs['src_security_group_name'] else None, kwargs['src_security_group_owner_id'][i] if kwargs['src_security_group_owner_id'] else None, kwargs['ip_protocol'][i], kwargs['from_port'][i], kwargs['to_port'][i], kwargs['cidr_ip'][i] if kwargs['cidr_ip'] else None, kwargs['group_id'][i] if kwargs['group_id'] else None, kwargs['src_security_group_group_id'][i] if kwargs['src_security_group_group_id'] else None)) Threads.instance().invokeCallback(callback, Response(data=ret)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def __run_instances_cb__(self, kwargs, callback): try: ret = self.clc.run_instances(kwargs['image_id'], kwargs['min_count'], kwargs['max_count'], kwargs['key_name'], kwargs['security_groups'], kwargs['user_data'], kwargs['addressing_type'], kwargs['instance_type'], kwargs['placement'], kwargs['kernel_id'], kwargs['ramdisk_id'], kwargs['monitoring_enabled'], kwargs['subnet_id'], kwargs['block_device_map'], kwargs['disable_api_termination'], kwargs['instance_initiated_shutdown_behavior'], kwargs['private_ip_address'], kwargs['placement_group'], kwargs['client_token'], kwargs['security_group_ids'], kwargs['additional_info'], kwargs['instance_profile_name'], kwargs['instance_profile_arn'], kwargs['tenancy']) Threads.instance().invokeCallback(callback, Response(data=self.__normalize_instances__([ret]))) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))
def handleGetPassword(self, clc, callback): instanceid = self.get_argument("InstanceId") Threads.instance().runThread(self.__get_password_cb__, ({"instanceid": instanceid}, callback))
def deregister_instances(self, load_balancer_name, instances, callback=None): params = {'load_balancer_name':load_balancer_name, 'instances':instances} Threads.instance().runThread(self.__deregister_instances_cb__, (params, callback))
def __get_all_load_balancers_cb__(self, kwargs, callback): try: self.caches['balancers'].values = self.bal.get_all_load_balancers(kwargs['load_balancer_names']) Threads.instance().invokeCallback(callback, Response(data=self.caches['balancers'].values)) except Exception as ex: Threads.instance().invokeCallback(callback, Response(error=ex))