예제 #1
0
파일: vim_api.py 프로젝트: rudwo5924/config
def vim_host_upgrade_state(token, uuid, hostname, upgrade_inprogress, timeout):
    """
    Inform VIM if we are in an upgrade
    """

    response = None

    api_cmd = None
    if token:
        api_cmd = token.get_service_url("nfvi", "nfv")

    if not api_cmd:
        api_cmd = "http://localhost:30001"

    api_cmd += "/nfvi-plugins/v1/hosts"

    api_cmd_headers = dict()
    api_cmd_headers['Content-type'] = "application/json"
    api_cmd_headers['User-Agent'] = "sysinv/1.0"

    upgrade = dict()

    upgrade_inprogress = bool(upgrade_inprogress)
    upgrade['inprogress'] = upgrade_inprogress
    upgrade['recover-instances'] = not upgrade_inprogress

    api_cmd_payload = dict()
    api_cmd_payload['uuid'] = uuid
    api_cmd_payload['hostname'] = hostname
    api_cmd_payload['upgrade'] = upgrade

    response = rest_api_request(token, "PATCH", api_cmd, api_cmd_headers,
                                json.dumps(api_cmd_payload), timeout)
    return response
예제 #2
0
파일: vim_api.py 프로젝트: rudwo5924/config
def vim_host_delete(token, uuid, hostname, timeout):
    """
    Asks VIM to delete a host
    """

    api_cmd = None
    if token:
        api_cmd = token.get_service_url("nfvi", "nfv")

    if not api_cmd:
        api_cmd = "http://localhost:30001"

    api_cmd += "/nfvi-plugins/v1/hosts/%s" % 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['uuid'] = uuid
    api_cmd_payload['hostname'] = hostname
    api_cmd_payload['action'] = 'delete'

    response = rest_api_request(token,
                                "DELETE",
                                api_cmd,
                                api_cmd_headers,
                                json.dumps(api_cmd_payload),
                                timeout=timeout)
    return response
예제 #3
0
파일: vim_api.py 프로젝트: rudwo5924/config
def vim_host_update(token, uuid, hostname, timeout):
    """
    Inform VIM of host change
    """

    api_cmd = None
    if token:
        api_cmd = token.get_service_url("nfvi", "nfv")

    if not api_cmd:
        api_cmd = "http://localhost:30001"

    api_cmd += "/nfvi-plugins/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['uuid'] = uuid
    api_cmd_payload['hostname'] = hostname

    response = rest_api_request(token, "PATCH", api_cmd, api_cmd_headers,
                                json.dumps(api_cmd_payload), timeout)

    LOG.debug("vim_host_update api_cmd=%s headers=%s payload=%s" %
              (api_cmd, api_cmd_headers, api_cmd_payload))

    return response
예제 #4
0
파일: vim_api.py 프로젝트: rudwo5924/config
def vim_host_get_instances(token, uuid, hostname, timeout):
    """
    Returns instance counts for a given host
    """

    response = None

    api_cmd = None
    if token:
        api_cmd = token.get_service_url("nfvi", "nfv")

    if not api_cmd:
        api_cmd = "http://localhost:30001"

    api_cmd += "/nfvi-plugins/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['uuid'] = uuid
    api_cmd_payload['hostname'] = hostname

    response = rest_api_request(token, "GET", api_cmd, api_cmd_headers,
                                json.dumps(api_cmd_payload), timeout)
    return response
예제 #5
0
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
예제 #6
0
파일: vim_api.py 프로젝트: rudwo5924/config
def vim_get_host_services_state(token, hostname, timeout):
    """
    Asks VIM for host services state for a host.
    """
    api_cmd = None
    if token:
        api_cmd = token.get_service_url("nfvi", "nfv")

    if not api_cmd:
        api_cmd = "http://localhost:30001"

    api_cmd += "nfvi-plugins/v1/hosts/" + hostname + "/servicestate"

    response = rest_api_request(token, "GET", api_cmd, timeout)
    return response
예제 #7
0
def service_show(hostname):
    """
    Sends a service show command to SM.
    """
    token = _get_token()
    api_cmd = SM_API_PATH
    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'] = "sysinv/1.0"

    response = rest_api_request(token, "GET", api_cmd, api_cmd_headers, None)
    return response
예제 #8
0
def patch_drop_host(token, timeout, hostname, region_name):
    """
    Notify the patch service to drop the specified host
    """
    api_cmd = None

    if not token:
        token = get_token(region_name)

    if token:
        api_cmd = token.get_service_url("patching", "patching")

    api_cmd += "/v1/drop_host/%s" % hostname

    response = rest_api_request(token, "POST", api_cmd, timeout=timeout)
    return response
예제 #9
0
def patch_query_hosts(token, timeout, region_name):
    """
    Request the patch state for all hosts known to the patch service
    """
    api_cmd = None

    if not token:
        token = get_token(region_name)

    if token:
        api_cmd = token.get_service_url("patching", "patching")

    api_cmd += "/v1/query_hosts/"

    response = rest_api_request(token, "GET", api_cmd, timeout=timeout)
    return response
예제 #10
0
def patch_is_applied(token, timeout, region_name, patches):
    """
    Query the applied state for a list of patches
    """
    api_cmd = None

    if not token:
        token = get_token(region_name)
    if token:
        api_cmd = token.get_service_url("patching", "patching")

    patch_dependencies = ""
    for patch in patches:
        patch_dependencies += "/%s" % patch

    api_cmd += "/v1/is_applied%s" % patch_dependencies

    response = rest_api_request(token, "GET", api_cmd, timeout=timeout)
    return response
예제 #11
0
def patch_report_app_dependencies(token, timeout, region_name, patches, app_name):
    """
    Report the application patch dependencies
    """
    api_cmd = None

    if not token:
        token = get_token(region_name)
    if token:
        api_cmd = token.get_service_url("patching", "patching")

    patch_dependencies = ""
    for patch in patches:
        patch_dependencies += "/%s" % patch

    api_cmd += "/v1/report_app_dependencies%s?app=%s" % (patch_dependencies, app_name)

    response = rest_api_request(token, "POST", api_cmd, timeout=timeout)
    return response
예제 #12
0
파일: vim_api.py 프로젝트: rudwo5924/config
def vim_host_action(token, uuid, hostname, action, timeout):
    """
    Request VIM to perform host action.
    """

    response = None
    _valid_actions = [
        constants.UNLOCK_ACTION, constants.LOCK_ACTION,
        constants.FORCE_LOCK_ACTION
    ]

    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 = None
    if token:
        api_cmd = token.get_service_url("nfvi", "nfv")

    if not api_cmd:
        api_cmd = "http://localhost:30001"

    api_cmd += "/nfvi-plugins/v1/hosts/%s" % 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['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(token, "PATCH", api_cmd, api_cmd_headers,
                                json.dumps(api_cmd_payload), timeout)
    return response
예제 #13
0
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
예제 #14
0
def sm_servicegroup_list():
    """
    Sends a service list command to SM.
    """
    token = _get_token()
    api_cmd = SM_API_PATH
    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'] = "sysinv/1.0"

    response = rest_api_request(token, "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
예제 #15
0
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)  # delays for 3 seconds
        except si_exception.SysInvSignalTimeout as e:
            # Note: Even there is a timeout but neither of these "except" got it.
            LOG.warn("WARNING rest_api_request Timeout Error e=%s" % (e))
            raise si_exception.SysInvSignalTimeout
        except si_exception.SysinvException as e:
            LOG.warn("WARNING rest_api_request Unexpected Error e=%s" % (e))

    return response
예제 #16
0
파일: vim_api.py 프로젝트: rudwo5924/config
def vim_host_add(token, uuid, hostname, subfunctions, admininistrative,
                 operational, availability, subfunction_oper,
                 subfunction_avail, timeout):
    """
    Requests VIM to add a host.
    """
    LOG.warn("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 = None
    if token:
        api_cmd = token.get_service_url("nfvi", "nfv")

    if not api_cmd:
        api_cmd = "http://localhost:30001"

    api_cmd += "/nfvi-plugins/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['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(token, "POST", api_cmd, api_cmd_headers,
                                json.dumps(api_cmd_payload), timeout)
    return response
예제 #17
0
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
예제 #18
0
def lock_pre_check(hostname, timeout):
    """
        Sends a Lock Pre-Check command to SM.
        """
    token = _get_token()
    api_cmd = SM_API_PATH
    api_cmd += "/v1/servicenode/%s" % hostname

    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['origin'] = "sysinv"
    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(token, "PATCH", api_cmd, api_cmd_headers,
                                json.dumps(api_cmd_payload), timeout)

    return response
예제 #19
0
파일: vim_api.py 프로젝트: rudwo5924/config
def vim_get_sw_update_strategy(token, timeout):
    """
    Returns software update type and strategy progress
    """

    api_cmd = None
    if token:
        api_cmd = token.get_service_url("nfvi", "nfv")

    if not api_cmd:
        api_cmd = "http://localhost:30001"

    api_cmd += "/nfvi-plugins/v1/sw-update"
    api_cmd_headers = dict()
    api_cmd_headers['Content-type'] = "application/json"
    api_cmd_headers['User-Agent'] = "sysinv/1.0"

    response = rest_api_request(token,
                                "GET",
                                api_cmd,
                                api_cmd_headers,
                                timeout=timeout)
    return response
예제 #20
0
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
예제 #21
0
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