def get_instance_type(type_id): global inst_types context = RequestContext('1', '1', is_admin=True) if type_id in inst_types: return inst_types[type_id] else: inst_type = sqlapi.model_query(context, novamodels.InstanceTypes)\ .filter_by(id=type_id).first() inst_types[type_id] = inst_type return inst_type
} def colorizer(num): if num <= 20: return "%s%.2f%%\033[0m" % (color_tbl['grey'], num) if num <= 40: return "%s%.2f%%\033[0m" % (color_tbl['green'], num) if num <= 60: return "%s%.2f%%\033[0m" % (color_tbl['blue'], num) if num <= 80: return "%s%.2f%%\033[0m" % (color_tbl['yellow'], num) return "%s%.2f%%\033[0m" % (color_tbl['red'], num) config.parse_args(sys.argv) cxt = RequestContext() host_manager.objects.register_all() def check_services(): objects.register_all() host_api = compute.HostAPI() servicegroup_api = servicegroup.API() api_services = ('nova-osapi_compute', 'nova-ec2', 'nova-metadata') isOK = True print "============================ services check ============================" for s in host_api.service_get_all(cxt, set_zones=True, all_cells=True): if s['binary'] in api_services: continue if not servicegroup_api.service_is_up(s): isOK = False print "%s %s is down" % (s['host'], s['binary'])
# # tab.write() # request_spec = eval(open('/home/kahn/request_spec.txt', 'r').read()) # if request_spec is None: # with open('/home/kahn/error.txt', 'w') as outfile: # outfile.write('Can not open request_spec file') # exit(0) # # others_params_dict = eval(open('/home/kahn/others_params.txt', 'r').read()) # if others_params_dict is None: # with open('/home/kahn/error.txt', 'w') as outfile: # outfile.write('Can not open others_params file') # exit(0) context_dict = eval(pending_instance.get('context')) context = RequestContext.from_dict(context_dict) request_spec = eval(pending_instance.get('request_spec')) others_params_dict = eval(pending_instance.get('other_params')) filter_properties = others_params_dict.get('filter_properties') requested_networks = others_params_dict.get('requested_networks') injected_files = others_params_dict.get('injected_files') admin_password = others_params_dict.get('admin_password') is_first_time = others_params_dict.get('is_first_time') legacy_bdm_in_spec = others_params_dict.get('legacy_bdm_in_spec') scheduler = TimingScheduler() scheduler.run_scheduled_instance(context, request_spec,
def __init__(self, *args, **kwargs): self.ctxt = RequestContext(*args, **kwargs) self.session = RomeSession()
def get_metadata(instance_uuid): context = RequestContext('1', '1', is_admin=True) return sqlapi.instance_system_metadata_get(context, instance_uuid)
def seed(period_length): usages = [] building_usages = [] in_flight_usages = [] deletes = [] start, end = get_previous_period(datetime.datetime.utcnow(), period_length) context = RequestContext(1, 1, is_admin=True) print "Selecting all active instances" active_instances = get_active_instances(period_length) print "Selected all active instances" print "Populating active usages, preparing for in-flight" for instance in active_instances: vm_state = instance['vm_state'] task_state = instance['task_state'] if vm_state == 'building': if instance['deleted'] != 0 and instance['deleted_at'] >= start: building_usages.append(_usage_for_instance(instance)) deletes.append(_delete_for_instance(instance)) elif instance['deleted'] == 0: building_usages.append(_usage_for_instance(instance)) else: if task_state in in_flight_tasks: if (instance['deleted'] != 0 and instance['deleted_at'] is not None and instance['deleted_at'] >= start): # Just in case... deletes.append(_delete_for_instance(instance)) in_flight_usages.append( _usage_for_instance(instance, task=task_state)) elif instance['deleted'] == 0: in_flight_usages.append( _usage_for_instance(instance, task=task_state)) else: if (instance['deleted'] != 0 and instance['deleted_at'] is not None and instance['deleted_at'] >= start): deletes.append(_delete_for_instance(instance)) usages.append(_usage_for_instance(instance)) elif instance['deleted'] == 0: usages.append(_usage_for_instance(instance)) print "Populated active instances, processing building" for usage in building_usages: action = get_action_for_instance(context, usage['instance'], 'create') if action is not None: usage['request_id'] = action['request_id'] print "Populated building, processing in-flight" for usage in in_flight_usages: instance = usage['instance'] action = None if usage['task'] in rebuild_tasks: action = get_action_for_instance(context, instance, 'rebuild') elif usage['task'] in resize_tasks: action = get_action_for_instance(context, instance, 'resize') elif usage['task'] in resize_revert_tasks: action = get_action_for_instance(context, instance, 'resizeRevert') elif usage['task'] in rescue_tasks: action = get_action_for_instance(context, instance, 'rescue') if action is not None: usage['request_id'] = action['request_id'] del usage['task'] print "Done cataloging usage" print "Saving active instances" active_InstanceUsages = map(lambda x: models.InstanceUsage(**x), usages) models.InstanceUsage.objects.bulk_create(active_InstanceUsages, batch_size=100) print "Saving building instances" building_InstanceUsages = map(lambda x: models.InstanceUsage(**x), building_usages) models.InstanceUsage.objects.bulk_create(building_InstanceUsages, batch_size=100) print "Saving in-flight instances" in_flight_InstanceUsages = map(lambda x: models.InstanceUsage(**x), in_flight_usages) models.InstanceUsage.objects.bulk_create(in_flight_InstanceUsages, batch_size=100) print "Saving deletes" all_InstanceDeletes = map(lambda x: models.InstanceDeletes(**x), deletes) models.InstanceDeletes.objects.bulk_create(all_InstanceDeletes, batch_size=100) return (len(usages), len(building_usages), len(in_flight_usages), len(deletes))
def get_computes(): context = RequestContext('1', '1', is_admin=True) return sqlapi.model_query(context, novamodels.Service, read_deleted='no')\ .filter_by(topic='compute').all()
def setUp(self): super(Ec2ErrorResponseTestCase, self).setUp() self.context = RequestContext('test_user_id', 'test_project_id') self.req = Request.blank('/test') self.req.environ['nova.context'] = self.context