Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion api/src/com/cloud/network/Network.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static class Service {
private static List<Service> supportedServices = new ArrayList<Service>();

public static final Service Vpn = new Service("Vpn", Capability.SupportedVpnProtocols, Capability.VpnTypes);
public static final Service Dhcp = new Service("Dhcp");
public static final Service Dhcp = new Service("Dhcp", Capability.ExtraDhcpOptions);
public static final Service Dns = new Service("Dns", Capability.AllowDnsSuffixModification);
public static final Service Gateway = new Service("Gateway");
public static final Service Firewall = new Service("Firewall", Capability.SupportedProtocols, Capability.MultipleIps, Capability.TrafficStatistics,
Expand Down Expand Up @@ -218,6 +218,7 @@ public static class Capability {
public static final Capability RegionLevelVpc = new Capability("RegionLevelVpc");
public static final Capability NoVlan = new Capability("NoVlan");
public static final Capability PublicAccess = new Capability("PublicAccess");
public static final Capability ExtraDhcpOptions = new Capability("ExtraDhcpOptions");

private final String name;

Expand Down
4 changes: 4 additions & 0 deletions api/src/com/cloud/network/element/DhcpServiceProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
// under the License.
package com.cloud.network.element;

import java.util.Map;

import com.cloud.deploy.DeployDestination;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
Expand All @@ -33,4 +35,6 @@ boolean configDhcpSupportForSubnet(Network network, NicProfile nic, VirtualMachi
throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException;

boolean removeDhcpSupportForSubnet(Network network) throws ResourceUnavailableException;

boolean setExtraDhcpOptions(Network network, long nicId, Map<Integer, String> dhcpOptions);
}
41 changes: 41 additions & 0 deletions api/src/com/cloud/vm/NicExtraDhcpOption.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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.vm;

import org.apache.cloudstack.api.Identity;
import org.apache.cloudstack.api.InternalIdentity;

public interface NicExtraDhcpOption extends InternalIdentity, Identity {

/**
* Returns the nic id for which the DHCP option applies
* @return nic id
*/
long getNicId();

/**
* Returns the DHCP option code
* @return
*/
int getCode();

/**
* Returns the Dhcp value
* @return
*/
String getValue();
}
12 changes: 9 additions & 3 deletions api/src/com/cloud/vm/UserVmService.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ UserVm startVirtualMachine(StartVMCmd cmd) throws StorageUnavailableException, E
* @param memory
* @param cpuNumber
* @param customId
* @param dhcpOptionMap
* - Maps the dhcp option code and the dhcp value to the network uuid
* @return UserVm object if successful.
*
* @throws InsufficientCapacityException
Expand All @@ -208,7 +210,7 @@ UserVm startVirtualMachine(StartVMCmd cmd) throws StorageUnavailableException, E
UserVm createBasicSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> securityGroupIdList,
Account owner, String hostName, String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, HTTPMethod httpmethod,
String userData, String sshKeyPair, Map<Long, IpAddresses> requestedIps, IpAddresses defaultIp, Boolean displayVm, String keyboard,
List<Long> affinityGroupIdList, Map<String, String> customParameter, String customId) throws InsufficientCapacityException,
List<Long> affinityGroupIdList, Map<String, String> customParameter, String customId, Map<String, Map<Integer, String>> dhcpOptionMap) throws InsufficientCapacityException,
ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException;

/**
Expand Down Expand Up @@ -267,6 +269,8 @@ UserVm createBasicSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering s
* @param memory
* @param cpuNumber
* @param customId
* @param dhcpOptionMap
* - Maps the dhcp option code and the dhcp value to the network uuid
* @return UserVm object if successful.
*
* @throws InsufficientCapacityException
Expand All @@ -281,7 +285,7 @@ UserVm createBasicSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering s
UserVm createAdvancedSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> networkIdList,
List<Long> securityGroupIdList, Account owner, String hostName, String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor,
HTTPMethod httpmethod, String userData, String sshKeyPair, Map<Long, IpAddresses> requestedIps, IpAddresses defaultIps, Boolean displayVm, String keyboard,
List<Long> affinityGroupIdList, Map<String, String> customParameters, String customId) throws InsufficientCapacityException,
List<Long> affinityGroupIdList, Map<String, String> customParameters, String customId, Map<String, Map<Integer, String>> dhcpOptionMap) throws InsufficientCapacityException,
ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException;

/**
Expand Down Expand Up @@ -338,6 +342,8 @@ UserVm createAdvancedSecurityGroupVirtualMachine(DataCenter zone, ServiceOfferin
* @param memory
* @param cpuNumber
* @param customId
* @param dhcpOptionMap
* - Map that maps the DhcpOption code and their value on the Network uuid
* @return UserVm object if successful.
*
* @throws InsufficientCapacityException
Expand All @@ -352,7 +358,7 @@ UserVm createAdvancedSecurityGroupVirtualMachine(DataCenter zone, ServiceOfferin
UserVm createAdvancedVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> networkIdList, Account owner,
String hostName, String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, HTTPMethod httpmethod, String userData,
String sshKeyPair, Map<Long, IpAddresses> requestedIps, IpAddresses defaultIps, Boolean displayVm, String keyboard, List<Long> affinityGroupIdList,
Map<String, String> customParameters, String customId)
Map<String, String> customParameters, String customId, Map<String, Map<Integer, String>> dhcpOptionMap)

throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException;

Expand Down
13 changes: 13 additions & 0 deletions api/src/org/apache/cloudstack/api/ApiConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ public class ApiConstants {
public static final String UTILIZATION = "utilization";
public static final String DRIVER = "driver";
public static final String ROOT_DISK_SIZE = "rootdisksize";
public static final String DHCP_OPTIONS_NETWORK_LIST = "dhcpoptionsnetworklist";
public static final String DHCP_OPTIONS = "dhcpoptions";
public static final String DHCP_PREFIX = "dhcp:";
public static final String DISPLAY_NAME = "displayname";
public static final String DISPLAY_NETWORK = "displaynetwork";
public static final String DISPLAY_NIC = "displaynic";
Expand All @@ -111,6 +114,10 @@ public class ApiConstants {
public static final String END_PORT = "endport";
public static final String ENTRY_TIME = "entrytime";
public static final String EXPIRES = "expires";
public static final String EXTRA_DHCP_OPTION = "extradhcpoption";
public static final String EXTRA_DHCP_OPTION_NAME = "extradhcpoptionname";
public static final String EXTRA_DHCP_OPTION_CODE = "extradhcpoptioncode";
public static final String EXTRA_DHCP_OPTION_VALUE = "extradhcpvalue";
public static final String FENCE = "fence";
public static final String FETCH_LATEST = "fetchlatest";
public static final String FIRSTNAME = "firstname";
Expand Down Expand Up @@ -242,6 +249,7 @@ public class ApiConstants {
public static final String SCHEDULE = "schedule";
public static final String SCOPE = "scope";
public static final String SECRET_KEY = "usersecretkey";
public static final String SECONDARY_IP = "secondaryip";
public static final String SINCE = "since";
public static final String KEY = "key";
public static final String SEARCH_BASE = "searchbase";
Expand Down Expand Up @@ -309,6 +317,7 @@ public class ApiConstants {
public static final String REMOVE_VLAN = "removevlan";
public static final String VLAN_ID = "vlanid";
public static final String ISOLATED_PVLAN = "isolatedpvlan";
public static final String ISOLATION_URI = "isolationuri";
public static final String VM_AVAILABLE = "vmavailable";
public static final String VM_LIMIT = "vmlimit";
public static final String VM_TOTAL = "vmtotal";
Expand Down Expand Up @@ -410,6 +419,7 @@ public class ApiConstants {
public static final String CAPACITY_IOPS = "capacityiops";
public static final String NETWORK_SPEED = "networkspeed";
public static final String BROADCAST_DOMAIN_RANGE = "broadcastdomainrange";
public static final String BROADCAST_URI = "broadcasturi";
public static final String ISOLATION_METHOD = "isolationmethod";
public static final String ISOLATION_METHODS = "isolationmethods";
public static final String PHYSICAL_NETWORK_ID = "physicalnetworkid";
Expand Down Expand Up @@ -536,6 +546,8 @@ public class ApiConstants {
public static final String NICIRA_NVP_DEVICE_NAME = "niciradevicename";
public static final String NICIRA_NVP_GATEWAYSERVICE_UUID = "l3gatewayserviceuuid";
public static final String NICIRA_NVP_L2_GATEWAYSERVICE_UUID = "l2gatewayserviceuuid";
public static final String NSX_LOGICAL_SWITCH = "nsxlogicalswitch";
public static final String NSX_LOGICAL_SWITCH_PORT = "nsxlogicalswitchport";
public static final String S3_ACCESS_KEY = "accesskey";
public static final String S3_SECRET_KEY = "secretkey";
public static final String S3_END_POINT = "endpoint";
Expand Down Expand Up @@ -665,6 +677,7 @@ public class ApiConstants {
public static final String SUPPORTS_PUBLIC_ACCESS = "supportspublicaccess";
public static final String REGION_LEVEL_VPC = "regionlevelvpc";
public static final String STRECHED_L2_SUBNET = "strechedl2subnet";
public static final String NETWORK_NAME = "networkname";
public static final String NETWORK_SPANNED_ZONES = "zonesnetworkspans";
public static final String METADATA = "metadata";
public static final String PHYSICAL_SIZE = "physicalsize";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
package org.apache.cloudstack.api.command.user.vm;

import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;

Expand All @@ -39,6 +42,7 @@
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.user.Account;
import com.cloud.uservm.UserVm;
import com.cloud.utils.net.Dhcp;
import com.cloud.utils.net.NetUtils;
import com.cloud.vm.VirtualMachine;

Expand All @@ -65,6 +69,10 @@ public class AddNicToVMCmd extends BaseAsyncCmd {
@Parameter(name = ApiConstants.MAC_ADDRESS, type = CommandType.STRING, description = "Mac Address for the new network")
private String macaddr;

@Parameter(name = ApiConstants.DHCP_OPTIONS, type = CommandType.MAP, description = "DHCP options which are passed to the nic"
+ " Example: dhcpoptions[0].dhcp:114=url&dhcpoptions[0].dhcp:66=www.test.com")
private Map dhcpOptions;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand Down Expand Up @@ -125,6 +133,28 @@ public long getEntityOwnerId() {
return vm.getAccountId();
}

public Map<Integer, String> getDhcpOptionsMap() {
Map<Integer, String> dhcpOptionsMap = new HashMap<>();
if (dhcpOptions != null && !dhcpOptions.isEmpty()) {

Collection<Map<String, String>> paramsCollection = this.dhcpOptions.values();
for(Map<String, String> dhcpNetworkOptions : paramsCollection) {
for (String key : dhcpNetworkOptions.keySet()) {
if (key.startsWith(ApiConstants.DHCP_PREFIX)) {
int dhcpOptionValue = Integer.parseInt(key.replaceFirst(ApiConstants.DHCP_PREFIX, ""));
dhcpOptionsMap.put(dhcpOptionValue, dhcpNetworkOptions.get(key));
} else {
Dhcp.DhcpOptionCode dhcpOptionEnum = Dhcp.DhcpOptionCode.valueOfString(key);
dhcpOptionsMap.put(dhcpOptionEnum.getCode(), dhcpNetworkOptions.get(key));
}
}

}
}

return dhcpOptionsMap;
}

@Override
public void execute() {
CallContext.current().setEventDetails("Vm Id: " + getVmId() + " Network Id: " + getNetworkId());
Expand Down
36 changes: 36 additions & 0 deletions api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import com.cloud.network.Network;
import com.cloud.network.Network.IpAddresses;
import com.cloud.uservm.UserVm;
import com.cloud.utils.net.Dhcp;
import com.cloud.utils.net.NetUtils;
import com.cloud.vm.VirtualMachine;

Expand Down Expand Up @@ -187,6 +188,10 @@ public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityG
@Parameter(name = ApiConstants.DEPLOYMENT_PLANNER, type = CommandType.STRING, description = "Deployment planner to use for vm allocation. Available to ROOT admin only", since = "4.4", authorized = { RoleType.Admin })
private String deploymentPlanner;

@Parameter(name = ApiConstants.DHCP_OPTIONS_NETWORK_LIST, type = CommandType.MAP, description = "DHCP options which are passed to the VM on start up"
+ " Example: dhcpoptionsnetworklist[0].dhcp:114=url&dhcpoptionsetworklist[0].networkid=networkid&dhcpoptionsetworklist[0].dhcp:66=www.test.com")
private Map dhcpOptionsNetworkList;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand Down Expand Up @@ -407,6 +412,37 @@ public String getKeyboard() {
return keyboard;
}

public Map<String, Map<Integer, String>> getDhcpOptionsMap() {
Map<String, Map<Integer, String>> dhcpOptionsMap = new HashMap<>();
if (dhcpOptionsNetworkList != null && !dhcpOptionsNetworkList.isEmpty()) {

Collection<Map<String, String>> paramsCollection = this.dhcpOptionsNetworkList.values();
for(Map<String, String> dhcpNetworkOptions : paramsCollection) {
String networkId = dhcpNetworkOptions.get(ApiConstants.NETWORK_ID);

if(networkId == null) {
throw new IllegalArgumentException("No networkid specified when providing extra dhcp options.");
}

Map<Integer, String> dhcpOptionsForNetwork = new HashMap<>();
dhcpOptionsMap.put(networkId, dhcpOptionsForNetwork);

for (String key : dhcpNetworkOptions.keySet()) {
if (key.startsWith(ApiConstants.DHCP_PREFIX)) {
int dhcpOptionValue = Integer.parseInt(key.replaceFirst(ApiConstants.DHCP_PREFIX, ""));
dhcpOptionsForNetwork.put(dhcpOptionValue, dhcpNetworkOptions.get(key));
} else if (!key.equals(ApiConstants.NETWORK_ID)){
Dhcp.DhcpOptionCode dhcpOptionEnum = Dhcp.DhcpOptionCode.valueOfString(key);
dhcpOptionsForNetwork.put(dhcpOptionEnum.getCode(), dhcpNetworkOptions.get(key));
}
}

}
}

return dhcpOptionsMap;
}

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
Expand Down
38 changes: 38 additions & 0 deletions api/src/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.cloudstack.api.command.user.vm;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -40,6 +41,7 @@
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.user.Account;
import com.cloud.uservm.UserVm;
import com.cloud.utils.net.Dhcp;
import com.cloud.vm.VirtualMachine;

@APICommand(name = "updateVirtualMachine", description="Updates properties of a virtual machine. The VM has to be stopped and restarted for the " +
Expand Down Expand Up @@ -121,6 +123,11 @@ public class UpdateVMCmd extends BaseCustomIdCmd implements SecurityGroupAction
description = "optional boolean field, which indicates if details should be cleaned up or not (if set to true, details removed for this resource, details field ignored; if false or not set, no action)")
private Boolean cleanupDetails;

@Parameter(name = ApiConstants.DHCP_OPTIONS_NETWORK_LIST, type = CommandType.MAP, description = "DHCP options which are passed to the VM on start up"
+ " Example: dhcpoptionsnetworklist[0].dhcp:114=url&dhcpoptionsetworklist[0].networkid=networkid&dhcpoptionsetworklist[0].dhcp:66=www.test.com")
private Map dhcpOptionsNetworkList;


/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand Down Expand Up @@ -182,6 +189,37 @@ public boolean isCleanupDetails(){
return cleanupDetails == null ? false : cleanupDetails.booleanValue();
}

public Map<String, Map<Integer, String>> getDhcpOptionsMap() {
Map<String, Map<Integer, String>> dhcpOptionsMap = new HashMap<>();
if (dhcpOptionsNetworkList != null && !dhcpOptionsNetworkList.isEmpty()) {

Collection<Map<String, String>> paramsCollection = this.dhcpOptionsNetworkList.values();
for(Map<String, String> dhcpNetworkOptions : paramsCollection) {
String networkId = dhcpNetworkOptions.get(ApiConstants.NETWORK_ID);

if(networkId == null) {
throw new IllegalArgumentException("No networkid specified when providing extra dhcp options.");
}

Map<Integer, String> dhcpOptionsForNetwork = new HashMap<>();
dhcpOptionsMap.put(networkId, dhcpOptionsForNetwork);

for (String key : dhcpNetworkOptions.keySet()) {
if (key.startsWith(ApiConstants.DHCP_PREFIX)) {
int dhcpOptionValue = Integer.parseInt(key.replaceFirst(ApiConstants.DHCP_PREFIX, ""));
dhcpOptionsForNetwork.put(dhcpOptionValue, dhcpNetworkOptions.get(key));
} else if (!key.equals(ApiConstants.NETWORK_ID)) {
Dhcp.DhcpOptionCode dhcpOptionEnum = Dhcp.DhcpOptionCode.valueOfString(key);
dhcpOptionsForNetwork.put(dhcpOptionEnum.getCode(), dhcpNetworkOptions.get(key));
}
}

}
}

return dhcpOptionsMap;
}

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
Expand Down
Loading