incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h...@apache.org
Subject [2/45] git commit: Summary: Add vlan configuration to the network inteface definition
Date Wed, 23 Jan 2013 07:15:58 GMT
Summary: Add vlan configuration to the network inteface definition

Add xml piece for defining vlans

Set vlan tag in the libvirt definition for the network inteface


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/9adf2771
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/9adf2771
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/9adf2771

Branch: refs/heads/master
Commit: 9adf2771825db8b8e102844db6ad638351e0b33e
Parents: ca57868
Author: Hugo Trippaers <trippie@gmail.com>
Authored: Fri Jan 11 17:04:32 2013 +0100
Committer: Hugo Trippaers <trippie@gmail.com>
Committed: Fri Jan 11 17:16:07 2013 +0100

----------------------------------------------------------------------
 .../hypervisor/kvm/resource/LibvirtVMDef.java      |   14 +++++-
 .../hypervisor/kvm/resource/OvsVifDriver.java      |   38 +++-----------
 2 files changed, 21 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/9adf2771/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
index 17f6eef..df27778 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
@@ -648,6 +648,7 @@ public class LibvirtVMDef {
         private nicModel _model;
         private String _virtualPortType;
         private String _virtualPortInterfaceId;
+        private int _vlanTag = -1;
 
         public void defBridgeNet(String brName, String targetBrName,
                 String macAddr, nicModel model) {
@@ -713,7 +714,15 @@ public class LibvirtVMDef {
         public String getVirtualPortInterfaceId() {
         	return _virtualPortInterfaceId;
         }
-
+        
+        public void setVlanTag(int vlanTag) {
+        	_vlanTag = vlanTag;
+        }
+        
+        public int getVlanTag() {
+        	return _vlanTag;
+        }
+        
         @Override
         public String toString() {
             StringBuilder netBuilder = new StringBuilder();
@@ -739,6 +748,9 @@ public class LibvirtVMDef {
             	}
             	netBuilder.append("</virtualport>\n");
             }
+            if (_vlanTag != -1) {
+            	netBuilder.append("<vlan trunk='no'>\n<tag id='" + _vlanTag + "'/>\n</vlan>");
+            }
             netBuilder.append("</interface>\n");
             return netBuilder.toString();
         }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/9adf2771/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java
b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java
index 6c3e496..52fc29e 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java
@@ -84,11 +84,11 @@ public class OvsVifDriver extends VifDriverBase {
                     && !vlanId.equalsIgnoreCase("untagged")) {
                 if(trafficLabel != null && !trafficLabel.isEmpty()) {
                     s_logger.debug("creating a vlan dev and bridge for guest traffic per
traffic label " + trafficLabel);
-                    String brName = createVlanBr(vlanId, _pifs.get(trafficLabel));
-                    intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType));
+                    intf.defBridgeNet(_pifs.get(trafficLabel), null, nic.getMac(), getGuestNicModel(guestOsType));
+                    intf.setVlanTag(Integer.parseInt(vlanId));
                 } else {
-                    String brName = createVlanBr(vlanId, _pifs.get("private"));
-                    intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType));
+                    intf.defBridgeNet(_pifs.get("private"), null, nic.getMac(), getGuestNicModel(guestOsType));
+                    intf.setVlanTag(Integer.parseInt(vlanId));
                 }
             } else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch) {
             	s_logger.debug("nic " + nic + " needs to be connected to LogicalSwitch " + logicalSwitchUuid);
@@ -108,11 +108,11 @@ public class OvsVifDriver extends VifDriverBase {
                     && !vlanId.equalsIgnoreCase("untagged")) {
                 if(trafficLabel != null && !trafficLabel.isEmpty()){
                     s_logger.debug("creating a vlan dev and bridge for public traffic per
traffic label " + trafficLabel);
-                    String brName = createVlanBr(vlanId, _pifs.get(trafficLabel));
-                    intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType));
+                    intf.defBridgeNet(_pifs.get(trafficLabel), null, nic.getMac(), getGuestNicModel(guestOsType));
+                    intf.setVlanTag(Integer.parseInt(vlanId));
                 } else {
-                    String brName = createVlanBr(vlanId, _pifs.get("public"));
-                    intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType));
+                    intf.defBridgeNet(_pifs.get("public"), null, nic.getMac(), getGuestNicModel(guestOsType));
+                    intf.setVlanTag(Integer.parseInt(vlanId));
                 }
             } else {
                 intf.defBridgeNet(_bridges.get("public"), null, nic.getMac(), getGuestNicModel(guestOsType));
@@ -143,28 +143,6 @@ public class OvsVifDriver extends VifDriverBase {
 
         return brName;
     }
-
-    private String createVlanBr(String vlanId, String nic)
-            throws InternalErrorException {
-        String brName = setVnetBrName(nic, vlanId);
-        createVnet(vlanId, nic, brName);
-        return brName;
-    }
-
-    private void createVnet(String vnetId, String pif, String brName)
-            throws InternalErrorException {
-        final Script command = new Script(_modifyVlanPath, _timeout, s_logger);
-        command.add("-v", vnetId);
-        command.add("-p", pif);
-        command.add("-b", brName);
-        command.add("-o", "add");
-
-        final String result = command.execute();
-        if (result != null) {
-            throw new InternalErrorException("Failed to create vnet " + vnetId
-                    + ": " + result);
-        }
-    }
     
 	private void deleteExitingLinkLocalRoutTable(String linkLocalBr) {
         Script command = new Script("/bin/bash", _timeout);


Mime
View raw message