def main(): """ Simple command-line program for listing the virtual machines on a system. """ parser = cli.Parser() args = parser.get_args() try: my_vcr = config.VCR(custom_patches=((SoapAdapter, "_HTTPSConnection", VCRHTTPSConnection), )) # use the vcr instance to setup an instance of service_instance with my_vcr.use_cassette('hello_world_vcenter.yaml', record_mode='all'): si = service_instance.connect(args) print("\nHello World!\n") print("If you got here, you authenticted into vCenter.") print("The server is {0}!".format(args.host)) # NOTE (hartsock): only a successfully authenticated session has a # session key aka session id. session_id = si.content.sessionManager.currentSession.key print("current session id: {0}".format(session_id)) print("Well done!") print("\n") print("Download, learn and contribute back:") print("https://github.com/vmware/pyvmomi-community-samples") print("\n\n") except vmodl.MethodFault as error: print("Caught vmodl fault : " + error.msg) return -1 return 0
class VCRTestBase(unittest.TestCase): my_vcr = config.VCR(custom_patches=((SoapAdapter, '_HTTPSConnection', VCRHTTPSConnection), )) def setUp(self): monkey_patch_vcrpy() logging.basicConfig()
class VCRTestBase(unittest.TestCase): my_vcr = config.VCR( custom_patches=((SoapAdapter, '_HTTPSConnection', VCRHTTPSConnection),)) def setUp(self): monkey_patch_vcrpy() logging.basicConfig() vcr_log = logging.getLogger('vcr') vcr_log.setLevel(logging.WARNING)
def test_iso8601_set_datetime(self): # NOTE (hartsock): This test is an example of how to register # a fixture based test to compare the XML document that pyVmomi # is transmitting. We needed to invent a set of tools to effectively # compare logical XML documents to each other. In this case we are # only interested in the 'soapenv:Body' tag and its children. now_string = "2014-08-19T04:29:36.070918-04:00" # NOTE (hartsock): the strptime formatter has a bug in python 2.x # http://bugs.python.org/issue6641 so we're building the date time # using the constructor arguments instead of parsing it. now = datetime( 2014, 8, 19, 4, 29, 36, 70918, TZManager.GetTZInfo(tzname='EDT', utcOffset=timedelta(hours=-4, minutes=0))) def has_tag(doc): if doc is None: return False return '<dateTime>' in doc.decode("utf-8") def correct_time_string(doc): return '<dateTime>{0}</dateTime>'.format(now_string) in doc.decode( "utf-8") def check_date_time_value(r1, r2): for r in [r1, r2]: if has_tag(r.body): if not correct_time_string(r.body): return False return True my_vcr = config.VCR(custom_patches=((SoapAdapter, '_HTTPSConnection', VCRHTTPSConnection), )) my_vcr.register_matcher('document', check_date_time_value) # NOTE (hartsock): the `match_on` option is altered to use the # look at the XML body sent to the server with my_vcr.use_cassette('iso8601_set_datetime.yaml', cassette_library_dir=tests.fixtures_path, record_mode='once', match_on=[ 'method', 'scheme', 'host', 'port', 'path', 'query', 'document' ]): si = connect.SmartConnect(host='vcsa', user='******', pwd='my_password') search_index = si.content.searchIndex uuid = "4c4c4544-0043-4d10-8056-b1c04f4c5331" host = search_index.FindByUuid(None, uuid, False) date_time_system = host.configManager.dateTimeSystem # NOTE (hartsock): sending the date time 'now' to host. date_time_system.UpdateDateTime(now)
def _base_serialize_test(self, soap_creator, request_matcher): my_vcr = config.VCR(custom_patches=((SoapAdapter, '_HTTPSConnection', VCRHTTPSConnection), )) my_vcr.register_matcher('request_matcher', request_matcher) with my_vcr.use_cassette('test_simple_request_serializer.yaml', cassette_library_dir=tests.fixtures_path, record_mode='none', match_on=['request_matcher']) as cass: stub = soap_creator() si = vim.ServiceInstance("ServiceInstance", stub) content = si.RetrieveContent() self.assertTrue(content is not None) self.assertTrue( '<_this type="ServiceInstance">ServiceInstance</_this>' in cass.requests[0].body.decode("utf-8"))