new program
This commit is contained in:
parent
f9ffcbc507
commit
1417460594
63
vmw_list_vm_mac_addresses
Executable file
63
vmw_list_vm_mac_addresses
Executable file
@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env python3
|
||||
from pyVmomi import vim
|
||||
import pyVim.connect
|
||||
import atexit
|
||||
import argparse
|
||||
import time
|
||||
import siteconf
|
||||
|
||||
site_conf = siteconf.read()
|
||||
|
||||
|
||||
def get_args():
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Set VM network')
|
||||
|
||||
parser.add_argument('-s', '--site',
|
||||
required=True,
|
||||
action='store',
|
||||
help='name of the site to connect to')
|
||||
|
||||
args = parser.parse_args()
|
||||
return args
|
||||
|
||||
|
||||
def get_vms(content):
|
||||
obj_view = content.viewManager.CreateContainerView(
|
||||
content.rootFolder, [vim.VirtualMachine], True)
|
||||
vms_list = obj_view.view
|
||||
obj_view.Destroy()
|
||||
return vms_list
|
||||
|
||||
|
||||
def main():
|
||||
args = get_args()
|
||||
|
||||
if not args.site in site_conf:
|
||||
print(f"site not found: {args.site}")
|
||||
exit(1)
|
||||
host = site_conf[args.site]['vcenter']
|
||||
user = site_conf[args.site]['vcenter_user']
|
||||
passwd = site_conf[args.site]['vcenter_passwd']
|
||||
|
||||
si = pyVim.connect.SmartConnectNoSSL(
|
||||
host = host,
|
||||
user = user,
|
||||
pwd = passwd
|
||||
)
|
||||
atexit.register(pyVim.connect.Disconnect, si)
|
||||
content = si.RetrieveContent()
|
||||
|
||||
vms = get_vms(content)
|
||||
for vm in vms:
|
||||
for d in vm.config.hardware.device:
|
||||
if hasattr(d, 'macAddress'):
|
||||
print(f'{d.macAddress} {vm.name}')
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
# vim: set tabstop=4 shiftwidth=4 expandtab smarttab:
|
||||
Loading…
x
Reference in New Issue
Block a user