Created
February 7, 2017 08:32
-
-
Save yfauser/ba11f737a2c536edb72bb6b7f956da85 to your computer and use it in GitHub Desktop.
A small script to retrieve the NSX Manager Version and IP from vCenters extension Manager
This file contains 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
#!/usr/bin/env python | |
# coding=utf-8 | |
# | |
# Copyright © 2015-2016 VMware, Inc. All Rights Reserved. | |
# | |
# Licensed under the X11 (MIT) (the “License”) set forth below; | |
# | |
# you may not use this file except in compliance with the License. Unless required by applicable law or agreed to in | |
# writing, software distributed under the License is distributed on an “AS IS” BASIS, without warranties or conditions | |
# of any kind, EITHER EXPRESS OR IMPLIED. See the License for the specific language governing permissions and | |
# limitations under the License. Permission is hereby granted, free of charge, to any person obtaining a copy of this | |
# software and associated documentation files (the "Software"), to deal in the Software without restriction, including | |
# without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the | |
# Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
# | |
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of | |
# the Software. | |
# | |
# "THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | |
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN | |
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
# DEALINGS IN THE SOFTWARE.” | |
from pyVim import connect | |
from pyVmomi import vim | |
import ssl | |
import atexit | |
import argparse | |
import sys | |
__author__ = 'yfauser' | |
def connect_to_api(vchost, user='root', pwd='vmware'): | |
if hasattr(ssl, 'SSLContext'): | |
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) | |
context.verify_mode = ssl.CERT_NONE | |
else: | |
context = None | |
if context: | |
service_instance = connect.SmartConnect(host=vchost, user=user, pwd=pwd, sslContext=context) | |
else: | |
service_instance = connect.SmartConnect(host=vchost, user=user, pwd=pwd) | |
atexit.register(connect.Disconnect, service_instance) | |
return service_instance.RetrieveContent() | |
def main(): | |
parser = argparse.ArgumentParser(description='Tool for NSX Manager details retrieval') | |
parser.add_argument('vc', help='The vCenter IP or hostname') | |
parser.add_argument('vc_user', help='The vCenter username') | |
parser.add_argument('vc_password', help='The vCenter password') | |
args = parser.parse_args() | |
content = connect_to_api(args.vc, user=args.vc_user, pwd=args.vc_password) | |
nsx_man_extension = content.extensionManager.FindExtension('com.vmware.vShieldManager') | |
assert isinstance(nsx_man_extension, vim.Extension), "Error, the returned Object of vCenter is not a " \ | |
"single extension Object, check in the vCenter MOB for errors" | |
try: | |
nsx_man_ip = nsx_man_extension.client[0].url.split('/')[2].split(':')[0] | |
except IndexError: | |
sys.exit('There was an error retrieving the NSX Manager URL, ' | |
'the received NSX Manager client Object was {}'.format(nsx_man_extension.client)) | |
print 'The NSX Manager Version is {}'.format(nsx_man_extension.version) | |
print 'The NSX Manager IP is {}'.format(nsx_man_ip) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment