Created
November 18, 2020 12:03
-
-
Save Akasurde/8b2567d15a91c50d520ab95f3d5791d7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pyVim.connect import SmartConnect, Disconnect | |
import ssl | |
import atexit | |
from pyVmomi import vim, vmodl, VmomiSupport | |
def connect(hostname, username, password, port): | |
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) | |
context.verify_mode = ssl.CERT_NONE | |
si = SmartConnect(host=hostname, | |
user=username, | |
pwd=password, | |
port=port, sslContext=context) | |
atexit.register(Disconnect, si) | |
return si, si.RetrieveContent() | |
def get_all_objs(content, vimtype, name=None): | |
""" | |
Return an object by name, if name is None the | |
first found object is returned | |
""" | |
obj = [] | |
container = content.viewManager.CreateContainerView(content.rootFolder, vimtype, True) | |
for c in container.view: | |
obj.append(c) | |
container.Destroy() | |
return obj | |
def main(hostname, username, password, port): | |
si, content = connect(hostname, username, password, port) | |
all_nsx_nw = get_all_objs(content, [vim.OpaqueNetwork]) | |
for nw in all_nsx_nw: | |
print(nw.summary.name) | |
if __name__ == "__main__": | |
hostname = '10.65.201.153' | |
username = '[email protected]' | |
password = 'Esxi@123$%' | |
port = '443' | |
main(hostname, username, password, port) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment