def test_get_data(self, mock_request, mock_config, mock_catalog, mock_get_bg_id): mock_request.return_value.get_object.return_value = ['fake_data'] vra_sdk = VraSdk(MagicMock(), '') vra_sdk.get_data('vm', 'key', 'value') mock_request.return_value.get_object.assert_called_once_with( 'vm', 'key', 'value', 1, 1, True)
def test_get_data_raises(self, mock_request, mock_config, mock_catalog, mock_get_bg_id): mock_request.return_value.get_object.return_value = None vra_sdk = VraSdk(MagicMock(), '') with self.assertRaises(VraSdkMainException): vra_sdk.get_data('', '', '')
environment = os.environ['vra_environment'] login = os.environ['vra_login'] password = os.environ['vra_password'] ###### # authentication part VraConfig('config.json') auth = VraAuthenticate(environment).auth_login_password( login, password, domain) my_business_group = 'my_bg_name' my_client = VraSdk(auth, my_business_group) ###### # get data on one vm from name vm_name = 'my_vm_name' vm_data = my_client.get_data('vm', 'name', vm_name)[0] print(vm_data.id) ###### # get data on one vm from id vm_id = 'my_vm_id' vm_data = my_client.get_data('vm', 'id', vm_id) print(vm_data.name) # you can either get the data as dict or as json pprint(vm_data.to_json()) pprint(vm_data.to_dict()) ###### # get list of vm vm_list = my_client.get_data('vm', None, None)