from urllib.error import HTTPError, URLError
from urllib.request import urlopen, Request
from pathlib import Path
-from cephadmlib.node_proxy.main import NodeProxy, NodeProxyInitialization, NodeProxyFetchIdracError
+from cephadmlib.node_proxy.main import NodeProxy, NodeProxyInitialization, NodeProxyFetchOobError
FuncT = TypeVar('FuncT', bound=Callable)
logger.error(f'node-proxy not running: {e.__class__.__name__}: {e}')
try:
self.init_node_proxy(ssl_ctx)
- except NodeProxyFetchIdracError:
- logger.info("No iDrac details could be loaded. "
+ except NodeProxyFetchOobError:
+ logger.info("No oob details could be loaded. "
"Aborting node-proxy initialization. "
"Will retry in 120s.")
time.sleep(120)
}
}
status, result = self.query_endpoint(data=json.dumps(node_proxy_meta).encode('ascii'),
- endpoint='/node-proxy/idrac',
+ endpoint='/node-proxy/oob',
ssl_ctx=ssl_ctx)
if status != 200:
- msg = f"Couldn't load iDrac details: {status}, {result}"
+ msg = f"Couldn't load oob details: {status}, {result}"
logger.debug(msg)
- raise NodeProxyFetchIdracError(msg)
+ raise NodeProxyFetchOobError(msg)
result_json = json.loads(result)
kwargs = {
'host': result_json['result']['addr'],
pass
-class NodeProxyFetchIdracError(Exception):
+class NodeProxyFetchOobError(Exception):
pass
if not self.is_logged_in():
self.log.logger.info("Logging in to "
f"{self.url} as '{self.username}'")
- idrac_credentials = json.dumps({"UserName": self.username,
- "Password": self.password})
+ oob_credentials = json.dumps({"UserName": self.username,
+ "Password": self.password})
headers = {"Content-Type": "application/json"}
try:
- _headers, _data, _status_code = self.query(data=idrac_credentials,
+ _headers, _data, _status_code = self.query(data=oob_credentials,
headers=headers,
endpoint='/redfish/v1/SessionService/Sessions/')
if _status_code != 201:
@cherrypy.tools.allow(methods=['POST'])
@cherrypy.tools.json_in()
@cherrypy.tools.json_out()
- def idrac(self) -> Dict[str, Any]:
+ def oob(self) -> Dict[str, Any]:
"""
- Get the iDrac details for a given host.
+ Get the out-of-band management tool details for a given host.
- :return: idrac details.
+ :return: oob details.
:rtype: dict
"""
data: Dict[str, Any] = cherrypy.request.json
self.validate_node_proxy_data(data)
host = data["cephx"]["name"]
- results['result'] = self.mgr.node_proxy.idrac.get(host)
+ results['result'] = self.mgr.node_proxy.oob.get(host)
if not results['result']:
raise cherrypy.HTTPError(400, 'The provided host has no iDrac details.')
return results
# TODO(guits): need to check the request is authorized
# allowing a specific keyring only ? (client.admin or client.agent.. ?)
data: str = json.dumps(cherrypy.request.json)
- username = self.mgr.node_proxy.idrac[hostname]['username']
- password = self.mgr.node_proxy.idrac[hostname]['password']
+ username = self.mgr.node_proxy.oob[hostname]['username']
+ password = self.mgr.node_proxy.oob[hostname]['password']
auth = f"{username}:{password}".encode("utf-8")
auth = base64.b64encode(auth).decode("utf-8")
headers = {"Authorization": f"Basic {auth}"}
def __init__(self, mgr: "CephadmOrchestrator") -> None:
self.mgr = mgr
self.data: Dict[str, Any] = {}
- self.idrac = {}
+ self.oob: Dict[str, Any] = {}
def load(self) -> None:
- _idrac = self.mgr.get_store('node_proxy/idrac', "{}")
- self.idrac = json.loads(_idrac)
+ _oob = self.mgr.get_store('node_proxy/oob', "{}")
+ self.oob = json.loads(_oob)
for k, v in self.mgr.get_store_prefix(NODE_PROXY_CACHE_PREFIX).items():
host = k.split('/')[-1:][0]
# remove entry for host that no longer exists
self.mgr.set_store(f"{NODE_PROXY_CACHE_PREFIX}/{host}", None)
try:
- self.idrac.pop(host)
+ self.oob.pop(host)
self.data.pop(host)
except KeyError:
pass
if spec.hostname in self.inventory and self.inventory.get_addr(spec.hostname) != spec.addr:
self.cache.refresh_all_host_info(spec.hostname)
- if spec.idrac:
- if not spec.idrac.get('addr'):
- spec.idrac['addr'] = spec.hostname
- if not spec.idrac.get('port'):
- spec.idrac['port'] = '443'
- data = json.loads(self.get_store('node_proxy/idrac', '{}'))
+ if spec.oob:
+ if not spec.oob.get('addr'):
+ spec.oob['addr'] = spec.hostname
+ if not spec.oob.get('port'):
+ spec.oob['port'] = '443'
+ data = json.loads(self.get_store('node_proxy/oob', '{}'))
data[spec.hostname] = dict()
- data[spec.hostname]['addr'] = spec.idrac['addr']
- data[spec.hostname]['port'] = spec.idrac['port']
- data[spec.hostname]['username'] = spec.idrac['username']
- data[spec.hostname]['password'] = spec.idrac['password']
- self.set_store('node_proxy/idrac', json.dumps(data))
+ data[spec.hostname]['addr'] = spec.oob['addr']
+ data[spec.hostname]['port'] = spec.oob['port']
+ data[spec.hostname]['username'] = spec.oob['username']
+ data[spec.hostname]['password'] = spec.oob['password']
+ self.set_store('node_proxy/oob', json.dumps(data))
# prime crush map?
if spec.location:
"addr": "10.10.10.11",
"labels": ["_admin"],
"status": "",
- "idrac": {"hostname": "10.10.10.11",
- "username": "root",
- "password": "ceph123"}},
+ "oob": {"hostname": "10.10.10.11",
+ "username": "root",
+ "password": "ceph123"}},
"host02": {"hostname": "host02",
"addr": "10.10.10.12",
"labels": [],
"status": "",
- "idrac": {"hostname": "10.10.10.12",
- "username": "root",
- "password": "ceph123"}}}
+ "oob": {"hostname": "10.10.10.12",
+ "username": "root",
+ "password": "ceph123"}}}
full_set = {
"host01": {
app = NodeProxy(mgr)
mgr.agent_cache.agent_keys = {"host01": "fake-secret01",
"host02": "fake-secret02"}
- mgr.node_proxy.idrac = {"host01": {"username": "idrac-user01",
- "password": "idrac-pass01"},
- "host02": {"username": "idrac-user02",
- "password": "idrac-pass02"}}
+ mgr.node_proxy.oob = {"host01": {"username": "oob-user01",
+ "password": "oob-pass01"},
+ "host02": {"username": "oob-user02",
+ "password": "oob-pass02"}}
mgr.node_proxy.data = node_proxy_data.full_set
@classmethod
self.PORT = PORT
self.monkeypatch = MonkeyPatch()
- def test_idrac_data_misses_cephx_field(self):
+ def test_oob_data_misses_cephx_field(self):
data = '{}'
- self.getPage("/idrac", method="POST", body=data, headers=[('Content-Type', 'application/json'),
+ self.getPage("/oob", method="POST", body=data, headers=[('Content-Type', 'application/json'),
('Content-Length', str(len(data)))])
self.assertStatus('400 Bad Request')
- def test_idrac_data_misses_name_field(self):
+ def test_oob_data_misses_name_field(self):
data = '{"cephx": {"secret": "fake-secret"}}'
- self.getPage("/idrac", method="POST", body=data, headers=[('Content-Type', 'application/json'),
+ self.getPage("/oob", method="POST", body=data, headers=[('Content-Type', 'application/json'),
('Content-Length', str(len(data)))])
self.assertStatus('400 Bad Request')
- def test_idrac_data_misses_secret_field(self):
+ def test_oob_data_misses_secret_field(self):
data = '{"cephx": {"name": "host01"}}'
- self.getPage("/idrac", method="POST", body=data, headers=[('Content-Type', 'application/json'),
+ self.getPage("/oob", method="POST", body=data, headers=[('Content-Type', 'application/json'),
('Content-Length', str(len(data)))])
self.assertStatus('400 Bad Request')
- def test_idrac_agent_not_running(self):
+ def test_oob_agent_not_running(self):
data = '{"cephx": {"name": "host03", "secret": "fake-secret03"}}'
- self.getPage("/idrac", method="POST", body=data, headers=[('Content-Type', 'application/json'),
+ self.getPage("/oob", method="POST", body=data, headers=[('Content-Type', 'application/json'),
('Content-Length', str(len(data)))])
self.assertStatus('502 Bad Gateway')
- def test_idrac_wrong_keyring(self):
+ def test_oob_wrong_keyring(self):
data = '{"cephx": {"name": "host01", "secret": "wrong-keyring"}}'
- self.getPage("/idrac", method="POST", body=data, headers=[('Content-Type', 'application/json'),
+ self.getPage("/oob", method="POST", body=data, headers=[('Content-Type', 'application/json'),
('Content-Length', str(len(data)))])
self.assertStatus('403 Forbidden')
- def test_idrac_ok(self):
+ def test_oob_ok(self):
data = '{"cephx": {"name": "host01", "secret": "fake-secret01"}}'
- self.getPage("/idrac", method="POST", body=data, headers=[('Content-Type', 'application/json'),
+ self.getPage("/oob", method="POST", body=data, headers=[('Content-Type', 'application/json'),
('Content-Length', str(len(data)))])
self.assertStatus('200 OK')
raise SpecValidationError(str(e) + f'. Got "{name}"')
-def assert_valid_idrac(idrac: Dict[str, str]) -> None:
+def assert_valid_oob(oob: Dict[str, str]) -> None:
fields = ['username', 'password']
try:
for field in fields:
- assert field in idrac.keys()
+ assert field in oob.keys()
except AssertionError as e:
raise SpecValidationError(str(e))
labels: Optional[List[str]] = None,
status: Optional[str] = None,
location: Optional[Dict[str, str]] = None,
- idrac: Optional[Dict[str, str]] = None,
+ oob: Optional[Dict[str, str]] = None,
):
self.service_type = 'host'
self.location = location
- #: idrac details, if provided
- self.idrac = idrac
+ #: oob details, if provided
+ self.oob = oob
def validate(self) -> None:
assert_valid_host(self.hostname)
- if self.idrac:
- assert_valid_idrac(self.idrac)
+ if self.oob:
+ assert_valid_oob(self.oob)
def to_json(self) -> Dict[str, Any]:
r: Dict[str, Any] = {
}
if self.location:
r['location'] = self.location
- if self.idrac:
- r['idrac'] = self.idrac
+ if self.oob:
+ r['oob'] = self.oob
return r
@classmethod
host_spec['labels'])) if 'labels' in host_spec else None,
host_spec['status'] if 'status' in host_spec else None,
host_spec.get('location'),
- host_spec['idrac'] if 'idrac' in host_spec else None,
+ host_spec['oob'] if 'oob' in host_spec else None,
)
return _cls