Example #1
0
def poweroff_vm(vcip, vmid):
    url = 'https://' + vcip + '/rest/vcenter/vm/' + vmid + '/power/stop'
    r = vc_session.post(url)
    try:
        return r.json()
    except Exception:
        return 'vm has power off'
Example #2
0
def create_vm(vcip, vmname):
    vm_json = {
        "spec": {
            "placement": {
                "folder": "group-v825",
                "host": "host-684",
                "datastore": "datastore-686"
            },
            "name": vmname,
            "guest_OS": "RHEL_7_64",
            "memory": {
                "hot_add_enabled": True,
                "size_MiB": 2048
            },
            "cpu": {
                "count": 1,
                "hot_add_enabled": True,
                "hot_remove_enabled": True,
                "cores_per_socket": 1
            }
        }
    }
    url = 'https://' + vcip + '/rest/vcenter/vm/'
    r = vc_session.post(url, json=vm_json)
    return r.json()
Example #3
0
def add_vm_sata_control(vcip, vmid):
    url = 'https://' + vcip + '/rest/vcenter/vm/' + vmid + '/hardware/adapter/sata'
    request_body = {
                  "spec": {
                    "bus": 0,
                    "pci_slot_number": 0,
                    "type": "AHCI"
                  }
                }

    r = vc_session.post(url, json=request_body)
    return r.json()
Example #4
0
def add_vm_nic(vcip, vmid, network_name):
    add_nic_json = {
        "spec": {
            "backing": {
                "type": "STANDARD_PORTGROUP",
                "network": network_name
            },
            "allow_guest_control": True,
            "mac_type": "ASSIGNED",
            "wake_on_lan_enabled": True,
            "start_connected": True,
            "type": "VMXNET3"
        }
    }
    url = 'https://' + vcip + '/rest/vcenter/vm/' + vmid + '/hardware/ethernet'
    r = vc_session.post(url, json=add_nic_json)
    return r.text
Example #5
0
def add_vm_cdrom(vcip, vmid):
    url = 'https://' + vcip + '/rest/vcenter/vm/' + vmid + '/hardware/cdrom'
    request_body = {
                    "spec": {
                        "sata": {
                            "unit": 0,
                            "bus": 0
                        },

                        "allow_guest_control": True,
                        "backing": {

                            "iso_file": "[data-esxi] IOS/ubuntu-18.04.3-desktop-amd64.iso",

                            "type": "ISO_FILE"
                        },
                        "start_connected": True,
                        "type": "SATA"
                    }
                }

    r = vc_session.post(url, json=request_body)
    return r.json()