def get_instances(request): nvclient = get_nova_client() search_opts = {} server_list = [] search_opts['all_tenants'] = True for s in nvclient.servers.list(False, search_opts): inst_name = str(nova.Server(s, request).name) inst_id = str(nova.Server(s, request).id) inst_dtls = {"id": inst_id, "name": inst_name} server_list.append(inst_dtls) return server_list
def server_list_nova(request, search_opts=None, all_tenants=False): page_size = utils.get_page_size(request) c = get_nova_client() paginate = False if search_opts is None: search_opts = {} elif 'paginate' in search_opts: paginate = search_opts.pop('paginate') if paginate: search_opts['limit'] = page_size + 1 if all_tenants: search_opts['all_tenants'] = True else: search_opts['project_id'] = request.user.tenant_id servers = [ nova.Server(s, request) for s in c.servers.list(True, search_opts) ] has_more_data = False if paginate and len(servers) > page_size: servers.pop(-1) has_more_data = True elif paginate and len(servers) == getattr(settings, 'API_RESULT_LIMIT', 1000): has_more_data = True return (servers, has_more_data)
def get_instance(request, instance_id): nvclient = get_nova_client() #Initializing the values vm_name = '' try: #Fetching the instance details instance_details = nova.Server(nvclient.servers.get(instance_id), request) if instance_details: vm_name = instance_details.name except Exception as e: print '-------------' print e print '-------------' #Case when VM is in deleted state return 'VM Deleted' return vm_name