def list_virtual_machine(**_): """ List all virtual machines of the system. Variables: offset => Offset at which we start giving virtual machines length => Numbers of virtual machines to return filter => Filter to apply on the virtual machines list Arguments: None Data Block: None Result example: [ { enabled: true, # Is VM enabled name: "Extract", # Name of the VM num-workers: 1, # Number of service workers in that VM os_type: "windows", # Type of OS os_variant: "win7", # Variant of OS ram: 1024, # Amount of RAM revert_every: 600, # Auto revert seconds interval vcpus: 1, # Number of CPUs virtual_disk_url: "img.qcow2" # Name of the virtual disk to download }, ...] """ return make_api_response(STORAGE.list_virtualmachines())
def load_system_info(**kwargs): """ Load the full system information Variables: None Arguments: None Data Block: None Result example: { "vms": {}, # Map of vms that are available in the system "services": {}, # Map of service that are available in the system "hosts": [] # List of physical hosts configured } """ temp_service_map = {x['name']: x for x in STORAGE.list_services()} vm_list = STORAGE.list_virtualmachines() hosts = STORAGE.list_node_keys() host_list = sorted( [ host for host in STORAGE.get_nodes(hosts) if host is not None and 'hostagent' in host.get('roles', []) ], key=lambda k: (k.get('machine_info', {}).get('cores', 1), k.get('machine_info', {}). get('memory', '11.7'), k.get('machine_info', {}).get('name', 1))) service_map = copy.copy(temp_service_map) out_vm_map = {} for vm in vm_list: service_name = vm['name'] srv_list = {service_name: vm['num_workers']} cpu_usage = temp_service_map.get(service_name, {}).get( 'cpu_cores', 1) * vm['num_workers'] out_vm_map[service_name] = { "cpu_usage": cpu_usage, "ram_usage": vm['ram'], "services": srv_list, "enabled": vm.get("enabled", False) } try: del service_map[service_name] except KeyError: continue out_service_map = {} for service in service_map.itervalues(): out_service_map[service['name']] = { "cpu_usage": service.get('cpu_cores', 1), "ram_usage": service.get('ram_mb', 1024), "enabled": service.get("enabled", False) } out_host_list = [] for host in host_list: out_host_list.append({ "hostname": host['machine_info']['name'], "profile": host['profile'], "cores": host['machine_info']['cores'], "memory": float(host['machine_info']['memory']) * 1024, "mac": host['mac_address'] }) return make_api_response({ 'vms': out_vm_map, 'services': out_service_map, "hosts": out_host_list })