X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=lcm%2Flcm%2Fpub%2Fvimapi%2Fadaptor.py;h=8ebddab0ef92ae0e222a311c044818ff0d6498b7;hb=0b8b410f563039cfc8879631bcb2587974de7875;hp=9ca3e8deee7dac05977e9f22b949dbf869e24b04;hpb=8f75d6276d4f1a8c5e9da1c77f2def362db11596;p=vfc%2Fgvnfm%2Fvnflcm.git diff --git a/lcm/lcm/pub/vimapi/adaptor.py b/lcm/lcm/pub/vimapi/adaptor.py index 9ca3e8de..8ebddab0 100644 --- a/lcm/lcm/pub/vimapi/adaptor.py +++ b/lcm/lcm/pub/vimapi/adaptor.py @@ -20,6 +20,7 @@ from lcm.pub.utils.values import ignore_case_get, set_opt_val from lcm.pub.msapi.aai import get_flavor_info from . import api from .exceptions import VimException +from lcm.nf.const import ACTION_TYPE logger = logging.getLogger(__name__) @@ -65,6 +66,50 @@ def get_res_id(res_cache, res_type, key): return res_cache[res_type][key] +def action_vm(action_type, server, vimId, tenantId): + param = {} + if action_type == ACTION_TYPE.START: + param = { + "os-start": None, + } + elif action_type == ACTION_TYPE.STOP: + param = { + "os-stop": None, + } + elif action_type == ACTION_TYPE.REBOOT: + param = { + "reboot": {} + } + if server["status"] == "ACTIVE": + param["reboot"]["type"] = "SOFT" + else: + param["reboot"]["type"] = "HARD" + res_id = server["id"] + api.action_vm(vimId, tenantId, res_id, param) + + +# TODO Have to check if the resources should be started and stopped in some order. +def operate_vim_res(data, changeStateTo, stopType, gracefulStopTimeout, do_notify_op): + for res in ignore_case_get(data, "vm"): + try: + if changeStateTo == "STARTED": + action_vm(ACTION_TYPE.START, res, res["vim_id"], res["tenant_id"]) + do_notify_op("ACTIVE", res["id"]) + elif changeStateTo == "STOPPED": + if stopType == "GRACEFUL": + if gracefulStopTimeout > 60: + gracefulStopTimeout = 60 + time.sleep(gracefulStopTimeout) + action_vm(ACTION_TYPE.STOP, res, res["vim_id"], res["tenant_id"]) + # TODO check if the we should poll getvm to get the status or the action_vm api + # successful return should suffice to mark vm as Active/Inactive + do_notify_op("INACTIVE", res["id"]) + except VimException as e: + # TODO Have to update database appropriately on failure + logger.error("Failed to Heal %s(%s)", RES_VM, res["res_id"]) + logger.error("%s:%s", e.http_code, e.message) + + def create_vim_res(data, do_notify): vim_cache, res_cache = {}, {} for vol in ignore_case_get(data, "volume_storages"):