Example #1
0
    def get_virtual_disk_count(cls,
                               client_object,
                               vm_ip_address=None,
                               esx_host_ip=None,
                               esx_username=None,
                               esx_password=None,
                               **kwargs):
        """
        Fetches the VIRTUAL DISK COUNT for given VM IP Addr

        The method uses the ESX ip and credentials to create
        the ESX managed object reference.
        Next it uses the ESX mor to fetch MOID of given vm_ip_address
        Thereafter it fetches the Disk Count using the moid
        Finally returns the fetched value to calling method

        @type client_object: instance
        @param client_object: VMAPIClient object.

        @rtype: int
        @param: Virtual Disk Count
        """

        hc = esx_facade.ESXFacade(esx_host_ip, esx_username, esx_password)
        edge_moid = hc.fetch_moid_from_ip(vm_ip_address=vm_ip_address)

        vm = vm_facade.VMFacade(edge_moid, parent=hc)
        actual_virtual_disk_count = vm.get_virtual_disk_count()

        pylogger.debug("actual_virtual_disk_count retrieved ...%s ",
                       actual_virtual_disk_count)

        pydict = {'expected_virtual_disk_count': actual_virtual_disk_count}
        return pydict
Example #2
0
    def get_nic_status(cls,
                       client_object,
                       vm_ip_address=None,
                       vnic_index=None,
                       esx_host_ip=None,
                       esx_username=None,
                       esx_password=None,
                       **kwargs):
        """
        Fetches the NIC STATUS for given VM IP Addr and vnic_index

        The method uses the ESX ip and credentials to create
        the ESX managed object reference.
        Next it uses the ESX mor to fetch MOID of given vm_ip_address
        Thereafter it fetches the NIC Status for the given index using the moid
        Finally returns the fetched value to calling method

        @type client_object: instance
        @param client_object: VMAPIClient object.

        @rtype: str
        @param: NIC Status
        """
        hc = esx_facade.ESXFacade(esx_host_ip, esx_username, esx_password)
        edge_moid = hc.fetch_moid_from_ip(vm_ip_address=vm_ip_address)

        vm = vm_facade.VMFacade(edge_moid, parent=hc)
        actual_nic_status = vm.get_nic_status(vnic_index=int(vnic_index))

        pylogger.debug("actual_nic_status retrieved ...%s ", actual_nic_status)

        pydict = {'expected_nic_status': actual_nic_status}
        return pydict
Example #3
0
    def get_guest_net_info(cls,
                           client_object,
                           vm_name=None,
                           host_ip=None,
                           username=None,
                           password=None,
                           **kwargs):
        """
        Fetches guest net info for given VM name

        The method uses the ESX ip and credentials to create
        the ESX managed object reference.
        Next it uses the ESX mor to fetch MOID of given vm_name
        Finally returns the fetched value to calling method

        @type client_object: instance
        @param client_object: VMAPIClient object.

        @rtype: table
        @param: guest net info table
        """

        hc = esx_facade.ESXFacade(host_ip, username, password)
        edge_moid = hc.fetch_vm_mor_from_name(vm_name=vm_name)

        vm = vm_facade.VMFacade(edge_moid, parent=hc)
        return vm.get_guest_net_info()
Example #4
0
    def get_max_cpu_usage(cls,
                          client_object,
                          vm_ip_address=None,
                          esx_host_ip=None,
                          esx_username=None,
                          esx_password=None,
                          **kwargs):
        """
        Fetches the MAX CPU value for given VM IP Addr

        The method uses the ESX ip and credentials to create the ESX
        managed object reference.
        Next it uses the ESX mor to fetch MOID of given vm_ip_address
        Thereafter it fetches the Maximum CPU Usage for the given moid
        Finally returns the fetched value to calling method

        @type client_object: instance
        @param client_object: VMAPIClient object.

        @rtype: str
        @param: Maximum CPU Usage
        """

        hc = esx_facade.ESXFacade(esx_host_ip, esx_username, esx_password)
        edge_moid = hc.fetch_moid_from_ip(vm_ip_address=vm_ip_address)

        vm = vm_facade.VMFacade(edge_moid, parent=hc)
        actual_max_cpu_usage = vm.get_max_cpu_usage()

        pylogger.debug("actual_max_cpu_usage retrieved ...%s ",
                       actual_max_cpu_usage)

        pydict = {'expected_max_cpu_usage': actual_max_cpu_usage}
        return pydict
Example #5
0
def main():

    import vmware.vsphere.esx.esx_facade as esx_facade
    import vmware.vsphere.esx.vsswitch.vsswitch_facade as vsswitch_facade
    import vmware.common.global_config as global_config

    pylogger = global_config.pylogger

    hv = esx_facade.ESXFacade("10.144.138.189", "root", "ca$hc0w")

    vss = vsswitch_facade.VSSwitchFacade(name="vSwitch0", parent=hv)

    result = vss.read()
    pylogger.info("Operation result = %r" % result)
Example #6
0
def main():

    import vmware.vsphere.esx.esx_facade as esx_facade
    import vmware.vsphere.esx.vmnic.vmnic_facade as vmnic_facade
    import vmware.common.global_config as global_config

    pylogger = global_config.pylogger
    args = GetArgs()
    password = args.password
    host = args.host
    username = args.username

    hc = esx_facade.ESXFacade(host, username, password)
    vmnic = vmnic_facade.VmnicFacade(parent=hc, name="vmnic1")
    result = vmnic.set_device_status(device_status="up")
    pylogger.info("Operation result= %r" % result)
Example #7
0
def main():

    import vmware.vsphere.esx.esx_facade as esx_facade
    import vmware.vsphere.esx.vmknic.vmknic_facade as vmknic_facade
    import vmware.common.global_config as global_config

    pylogger = global_config.pylogger
    args = GetArgs()
    password = args.password
    host = args.host
    username = args.username

    hc = esx_facade.ESXFacade(host, username, password)

    # hc = esx_facade.ESXFacade("10.144.139.194", "root", "ca$hc0w")

    vmknic = vmknic_facade.VmknicFacade(name="vmk0", parent=hc)

    result = vmknic.enable_vmotion()

    pylogger.info("Operation result= %r" % result)
Example #8
0
def main():

    import vmware.vsphere.esx.esx_facade as esx_facade
    import vmware.vsphere.esx.vsswitch.vsswitch_facade as vsswitch_facade
    import vmware.common.global_config as global_config
    import vmware.vsphere.esx.vsswitch.portgroup.portgroup_facade as portgroup_facade  # noqa

    pylogger = global_config.pylogger

    hv = esx_facade.ESXFacade(ip="10.144.139.194",
                              username="******",
                              password="******")

    vss = vsswitch_facade.VSSwitchFacade(name="vSwitch1", parent=hv)

    pg = portgroup_facade.PortgroupFacade(name="VM Network 2", parent=vss)

    result = pg.edit_traffic_shaping(enabled=True,
                                     avg_bandwidth=100000,
                                     peak_bandwidth=100000,
                                     burst_size=102400)
    pylogger.info("Operation result = %r" % result)
Example #9
0
                        action='store', help='Remote host to connect to')
    parser.add_argument('-u', '--username', required=True,
                        action='store', help='Username for host')
    parser.add_argument('-p', '--password', required=False,
                        action='store', help='Password for host')
    args = parser.parse_args()
    return args


if __name__ == "__main__":

    import vmware.vsphere.esx.esx_facade as esx_facade
    args = GetArgs()
    password = args.password
    host = args.host
    username = args.username

    # $ python esx_facade.py -s 10.144.138.189 -u root -p ca\$hc0w
    hv = esx_facade.ESXFacade(host, username, password)
    result = hv.list_networks()
    # hv = esx_facade.ESXFacade("10.24.20.59", "root", "ca$hc0w")

    pylogger.info("client object %s" % hv.get_client(
        constants.ExecutionType.CLI).connection)
    hv.set_nsx_registration(
        execution_type='cli',
        manager_ip='10.144.139.105',
        manager_thumbprint='435143a1b5fc8bb70a3aa9b15f9dd29e0f6673a8',
        manager_username='******',
        manager_password='******')