示例#1
0
def create_vm(body):  # noqa: E501
    """create a new vm

     # noqa: E501

    :param body: VM object that needs to be added
    :type body: dict | bytes

    :rtype: None
    """

    if connexion.request.is_json:
        body = VM.from_dict(connexion.request.get_json())  # noqa: E501

    vm = {
        "vmId": body.vm_id,
        "name": body.name,
        "image": body.image,
        "location": body.location,
        "ramSize": body.ram_size,
        "diskSize": body.disk_size,
        "status": body.status
        }


    vmid = vmdao.insertVM(vm)
    return "vm created"
示例#2
0
def vms_get():  # noqa: E501
    """vms_get

    Returns a list of VMs # noqa: E501


    :rtype: List[VM]
    """
    vms = []
    compute = googleapiclient.discovery.build('compute', 'v1')

    zones = compute.zones().list(project=project).execute()
    results = []

    for zone in zones['items']:
        instances = compute.instances().list(project=project,
                                             zone=zone['name']).execute()
        if 'items' in instances.keys():
            results = results + instances['items']

    for result in results:
        vm = VM(id=result['id'],
                creation_timestamp=result['creationTimestamp'],
                name=result['name'],
                description=result['description'],
                machine_type=result['machineType'],
                status=result['status'],
                zone=result['zone'],
                can_ip_forward=result['canIpForward'])
        vms.append(vm)

    return vms
def vms_id_get(id):  # noqa: E501
    """vms_id_get

    Returns list of virtual machines present in given resource group # noqa: E501

    :param id: name of the resource group
    :type id: str

    :rtype: VM
    """
    print('\nList VMs in resource group')
    listofvm = []
    for vm in compute_client.virtual_machines.list(id):
        nic = vm.network_profile.network_interfaces
        listofvm.append(
            VM(
                vm.identity,
                VMOsProfile(vm.os_profile.computer_name,
                            vm.os_profile.admin_username,
                            vm.os_profile.admin_password),
                VMStorageProfile(
                    VMStorageProfileImageRef(
                        vm.storage_profile.image_reference.publisher,
                        vm.storage_profile.image_reference.offer,
                        vm.storage_profile.image_reference.sku,
                        vm.storage_profile.image_reference.version)), vm.name,
                vm.tags, vm.vm_id,
                VMHardwareProfile(vm.hardware_profile.vm_size),
                vm.provisioning_state, VMNetworkProfile(nic[0].id), vm.type,
                vm.id, vm.location))
    return listofvm
def get_virtual_machine_by_id(detail):  # noqa: E501
    """get_virtual_machine_by_id

    Returns details of virtual machine with given name # noqa: E501

    :param detail: name of the virtual machine and resource group
    :type detail: dict | bytes

    :rtype: VM
    """
    if connexion.request.is_json:
        detail = connexion.request.get_json()  # noqa: E501

    print('\nGet Virtual Machine by Name')
    print(detail['group_name'], detail['vm_name'])
    vm = compute_client.virtual_machines.get(detail['group_name'],
                                             detail['vm_name'])
    nic = vm.network_profile.network_interfaces
    return VM(
        vm.identity,
        VMOsProfile(vm.os_profile.computer_name, vm.os_profile.admin_username,
                    vm.os_profile.admin_password),
        VMStorageProfile(
            VMStorageProfileImageRef(
                vm.storage_profile.image_reference.publisher,
                vm.storage_profile.image_reference.offer,
                vm.storage_profile.image_reference.sku,
                vm.storage_profile.image_reference.version)),
        vm.name, vm.tags, vm.vm_id,
        VMHardwareProfile(vm.hardware_profile.vm_size), vm.provisioning_state,
        VMNetworkProfile(nic[0].id), vm.type, vm.id, vm.location)
def vms_get():  # noqa: E501
    """vms_get

    Returns list on VMs # noqa: E501


    :rtype: List[VM]
    """
    vms = []
    for vmInst in vmdao.getAllVMS():
        vm = VM(vm_id=vmInst['vmId'],
                name=vmInst['name'],
                image=vmInst['image'],
                location=vmInst['location'],
                ram_size=vmInst['ramSize'],
                disk_size=vmInst['diskSize'],
                status=vmInst['status'])
        vms.append(vm)

    return vms
示例#6
0
def get_vm_by_id(vmId):  # noqa: E501
    """Find vm by ID

    Returns a single vm # noqa: E501

    :param vmId: ID of VM to return
    :type vmId: int

    :rtype: VM
    """
    vmInst = vmdao.getVMbyID(vmId)
    vm = VM(vm_id=vmInst['vmId'],
            name=vmInst['name'],
            image=vmInst['image'],
            location=vmInst['location'],
            ram_size=vmInst['ramSize'],
            disk_size=vmInst['diskSize'],
            status=vmInst['status']
            )

    return vm