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__)
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"):
vdu["cps"].append(port["cp_id"])
break
if not location_info:
- err_msg = "vdu_id(%s) for cp(%s) is not defined"
+ err_msg = "vdu_id(%s) for cp(%s) is not defined."
raise VimException(err_msg % (port_ref_vdu_id, port["cp_id"]), ERR_CODE)
network_id = ignore_case_get(port, "networkId")
subnet_id = ignore_case_get(port, "subnetId")
set_opt_val(param, "macAddress", ignore_case_get(port["properties"], "mac_address"))
ip_address = []
for one_protocol_data in port["properties"]["protocol_data"]:
- l3_address_data = one_protocol_data["address_data"]["l3_address_data"]
+ l3_address_data = one_protocol_data["address_data"]["l3_address_data"] # l3 is not 13
fixed_ip_address = ignore_case_get(l3_address_data, "fixed_ip_address")
ip_address.extend(fixed_ip_address)
set_opt_val(param, "ip", ",".join(ip_address))
vdu_memory_requirements = ignore_case_get(virtual_memory, "vdu_memory_requirements")
if "memoryPageSize" in vdu_memory_requirements:
memory_page_size = int(vdu_memory_requirements["memoryPageSize"].replace('MB', '').strip())
- flavor_extra_specs = ("hw:mem_page_size=%sMB" % memory_page_size)
+ flavor_extra_specs = {"hw": memory_page_size, } # TODO
logger.debug("flavor_extra_specs:%s" % flavor_extra_specs)
# FIXME: search aai flavor