├── .gitignore ├── README.md ├── bin └── rvtools ├── references └── some_references.txt ├── requirements.txt ├── rvtools ├── __init__.py ├── corerv.py ├── printrv │ ├── __init__.py │ └── csv_print.py ├── rvtools.py ├── rvtools_db.py ├── test.py └── vinfo │ ├── __init__.py │ └── vinfo.py ├── setup.py └── test └── __init__.py /.gitignore: -------------------------------------------------------------------------------- 1 | data_files 2 | *.conf 3 | *.pyc 4 | */__pycache__/* 5 | .vscode 6 | *.csv 7 | .~lock* 8 | rvtools.conf 9 | build 10 | dist 11 | rvtools_python.egg-info 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # rvtools python 2 | Application to be executed on Linux and collect all information from vCenter 3 | 4 | The idea is to be a similar application as RVTools [1] the main difference is, the application from website was designed to be executed only on MS platform, this version will be written in python 3 so will be possible execute on Linux environment. 5 | 6 | About the final result, the idea is generate similar output *CSV files*. 7 | 8 | The point here is not about COPY but just improve the Python skill and use the project [1] as reference once this one is a fantastic product!!! 9 | 10 | Thank you and feel free to request Features / Enhancements. 11 | 12 | Ps.: Necessary python 3.9 or greather. 13 | 14 | # How to use?? 15 | 16 | First, install the python module 17 | ``` 18 | $ pip install rvtools-python 19 | ``` 20 | 21 | Now it's time to execute it. 22 | ``` 23 | 24 | $ rvtools 25 | ``` 26 | 27 | On the first run, will be created the file ~/.rvtools.conf 28 | ``` 29 | vcenter= 30 | username= 31 | password= 32 | directory= 33 | ``` 34 | Note. the directory above is the area where all the `CSV` files will be saved by default. 35 | 36 | 37 | You can just update the information on the file to be seamless and generate all reports without ask you the password again or you are able to pass the information all the time as parameter 38 | ``` 39 | $ rvtools --help 40 | usage: rvtools [-h] [-s HOST] [-u USERNAME] [-p PASSWORD] [-d DIRECTORY] 41 | [-v VERBOSE] 42 | 43 | RVTools Python parameters 44 | 45 | optional arguments: 46 | -h, --help show this help message and exit 47 | -s HOST, --host HOST vCenter server to connect to 48 | -u USERNAME, --username USERNAME 49 | vCenter username 50 | -p PASSWORD, --password PASSWORD 51 | vCenter username password 52 | -d DIRECTORY, --directory DIRECTORY 53 | Directory where will be saved all csv files. Should be 54 | empty 55 | -v VERBOSE, --verbose VERBOSE 56 | Show additional info. 57 | $ 58 | ``` 59 | 60 | The result will be the csv file created on the directory defined on the conf file by `directory=` or via CLI by `-d DIRECTORY`. 61 | ``` 62 | vinfo.csv 63 | ... 64 | ``` 65 | 66 | Hope you enjoy it. Still working to improve/add all features. Feel free to send your feedback or just submit the new Issue [here](https://github.com/waldirio/rvtools_python/issues). 67 | 68 | Best 69 | Waldirio 70 | 71 | [1]. https://www.robware.net/rvtools/ -------------------------------------------------------------------------------- /bin/rvtools: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | 4 | VERSION = "" 5 | 6 | project_dir = os.path.dirname(os.path.dirname(__file__)) 7 | os.sys.path.append(project_dir) 8 | 9 | from rvtools import rvtools 10 | rvtools.main() 11 | -------------------------------------------------------------------------------- /references/some_references.txt: -------------------------------------------------------------------------------- 1 | https://github.com/vmware/pyvmomi/blob/master/docs/vim/vm/GuestInfo/ToolsStatus.rst 2 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | altgraph==0.17.4 2 | appnope==0.1.4 3 | astroid==3.0.3 4 | asttokens==2.4.1 5 | backcall==0.2.0 6 | certifi==2024.2.2 7 | chardet==5.2.0 8 | charset-normalizer==3.3.2 9 | decorator==5.1.1 10 | dill==0.3.8 11 | docopt==0.6.2 12 | exceptiongroup==1.2.0 13 | executing==2.0.1 14 | flake8==7.0.0 15 | gitdb==4.0.11 16 | gitdb2==4.0.2 17 | GitPython==3.1.42 18 | idna==3.6 19 | importlib-metadata==7.0.1 20 | ipython==8.18.1 21 | ipython-genutils==0.2.0 22 | isort==5.13.2 23 | jedi==0.19.1 24 | lazy-object-proxy==1.10.0 25 | lint==1.2.1 26 | macholib==1.16.3 27 | matplotlib-inline==0.1.6 28 | mccabe==0.7.0 29 | packaging==23.2 30 | parso==0.8.3 31 | pexpect==4.9.0 32 | pickleshare==0.7.5 33 | platformdirs==4.2.0 34 | prompt-toolkit==3.0.43 35 | ptyprocess==0.7.0 36 | pure-eval==0.2.2 37 | pycodestyle==2.11.1 38 | pyflakes==3.2.0 39 | Pygments==2.17.2 40 | pyinstaller==6.4.0 41 | pyinstaller-hooks-contrib==2024.1 42 | pylint==3.0.3 43 | pytoolconfig==1.3.1 44 | pyvim==3.0.3 45 | pyvmomi==8.0.2.0.1 46 | requests==2.31.0 47 | rope==1.12.0 48 | simplegeneric==0.8.1 49 | six==1.16.0 50 | smmap==5.0.1 51 | smmap2==3.0.1 52 | stack-data==0.6.3 53 | toml==0.10.2 54 | tomli==2.0.1 55 | tomlkit==0.12.3 56 | traitlets==5.14.1 57 | typing_extensions==4.9.0 58 | urllib3==2.2.1 59 | wcwidth==0.2.13 60 | wrapt==1.16.0 61 | zipp==3.17.0 62 | -------------------------------------------------------------------------------- /rvtools/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waldirio/rvtools_python/a77bff69bde10577e814200fa8dccee004199bf0/rvtools/__init__.py -------------------------------------------------------------------------------- /rvtools/corerv.py: -------------------------------------------------------------------------------- 1 | """ Module to read the conf file / vcenter, username and password """ 2 | import re 3 | import os 4 | 5 | 6 | class CoreCode(object): 7 | """ Main Class *CoreCode* responsible for read the conf file feature """ 8 | 9 | def read_conf_file(self): 10 | """ Definition to read the conf file rvtools.conf """ 11 | 12 | home_area = os.path.expanduser('~') 13 | 14 | try: 15 | fp_conf_file = open(home_area + "/.rvtools.conf", "r") 16 | for line in fp_conf_file: 17 | if re.search('^vcenter', line): 18 | # VCENTER = re.split('=', re.search('^vcenter',line).string)[1] 19 | self._vcenter = re.split('=', re.search('^vcenter', line).string)[1].strip() 20 | if re.search('^username', line): 21 | # USERNAME = re.split('=', re.search('^username',line).string)[1] 22 | self._username = re.split('=', re.search('^username', line).string)[1].strip() 23 | if re.search('^password', line): 24 | # PASSWORD = re.split('=', re.search('^password',line).string)[1] 25 | self._password = re.split('=', re.search('^password', line).string)[1].strip() 26 | if re.search('^directory', line): 27 | # DIRECTORY = re.split('=', re.search('^directory',line).string)[1] 28 | self._directory = re.split('=', re.search('^directory', line).string)[1].strip() 29 | 30 | return self 31 | except FileNotFoundError: 32 | print("There isn't the conf file on ~/.rvtools.conf, creating a new one now") 33 | print("according to the example below:") 34 | print("-----------------------") 35 | print("vcenter=") 36 | print("username=") 37 | print("password=") 38 | print("directory=") 39 | print("-----------------------") 40 | print("") 41 | print("Please update the info if you would like to persist the credentials") 42 | 43 | template_conf_file = open(home_area + "/.rvtools.conf", "w+") 44 | print("vcenter=", file=template_conf_file) 45 | print("username=", file=template_conf_file) 46 | print("password=", file=template_conf_file) 47 | print("directory=", file=template_conf_file) 48 | template_conf_file.close() 49 | -------------------------------------------------------------------------------- /rvtools/printrv/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waldirio/rvtools_python/a77bff69bde10577e814200fa8dccee004199bf0/rvtools/printrv/__init__.py -------------------------------------------------------------------------------- /rvtools/printrv/csv_print.py: -------------------------------------------------------------------------------- 1 | """ Module responsible to save the content as csv file """ 2 | import csv 3 | 4 | 5 | def csv_print(module_name, server_list, directory): 6 | """ 7 | Def which will receive the server list and then will 8 | populate all fields from header as the content. 9 | 10 | Note. All fields will be populated automatically, then according to 11 | the module which will call csv_print, the # of fields will be updated 12 | automatically. 13 | """ 14 | 15 | full_file_path = directory+"/"+module_name 16 | 17 | print("## Creating {} file.".format(full_file_path)) 18 | 19 | with open(full_file_path, 'w', newline='') as f: 20 | fieldnames = server_list[0].keys() 21 | thewriter = csv.DictWriter(f, fieldnames=fieldnames) 22 | thewriter.writeheader() 23 | 24 | for each_line in server_list: 25 | csv_data_fields = {} 26 | for each_field in fieldnames: 27 | csv_data_fields[each_field] = each_line[each_field] 28 | thewriter.writerow(csv_data_fields) 29 | -------------------------------------------------------------------------------- /rvtools/rvtools.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ Main rvtools module """ 3 | 4 | import sys 5 | import os 6 | import ssl 7 | import argparse 8 | import requests 9 | import urllib3 10 | from pyVim import connect 11 | 12 | from rvtools.corerv import * 13 | from rvtools.vinfo.vinfo import * 14 | 15 | 16 | # requests.packages.urllib3.disable_warnings() 17 | urllib3.disable_warnings() 18 | 19 | def get_args(): 20 | parser = argparse.ArgumentParser(description="RVTools Python parameters") 21 | 22 | parser.add_argument('-s', '--host', 23 | required=False, 24 | action='store', 25 | help='vCenter server to connect to') 26 | 27 | parser.add_argument('-u', '--username', 28 | required=False, 29 | action='store', 30 | help='vCenter username') 31 | 32 | parser.add_argument('-p', '--password', 33 | required=False, 34 | action='store', 35 | help='vCenter username password') 36 | 37 | parser.add_argument('-d', '--directory', 38 | required=False, 39 | action='store', 40 | help='Directory where will be saved all csv files. Should be empty') 41 | 42 | parser.add_argument('-v', '--verbose', 43 | required=False, 44 | action='store', 45 | help='Show additional info.') 46 | 47 | 48 | args = parser.parse_args() 49 | 50 | return args 51 | 52 | 53 | def main(): 54 | """ Def responsible to start the vCenter connection and call all report modules """ 55 | 56 | args = get_args() 57 | 58 | if (args.host is None or args.username is None or args.password is None or args.directory is None): 59 | print("Reading Conf File") 60 | obj = CoreCode() 61 | conn = obj.read_conf_file() 62 | if conn is None: 63 | sys.exit() 64 | else: 65 | server = conn._vcenter 66 | username = conn._username 67 | password = conn._password 68 | directory = conn._directory 69 | if server == '': 70 | print("You are using default values. Please update the file") 71 | print("~/.rvtools.conf or just pass all mandatory parameters.") 72 | sys.exit() 73 | else: 74 | print("Using flags") 75 | server = args.host 76 | username = args.username 77 | password = args.password 78 | directory = args.directory 79 | 80 | 81 | if not os.path.isdir(directory): 82 | print("You have to create the dir {}".format(directory)) 83 | sys.exit() 84 | 85 | ssl_context = ssl._create_unverified_context() 86 | 87 | print("vcenter: {}\nuser: {}\n".format(server, username)) 88 | 89 | service_instance = connect.SmartConnect(host=server, user=username, \ 90 | pwd=password, port=443, sslContext=ssl_context) 91 | 92 | 93 | # VM Information 94 | # vinfo_collect(service_instance) 95 | vinfo_collect(service_instance, directory) 96 | 97 | 98 | # https://code.vmware.com/apis/358/vsphere 99 | 100 | if __name__ == "__main__": 101 | main() 102 | -------------------------------------------------------------------------------- /rvtools/rvtools_db.py: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | -------------------------------------------------------------------------------- /rvtools/test.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waldirio/rvtools_python/a77bff69bde10577e814200fa8dccee004199bf0/rvtools/test.py -------------------------------------------------------------------------------- /rvtools/vinfo/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waldirio/rvtools_python/a77bff69bde10577e814200fa8dccee004199bf0/rvtools/vinfo/__init__.py -------------------------------------------------------------------------------- /rvtools/vinfo/vinfo.py: -------------------------------------------------------------------------------- 1 | from pyVmomi import vim 2 | import pyVmomi 3 | from rvtools.printrv.csv_print import * 4 | 5 | 6 | def get_obj(content, vimtype): 7 | obj = None 8 | container = content.viewManager.CreateContainerView(content.rootFolder, vimtype, True) 9 | obj = container.view[0].name 10 | # for c in container.view: 11 | # if name: 12 | # if c.name == name: 13 | # obj = c 14 | # break 15 | # else: 16 | # obj = c 17 | # break 18 | return obj 19 | 20 | 21 | def vinfo_collect(service_instance, directory): 22 | """ Def responsible to connect on the vCenter and retrieve VM information """ 23 | 24 | print("## Processing vInfo module") 25 | 26 | content = service_instance.RetrieveContent() 27 | container = content.rootFolder 28 | 29 | view_type = [vim.VirtualMachine] 30 | container_view = content.viewManager.CreateContainerView(container, view_type, True) 31 | 32 | server_list = [] 33 | 34 | children = container_view.view 35 | for child in children: 36 | # if 'sat62' in child.name: 37 | # if 'akavir-sat63' in child.name: 38 | # if 'waldirio' in child.name: 39 | if True: 40 | 41 | # get_obj(content, [vim.Datacenter], name) 42 | 43 | vinfo_data = {} 44 | 45 | # OK 46 | vm = child.name 47 | if vm is None: 48 | vm = "" 49 | print("Machine Name: {}".format(vm)) 50 | vinfo_data['vm'] = vm 51 | 52 | # OK 53 | powerstate = child.runtime.powerState 54 | if powerstate is None: 55 | powerstate = "" 56 | # print("Powerstate: {}".format(powerstate)) 57 | vinfo_data['powerstate'] = str(powerstate) 58 | 59 | # OK 60 | template = child.config.template 61 | if template is None: 62 | template = "" 63 | # print("Template: {}".format(template)) 64 | vinfo_data['template'] = str(template) 65 | 66 | # OK 67 | config_status = child.configStatus 68 | if config_status is None: 69 | config_status = "" 70 | # print("Config status: {}".format(config_status)) 71 | vinfo_data['config_status'] = str(config_status) 72 | 73 | # OK 74 | dns_name = child.guest.hostName 75 | if dns_name is None: 76 | dns_name = "" 77 | # print("DNS Name: {}".format(dns_name)) 78 | vinfo_data['dns_name'] = str(dns_name) 79 | 80 | # OK 81 | connection_state = child.runtime.connectionState 82 | if connection_state is None: 83 | connection_state = "" 84 | # print("Connection state: {}".format(connection_state)) 85 | vinfo_data['connection_state'] = str(connection_state) 86 | 87 | # OK 88 | guest_state = child.guest.guestState 89 | if guest_state is None: 90 | guest_state = "" 91 | # print("Guest state: {}".format(guest_state)) 92 | vinfo_data['guest_state'] = str(guest_state) 93 | 94 | # OK 95 | heartbeat = child.guestHeartbeatStatus 96 | if heartbeat is None: 97 | heartbeat = "" 98 | # print("Heartbeat: {}".format(heartbeat)) 99 | vinfo_data['heartbeat'] = str(heartbeat) 100 | 101 | # OK 102 | consolidation_needed = child.runtime.consolidationNeeded 103 | if consolidation_needed is None: 104 | consolidation_needed = "" 105 | # print("Consolidation needed: {}".format(consolidation_needed)) 106 | vinfo_data['consolidation_needed'] = str(consolidation_needed) 107 | 108 | # poweron = "xx" 109 | # print("Power On: {}".format(poweron)) 110 | # vinfo_data['xx'] = str(xx) 111 | 112 | # OK 113 | suspend_time = child.runtime.suspendTime 114 | if suspend_time is None: 115 | suspend_time = "" 116 | # print("Suspend time: {}".format(suspend_time)) 117 | vinfo_data['suspend_time'] = str(suspend_time) 118 | 119 | # OK 120 | change_version = child.config.changeVersion 121 | if change_version is None: 122 | change_version = "" 123 | # print("Change version: {}".format(change_version)) 124 | vinfo_data['change_version'] = str(change_version) 125 | 126 | # OK 127 | cpus = child.config.hardware.numCPU 128 | if cpus is None: 129 | cpus = "" 130 | # print("CPUs: {}".format(cpus)) 131 | vinfo_data['cpus'] = str(cpus) 132 | 133 | # OK 134 | try: 135 | latency_sensitivity = child.config.latencySensitivity.level 136 | except AttributeError: 137 | latency_sensitivity = "" 138 | 139 | # print("Latency sensitivy: {}".format(latency_sensitivity)) 140 | vinfo_data['latency_sensitivity'] = str(latency_sensitivity) 141 | 142 | # OK 143 | memory = child.config.hardware.memoryMB 144 | if memory is None: 145 | memory = "" 146 | # print("Memory: {}".format(memory)) 147 | vinfo_data['memory'] = str(memory) 148 | 149 | # OK 150 | nics = child.network.__len__() 151 | # print("Nics: {}".format(nics)) 152 | vinfo_data['nics'] = str(nics) 153 | 154 | # OK 155 | disks = child.layout.disk.__len__() 156 | if disks is None: 157 | disks = "" 158 | # print("Disks: {}".format(disks)) 159 | vinfo_data['disks'] = str(disks) 160 | 161 | # enable_uuid = "xx" 162 | # print("Enable UUID: {}".format(enable_uuid)) 163 | # vinfo_data['xx'] = str(xx) 164 | 165 | # cbt = "xx" 166 | # print("CBT: {}".format(cbt)) 167 | # vinfo_data['xx'] = str(xx) 168 | 169 | # OK 170 | try: 171 | if child.network[0].name: 172 | network_01 = child.network[0].name 173 | except IndexError: 174 | network_01 = "" 175 | 176 | # print("Network #1: {}".format(network_01)) 177 | vinfo_data['network_01'] = str(network_01) 178 | 179 | # OK 180 | try: 181 | if child.network[1].name: 182 | network_02 = child.network[1].name 183 | except IndexError: 184 | network_02 = "" 185 | 186 | # print("Network #2: {}".format(network_02)) 187 | vinfo_data['network_02'] = str(network_02) 188 | 189 | # OK 190 | try: 191 | if child.network[2].name: 192 | network_03 = child.network[2].name 193 | except IndexError: 194 | network_03 = "" 195 | 196 | # print("Network #3: {}".format(network_03)) 197 | vinfo_data['network_03'] = str(network_03) 198 | 199 | # OK 200 | try: 201 | if child.network[3].name: 202 | network_04 = child.network[3].name 203 | except IndexError: 204 | network_04 = "" 205 | 206 | # print("Network #4: {}".format(network_04)) 207 | vinfo_data['network_04'] = str(network_04) 208 | 209 | # OK 210 | for device in child.config.hardware.device: 211 | if device._wsdlName == 'VirtualMachineVideoCard': 212 | num_monitors = device.numDisplays 213 | # print("Num monitors: {}".format(num_monitors)) 214 | vinfo_data['num_monitors'] = str(num_monitors) 215 | break 216 | 217 | # OK 218 | for device in child.config.hardware.device: 219 | if device._wsdlName == 'VirtualMachineVideoCard': 220 | video_ram_kb = device.videoRamSizeInKB 221 | # print("Video ram KB: {}".format(video_ram_kb)) 222 | vinfo_data['video_ram_kb'] = str(video_ram_kb) 223 | break 224 | 225 | # resource_pool = "xx" 226 | # print("Resource pool: {}".format(resource_pool)) 227 | # vinfo_data['xx'] = str(xx) 228 | 229 | # folder = "xx" 230 | # print("Folder: {}".format(folder)) 231 | # vinfo_data['xx'] = str(xx) 232 | 233 | # vapp = "xx" 234 | # print("vApp: {}".format(vapp)) 235 | # vinfo_data['xx'] = str(xx) 236 | 237 | # das_protection = "xx" 238 | # print("DAS protection: {}".format(das_protection)) 239 | # vinfo_data['xx'] = str(xx) 240 | 241 | # OK 242 | ft_state = child.runtime.faultToleranceState 243 | if ft_state is None: 244 | ft_state = "" 245 | # print("FT state: {}".format(ft_state)) 246 | vinfo_data['ft_state'] = str(ft_state) 247 | 248 | # ft_latency = "xx" 249 | # print("FT latency: {}".format(ft_latency)) 250 | # vinfo_data['xx'] = str(xx) 251 | 252 | # ft_bandwidth = "xx" 253 | # print("FT bandwidth: {}".format(ft_bandwidth)) 254 | # vinfo_data['xx'] = str(xx) 255 | 256 | # ft_sec_latency = "xx" 257 | # print("FT sec latency: {}".format(ft_sec_latency)) 258 | # vinfo_data['xx'] = str(xx) 259 | 260 | # provisioned_mb = "xx" 261 | # print("Provisioned MB: {}".format(provisioned_mb)) 262 | # vinfo_data['xx'] = str(xx) 263 | 264 | # in_use_mb = "xx" 265 | # print("In use MB: {}".format(in_use_mb)) 266 | # vinfo_data['xx'] = str(xx) 267 | 268 | # unshared_mb = "xx" 269 | # print("Unshared MB: {}".format(unshared_mb)) 270 | # vinfo_data['xx'] = str(xx) 271 | 272 | # ha_restart_priority = "xx" 273 | # print("HA restart priority: {}".format(ha_restart_priority)) 274 | # vinfo_data['xx'] = str(xx) 275 | 276 | # ha_isolation_response = "xx" 277 | # print("HA isolation response: {}".format(ha_isolation_response)) 278 | # vinfo_data['xx'] = str(xx) 279 | 280 | # ha_vm_monitoring = "xx" 281 | # print("HA VM monitoring: {}".format(ha_vm_monitoring)) 282 | # vinfo_data['xx'] = str(xx) 283 | 284 | # cluster_rule = "xx" 285 | # print("Cluster rule: {}".format(cluster_rule)) 286 | # vinfo_data['xx'] = str(xx) 287 | 288 | # cluster_rule_name = "xx" 289 | # print("Cluster rule name: {}".format(cluster_rule_name)) 290 | # vinfo_data['xx'] = str(xx) 291 | 292 | # boot_required = "xx" 293 | # print("Boot required: {}".format(boot_required)) 294 | # vinfo_data['xx'] = str(xx) 295 | 296 | # OK 297 | boot_delay = child.config.bootOptions.bootDelay 298 | if boot_delay is None: 299 | boot_delay = "" 300 | # print("Boot delay: {}".format(boot_delay)) 301 | vinfo_data['boot_delay'] = str(boot_delay) 302 | 303 | # OK 304 | boot_retry_delay = child.config.bootOptions.bootRetryDelay 305 | if boot_retry_delay is None: 306 | boot_retry_delay = "" 307 | # print("Boot retry delay: {}".format(boot_retry_delay)) 308 | vinfo_data['boot_retry_delay'] = str(boot_retry_delay) 309 | 310 | # OK 311 | boot_retry_enabled = child.config.bootOptions.bootRetryEnabled 312 | if boot_retry_enabled is None: 313 | boot_retry_enabled = "" 314 | # print("Boot retry enabled: {}".format(boot_retry_enabled)) 315 | vinfo_data['boot_retry_enabled'] = str(boot_retry_enabled) 316 | 317 | # boot_bios_setup = "xx" 318 | # print("Boot bios setup: {}".format(boot_bios_setup)) 319 | # vinfo_data['xx'] = str(xx) 320 | 321 | # OK 322 | firmware = child.config.firmware 323 | if firmware is None: 324 | firmware = "" 325 | # print("Firmware: {}".format(firmware)) 326 | vinfo_data['firmware'] = str(firmware) 327 | 328 | # hw_version = "xx" 329 | # print("HW Version: {}".format(hw_version)) 330 | # vinfo_data['xx'] = str(xx) 331 | 332 | # hw_upgrade_status = "xx" 333 | # print("HW Upgrade Status: {}".format(hw_upgrade_status)) 334 | # vinfo_data['xx'] = str(xx) 335 | 336 | # hw_upgrade_policy = "xx" 337 | # print("HW Upgrade Policy: {}".format(hw_upgrade_policy)) 338 | # vinfo_data['xx'] = str(xx) 339 | 340 | # hw_target = "xx" 341 | # print("HW Target: {}".format(hw_target)) 342 | # vinfo_data['xx'] = str(xx) 343 | 344 | # OK 345 | path = child.config.files.vmPathName 346 | if path is None: 347 | path = "" 348 | # print("Path: {}".format(path)) 349 | vinfo_data['path'] = str(path) 350 | 351 | # annotation = "xx" 352 | # print("Annotation: {}".format(annotation)) 353 | # vinfo_data['xx'] = str(xx) 354 | 355 | # OK 356 | datacenter = get_obj(content, [vim.Datacenter]) 357 | # datacenter = get_obj(child, [vim.Datacenter]) 358 | print("Datacenter: {}".format(datacenter)) 359 | vinfo_data['datacenter'] = str(datacenter) 360 | 361 | # OK 362 | cluster = get_obj(content, [vim.ClusterComputeResource]) 363 | print("Cluster: {}".format(cluster)) 364 | vinfo_data['cluster'] = str(cluster) 365 | 366 | # try: 367 | # host = child.runtime.host.name 368 | # except pyVmomi.VmomiSupport.NoPermission: 369 | # # except vim.fault.noPermission: 370 | # host = None 371 | 372 | # if host is None: 373 | # host = "" 374 | # # print("Host: {}".format(host)) 375 | # vinfo_data['host'] = str(host) 376 | 377 | # os_according_to_the_configuration_file = "xx" 378 | # print("OS According to the configuration file: {}".format(os_according_to_the_configuration_file)) 379 | # vinfo_data['xx'] = str(xx) 380 | 381 | # OK 382 | os_according_to_the_vmware_tools = child.config.guestFullName 383 | if os_according_to_the_vmware_tools is None: 384 | os_according_to_the_vmware_tools = "" 385 | # print("OS According to the vmware tools: {}".format(os_according_to_the_vmware_tools)) 386 | vinfo_data['os_according_to_the_vmware_tools'] = str(os_according_to_the_vmware_tools) 387 | 388 | # OK 389 | vm_id = child._moId 390 | if vm_id is None: 391 | vm_id = "" 392 | # print("VM ID: {}".format(vm_id)) 393 | vinfo_data['vm_id'] = str(vm_id) 394 | 395 | # OK 396 | vm_uuid = child.config.uuid 397 | if vm_uuid is None: 398 | vm_uuid = "" 399 | # print("VM UUID: {}".format(vm_uuid)) 400 | vinfo_data['vm_uuid'] = str(vm_uuid) 401 | 402 | # vi_sdk_server_type = "xx" 403 | # print("VI SDK SERVER TYPE: {}".format(vi_sdk_server_type)) 404 | # vinfo_data['xx'] = str(xx) 405 | 406 | # vi_sdk_api_version = "xx" 407 | # print("VI SDK API VERSION: {}".format(vi_sdk_api_version)) 408 | # vinfo_data['xx'] = str(xx) 409 | 410 | # vi_sdk_server = "xx" 411 | # print("VI SDK SERVER: {}".format(vi_sdk_server)) 412 | # vinfo_data['xx'] = str(xx) 413 | 414 | # vi_sdk_uuid = "xx" 415 | # print("VI SDK UUID: {}".format(vi_sdk_uuid)) 416 | # vinfo_data['xx'] = str(xx) 417 | 418 | print("=====================") 419 | 420 | server_list.append(vinfo_data) 421 | 422 | csv_print("vinfo.csv", server_list, directory) 423 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import find_packages, setup 2 | 3 | 4 | with open("README.md", "r") as fh: 5 | long_description = fh.read() 6 | 7 | with open("requirements.txt", "r") as req: 8 | requirements = req.readlines() 9 | 10 | 11 | setup( 12 | name="rvtools_python", 13 | version="1.0.0", 14 | author="Waldirio", 15 | author_email="waldirio@gmail.com", 16 | description="Simple app to collect information from vSphere", 17 | long_description=long_description, 18 | long_description_content_type="text/markdown", 19 | install_requires=requirements, 20 | url="https://github.com/waldirio/rvtools_python/", 21 | packages=find_packages(), 22 | python_requires=">=3.9", 23 | scripts=['bin/rvtools'], 24 | include_package_data=True, 25 | classifiers=( 26 | "Programming Language :: Python :: 3", 27 | "License :: OSI Approved :: MIT License", 28 | "Operating System :: OS Independent", 29 | ), 30 | ) 31 | -------------------------------------------------------------------------------- /test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waldirio/rvtools_python/a77bff69bde10577e814200fa8dccee004199bf0/test/__init__.py --------------------------------------------------------------------------------