コード例 #1
0
ファイル: ssh-enable.py プロジェクト: shadowychaos/vmwc
def main():
    host = '192.168.1.1'
    username = '******'
    password = '******'

    with VMWareClient(host, username, password) as client:
        client.enable_ssh()
コード例 #2
0
def main():
    host = '192.168.1.1'
    username = '******'
    password = '******'

    with VMWareClient(host, username, password) as client:
        for item in client.get_services():
            print item
コード例 #3
0
def main():
    host = '192.168.1.1'
    username = '******'
    password = '******'

    with VMWareClient(host, username, password) as client:
        for vm in client.get_virtual_machines():
            print vm.name
コード例 #4
0
def main():
    host = '192.168.1.1'
    username = '******'
    password = '******'

    with VMWareClient(host, username, password) as client:
        new_value = datetime.datetime(2025, 11, 22, 22, 0, 0)
        client.set_server_datetime(new_value)
コード例 #5
0
def main():
    host = '192.168.1.1'
    username = '******'
    password = '******'

    with VMWareClient(host, username, password) as client:
        for datastore in client.get_datastores():
            print datastore
コード例 #6
0
 def CreateVM(self,username, host, password, vmname, numcpu, ramMB, disksizeGB):
     with VMWareClient(host, username, password) as client:
        vm = client.new_virtual_machine(vmname, cpus=numcpu, ram_mb=ramMB, disk_size_gb=disksizeGB)
        vm.configure_bios(boot_delay=5000, boot_order=['network', 'disk'])
        vm.uuid=uuid.uuid1()
        vm.power_on()
        create_date = datetime.datetime.now()
        vm_life_time = create_date + datetime.timedelta(days=30)
コード例 #7
0
ファイル: replace-license.py プロジェクト: shadowychaos/vmwc
def main():
    host = '192.168.1.1'
    username = '******'
    password = '******'
    license = 'XXXXX-XXXXX-XXXXX-XXXXX-XXXXX'

    with VMWareClient(host, username, password) as client:
        client.replace_license(license)
コード例 #8
0
def view_vm_by_name(host, username, password):
    status = 0
    with VMWareClient(host, username, password) as client:
        for vm in client.get_virtual_machines():
            print("VM name:", vm.name)
            status = 1

    if status != 1:
        print("No virtual machines were found with this name!!!")
コード例 #9
0
def main():
    host = '192.168.1.1'
    username = '******'
    password = '******'

    service_id = 'TSM-SSH'

    with VMWareClient(host, username, password) as client:
        client.start_service(service_id)
コード例 #10
0
def main():
    host = '192.168.1.1'
    username = '******'
    password = '******'

    with VMWareClient(host, username, password) as client:
        for vm in client.get_virtual_machines():
            print 'powering on "{}" ...'.format(vm.name)
            vm.power_on()
コード例 #11
0
def main():
    host = '192.168.1.1'
    username = '******'
    password = '******'

    with VMWareClient(host, username, password) as client:
        for vm in client.get_virtual_machines():
            vm.power_off()

            # Good configuration for PXE boot from lan (you'd like that the network will prioritize pre-disk, the boot delay)
            vm.configure_bios(boot_delay=5000, boot_order=['network', 'disk'])
コード例 #12
0
def delete_vm_by_name(host, username, password,vmname):
    status = 0
    with VMWareClient(host, username, password) as client:
        for vm in client.get_virtual_machines():
            if vm.name == vmname :
                vm.delete()
                VMDBExpress01.VMDB().deleteFromVMDBbyName(vmname)
                status = 1
                print("Deleted VM")
    if status != 1 :
        print("No virtual machines were found with this name!!!")
コード例 #13
0
def main():
    host = '192.168.1.1'
    username = '******'
    password = '******'

    print 'WARNING - you must acknowledge that by executing the code below will result in deletion of all switches. (remove the "return" statement and re run this script to proceed)'
    return

    with VMWareClient(host, username, password) as client:
        for vs in client.get_virtual_switches():
            vs.delete()
コード例 #14
0
def main():
    host = '192.168.1.1'
    username = '******'
    password = '******'

    snapshot_name = 'MY-AWESOME-SNAPSHOT'

    with VMWareClient(host, username, password) as client:
        for vm in client.get_virtual_machines():
            print 'taking a snapshot for "{}" named "{}" ...'.format(
                vm.name, snapshot_name)
            vm.take_snapshot(snapshot_name, memory=False)
コード例 #15
0
def main():
    host = '192.168.1.1'
    username = '******'
    password = '******'

    with VMWareClient(host, username, password) as client:
        vm = client.new_virtual_machine("Virtual Machine 1",
                                        cpus=2,
                                        ram_mb=1024,
                                        disk_size_gb=20)
        vm.configure_bios(boot_delay=5000, boot_order=['network', 'disk'])
        vm.power_on()
コード例 #16
0
def ViewAllVMByName(host, username, password):
    status = 0
    all_vm = []
    with VMWareClient(host, username, password) as client:
        for vm in client.get_virtual_machines():
            print("VM name:", vm.name)
            all_vm.append(vm.name)
            status = 1

    if status != 1:
        print("No virtual machines were found with this name!!!")
    print("vm's in esxi now \n", all_vm)
    return all_vm
コード例 #17
0
def main():
    host = '192.168.1.1'
    username = '******'
    password = '******'

    virtual_switch_name = 'Custom Network 1'

    with VMWareClient(host, username, password) as client:
        # Good configuration for traffic recording
        client.new_virtual_switch(virtual_switch_name,
                                  allow_promiscuous=True,
                                  allow_mac_changes=True,
                                  allow_forged_transmits=True)
コード例 #18
0
def main():
    host = '192.168.1.1'
    username = '******'
    password = '******'

    print 'WARNING - you must acknowledge that by executing the code below will result in deletion of all snapshots. (remove the "return" statement and re run this script to proceed)'
    return

    with VMWareClient(host, username, password) as client:
        for vm in client.get_virtual_machines():
            print vm.name

            # VMWare gave a specific API to delete all machines. guess this is more efficient instead of iterating all snapshots and delete them 1 by 1
            vm.remove_all_snapshots()
コード例 #19
0
def delete_vm_by_name(host, username, password, vmname):
    status = False
    with VMWareClient(host, username, password) as client:
        for vm in client.get_virtual_machines():
            if (vm.name == vmname):
                if (vm.is_powered_on() == True):
                    print('power OFF  "{}" ...'.format(vm.name))
                    vm.power_off()
                vm.delete()
                status = True
                print('Deleted  "{}" ...'.format(vm.name))
    if status != True:
        print("No virtual machines were found with this name!!!")
    return status
コード例 #20
0
def main():
    host = '192.168.1.1'
    username = '******'
    password = '******'

    snapshot_name = 'MY-AWESOME-SNAPSHOT'

    print 'WARNING - you must acknowledge that by executing the code below will result in deletion of all snapshots. (remove the "return" statement and re run this script to proceed)'
    return

    with VMWareClient(host, username, password) as client:
        for vm in client.get_virtual_machines():
            for snapshot in vm.get_snapshots():
                if snapshot.name == snapshot_name:
                    snapshot.delete()
コード例 #21
0
def CreateVM(host, username, password, name, OS, Ram, Storage, PathISO,
             Status):
    with VMWareClient(host, username, password) as client:
        vm = client.new_virtual_machine(name=name,
                                        cpus=2,
                                        ram_mb=Ram,
                                        disk_size_gb=Storage,
                                        operating_system_type=OS)
        disk = PathISO
        vm.configure_bios(boot_delay=5000, boot_order=['network', 'disk'])
        if (Status == "PowerOn"):
            vm.power_on()
        else:
            vm.power_off()
    print(vm.uuid)
    return vm
def main():
    host = '192.168.1.1'
    username = '******'
    password = '******'

    with VMWareClient(host, username, password) as client:
        for vm in client.get_virtual_machines():
            vm.remove_all_network_interfaces()

            vm.add_network_interface(
                'VM Network'
            )  # first NIC, with default the virtual "VM Network" switch
            vm.add_network_interface(
                'VM Network')  # second NIC similar to the prev one
            vm.add_network_interface(
                'Custom Network 1'
            )  # third NIC. this time uses different virtual switch
コード例 #23
0
    def get_network_int(self, vm_name_string):

        with VMWareClient(self.host, self.user, self.password) as client:
            for vm in client.get_virtual_machines():
                if vm_name_string in vm.name:
                    interfaces = {}
                    for (hardware_device
                         ) in vm._raw_virtual_machine.config.hardware.device:
                        if isinstance(hardware_device,
                                      vim.vm.device.VirtualEthernetCard):
                            interfaces[hardware_device.deviceInfo.label] = {
                                "port_group":
                                hardware_device.deviceInfo.summary,
                                "mac": hardware_device.macAddress,
                            }

                    return interfaces
コード例 #24
0
def main():
    host = '192.168.1.1'
    username = '******'
    password = '******'

    remote_file_path = 'C:\\file.txt'
    download_path = '/tmp/downloaded_file.txt'

    with VMWareClient(host, username, password) as client:
        for vm in client.get_virtual_machines():
            print 'downloading "{}" from {}...'.format(remote_file_path,
                                                       vm.name)
            try:
                size = vm.download_file(remote_file_path, download_path)
                print 'successfully downloaded {} bytes'.format(size)
            except Exception as e:
                'Failed to download file: {}'.format(e)
コード例 #25
0
ファイル: install_dlQT5.py プロジェクト: vnkazna/InstallDL
    def install(self):
        self.mythread_instance = MyThread(mainwindow=self)
        self.mythread_instance.start()
        self.timer = QTimer(self)
        self.timer.start(1000)
        self.printInbox('Программа автоустановки Dallas Lock запущена!...')
        QThread.msleep(2000)
        bn = self.bnChange.currentText()
        try:
            os.remove('//192.168.0.162/Soft/TestIPS/auto/ip.txt')
            os.remove('//192.168.0.162/Soft/TestIPS/auto/usr.txt')
        except Exception as e:
            self.printInbox("Удаление файлов предыдущей установки")
        sroot = r'\\192.168.0.162\czi-share\! DallasLock\DL80'
        self.ProgressBar()
        szi = r'DallasLock8.0C.msi'
        sb = r'DL80.SecServerDemo10.msi'
        os.chdir(sroot)
        os.chdir(bn)
        shutil.copy(
            'DallasLock8.0C.msi',
            '//192.168.0.162/Soft/TestIPS/auto/Auto_Install/PY_Inst/DallasLock8.0C.msi'
        )
        shutil.copy(
            'DL80.SecServerDemo10.msi',
            '//192.168.0.162/Soft/TestIPS/auto/Auto_Install/PY_Inst/DL80.SecServerDemo10.msi'
        )
        self.printInbox(bn)
        self.printInbox('Идет копирование файлов установки...')
        QThread.msleep(2000)
        self.printInbox('Установка будет быполнена на следующие машины:')
        host = '192.168.13.138'
        username = '******'
        password = ''
        snapshot_name = 'install'

        with VMWareClient(host, username, password) as client:
            for vm in client.get_virtual_machines():
                for v in self.osvm:
                    if vm.name == v:
                        for snapshot in vm.get_snapshots():
                            if snapshot.name == snapshot_name:
                                self.printInbox(vm.name)
                                vm_tofix = vm.name
                                snapshot.revert()
                                QThread.msleep(3000)
                                self.fix_reboot_stuck(vm_tofix)
                                self.printInbox(
                                    "Загрузка виртуальной машины...")
        QThread.msleep(10000)
        if len(bn) > 24:
            bn = bn[:24]
            if bn[-3] == ' ':
                bn = bn[-4::-1]
                bn = bn[::-1]
        elif len(bn) < 24:
            l = len(bn)
            bn = bn[:l]
        time.sleep(2)
        if bn.find('.') == 8:
            if bn.find(' ') == 10:
                bn1 = bn[5:10]
            else:
                bn1 = bn[5:11]
        else:
            bn1 = bn[5:8]

        b = open(
            '//192.168.0.162/Soft/TestIPS/auto/Auto_Install/PY_Inst/bn.txt',
            'w')
        b.write(bn1)
        b.close()
        self.ProgressBar()
        QThread.msleep(300000)
        for vm_name in self.osvm:
            if vm_name == 'Deploy2016':
                self.autorization(vm_name, 'RU')
            else:
                self.autorization(vm_name, 'EN')
        self.printInbox('Вход в систему выполнен успешно')
コード例 #26
0
#!/usr/bin/env python
# instalacia balicka:
# pip install --trusted-host pypi.python.org vmwc
# Popis API
# https://pypi.python.org/pypi/vmwc/1.0.2

import os
import getpass
from vmwc import VMWareClient

host = 'vcenter.domain.com'
myvm = 'my_server'
username = os.getenv('USERNAME', '')
password = getpass.getpass("Password:"******"Login or password !"
    exit()

with VMWareClient(host, username, password) as client:
    for vm in client.get_virtual_machines():
        if vm.name == myvm:
            print "%s ... starting." % (myvm)
            vm.power_on()
        else:
            print "%s .... found" % (vm.name)
コード例 #27
0
 def __init__(self):
     host = '192.168.174.139'
     username = '******'
     password = '******'
     with VMWareClient(host, username, password) as client:
         print("The ESXI connection was successful")