New resource for getting the managers IPs of the cluster
Change-Id: If0d711323efa5fb6f39e3a9d4bf02b61973bcabb
This commit is contained in:
parent
99f7317575
commit
35be517d38
@ -588,3 +588,52 @@ FAKE_TRANS_NODE = {
|
|||||||
}],
|
}],
|
||||||
"node_id": "f5a2b5ca-8dba-11e8-9799-020039422cc8"
|
"node_id": "f5a2b5ca-8dba-11e8-9799-020039422cc8"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FAKE_MANAGER_IP1 = "10.192.210.181"
|
||||||
|
FAKE_MANAGER_IP2 = "10.192.210.182"
|
||||||
|
FAKE_CLUSTER_NODES_CONFIG = [{
|
||||||
|
"resource_type": "ClusterNodeConfig",
|
||||||
|
"manager_role": {
|
||||||
|
"type": "ManagementClusterRoleConfig",
|
||||||
|
"mgmt_cluster_listen_addr": {
|
||||||
|
"port": 0,
|
||||||
|
"ip_address": FAKE_MANAGER_IP1
|
||||||
|
},
|
||||||
|
"api_listen_addr": {
|
||||||
|
"port": 443,
|
||||||
|
"ip_address": FAKE_MANAGER_IP1
|
||||||
|
},
|
||||||
|
"mgmt_plane_listen_addr": {
|
||||||
|
"port": 5671,
|
||||||
|
"ip_address": FAKE_MANAGER_IP1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"appliance_mgmt_listen_addr": FAKE_MANAGER_IP1
|
||||||
|
}, {
|
||||||
|
"resource_type": "ClusterNodeConfig",
|
||||||
|
"controller_role": {
|
||||||
|
"type": "ControllerClusterRoleConfig",
|
||||||
|
"control_cluster_listen_addr": {
|
||||||
|
"port": 7777,
|
||||||
|
"ip_address": "127.0.0.1"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
"resource_type": "ClusterNodeConfig",
|
||||||
|
"manager_role": {
|
||||||
|
"type": "ManagementClusterRoleConfig",
|
||||||
|
"mgmt_cluster_listen_addr": {
|
||||||
|
"port": 0,
|
||||||
|
"ip_address": FAKE_MANAGER_IP2
|
||||||
|
},
|
||||||
|
"api_listen_addr": {
|
||||||
|
"port": 443,
|
||||||
|
"ip_address": FAKE_MANAGER_IP2
|
||||||
|
},
|
||||||
|
"mgmt_plane_listen_addr": {
|
||||||
|
"port": 5671,
|
||||||
|
"ip_address": FAKE_MANAGER_IP2
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"appliance_mgmt_listen_addr": FAKE_MANAGER_IP2
|
||||||
|
}]
|
||||||
|
@ -1918,6 +1918,24 @@ class NodeHttpServicePropertiesTestCase(BaseTestResource):
|
|||||||
headers=self.default_headers())
|
headers=self.default_headers())
|
||||||
|
|
||||||
|
|
||||||
|
class TestNsxlibClusterNodesConfigTestCase(BaseTestResource):
|
||||||
|
def setUp(self):
|
||||||
|
super(TestNsxlibClusterNodesConfigTestCase, self).setUp(
|
||||||
|
resources.NsxlibClusterNodesConfig)
|
||||||
|
|
||||||
|
def test_delete_resource(self):
|
||||||
|
self.skipTest("The action is not supported by this resource")
|
||||||
|
|
||||||
|
def test_get_managers_ips(self):
|
||||||
|
mocked_resource = self.get_mocked_resource()
|
||||||
|
body = {'results': test_constants.FAKE_CLUSTER_NODES_CONFIG}
|
||||||
|
with mock.patch.object(mocked_resource.client, "url_get",
|
||||||
|
return_value=body):
|
||||||
|
result = mocked_resource.get_managers_ips()
|
||||||
|
self.assertEqual([test_constants.FAKE_MANAGER_IP1,
|
||||||
|
test_constants.FAKE_MANAGER_IP2], result)
|
||||||
|
|
||||||
|
|
||||||
class DummyCachedResource(utils.NsxLibApiBase):
|
class DummyCachedResource(utils.NsxLibApiBase):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -296,6 +296,8 @@ class NsxLib(NsxLibBase):
|
|||||||
self.client, self.nsxlib_config, nsxlib=self)
|
self.client, self.nsxlib_config, nsxlib=self)
|
||||||
self.http_services = resources.NodeHttpServiceProperties(
|
self.http_services = resources.NodeHttpServiceProperties(
|
||||||
self.client, self.nsxlib_config, nsxlib=self)
|
self.client, self.nsxlib_config, nsxlib=self)
|
||||||
|
self.cluster_nodes = resources.NsxlibClusterNodesConfig(
|
||||||
|
self.client, self.nsxlib_config, nsxlib=self)
|
||||||
|
|
||||||
# Update tag limits
|
# Update tag limits
|
||||||
self.tag_limits = self.get_tag_limits()
|
self.tag_limits = self.get_tag_limits()
|
||||||
|
@ -691,3 +691,32 @@ class NodeHttpServiceProperties(utils.NsxLibApiBase):
|
|||||||
"""Not supported"""
|
"""Not supported"""
|
||||||
msg = _("Find is not supported for %s") % self.uri_segment
|
msg = _("Find is not supported for %s") % self.uri_segment
|
||||||
raise exceptions.ManagerError(details=msg)
|
raise exceptions.ManagerError(details=msg)
|
||||||
|
|
||||||
|
|
||||||
|
class NsxlibClusterNodesConfig(utils.NsxLibApiBase):
|
||||||
|
@property
|
||||||
|
def uri_segment(self):
|
||||||
|
return 'cluster/nodes'
|
||||||
|
|
||||||
|
@property
|
||||||
|
def resource_type(self):
|
||||||
|
return 'ClusterNodeConfig'
|
||||||
|
|
||||||
|
def delete(self, uuid):
|
||||||
|
"""Not supported"""
|
||||||
|
msg = _("Delete is not supported for %s") % self.uri_segment
|
||||||
|
raise exceptions.ManagerError(details=msg)
|
||||||
|
|
||||||
|
def get_managers_ips(self):
|
||||||
|
manager_ips = []
|
||||||
|
nodes_config = self.client.get(self.get_path())['results']
|
||||||
|
for node in nodes_config:
|
||||||
|
if 'manager_role' in node:
|
||||||
|
manager_conf = node['manager_role']
|
||||||
|
if 'api_listen_addr' in manager_conf:
|
||||||
|
list_addr = manager_conf['mgmt_cluster_listen_addr']
|
||||||
|
ip = list_addr['ip_address']
|
||||||
|
if ip != '127.0.0.1':
|
||||||
|
manager_ips.append(list_addr['ip_address'])
|
||||||
|
|
||||||
|
return manager_ips
|
||||||
|
Loading…
x
Reference in New Issue
Block a user