Skip to content

Commit

Permalink
New feature: VNF templates and appliances integration
Browse files Browse the repository at this point in the history
This feature introduce a new type of template in CloudStack: "VNF"

It supports the life cycle of VNF templates:
- register
- update
- list
- delete

It also supports the management of VNF templates and deployment of VNF appliances (from VNF templates) on GUI

Design:
https://cwiki.apache.org/confluence/display/CLOUDSTACK/VNF+Appliance+Integration
  • Loading branch information
weizhouapache committed Sep 29, 2023
1 parent a256604 commit 97bd2f3
Show file tree
Hide file tree
Showing 62 changed files with 6,536 additions and 55 deletions.
106 changes: 106 additions & 0 deletions api/src/main/java/com/cloud/network/VNF.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network;

import org.apache.commons.lang3.StringUtils;

public interface VNF {

enum AccessMethod {
SSH_WITH_PASSWORD("ssh-password"),
SSH_WITH_KEY("ssh-key"),
HTTP("http"),
HTTPS("https"),
CONSOLE("console");

String _method;

AccessMethod(String method) {
_method = method;
}

@Override
public String toString() {
return _method;
}

public static AccessMethod fromValue(String method) {
if (StringUtils.isBlank(method)) {
return null;
} else {
for (AccessMethod accessMethod : AccessMethod.values()) {
if (accessMethod.toString().equalsIgnoreCase(method)) {
return accessMethod;
}
}
}
return null;
}
}

enum AccessDetail {
ACCESS_METHODS,
USERNAME,
PASSWORD,
SSH_USER,
SSH_PASSWORD,
SSH_PORT,
WEB_USER,
WEB_PASSWORD,
HTTP_PATH,
HTTP_PORT,
HTTPS_PATH,
HTTPS_PORT
}

enum VnfDetail {
ICON,
VERSION,
VENDOR,
MAINTAINER
}

class VnfNic {
int deviceId;
String name;
boolean required;
String description;

public VnfNic(int deviceId, String nicName, boolean required, String nicDescription) {
this.deviceId = deviceId;
this.name = nicName;
this.required = required;
this.description = nicDescription;
}

public int getDeviceId() {
return deviceId;
}

public String getName() {
return name;
}

public boolean isRequired() {
return required;
}

public String getDescription() {
return description;
}
}
}
1 change: 1 addition & 0 deletions api/src/main/java/com/cloud/server/ResourceTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public interface ResourceTag extends ControlledEntity, Identity, InternalIdentit
public enum ResourceObjectType {
UserVm(true, true, true),
Template(true, true, true),
VnfTemplate(true, true, true),
ISO(true, false, true),
Volume(true, true),
Snapshot(true, false),
Expand Down
1 change: 1 addition & 0 deletions api/src/main/java/com/cloud/storage/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public static enum TemplateType {
BUILTIN, /* buildin template */
PERHOST, /* every host has this template, don't need to install it in secondary storage */
USER, /* User supplied template/iso */
VNF, /* VNFs (virtual network functions) template */
DATADISK, /* Template corresponding to a datadisk(non root disk) present in an OVA */
ISODISK /* Template corresponding to a iso (non root disk) present in an OVA */
}
Expand Down
9 changes: 7 additions & 2 deletions api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ public class ApiConstants {
public static final String TEMPLATE_ID = "templateid";
public static final String TEMPLATE_IDS = "templateids";
public static final String TEMPLATE_NAME = "templatename";
public static final String TEMPLATE_TYPE = "templatetype";
public static final String TIMEOUT = "timeout";
public static final String TIMEZONE = "timezone";
public static final String TIMEZONEOFFSET = "timezoneoffset";
Expand Down Expand Up @@ -1008,7 +1009,6 @@ public class ApiConstants {
public static final String DEPLOY_AS_IS = "deployasis";
public static final String DEPLOY_AS_IS_DETAILS = "deployasisdetails";
public static final String CROSS_ZONES = "crossZones";
public static final String TEMPLATETYPE = "templatetype";
public static final String SOURCETEMPLATEID = "sourcetemplateid";
public static final String DYNAMIC_SCALING_ENABLED = "dynamicscalingenabled";
public static final String IOTHREADS_ENABLED = "iothreadsenabled";
Expand Down Expand Up @@ -1042,6 +1042,11 @@ public class ApiConstants {
public static final String SOURCE_NAT_IP_ID = "sourcenatipaddressid";
public static final String HAS_RULES = "hasrules";

public static final String IS_VNF = "isvnf";
public static final String VNF_NICS = "vnfnics";
public static final String VNF_DETAILS = "vnfdetails";
public static final String CLEAN_UP_VNF_DETAILS = "cleanupvnfdetails";

/**
* This enum specifies IO Drivers, each option controls specific policies on I/O.
* Qemu guests support "threads" and "native" options Since 0.8.8 ; "io_uring" is supported Since 6.3.0 (QEMU 5.0).
Expand Down Expand Up @@ -1087,7 +1092,7 @@ public enum HostDetails {
}

public enum VMDetails {
all, group, nics, stats, secgrp, tmpl, servoff, diskoff, backoff, iso, volume, min, affgrp;
all, group, nics, stats, secgrp, tmpl, servoff, diskoff, backoff, iso, volume, min, affgrp, vnfnics;
}

public enum DomainDetails {
Expand Down
3 changes: 3 additions & 0 deletions api/src/main/java/org/apache/cloudstack/api/BaseCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.apache.cloudstack.network.lb.InternalLoadBalancerVMService;
import org.apache.cloudstack.query.QueryService;
import org.apache.cloudstack.storage.ImageStoreService;
import org.apache.cloudstack.storage.template.VnfTemplateManager;
import org.apache.cloudstack.usage.UsageService;
import org.apache.commons.collections.MapUtils;
import org.apache.log4j.Logger;
Expand Down Expand Up @@ -213,6 +214,8 @@ public static enum CommandType {
public ResourceIconManager resourceIconManager;
@Inject
public Ipv6Service ipv6Service;
@Inject
public VnfTemplateManager vnfTemplateManager;

public abstract void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException,
ResourceAllocationException, NetworkRuleConflictException;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.api.command.admin.template;

import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ResponseObject.ResponseView;
import org.apache.cloudstack.api.command.admin.AdminCmd;
import org.apache.cloudstack.api.command.user.template.ListVnfTemplatesCmd;
import org.apache.cloudstack.api.response.TemplateResponse;

import com.cloud.template.VirtualMachineTemplate;

@APICommand(name = "listVnfTemplates", description = "List all public, private, and privileged VNF templates.",
responseObject = TemplateResponse.class, entityType = {VirtualMachineTemplate.class}, responseView = ResponseView.Full,
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
public class ListVnfTemplatesCmdByAdmin extends ListVnfTemplatesCmd implements AdminCmd {
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@

import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ResponseObject.ResponseView;
import org.apache.cloudstack.api.command.admin.AdminCmd;
import org.apache.cloudstack.api.command.user.template.RegisterTemplateCmd;
import org.apache.cloudstack.api.response.TemplateResponse;

@APICommand(name = "registerTemplate", description = "Registers an existing template into the CloudStack cloud.", responseObject = TemplateResponse.class, responseView = ResponseView.Full,
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
public class RegisterTemplateCmdByAdmin extends RegisterTemplateCmd {}
public class RegisterTemplateCmdByAdmin extends RegisterTemplateCmd implements AdminCmd {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.api.command.admin.template;

import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ResponseObject.ResponseView;
import org.apache.cloudstack.api.command.admin.AdminCmd;
import org.apache.cloudstack.api.command.user.template.RegisterVnfTemplateCmd;
import org.apache.cloudstack.api.response.TemplateResponse;

@APICommand(name = "registerVnfTemplate",
description = "Registers an existing VNF template into the CloudStack cloud. ",
responseObject = TemplateResponse.class, responseView = ResponseView.Full,
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
public class RegisterVnfTemplateCmdByAdmin extends RegisterVnfTemplateCmd implements AdminCmd {
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@

@APICommand(name = "updateTemplate", description = "Updates attributes of a template.", responseObject = TemplateResponse.class, responseView = ResponseView.Full,
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
public class UpdateTemplateCmdByAdmin extends UpdateTemplateCmd implements AdminCmd {}
public class UpdateTemplateCmdByAdmin extends UpdateTemplateCmd implements AdminCmd {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.api.command.admin.template;

import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ResponseObject.ResponseView;
import org.apache.cloudstack.api.command.admin.AdminCmd;
import org.apache.cloudstack.api.command.user.template.UpdateVnfTemplateCmd;
import org.apache.cloudstack.api.response.TemplateResponse;

@APICommand(name = "updateVnfTemplate",
description = "Updates a template to VNF template or attributes of a VNF template.",
responseObject = TemplateResponse.class, responseView = ResponseView.Full,
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
public class UpdateVnfTemplateCmdByAdmin extends UpdateVnfTemplateCmd implements AdminCmd {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.api.command.admin.vm;

import com.cloud.vm.VirtualMachine;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ResponseObject;
import org.apache.cloudstack.api.response.UserVmResponse;

@APICommand(name = "deployVnfAppliance",
description = "Creates and automatically starts a VNF appliance based on a service offering, disk offering, and template.",
responseObject = UserVmResponse.class,
responseView = ResponseObject.ResponseView.Full,
entityType = {VirtualMachine.class},
requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
public class DeployVnfApplianceCmdByAdmin extends DeployVMCmdByAdmin {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.api.command.user.template;

import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.response.SuccessResponse;

import com.cloud.template.VirtualMachineTemplate;
import com.cloud.user.Account;

@APICommand(name = "deleteVnfTemplate",
responseObject = SuccessResponse.class,
description = "Deletes a VNF template from the system. All virtual machines using the deleted template will not be affected.",
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User})
public class DeleteVnfTemplateCmd extends DeleteTemplateCmd {

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////

@Override
public long getEntityOwnerId() {
VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, getId());
if (template != null) {
return template.getAccountId();
}

return Account.ACCOUNT_ID_SYSTEM;
}
}
Loading

0 comments on commit 97bd2f3

Please sign in to comment.