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 <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/1777f160 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/1777f160 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/1777f160 Branch: refs/heads/master Commit: 1777f160c43df1f6bcac6606b1288ddc44d2f827 Parents: a508309 Author: sateesh <[email protected]> Authored: Mon Feb 25 16:40:58 2013 +0530 Committer: Sateesh Chodapuneedi <[email protected]> Committed: Wed Feb 27 18:37:14 2013 +0530 ---------------------------------------------------------------------- api/src/com/cloud/network/TrafficLabel.java | 36 +++++ .../src/com/cloud/network/VmwareTrafficLabel.java | 118 +++++++++++++++ .../vmware/mo/DistributedVirtualSwitchMO.java | 47 ++++++ 3 files changed, 201 insertions(+), 0 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1777f160/api/src/com/cloud/network/TrafficLabel.java ---------------------------------------------------------------------- diff --git a/api/src/com/cloud/network/TrafficLabel.java b/api/src/com/cloud/network/TrafficLabel.java new file mode 100644 index 0000000..782df14 --- /dev/null +++ b/api/src/com/cloud/network/TrafficLabel.java @@ -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(); + +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1777f160/plugins/hypervisors/vmware/src/com/cloud/network/VmwareTrafficLabel.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/vmware/src/com/cloud/network/VmwareTrafficLabel.java b/plugins/hypervisors/vmware/src/com/cloud/network/VmwareTrafficLabel.java new file mode 100644 index 0000000..90a4278 --- /dev/null +++ b/plugins/hypervisors/vmware/src/com/cloud/network/VmwareTrafficLabel.java @@ -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; + } +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1777f160/vmware-base/src/com/cloud/hypervisor/vmware/mo/DistributedVirtualSwitchMO.java ---------------------------------------------------------------------- diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/DistributedVirtualSwitchMO.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/DistributedVirtualSwitchMO.java new file mode 100644 index 0000000..494477e --- /dev/null +++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/DistributedVirtualSwitchMO.java @@ -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); + } +}
