summaryrefslogtreecommitdiffstats
path: root/vesagent/py
diff options
context:
space:
mode:
Diffstat (limited to 'vesagent/py')
-rw-r--r--vesagent/py/dummylist.py5
-rw-r--r--vesagent/py/getAllVmInfo.py178
-rw-r--r--vesagent/py/test_getAllVmInfo.py36
3 files changed, 219 insertions, 0 deletions
diff --git a/vesagent/py/dummylist.py b/vesagent/py/dummylist.py
new file mode 100644
index 0000000..28ed71f
--- /dev/null
+++ b/vesagent/py/dummylist.py
@@ -0,0 +1,5 @@
+dummylist = []
+dummysingleinfo = {'Heartbeatstatus': 'gray', 'Name': 'openstack-template', 'Instance UUID': '502261f8-f9b5-4430-fc9b-4cbbd9a9da1c'}
+dummylist.append(dummysingleinfo)
+print("in dummylist.py",dummylist)
+#listjson[] = [{'Heartbeatstatus': 'gray', 'Name': 'openstack-template', 'Instance UUID': '502261f8-f9b5-4430-fc9b-4cbbd9a9da1c'}, {'Heartbeatstatus': 'green', 'Name': 'management-server', 'Instance UUID': '50229363-1961-25ea-5909-b395b5e90701'}, {'Heartbeatstatus': 'gray', 'Name': 'New Virtual Machine', 'Instance UUID': '5022143f-6758-05f8-c5bc-777994f09590'}, {'Heartbeatstatus': 'gray', 'Name': 'metadata_proxy_router-8802f84c-bc25-437a-b7f7-6b1f44db673a-0', 'Instance UUID': '5022efd1-8dff-6dab-92ac-f56be0ef2890'}, {'Heartbeatstatus': 'gray', 'Name': 'ubuntu_onap', 'Instance UUID': '5022889f-48e5-cfb7-7e42-849492f52074'}, {'Heartbeatstatus': 'gray', 'Name': 'testvm2', 'Instance UUID': '50227161-5bdb-f1c7-a35e-9e1ccc690c4a'}, {'Heartbeatstatus': 'green', 'Name': 'dhcp-ddaec694-47ac-4-0', 'Instance UUID': '5022b051-bee7-970e-b542-03c1dd2371f8'}, {'Heartbeatstatus': 'green', 'Name': 'JumoHost3', 'Instance UUID': '5022a29a-c22b-95f6-8db1-64ed99b466a7'}, {'Heartbeatstatus': 'gray', 'Name': 'backup-9dfc0681-0884-0', 'Instance UUID': '5022c282-d2b3-ddfe-afb9-3e3b1eff586a'}, {'Heartbeatstatus': 'gray', 'Name': 'DNS-clone', 'Instance UUID': '502286c7-5ae5-d832-c8e3-1cd2fb9fdfd5'}, {'Heartbeatstatus': 'gray', 'Name': 'Ubuntu_14.04', 'Instance UUID': '502237a7-1af7-5276-7661-447a00f555c2'}, {'Heartbeatstatus': 'gray', 'Name': 'backup-6ff1b0b8-a87f-0', 'Instance UUID': '50224658-086c-b89c-fec8-99a9a68b79e5'}, {'Heartbeatstatus': 'green', 'Name': 'NSX_Controller_abfcd152-179c-441d-bde1-7eb3c95515e8', 'Instance UUID': '5022c971-9074-73b7-436e-df4ed727de18'}, {'Heartbeatstatus': 'gray', 'Name': 'backup-341aac43-9b8d-0', 'Instance UUID': '5022bfea-4d1a-18be-31c0-4f47deb9d45b'}, {'Heartbeatstatus': 'green', 'Name': 'NSX_Controller_210c505a-fd0d-487c-aa13-c8e7c783fbd2', 'Instance UUID': '5022decc-330a-27f2-9b0c-22bda29849d5'}, {'Heartbeatstatus': 'gray', 'Name': 'backup-f373c488-30bf-0', 'Instance UUID': '5022fc7e-13cc-45a6-5eb2-c583c90d232c'}, {'Heartbeatstatus': 'green', 'Name': 'NSX_Controller_d91e4639-fb12-4db3-b724-840ab671fee7', 'Instance UUID': '5022dd32-6c9b-a926-3545-84ed04654aef'}, {'Heartbeatstatus': 'gray', 'Name': 'backup-696832d4-f7a3-0', 'Instance UUID': '5022b4e3-8298-becf-d7ff-9327ddd79da3'}, {'Heartbeatstatus': 'gray', 'Name': 'testvm1', 'Instance UUID': '502284ac-8a4b-00d7-7a1b-b457d16279e5'}, {'Heartbeatstatus': 'gray', 'Name': 'backup-750f9290-a800-0', 'Instance UUID': '50226a36-d367-4dbe-2424-c6b9f9dab53f'}, {'Heartbeatstatus': 'gray', 'Name': 'backup-08096265-239d-0', 'Instance UUID': '502224a1-8cbf-1b5a-f24e-0b462947cd34'}, {'Heartbeatstatus': 'gray', 'Name': 'metadata_proxy_router-79872529-425b-4621-8ec6-ffbbbd9cf2fd-0', 'Instance UUID': '50224e05-a656-2b9b-ffb5-e1bd940f5bac'}, {'Heartbeatstatus': 'green', 'Name': 'centos_gui', 'Instance UUID': '5022a5e7-6328-f472-43e9-c0b6a61fcb99'}, {'Heartbeatstatus': 'gray', 'Name': 'shared-7acbe88d-afb7-0', 'Instance UUID': '50225be5-1b5f-689e-05ae-2db75283c488'}, {'Heartbeatstatus': 'green', 'Name': 'dhcp-7b44ffd8-57d3-4-0', 'Instance UUID': '502262bb-cf5d-587e-e912-8f8625357e75'}, {'Heartbeatstatus': 'green', 'Name': 'NSX-Manager', 'Instance UUID': '5022c6c8-eb9f-a95d-efa0-d8889c590ed2'}, {'Heartbeatstatus': 'gray', 'Name': 'backup-69b84c8d-a635-0', 'Instance UUID': '5022e51a-2628-0f0d-440a-ab979ff6fd64'}, {'Heartbeatstatus': 'green', 'Name': 'shared-f5021549-8b6c-0', 'Instance UUID': '50229bc3-4b19-51a3-a4fe-269312933c6a'}, {'Heartbeatstatus': 'gray', 'Name': 'backup-c4a0d176-07d1-0', 'Instance UUID': '502209c6-f740-7c95-e817-c5e5bb2dc688'}, {'Heartbeatstatus': 'gray', 'Name': 'backup-2510da43-bd31-0', 'Instance UUID': '502288dd-9288-c7b1-50d7-865735068d4e'}, {'Heartbeatstatus': 'gray', 'Name': 'Jumphost2', 'Instance UUID': '500b1c61-6325-f84b-ed15-5a6f309170fd'}, {'Heartbeatstatus': 'green', 'Name': 'DNS', 'Instance UUID': '525fdeb5-a56b-f1e0-61bc-e057a5342431'}, {'Heartbeatstatus': 'green', 'Name': 'vcenter', 'Instance UUID': '527db7b5-e830-3a61-af22-9fb3cc5fb729'}, {'Heartbeatstatus': 'green', 'Name': 'VIO-ControlPlane-0', 'Instance UUID': '502266d2-a940-5983-3ac9-052fcb4b3c5e'}, {'Heartbeatstatus': 'gray', 'Name': 'VIO-Compute-0', 'Instance UUID': '50228a13-2863-ae65-1041-5858a1e266fb'}, {'Heartbeatstatus': 'gray', 'Name': 'ubuntu16.04testsnap (680d3f89-3407-41b4-85f6-72a1696926b3)', 'Instance UUID': '502243bd-6973-239d-a749-26a31e0a2101'}, {'Heartbeatstatus': 'gray', 'Name': 'ubuntu_16.04_postgres_eph_snap (1d2e2ca8-f566-4108-9af6-e5539cf9e9ca)', 'Instance UUID': '5022f98b-c465-86bb-2044-1e285e0c5dd8'}, {'Heartbeatstatus': 'gray', 'Name': 'Z1dcZONESTATEpstg00_snapshot (c70da0d9-5b0f-414d-b1c7-6ca521879ed6)', 'Instance UUID': '5022ae6f-b728-acce-0eb2-01a19f38958e'}, {'Heartbeatstatus': 'gray', 'Name': 'ubuntu_16.04_snapEFI (7b5ad0bd-acbb-40d8-af84-5f6b3a8be85e)', 'Instance UUID': '502221a2-7c23-d7a3-11f2-9656368e4cd3'}, {'Heartbeatstatus': 'gray', 'Name': 'onap-vm-vid (a40d3b40-7542-4410-990f-d0be53060879)', 'Instance UUID': 'a40d3b40-7542-4410-990f-d0be53060879'}, {'Heartbeatstatus': 'green', 'Name': 'zldcNorthIndiaUPcdap02 (3dda2c96-1fd0-4ae1-b820-95e857464315)', 'Instance UUID': '3dda2c96-1fd0-4ae1-b820-95e857464315'}, {'Heartbeatstatus': 'gray', 'Name': 'onap-vm-aai (737e06e7-cc36-4196-bc67-1675f15957cd)', 'Instance UUID': '737e06e7-cc36-4196-bc67-1675f15957cd'}, {'Heartbeatstatus': 'green', 'Name': 'onap-vm-robot (676703cd-49d6-499d-9cd7-3d317097ef90)', 'Instance UUID': '676703cd-49d6-499d-9cd7-3d317097ef90'}, {'Heartbeatstatus': 'green', 'Name': 'zldcNorthIndiaUPpstg00 (66e51416-b6c0-443a-acda-731230c06a96)', 'Instance UUID': '66e51416-b6c0-443a-acda-731230c06a96'}, {'Heartbeatstatus': 'green', 'Name': 'test ubuntu 13oct (337a4ebc-51f6-4119-bca8-f06f57a7907f)', 'Instance UUID': '337a4ebc-51f6-4119-bca8-f06f57a7907f'}, {'Heartbeatstatus': 'green', 'Name': 'onap-vm-message-router (0e14c790-2bdb-4eaa-adee-d0655931499c)', 'Instance UUID': '0e14c790-2bdb-4eaa-adee-d0655931499c'}, {'Heartbeatstatus': 'gray', 'Name': 'onap-vm-sdnc (7337a948-b303-4409-b643-d09e92b48950)', 'Instance UUID': '7337a948-b303-4409-b643-d09e92b48950'}, {'Heartbeatstatus': 'green', 'Name': 'zldcNorthIndiaUPcoll00 (91145edd-f916-46b4-9193-4f1cc7ba836e)', 'Instance UUID': '91145edd-f916-46b4-9193-4f1cc7ba836e'}, {'Heartbeatstatus': 'green', 'Name': 'zldcNorthIndiaUPcdap00 (1e452aaa-ed6d-4519-b16b-eee6294bbaae)', 'Instance UUID': '1e452aaa-ed6d-4519-b16b-eee6294bbaae'}, {'Heartbeatstatus': 'gray', 'Name': 'onap-vm-appc (d22a37b3-56c5-45e3-b07e-3b57a953c70e)', 'Instance UUID': 'd22a37b3-56c5-45e3-b07e-3b57a953c70e'}, {'Heartbeatstatus': 'green', 'Name': 'onap-vm-policy (a2fd952d-398f-4a10-8d67-517d7568d7ae)', 'Instance UUID': 'a2fd952d-398f-4a10-8d67-517d7568d7ae'}, {'Heartbeatstatus': 'gray', 'Name': 'onap-vm-portal (9b0aec34-59e2-44bd-8009-0f2a80db62e2)', 'Instance UUID': '9b0aec34-59e2-44bd-8009-0f2a80db62e2'}, {'Heartbeatstatus': 'green', 'Name': 'zldcNorthIndiaUPcdap01 (77abd09e-c88c-4a75-a68d-6ef47236a6d8)', 'Instance UUID': '77abd09e-c88c-4a75-a68d-6ef47236a6d8'}, {'Heartbeatstatus': 'green', 'Name': 'onap-vm-sdc (c310a0bd-4d56-4e95-85d8-93acc8335c36)', 'Instance UUID': 'c310a0bd-4d56-4e95-85d8-93acc8335c36'}, {'Heartbeatstatus': 'green', 'Name': 'ubuntu14.04HA (fbcc941e-e61d-48a6-85e0-9a26695d8a0f)', 'Instance UUID': 'fbcc941e-e61d-48a6-85e0-9a26695d8a0f'}, {'Heartbeatstatus': 'green', 'Name': 'onap-vm-dcae-controller (c723b2de-25b7-4e9f-b85b-1fb20b52c339)', 'Instance UUID': 'c723b2de-25b7-4e9f-b85b-1fb20b52c339'}, {'Heartbeatstatus': 'green', 'Name': 'onap-vm-mso (01dc316e-388e-4cd9-a72a-c806da4b0833)', 'Instance UUID': '01dc316e-388e-4cd9-a72a-c806da4b0833'}, {'Heartbeatstatus': 'gray', 'Name': 'onap-vm-dns-server (f162bab2-26dc-4288-ac3c-f332b7dd64c7)', 'Instance UUID': 'f162bab2-26dc-4288-ac3c-f332b7dd64c7'}, {'Heartbeatstatus': 'gray', 'Name': 'zldcNorthIndiaUPcdap01 (59d1953b-eec1-40f0-b3c3-160d2eae87f3)', 'Instance UUID': '59d1953b-eec1-40f0-b3c3-160d2eae87f3'}, {'Heartbeatstatus': 'gray', 'Name': 'zldcNorthIndiaUPcoll00 (98273d87-f516-4112-80ad-42a1e8139d0e)', 'Instance UUID': '98273d87-f516-4112-80ad-42a1e8139d0e'}, {'Heartbeatstatus': 'gray', 'Name': 'zldcNorthIndiaUPcdap02 (27eaa1d3-1257-40e3-b0ca-2c6911236ab4)', 'Instance UUID': '27eaa1d3-1257-40e3-b0ca-2c6911236ab4'}, {'Heartbeatstatus': 'gray', 'Name': 'zldcNorthIndiaUPpstg00 (d96aef31-73b4-4ff7-9dd2-21abaf07825f)', 'Instance UUID': 'd96aef31-73b4-4ff7-9dd2-21abaf07825f'}, {'Heartbeatstatus': 'gray', 'Name': 'zldcNorthIndiaUPcdap00 (131adfc0-91a7-468c-8b70-49c7512f26a3)', 'Instance UUID': '131adfc0-91a7-468c-8b70-49c7512f26a3'}, {'Heartbeatstatus': 'gray', 'Name': 'vol1-sdc-data (9c8cae82-2fc9-4014-b4e8-c48fbaa3a39c)', 'Instance UUID': '9c8cae82-2fc9-4014-b4e8-c48fbaa3a39c'}, {'Heartbeatstatus': 'gray', 'Name': '1b38a795-3342-4c78-9561-bd835f3fb150', 'Instance UUID': '502285f4-16c6-cc8b-7a0a-b740487be8fb'}, {'Heartbeatstatus': 'gray', 'Name': '44969d2f-b610-41d8-a1be-b7d648e7855e', 'Instance UUID': '5022e405-1e15-71c1-d711-fdbd77a6e63c'}, {'Heartbeatstatus': 'gray', 'Name': '1ce25f97-3fe6-46ea-803c-fa408963c7c3', 'Instance UUID': '5022731d-8005-5c75-6bb2-0c4d41abc8d3'}, {'Heartbeatstatus': 'gray', 'Name': 'd54d3255-9e97-4f3b-a5eb-7df2790079c9', 'Instance UUID': '5022a091-4198-6a2e-1934-9b567d6db8e1'}, {'Heartbeatstatus': 'gray', 'Name': 'f5758da1-1cc6-4dba-b49d-06c1b916e9e9', 'Instance UUID': '50224e2e-0e55-a2b5-e8f8-30c18022b5dc'}, {'Heartbeatstatus': 'gray', 'Name': '85c03839-ac42-4553-93c1-edfef7654c63', 'Instance UUID': '5022486d-8639-24aa-28fe-adbc2e7847e9'}, {'Heartbeatstatus': 'gray', 'Name': '6b829ed7-a6d2-4515-aff6-9c14502c31fb', 'Instance UUID': '502252b3-9a2d-8d59-8322-f438c9c7ca19'}, {'Heartbeatstatus': 'gray', 'Name': '2d7366ee-7082-451f-9651-3032eb21060c', 'Instance UUID': '5022fac2-8658-85a4-7e1f-d916ce3b1f95'}, {'Heartbeatstatus': 'gray', 'Name': '369dbffd-b575-40fc-93e8-0beeb6aa2c1c', 'Instance UUID': '50228391-c5d2-c62a-456e-0436aab9c2e9'}, {'Heartbeatstatus': 'gray', 'Name': 'fbebd7f9-7e5b-4390-adad-2df091abc2b5', 'Instance UUID': '50228af3-7686-ea84-4c90-8b525897a7be'}, {'Heartbeatstatus': 'gray', 'Name': 'inettest (60d1974d-a4c0-4692-a344-0ea2d9256d96)', 'Instance UUID': '60d1974d-a4c0-4692-a344-0ea2d9256d96'}, {'Heartbeatstatus': 'gray', 'Name': '89848475-69fa-4375-924c-79eb4dc9cdc7', 'Instance UUID': '50226fb3-7fc8-23aa-474f-f888833329b7'}, {'Heartbeatstatus': 'gray', 'Name': 'xenial-server-cloud-80G (fbebd7f9-7e5b-4390-adad-2df091abc2b5)', 'Instance UUID': 'c8f5248f-f488-5f8c-b08c-4395f005e75d'}, {'Heartbeatstatus': 'gray', 'Name': 'ubuntu_16.04_snapEFI-20G (7b5ad0bd-acbb-40d8-af84-5f6b3a8be85e)', 'Instance UUID': '39de4ab1-7dfa-55d0-8964-f5bf5742d9ee'}, {'Heartbeatstatus': 'gray', 'Name': 'ubuntu_14.04b-160G (369dbffd-b575-40fc-93e8-0beeb6aa2c1c)', 'Instance UUID': '1aa874c2-c3f2-5f96-b303-0bd3af3d7c52'}, {'Heartbeatstatus': 'gray', 'Name': 'ubuntu_14.04b-20G (369dbffd-b575-40fc-93e8-0beeb6aa2c1c)', 'Instance UUID': 'ed786c81-be81-566a-8710-a122dc0399be'}, {'Heartbeatstatus': 'gray', 'Name': 'xenial-server-cloud-20G (fbebd7f9-7e5b-4390-adad-2df091abc2b5)', 'Instance UUID': 'a7eb1923-fc15-58e1-b50f-6c1eb4af1c2d'}, {'Heartbeatstatus': 'gray', 'Name': 'ubuntu_16.04_snapEFI-80G (7b5ad0bd-acbb-40d8-af84-5f6b3a8be85e)', 'Instance UUID': '88751a88-d1e2-50aa-be95-b3f66b2f5ba5'}, {'Heartbeatstatus': 'gray', 'Name': 'xenial-server-cloud-160G (fbebd7f9-7e5b-4390-adad-2df091abc2b5)', 'Instance UUID': 'f9907133-7005-5de5-a5c0-80902324435e'}, {'Heartbeatstatus': 'gray', 'Name': 'ubuntu_14.04b-40G (369dbffd-b575-40fc-93e8-0beeb6aa2c1c)', 'Instance UUID': 'eb590b86-a4bd-5da2-b33a-52a88c803250'}, {'Heartbeatstatus': 'gray', 'Name': 'ubuntu_14.04b-80G (369dbffd-b575-40fc-93e8-0beeb6aa2c1c)', 'Instance UUID': 'c96367fe-35b8-51be-8391-ea7a1f075cec'}]
diff --git a/vesagent/py/getAllVmInfo.py b/vesagent/py/getAllVmInfo.py
new file mode 100644
index 0000000..a0c7c6b
--- /dev/null
+++ b/vesagent/py/getAllVmInfo.py
@@ -0,0 +1,178 @@
+#!/usr/bin/env python
+# VMware vSphere Python SDK
+# Copyright (c) 2008-2015 VMware, Inc. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# 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.
+
+"""
+List the vms on an ESX / vCenter host
+"""
+
+from __future__ import print_function
+from pyVim.connect import SmartConnect, Disconnect
+from pyVmomi import vim
+import argparse
+import atexit
+import getpass
+import ssl
+import json
+import os.path
+
+fp = None
+listjson = []
+propFile="/opt/etc/Agent.properties"
+
+def GetJsonFileLocation():
+ AgntProps = {}
+ if True == os.path.isfile(propFile):
+ with open("/opt/etc/Agent.properties") as propfile:
+ for line in propfile:
+ name, var = line.partition("=")[::2]
+ AgntProps[name.strip()] = var
+ return AgntProps["Python_Output_Json"].strip()
+ else:
+ print(propFile+" Not Found")
+ return None
+
+
+def GetArgs():
+ """
+ Supports the command-line arguments listed below.
+ """
+ parser = argparse.ArgumentParser(
+ description='Process args for retrieving all the Virtual Machines')
+ parser.add_argument('-s', '--host', required=True, action='store',
+ help='Remote host to connect to')
+ parser.add_argument('-o', '--port', type=int, default=443, action='store',
+ help='Port to connect on')
+ parser.add_argument('-u', '--user', required=True, action='store',
+ help='User name to use when connecting to host')
+ parser.add_argument('-p', '--password', required=True, action='store',
+ help='Password to use when connecting to host')
+ args = parser.parse_args()
+ return args
+
+
+def PrintVmInfo(vm, depth=1):
+
+ """
+ Print information for a particular virtual machine or recurse into a folder
+ or vApp with depth protection
+ """
+ maxdepth = 10
+
+
+ # if this is a group it will have children. if it does, recurse into them
+ # and then return
+ if hasattr(vm, 'childEntity'):
+ if depth > maxdepth:
+ return
+ vmList = vm.childEntity
+ for c in vmList:
+ PrintVmInfo(c, depth+1)
+ return
+
+
+ # if this is a vApp, it likely contains child VMs
+ # (vApps can nest vApps, but it is hardly a common usecase, so ignore that)
+ if isinstance(vm, vim.VirtualApp):
+ vmList = vm.vm
+ for c in vmList:
+ PrintVmInfo(c, depth + 1)
+ return
+
+
+ summary = vm.summary
+ #print("Name : ", summary.config.name)
+ #print("Path : ", summary.config.vmPathName)
+ #print("Guest : ", summary.config.guestFullName)
+ #print("Instance UUID: ", summary.config.instanceUuid)
+ #print("Heartbeatstatus: ", vm.guestHeartbeatStatus)
+ if summary.config.name and vm.guestHeartbeatStatus:
+ singleinfo={}
+ singleinfo.update({"Name":summary.config.name})
+ singleinfo.update({"Instance UUID":summary.config.instanceUuid})
+ singleinfo.update({"Heartbeatstatus":vm.guestHeartbeatStatus})
+ #print ("Final SINGLEINFO")
+ listjson.append(singleinfo)
+ else:
+ print ("NAME, UUID OR HEARTBEAT NOT PRESENT")
+
+
+def GetContent(args, context):
+ if hasattr(ssl, '_create_unverified_context'):
+ context = ssl._create_unverified_context()
+ si = SmartConnect(host=args.host,
+ user=args.user,
+ pwd=args.password,
+ port=int(args.port),
+ sslContext=context)
+ if not si:
+ print("Could not connect to the specified host using specified "
+ "username and password")
+ return -1
+
+ atexit.register(Disconnect, si)
+ return si.RetrieveContent()
+
+
+def CreateJsonList(content):
+ for child in content.rootFolder.childEntity:
+ if hasattr(child, 'vmFolder'):
+ datacenter = child
+ vmFolder = datacenter.vmFolder
+ vmList = vmFolder.childEntity
+ for vm in vmList:
+ PrintVmInfo(vm)
+ print (listjson)
+ return listjson
+
+
+def CreateJsonFile(JsonFile, jsonrecord):
+ if(len(jsonrecord) == 0):
+ return False
+ else:
+ #Return False if File Location is None
+ print("Json File Location is:",JsonFile)
+ fp = open(JsonFile, 'w')
+ if not fp:
+ return False
+ else:
+ json.dump(jsonrecord, fp,sort_keys=True, indent=2)
+ fp.close()
+ return True
+
+
+def main():
+ """
+ Simple command-line program for listing the virtual machines on a system.
+ """
+ args = GetArgs()
+
+ context = None
+ content = GetContent(args, context)
+
+ jsonrecord = CreateJsonList(content)
+
+ JsonFile = GetJsonFileLocation()
+ if (None == JsonFile):
+ return -1
+
+ if(True == CreateJsonFile(JsonFile, jsonrecord)):
+ return 0
+ else:
+ return -1
+
+# Start program
+if __name__ == "__main__":
+ main()
diff --git a/vesagent/py/test_getAllVmInfo.py b/vesagent/py/test_getAllVmInfo.py
new file mode 100644
index 0000000..4010d89
--- /dev/null
+++ b/vesagent/py/test_getAllVmInfo.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+# VMware vSphere Python SDK
+# Copyright (c) 2008-2015 VMware, Inc. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# 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.
+
+
+import unittest
+import getAllVmInfo
+import argparse
+from dummylist import dummylist
+
+DummyJsonFile = "final-res.json"
+
+class TestgetAllVmInfo(unittest.TestCase):
+ def test_CreateJsonFilePositive(self):
+ #print ("dummylist is:",dummylist)
+ self.assertTrue(getAllVmInfo.CreateJsonFile(DummyJsonFile, dummylist))
+
+ def test_CreateJsonFileNegative(self):
+ dummylistempty = []
+ #print ("dummylist is:",dummylistempty)
+ self.assertFalse(getAllVmInfo.CreateJsonFile(DummyJsonFile, dummylistempty))
+
+if __name__ == '__main__':
+ unittest.main()