def create_ahv_nic( subnet=None, network_function_nic_type="INGRESS", nic_type="NORMAL_NIC", network_function_chain=None, # TODO Deal with it mac_address="", ip_endpoints=[], ): kwargs = {} if subnet: subnet_uuid = Cache.get_entity_uuid("AHV_SUBNET", subnet) if not subnet_uuid: raise Exception( "AHV Subnet {} not found. Please run: calm update cache". format(subnet)) kwargs["subnet_reference"] = {"name": subnet, "uuid": subnet_uuid} if network_function_chain: nfc_uuid = Cache.get_entity_uuid("AHV_NETWORK_FUNCTION_CHAIN", network_function_chain) if not nfc_uuid: raise Exception( "AHV Network Function Chain {} not found. Please run: calm update cache" .format(network_function_chain)) kwargs["network_function_chain_reference"] = { "name": network_function_chain, "uuid": nfc_uuid, "kind": "network_function_chain", } for ip in ip_endpoints: if not kwargs.get("ip_endpoint_list"): kwargs["ip_endpoint_list"] = [] # Note the IP type is set to be ASSIGNED always kwargs["ip_endpoint_list"].append({"ip": ip, "type": "ASSIGNED"}) kwargs.update({ "network_function_nic_type": network_function_nic_type, "nic_type": nic_type, "mac_address": mac_address, }) return ahv_vm_nic(**kwargs)
def render_ahv_template(template, bp_name): # Getting the subnet registered to the project client = get_api_client() config = get_config() project_name = config["PROJECT"].get("name", "default") project_uuid = Cache.get_entity_uuid("PROJECT", project_name) LOG.info("Fetching ahv subnets attached to the project {}".format(project_name)) res, err = client.project.read(project_uuid) if err: raise Exception("[{}] - {}".format(err["code"], err["error"])) LOG.info("Success") res = res.json() subnets = res["status"]["project_status"]["resources"].get( "subnet_reference_list", [] ) if not subnets: raise Exception("no subnets registered !!!") default_subnet = subnets[0]["name"] LOG.info("Rendering ahv template") text = template.render(bp_name=bp_name, subnet_name=default_subnet) LOG.info("Success") return text.strip() + os.linesep
def clone_from_image_service(device_type="DISK", adapter_type="SCSI", image_name="", bootable=False): if not image_name: raise ValueError("image_name not provided !!!") image_uuid = Cache.get_entity_uuid("AHV_DISK_IMAGE", image_name) if not image_uuid: raise Exception( "Ahv Disk Image {} not found. Please run: calm update cache". format(image_name)) image_data = {"kind": "image", "name": image_name, "uuid": image_uuid} return update_disk_config(device_type, adapter_type, image_data, bootable)
def compile_blueprint_command(bp_file, out, no_sync=False): bp_payload = compile_blueprint(bp_file, no_sync) if bp_payload is None: click.echo("User blueprint not found in {}".format(bp_file)) return config = get_config() project_name = config["PROJECT"].get("name", "default") project_uuid = Cache.get_entity_uuid("PROJECT", project_name) if not project_uuid: raise Exception( "Project {} not found. Please run: calm update cache".format( project_name)) bp_payload["metadata"]["project_reference"] = { "type": "project", "uuid": project_uuid, "name": project_name, } credential_list = bp_payload["spec"]["resources"][ "credential_definition_list"] is_secret_avl = False for cred in credential_list: if cred["secret"].get("secret", None): cred["secret"].pop("secret") is_secret_avl = True # At compile time, value will be empty cred["secret"]["value"] = "" if is_secret_avl: click.echo( highlight_text("Warning: Secrets are not shown in payload !!!")) if out == "json": click.echo(json.dumps(bp_payload, indent=4, separators=(",", ": "))) elif out == "yaml": click.echo(yaml.dump(bp_payload, default_flow_style=False)) else: click.echo("Unknown output format {} given".format(out))
def init_bp(service_name, dir_name, provider_type): bp_name = "{}Blueprint".format(service_name, ) bp_dir, local_dir, key_dir, script_dir = make_bp_dirs(dir_name, bp_name) # sync cache Cache.sync() # Getting the subnet registered to the project client = get_api_client() config = get_config() project_name = config["PROJECT"].get("name", "default") project_uuid = Cache.get_entity_uuid("PROJECT", project_name) res, err = client.project.read(project_uuid) if err: raise Exception("[{}] - {}".format(err["code"], err["error"])) res = res.json() subnets = res["status"]["project_status"]["resources"].get( "subnet_reference_list", []) if not subnets: raise Exception("no subnets registered !!!") default_subnet = subnets[0]["name"] create_bp_file(bp_dir, service_name, default_subnet, provider_type) # Creating keys create_cred_keys(key_dir) # create scripts create_scripts(script_dir)