def sensorgroup_modify(token, address, port, isensorgroup_hwmon, timeout): """ Sends a SensorGroup Modify command to maintenance. """ api_cmd = "http://%s:%s" % (address, port) api_cmd += "/v1/isensorgroups/%s" % isensorgroup_hwmon['uuid'] api_cmd_headers = dict() api_cmd_headers['Content-type'] = "application/json" api_cmd_headers['User-Agent'] = "sysinv/1.0" api_cmd_payload = dict() api_cmd_payload = isensorgroup_hwmon LOG.info("sensorgroup_modify for %s cmd=%s hdr=%s payload=%s" % (isensorgroup_hwmon['sensorgroupname'], api_cmd, api_cmd_headers, api_cmd_payload)) response = rest_api_request(token, "PATCH", api_cmd, api_cmd_headers, json.dumps(api_cmd_payload), timeout) LOG.debug("sensorgroup modify response=%s" % response) return response
def vim_host_delete(context, uuid, hostname, timeout=constants.VIM_DEFAULT_TIMEOUT_IN_SECS): """ Asks VIM to delete a host """ api_cmd = _get_endpoint(context) api_cmd += "/nfvi-plugins/v1/hosts/%s" % uuid api_cmd_headers = dict() api_cmd_headers['Content-type'] = "application/json" api_cmd_headers['User-Agent'] = "inventory/1.0" api_cmd_payload = dict() api_cmd_payload['uuid'] = uuid api_cmd_payload['hostname'] = hostname api_cmd_payload['action'] = 'delete' response = rest_api_request(context, "DELETE", api_cmd, api_cmd_headers, json.dumps(api_cmd_payload), timeout=timeout) return response
def patch_query_hosts(context, region_name, timeout=constants.PATCH_DEFAULT_TIMEOUT_IN_SECS): """ Request the patch state for all hosts known to the patch service """ api_cmd = _get_endpoint(context, region_name) api_cmd += "/v1/query_hosts/" return rest_api_request(context, "GET", api_cmd, timeout=timeout)
def patch_drop_host(context, hostname, region_name, timeout=constants.PATCH_DEFAULT_TIMEOUT_IN_SECS): """ Notify the patch service to drop the specified host """ api_cmd = _get_endpoint(context, region_name) api_cmd += "/v1/drop_host/%s" % hostname return rest_api_request(context, "POST", api_cmd, timeout=timeout)
def service_show(context, hostname): """ Sends a service show command to SM. """ api_cmd = _get_endpoint(context) api_cmd += "/v1/services/%s" % hostname api_cmd_headers = dict() api_cmd_headers['Content-type'] = "application/json" api_cmd_headers['Accept'] = "application/json" api_cmd_headers['User-Agent'] = "inventory/1.0" response = rest_api_request(context, "GET", api_cmd, api_cmd_headers, None) return response
def servicenode_list(context): """ Sends a service list command to SM. """ api_cmd = _get_endpoint(context) api_cmd += "/v1/nodes" api_cmd_headers = dict() api_cmd_headers['Content-type'] = "application/json" api_cmd_headers['Accept'] = "application/json" api_cmd_headers['User-Agent'] = "inventory/1.0" response = rest_api_request(context, "GET", api_cmd, api_cmd_headers, None) return response
def sm_servicegroup_list(context): """ Sends a service list command to SM. """ api_cmd = _get_endpoint(context) api_cmd += "/v1/sm_sda" api_cmd_headers = dict() api_cmd_headers['Content-type'] = "application/json" api_cmd_headers['Accept'] = "application/json" api_cmd_headers['User-Agent'] = "inventory/1.0" response = rest_api_request(context, "GET", api_cmd, api_cmd_headers, None) # rename the obsolete sm_sda to sm_servicegroups if isinstance(response, dict): if 'sm_sda' in response: response['sm_servicegroup'] = response.pop('sm_sda') return response
def vim_host_add(context, uuid, hostname, subfunctions, admininistrative, operational, availability, subfunction_oper, subfunction_avail, timeout=constants.VIM_DEFAULT_TIMEOUT_IN_SECS): """ Requests VIM to add a host. """ LOG.info("vim_host_add hostname=%s, subfunctions=%s " "%s-%s-%s subfunction_oper=%s subfunction_avail=%s" % (hostname, subfunctions, admininistrative, operational, availability, subfunction_oper, subfunction_avail)) api_cmd = _get_endpoint(context) api_cmd += "/nfvi-plugins/v1/hosts/" api_cmd_headers = dict() api_cmd_headers['Content-type'] = "application/json" api_cmd_headers['User-Agent'] = "inventory/1.0" api_cmd_payload = dict() api_cmd_payload['uuid'] = uuid api_cmd_payload['hostname'] = hostname api_cmd_payload['subfunctions'] = subfunctions api_cmd_payload['administrative'] = admininistrative api_cmd_payload['operational'] = operational api_cmd_payload['availability'] = availability api_cmd_payload['subfunction_oper'] = subfunction_oper api_cmd_payload['subfunction_avail'] = subfunction_avail LOG.warn("vim_host_add api_cmd=%s headers=%s payload=%s" % (api_cmd, api_cmd_headers, api_cmd_payload)) response = rest_api_request(context, "POST", api_cmd, api_cmd_headers, json.dumps(api_cmd_payload), timeout) return response
def host_delete(token, address, port, ihost_mtce, timeout): """ Sends a Host Delete command to maintenance. """ api_cmd = "http://%s:%s" % (address, port) api_cmd += "/v1/hosts/%s" % ihost_mtce['uuid'] api_cmd_headers = dict() api_cmd_headers['Content-type'] = "application/json" api_cmd_headers['User-Agent'] = "sysinv/1.0" api_cmd_payload = None LOG.info("host_delete for %s cmd=%s hdr=%s payload=%s" % (ihost_mtce['uuid'], api_cmd, api_cmd_headers, api_cmd_payload)) response = rest_api_request(token, "DELETE", api_cmd, api_cmd_headers, json.dumps(api_cmd_payload), timeout) return response
def lock_pre_check(context, hostname, timeout=30): """ Sends a Lock Pre-Check command to SM. """ api_cmd = _get_endpoint(context) api_cmd += "/v1/servicenode/%s" % hostname api_cmd_headers = dict() api_cmd_headers['Content-type'] = "application/json" api_cmd_headers['User-Agent'] = "inventory/1.0" api_cmd_payload = dict() api_cmd_payload['origin'] = "inventory" api_cmd_payload['action'] = "lock-pre-check" api_cmd_payload['admin'] = "unknown" api_cmd_payload['oper'] = "unknown" api_cmd_payload['avail'] = "" response = rest_api_request(context, "PATCH", api_cmd, api_cmd_headers, json.dumps(api_cmd_payload), timeout) return response
def host_modify(token, address, port, ihost_mtce, timeout, max_retries=1): """ Sends a Host Modify command to maintenance. """ # api_cmd = "http://localhost:2112" api_cmd = "http://%s:%s" % (address, port) api_cmd += "/v1/hosts/%s" % ihost_mtce['uuid'] api_cmd_headers = dict() api_cmd_headers['Content-type'] = "application/json" api_cmd_headers['User-Agent'] = "sysinv/1.0" api_cmd_payload = dict() api_cmd_payload = ihost_mtce LOG.debug("host_modify for %s cmd=%s hdr=%s payload=%s" % (ihost_mtce['hostname'], api_cmd, api_cmd_headers, api_cmd_payload)) num_of_try = 0 response = None while num_of_try < max_retries and response is None: try: num_of_try = num_of_try + 1 LOG.info("number of calls to rest_api_request=%d (max_retry=%d)" % (num_of_try, max_retries)) response = rest_api_request( token, "PATCH", api_cmd, api_cmd_headers, json.dumps(api_cmd_payload), timeout) if response is None: time.sleep(3) except si_exception.SysInvSignalTimeout as e: LOG.warn("WARNING rest_api_request Timeout Error e=%s" % (e)) raise si_exception.SysInvSignalTimeout except si_exception.InventoryException as e: LOG.warn("WARNING rest_api_request Unexpected Error e=%s" % (e)) return response
def sensorgroup_relearn(token, address, port, payload, timeout): """ Sends a SensorGroup Relearn command to maintenance. """ api_cmd = "http://%s:%s" % (address, port) api_cmd += "/v1/isensorgroups/relearn" api_cmd_headers = dict() api_cmd_headers['Content-type'] = "application/json" api_cmd_headers['User-Agent'] = "sysinv/1.0" api_cmd_payload = dict() api_cmd_payload = payload LOG.info("sensorgroup_relearn for %s cmd=%s hdr=%s payload=%s" % (payload['host_uuid'], api_cmd, api_cmd_headers, api_cmd_payload)) response = rest_api_request(token, "POST", api_cmd, api_cmd_headers, json.dumps(api_cmd_payload), timeout) return response
def vim_host_action(context, uuid, hostname, action, timeout=constants.VIM_DEFAULT_TIMEOUT_IN_SECS): """ Request VIM to perform host action. """ response = None _valid_actions = [ k_host.ACTION_UNLOCK, k_host.ACTION_LOCK, k_host.ACTION_FORCE_LOCK ] if action not in _valid_actions: LOG.error("Unrecognized vim_host_action=%s" % action) return response LOG.warn("vim_host_action hostname=%s, action=%s" % (hostname, action)) api_cmd = _get_endpoint(context) api_cmd += "/nfvi-plugins/v1/hosts/%s" % uuid api_cmd_headers = dict() api_cmd_headers['Content-type'] = "application/json" api_cmd_headers['User-Agent'] = "inventory/1.0" api_cmd_payload = dict() api_cmd_payload['uuid'] = uuid api_cmd_payload['hostname'] = hostname api_cmd_payload['action'] = action LOG.warn("vim_host_action hostname=%s, action=%s api_cmd=%s " "headers=%s payload=%s" % (hostname, action, api_cmd, api_cmd_headers, api_cmd_payload)) response = rest_api_request(context, "PATCH", api_cmd, api_cmd_headers, json.dumps(api_cmd_payload), timeout) return response
def sensor_add(token, address, port, isensor_hwmon, timeout): """ Sends a Sensor Add command to maintenance. """ api_cmd = "http://%s:%s" % (address, port) api_cmd += "/v1/isensors/" api_cmd_headers = dict() api_cmd_headers['Content-type'] = "application/json" api_cmd_headers['User-Agent'] = "sysinv/1.0" api_cmd_payload = dict() api_cmd_payload = isensor_hwmon LOG.info("sensor_add for %s cmd=%s hdr=%s payload=%s" % (isensor_hwmon['sensorname'], api_cmd, api_cmd_headers, api_cmd_payload)) response = rest_api_request(token, "POST", api_cmd, api_cmd_headers, json.dumps(api_cmd_payload), timeout) return response
def vim_host_get_instances(context, uuid, hostname, timeout=constants.VIM_DEFAULT_TIMEOUT_IN_SECS): """ Returns instance counts for a given host """ response = None api_cmd = _get_endpoint(context) api_cmd += "/nfvi-plugins/v1/hosts" api_cmd_headers = dict() api_cmd_headers['Content-type'] = "application/json" api_cmd_headers['User-Agent'] = "inventory/1.0" api_cmd_payload = dict() api_cmd_payload['uuid'] = uuid api_cmd_payload['hostname'] = hostname response = rest_api_request(context, "GET", api_cmd, api_cmd_headers, json.dumps(api_cmd_payload), timeout) return response
def host_add(token, address, port, ihost_mtce, timeout): """ Sends a Host Add command to maintenance. """ # api_cmd = "http://localhost:2112" api_cmd = "http://%s:%s" % (address, port) api_cmd += "/v1/hosts/" api_cmd_headers = dict() api_cmd_headers['Content-type'] = "application/json" api_cmd_headers['User-Agent'] = "sysinv/1.0" api_cmd_payload = dict() api_cmd_payload = ihost_mtce LOG.info("host_add for %s cmd=%s hdr=%s payload=%s" % (ihost_mtce['hostname'], api_cmd, api_cmd_headers, api_cmd_payload)) response = rest_api_request(token, "POST", api_cmd, api_cmd_headers, json.dumps(api_cmd_payload), timeout) return response