def test_init_ssl_verify_bool(self): netmri = InfobloxNetMRI(**self.opts) self.assertEqual(False, netmri.ssl_verify) netmri = InfobloxNetMRI(ssl_verify="no", **self.opts) self.assertEqual(False, netmri.ssl_verify) netmri = InfobloxNetMRI(ssl_verify="off", **self.opts) self.assertEqual(False, netmri.ssl_verify) netmri = InfobloxNetMRI(ssl_verify=False, **self.opts) self.assertEqual(False, netmri.ssl_verify) netmri = InfobloxNetMRI(ssl_verify="false", **self.opts) self.assertEqual(False, netmri.ssl_verify) netmri = InfobloxNetMRI(ssl_verify="true", **self.opts) self.assertEqual(True, netmri.ssl_verify) netmri = InfobloxNetMRI(ssl_verify='yes', **self.opts) self.assertEqual(True, netmri.ssl_verify) netmri = InfobloxNetMRI(ssl_verify='on', **self.opts) self.assertEqual(True, netmri.ssl_verify) netmri = InfobloxNetMRI(ssl_verify=True, **self.opts) self.assertEqual(True, netmri.ssl_verify)
def test_check_single_device(self): netmri = InfobloxNetMRI(**self.opts) broker = netmri.get_broker('Device') with patch.object(netmri.session, 'request', side_effect=single_device): res = broker.show(DeviceID=1) self.assertEquals(res.DeviceID, 1, "Wrong id")
def test_check_return_values(self): netmri = InfobloxNetMRI(**self.opts) broker = netmri.get_broker('Device') with patch.object(netmri.session, 'request', side_effect=devices_list): res = broker.index() self.assertEquals(res[0].DeviceID, 1, "Wrong id device 1") self.assertEquals(res[1].DeviceID, 2, "Wrong id device 2")
def test_delete_with_string(self): netmri = InfobloxNetMRI(**self.opts) with patch.object(netmri, 'session') as mock_request: netmri.delete('job', '321') mock_request.request.assert_called_with( "delete", 'https://localhost/api/3.1/jobs/321', headers={'Content-type': 'application/json'}, data=None)
def test_show(self): netmri = InfobloxNetMRI(**self.opts) with patch.object(netmri, 'session') as mock_request: netmri.show('job', 123) mock_request.request.assert_called_with( "get", 'https://localhost/api/3.1/jobs/123', headers={'Content-type': 'application/json'}, data=None)
def test_get_device(self): netmri = InfobloxNetMRI(**self.opts) broker = netmri.get_broker('Device') with patch.object(netmri, 'session') as mock_request: broker.show(DeviceID=2) mock_request.request.assert_called_with( "post", 'https://localhost/api/3/devices/show', headers={'Content-type': 'application/json'}, data='{"DeviceID": 2}')
def test_init_ssl_verify_file(self, mock_isfile): mock_isfile.return_value = True netmri = InfobloxNetMRI(ssl_verify='/some/path.crt', **self.opts) self.assertEqual('/some/path.crt', netmri.ssl_verify) mock_isfile.return_value = False self.assertRaises(ValueError, InfobloxNetMRI, ssl_verify='/some/path.crt', **self.opts)
def get_api_client(): global _client conf = get_config() if _client is None: _client = InfobloxNetMRI(conf.host, conf.username, conf.password, api_version=NETMRI_API_VERSION) return _client
def test_get_device_broker(self): netmri = InfobloxNetMRI(**self.opts) broker = netmri.get_broker('Device') self.assertEquals(broker.__class__.__name__, 'DeviceBroker', "Device broker import error") broker = netmri.get_broker('AccessChange') self.assertEquals(broker.__class__.__name__, 'AccessChangeBroker', "AccessChangeBroker broker import error") broker = netmri.get_broker('ChangedPortNetExplorerInvSummaryGrid') self.assertEquals( broker.__class__.__name__, 'ChangedPortNetExplorerInvSummaryGridBroker', 'ChangedPortNetExplorerInvSummaryGridBroker broker import error ')
def __init__(self, debug=False, **kwargs): self.debug = debug self.api_version = kwargs.get('api_version') or "auto" self.host = urlparse(kwargs.get('api_url')).hostname self.username = kwargs.get('http_username') self.password = kwargs.get('http_password') self.job_id = kwargs.get('job_id') self.device_id = kwargs.get('device_id') self.batch_id = kwargs.get('batch_id') self.script_login = kwargs.get('script_login') if (not self.job_id) or (not self.device_id) or (not self.batch_id): raise RuntimeError( 'job_id or device_id or batch_id not initialized') self.client = InfobloxNetMRI(self.host, self.username, self.password, api_version=self.api_version) self.dis_session = self._open_dis_session() if not self.script_login == 'false': self.cli_connection = self._open_cli_connection() self._setup_logging()
def print_info(object): print(type(object)) print(dir(object)) netmri_password = getpass.getpass("Enter the Password: "******"host": "netmri.yourdomain", "username": "******", "password": netmri_password, } client = InfobloxNetMRI( defaults.get("host"), defaults.get("username"), defaults.get("password"), ) ''' Below broker is to get device ID from the "Device" broker ''' dev_broker = client.get_broker("Device") devices = dev_broker.index( ) # Indexes all NetMRI devices, but you could limit based on DeviceID or DeviceGroupID devname = "your-device-name" # You could always make this some other input, or just index the DeviceID if you know it. ''' Below iterates through devices from the device broker indexing. Then, pull out the "DeviceID" value from the device that matches "devname" and put that DeviceID in the "VlanMember" broker index method. ''' for device in devices:
def test_package_creation(self): netmri = InfobloxNetMRI(**self.opts) package = "infoblox_netmri.api.broker.v3_0_0.device_broker.DeviceBroker" self.assertEquals(package, netmri._get_broker_package("Device"))
def test_init_valid(self): netmri = InfobloxNetMRI(**self.opts) self.assertEqual(type(netmri), InfobloxNetMRI)
# to fetch the interface details of a devices from infoblox_netmri.client import InfobloxNetMRI from pprint import pprint import time defaults = { "host": "10.*.*.*", "username": "******", "password": "******", } infoblox_client = InfobloxNetMRI( defaults.get("host"), defaults.get("username"), defaults.get("password"), api_version="3.*.*", ) x = 'aj-test-switch' querystring = { 'op_DeviceName': "=", 'val_c_DeviceName': x, 'methods': "interfaces", 'select': "interfaces", } devicedetails = infoblox_client.api_request( 'devices/find', querystring ) # the interface details will be stored in devicedetails in multi-level dictionary pprint(devicedetails['devices'])