def main(): host = '192.168.1.1' username = '******' password = '******' with VMWareClient(host, username, password) as client: client.enable_ssh()
def main(): host = '192.168.1.1' username = '******' password = '******' with VMWareClient(host, username, password) as client: for item in client.get_services(): print item
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
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)
def main(): host = '192.168.1.1' username = '******' password = '******' with VMWareClient(host, username, password) as client: for datastore in client.get_datastores(): print datastore
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)
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)
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!!!")
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)
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()
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'])
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!!!")
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()
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)
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()
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
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)
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()
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
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()
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
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
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)
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('Вход в систему выполнен успешно')
#!/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)
def __init__(self): host = '192.168.174.139' username = '******' password = '******' with VMWareClient(host, username, password) as client: print("The ESXI connection was successful")