mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-657 VMware vNetwork Distributed Virtual Switch support in CloudStack
This is 1st patch for feature 'Support for VMware dvSwitch in CloudStack'. This contains 3 newly introduced classes. Added apache license header for all 3 files. [1]TrafficLable and [2]VmwareTrafficLabel classes are to define and encapsulate virtual switch type per traffic type along with other network label fields (VLAN ID and physical network). [3]DistributedVirtualSwitchMO class is wrapper class for vSphere API calls specific to a distributed virtual switch in a vCenter datacenter. Signed-off-by: Sateesh Chodapuneedi <sateesh@apache.org>
This commit is contained in:
parent
a508309e7d
commit
1777f160c4
|
|
@ -0,0 +1,36 @@
|
|||
// 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 com.cloud.network.Networks.TrafficType;
|
||||
|
||||
/* User can provide a Label, while configuring a zone, to specify
|
||||
* a physical network that is to be used for a traffic type defined
|
||||
* by CloudStack. See the enum data type TrafficType. This label is
|
||||
* called Traffic label. This might encapsulate physical network
|
||||
* specific properties like VLAN ID, name of virtual network object or more.
|
||||
* The name of virtual network object is dependent on type of hypervisor.
|
||||
* For example it is name of xenserver bridge in case of XenServer and
|
||||
* name of virtual switch in case of VMware hypervisor
|
||||
*/
|
||||
public interface TrafficLabel {
|
||||
|
||||
public TrafficType getTrafficType();
|
||||
|
||||
public String getNetworkLabel();
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
// 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 com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.hypervisor.vmware.mo.VirtualSwitchType;
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
|
||||
public class VmwareTrafficLabel implements TrafficLabel {
|
||||
public static final String DEFAULT_VSWITCH_NAME = "vSwitch0";
|
||||
public static final String DEFAULT_DVSWITCH_NAME = "dvSwitch0";
|
||||
public static final String DEFAULT_NDVSWITCH_NAME = "epp0";
|
||||
public static final int MAX_FIELDS_VMWARE_LABEL = 3;
|
||||
public static final int VMWARE_LABEL_FIELD_INDEX_NAME = 0;
|
||||
public static final int VMWARE_LABEL_FIELD_INDEX_VLANID = 1;
|
||||
public static final int VMWARE_LABEL_FIELD_INDEX_VSWITCH_TYPE = 2;
|
||||
|
||||
TrafficType _trafficType = TrafficType.None;
|
||||
VirtualSwitchType _vSwitchType = VirtualSwitchType.StandardVirtualSwitch;
|
||||
String _vSwitchName = DEFAULT_VSWITCH_NAME;
|
||||
String _vlanId = null;
|
||||
|
||||
public VmwareTrafficLabel(String networkLabel, TrafficType trafficType, VirtualSwitchType defVswitchType) {
|
||||
_trafficType = trafficType;
|
||||
_parseLabel(networkLabel, defVswitchType);
|
||||
}
|
||||
|
||||
public VmwareTrafficLabel(String networkLabel, TrafficType trafficType) {
|
||||
_trafficType = trafficType;
|
||||
_parseLabel(networkLabel, VirtualSwitchType.StandardVirtualSwitch);
|
||||
}
|
||||
|
||||
public VmwareTrafficLabel(TrafficType trafficType, VirtualSwitchType defVswitchType) {
|
||||
_trafficType = trafficType; // Define traffic label with specific traffic type
|
||||
_parseLabel(null, defVswitchType);
|
||||
}
|
||||
|
||||
public VmwareTrafficLabel(TrafficType trafficType) {
|
||||
_trafficType = trafficType; // Define traffic label with specific traffic type
|
||||
_parseLabel(null, VirtualSwitchType.StandardVirtualSwitch);
|
||||
}
|
||||
|
||||
public VmwareTrafficLabel() {
|
||||
}
|
||||
|
||||
private void _parseLabel(String networkLabel, VirtualSwitchType defVswitchType) {
|
||||
if (networkLabel == null || networkLabel.isEmpty()) {
|
||||
// Set defaults for label in case of distributed vSwitch
|
||||
if (defVswitchType.equals(VirtualSwitchType.VMwareDistributedVirtualSwitch)) {
|
||||
_vSwitchName = DEFAULT_DVSWITCH_NAME;
|
||||
_vSwitchType = VirtualSwitchType.VMwareDistributedVirtualSwitch;
|
||||
} else if (defVswitchType.equals(VirtualSwitchType.NexusDistributedVirtualSwitch)) {
|
||||
_vSwitchName = DEFAULT_NDVSWITCH_NAME;
|
||||
_vSwitchType = VirtualSwitchType.NexusDistributedVirtualSwitch;
|
||||
}
|
||||
return;
|
||||
}
|
||||
String[] tokens = networkLabel.split(",");
|
||||
if (tokens.length > VMWARE_LABEL_FIELD_INDEX_NAME) {
|
||||
_vSwitchName = tokens[VMWARE_LABEL_FIELD_INDEX_NAME].trim();
|
||||
}
|
||||
if (tokens.length > VMWARE_LABEL_FIELD_INDEX_VLANID) {
|
||||
_vlanId = tokens[VMWARE_LABEL_FIELD_INDEX_VLANID].trim();
|
||||
}
|
||||
if (tokens.length > VMWARE_LABEL_FIELD_INDEX_VSWITCH_TYPE) {
|
||||
_vSwitchType = VirtualSwitchType.getType(tokens[VMWARE_LABEL_FIELD_INDEX_VSWITCH_TYPE].trim());
|
||||
if(VirtualSwitchType.None == _vSwitchType) {
|
||||
throw new InvalidParameterValueException("Invalid virtual switch type : " + tokens[VMWARE_LABEL_FIELD_INDEX_VSWITCH_TYPE].trim());
|
||||
}
|
||||
}
|
||||
if (tokens.length > MAX_FIELDS_VMWARE_LABEL ) {
|
||||
throw new InvalidParameterValueException("Found extraneous fields in vmware traffic label : " + networkLabel);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrafficType getTrafficType() {
|
||||
return _trafficType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNetworkLabel() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public VirtualSwitchType getVirtualSwitchType() {
|
||||
return _vSwitchType;
|
||||
}
|
||||
|
||||
public String getVirtualSwitchName() {
|
||||
return _vSwitchName;
|
||||
}
|
||||
|
||||
public String getVlanId() {
|
||||
return _vlanId;
|
||||
}
|
||||
public void setVirtualSwitchName(String vSwitchName) {
|
||||
_vSwitchName = vSwitchName;
|
||||
}
|
||||
|
||||
public void setVirtualSwitchType(VirtualSwitchType vSwitchType) {
|
||||
_vSwitchType = vSwitchType;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
// 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.hypervisor.vmware.mo;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||
import com.vmware.vim25.DVPortgroupConfigSpec;
|
||||
import com.vmware.vim25.HostPortGroupSpec;
|
||||
import com.vmware.vim25.ManagedObjectReference;
|
||||
|
||||
public class DistributedVirtualSwitchMO extends BaseMO {
|
||||
private static final Logger s_logger = Logger.getLogger(DistributedVirtualSwitchMO.class);
|
||||
|
||||
public DistributedVirtualSwitchMO(VmwareContext context, ManagedObjectReference morDvs) {
|
||||
super(context, morDvs);
|
||||
}
|
||||
|
||||
public DistributedVirtualSwitchMO(VmwareContext context, String morType, String morValue) {
|
||||
super(context, morType, morValue);
|
||||
}
|
||||
|
||||
public void createDVPortGroup(DVPortgroupConfigSpec dvPortGroupSpec) throws Exception {
|
||||
DVPortgroupConfigSpec[] dvPortGroupSpecArray = new DVPortgroupConfigSpec[1];
|
||||
dvPortGroupSpecArray[0] = dvPortGroupSpec;
|
||||
_context.getService().addDVPortgroup_Task(_mor, dvPortGroupSpecArray);
|
||||
}
|
||||
|
||||
public void updateDvPortGroup(ManagedObjectReference dvPortGroupMor, DVPortgroupConfigSpec dvPortGroupSpec) throws Exception {
|
||||
// TODO(sateesh): Update numPorts
|
||||
_context.getService().reconfigureDVPortgroup_Task(dvPortGroupMor, dvPortGroupSpec);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue