| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
29 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,121 @@ | |||
| 1 | + // Licensed to the Apache Software Foundation (ASF) under one | ||
| 2 | + // or more contributor license agreements. See the NOTICE file | ||
| 3 | + // distributed with this work for additional information | ||
| 4 | + // regarding copyright ownership. The ASF licenses this file | ||
| 5 | + // to you under the Apache License, Version 2.0 (the | ||
| 6 | + // "License"); you may not use this file except in compliance | ||
| 7 | + // with the License. You may obtain a copy of the License at | ||
| 8 | + // | ||
| 9 | + // http://www.apache.org/licenses/LICENSE-2.0 | ||
| 10 | + // | ||
| 11 | + // Unless required by applicable law or agreed to in writing, | ||
| 12 | + // software distributed under the License is distributed on an | ||
| 13 | + // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| 14 | + // KIND, either express or implied. See the License for the | ||
| 15 | + // specific language governing permissions and limitations | ||
| 16 | + // under the License. | ||
| 17 | + package com.cloud.agent.api; | ||
| 18 | + | ||
| 19 | + import java.net.URI; | ||
| 20 | + | ||
| 21 | + import com.cloud.utils.net.NetUtils; | ||
| 22 | + | ||
| 23 | + public class PvlanSetupCommand extends Command { | ||
| 24 | + public enum Type { | ||
| 25 | + DHCP, | ||
| 26 | + VM | ||
| 27 | + } | ||
| 28 | + private String op; | ||
| 29 | + private String primary; | ||
| 30 | + private String isolated; | ||
| 31 | + private String vmMac; | ||
| 32 | + private String dhcpName; | ||
| 33 | + private String dhcpMac; | ||
| 34 | + private String dhcpIp; | ||
| 35 | + private Type type; | ||
| 36 | + private String networkTag; | ||
| 37 | + | ||
| 38 | + protected PvlanSetupCommand() {} | ||
| 39 | + | ||
| 40 | + protected PvlanSetupCommand(Type type, String op, URI uri, String networkTag) | ||
| 41 | + { | ||
| 42 | + this.type = type; | ||
| 43 | + this.op = op; | ||
| 44 | + this.primary = NetUtils.getPrimaryPvlanFromUri(uri); | ||
| 45 | + this.isolated = NetUtils.getIsolatedPvlanFromUri(uri); | ||
| 46 | + this.networkTag = networkTag; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + static public PvlanSetupCommand createDhcpSetup(String op, URI uri, String networkTag, String dhcpName, String dhcpMac, String dhcpIp) | ||
| 50 | + { | ||
| 51 | + PvlanSetupCommand cmd = new PvlanSetupCommand(Type.DHCP, op, uri, networkTag); | ||
| 52 | + cmd.setDhcpName(dhcpName); | ||
| 53 | + cmd.setDhcpMac(dhcpMac); | ||
| 54 | + cmd.setDhcpIp(dhcpIp); | ||
| 55 | + return cmd; | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + static public PvlanSetupCommand createVmSetup(String op, URI uri, String networkTag, String vmMac) | ||
| 59 | + { | ||
| 60 | + PvlanSetupCommand cmd = new PvlanSetupCommand(Type.VM, op, uri, networkTag); | ||
| 61 | + cmd.setVmMac(vmMac); | ||
| 62 | + return cmd; | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + @Override | ||
| 66 | + public boolean executeInSequence() { | ||
| 67 | + return true; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + public String getOp() { | ||
| 71 | + return op; | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + public String getPrimary() { | ||
| 75 | + return primary; | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + public String getIsolated() { | ||
| 79 | + return isolated; | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + public String getVmMac() { | ||
| 83 | + return vmMac; | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + protected void setVmMac(String vmMac) { | ||
| 87 | + this.vmMac = vmMac; | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + public String getDhcpMac() { | ||
| 91 | + return dhcpMac; | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + protected void setDhcpMac(String dhcpMac) { | ||
| 95 | + this.dhcpMac = dhcpMac; | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + public String getDhcpIp() { | ||
| 99 | + return dhcpIp; | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + protected void setDhcpIp(String dhcpIp) { | ||
| 103 | + this.dhcpIp = dhcpIp; | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + public Type getType() { | ||
| 107 | + return type; | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + public String getDhcpName() { | ||
| 111 | + return dhcpName; | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + public void setDhcpName(String dhcpName) { | ||
| 115 | + this.dhcpName = dhcpName; | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + public String getNetworkTag() { | ||
| 119 | + return networkTag; | ||
| 120 | + } | ||
| 121 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -63,6 +63,7 @@ public enum BroadcastDomainType { | |||
| 63 | 63 | Storage("storage", Integer.class), | |
| 64 | 64 | Lswitch("lswitch", String.class), | |
| 65 | 65 | Mido("mido", String.class), | |
| 66 | + Pvlan("pvlan", String.class), | ||
| 66 | 67 | UnDecided(null, null); | |
| 67 | 68 | ||
| 68 | 69 | private String scheme; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -230,6 +230,7 @@ public class ApiConstants { | |||
| 230 | 230 | public static final String VLAN_RANGE = "vlanrange"; | |
| 231 | 231 | public static final String REMOVE_VLAN="removevlan"; | |
| 232 | 232 | public static final String VLAN_ID = "vlanid"; | |
| 233 | + public static final String ISOLATED_PVLAN = "isolatedpvlan"; | ||
| 233 | 234 | public static final String VM_AVAILABLE = "vmavailable"; | |
| 234 | 235 | public static final String VM_LIMIT = "vmlimit"; | |
| 235 | 236 | public static final String VM_TOTAL = "vmtotal"; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -80,6 +80,9 @@ public class CreateNetworkCmd extends BaseCmd { | |||
| 80 | 80 | @Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, description="the ID or VID of the network") | |
| 81 | 81 | private String vlan; | |
| 82 | 82 | ||
| 83 | + @Parameter(name=ApiConstants.ISOLATED_PVLAN, type=CommandType.STRING, description="the isolated private vlan for this network") | ||
| 84 | + private String isolatedPvlan; | ||
| 85 | + | ||
| 83 | 86 | @Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, description="network domain") | |
| 84 | 87 | private String networkDomain; | |
| 85 | 88 | ||
@@ -141,6 +144,10 @@ public String getVlan() { | |||
| 141 | 144 | return vlan; | |
| 142 | 145 | } | |
| 143 | 146 | ||
| 147 | + public String getIsolatedPvlan() { | ||
| 148 | + return isolatedPvlan; | ||
| 149 | + } | ||
| 150 | + | ||
| 144 | 151 | public String getAccountName() { | |
| 145 | 152 | return accountName; | |
| 146 | 153 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -125,6 +125,7 @@ | |||
| 125 | 125 | import com.cloud.agent.api.PlugNicCommand; | |
| 126 | 126 | import com.cloud.agent.api.PrepareForMigrationAnswer; | |
| 127 | 127 | import com.cloud.agent.api.PrepareForMigrationCommand; | |
| 128 | + import com.cloud.agent.api.PvlanSetupCommand; | ||
| 128 | 129 | import com.cloud.agent.api.ReadyAnswer; | |
| 129 | 130 | import com.cloud.agent.api.ReadyCommand; | |
| 130 | 131 | import com.cloud.agent.api.RebootAnswer; | |
@@ -267,6 +268,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements | |||
| 267 | 268 | private String _createTmplPath; | |
| 268 | 269 | private String _heartBeatPath; | |
| 269 | 270 | private String _securityGroupPath; | |
| 271 | + private String _ovsPvlanDhcpHostPath; | ||
| 272 | + private String _ovsPvlanVmPath; | ||
| 270 | 273 | private String _routerProxyPath; | |
| 271 | 274 | private String _host; | |
| 272 | 275 | private String _dcId; | |
@@ -587,6 +590,18 @@ public boolean configure(String name, Map<String, Object> params) | |||
| 587 | 590 | "Unable to find the router_proxy.sh"); | |
| 588 | 591 | } | |
| 589 | 592 | ||
| 593 | + _ovsPvlanDhcpHostPath = Script.findScript(networkScriptsDir, "ovs-pvlan-dhcp-host.sh"); | ||
| 594 | + if ( _ovsPvlanDhcpHostPath == null) { | ||
| 595 | + throw new ConfigurationException( | ||
| 596 | + "Unable to find the ovs-pvlan-dhcp-host.sh"); | ||
| 597 | + } | ||
| 598 | + | ||
| 599 | + _ovsPvlanVmPath = Script.findScript(networkScriptsDir, "ovs-pvlan-vm.sh"); | ||
| 600 | + if ( _ovsPvlanVmPath == null) { | ||
| 601 | + throw new ConfigurationException( | ||
| 602 | + "Unable to find the ovs-pvlan-vm.sh"); | ||
| 603 | + } | ||
| 604 | + | ||
| 590 | 605 | String value = (String) params.get("developer"); | |
| 591 | 606 | boolean isDeveloper = Boolean.parseBoolean(value); | |
| 592 | 607 | ||
@@ -1202,6 +1217,8 @@ public Answer executeRequest(Command cmd) { | |||
| 1202 | 1217 | return execute((CheckNetworkCommand) cmd); | |
| 1203 | 1218 | } else if (cmd instanceof NetworkRulesVmSecondaryIpCommand) { | |
| 1204 | 1219 | return execute((NetworkRulesVmSecondaryIpCommand) cmd); | |
| 1220 | + } else if (cmd instanceof PvlanSetupCommand) { | ||
| 1221 | + return execute((PvlanSetupCommand) cmd); | ||
| 1205 | 1222 | } else { | |
| 1206 | 1223 | s_logger.warn("Unsupported command "); | |
| 1207 | 1224 | return Answer.createUnsupportedCommandAnswer(cmd); | |
@@ -1517,6 +1534,65 @@ private String getVlanIdFromBridge(String brName) { | |||
| 1517 | 1534 | } | |
| 1518 | 1535 | } | |
| 1519 | 1536 | ||
| 1537 | + private Answer execute(PvlanSetupCommand cmd) { | ||
| 1538 | + String primaryPvlan = cmd.getPrimary(); | ||
| 1539 | + String isolatedPvlan = cmd.getIsolated(); | ||
| 1540 | + String op = cmd.getOp(); | ||
| 1541 | + String dhcpName = cmd.getDhcpName(); | ||
| 1542 | + String dhcpMac = cmd.getDhcpMac(); | ||
| 1543 | + String dhcpIp = cmd.getDhcpIp(); | ||
| 1544 | + String vmMac = cmd.getVmMac(); | ||
| 1545 | + boolean add = true; | ||
| 1546 | + | ||
| 1547 | + String opr = "-A"; | ||
| 1548 | + if (op.equals("delete")) { | ||
| 1549 | + opr = "-D"; | ||
| 1550 | + add = false; | ||
| 1551 | + } | ||
| 1552 | + | ||
| 1553 | + String result = null; | ||
| 1554 | + Connect conn; | ||
| 1555 | + try { | ||
| 1556 | + if (cmd.getType() == PvlanSetupCommand.Type.DHCP) { | ||
| 1557 | + Script script = new Script(_ovsPvlanDhcpHostPath, _timeout, s_logger); | ||
| 1558 | + if (add) { | ||
| 1559 | + conn = LibvirtConnection.getConnectionByVmName(dhcpName); | ||
| 1560 | + List<InterfaceDef> ifaces = getInterfaces(conn, dhcpName); | ||
| 1561 | + InterfaceDef guestNic = ifaces.get(0); | ||
| 1562 | + script.add(opr, "-b", _guestBridgeName, | ||
| 1563 | + "-p", primaryPvlan, "-i", isolatedPvlan, "-n", dhcpName, | ||
| 1564 | + "-d", dhcpIp, "-m", dhcpMac, "-I", guestNic.getDevName()); | ||
| 1565 | + } else { | ||
| 1566 | + script.add(opr, "-b", _guestBridgeName, | ||
| 1567 | + "-p", primaryPvlan, "-i", isolatedPvlan, "-n", dhcpName, | ||
| 1568 | + "-d", dhcpIp, "-m", dhcpMac); | ||
| 1569 | + } | ||
| 1570 | + result = script.execute(); | ||
| 1571 | + if (result != null) { | ||
| 1572 | + s_logger.warn("Failed to program pvlan for dhcp server with mac " + dhcpMac); | ||
| 1573 | + return new Answer(cmd, false, result); | ||
| 1574 | + } else { | ||
| 1575 | + s_logger.info("Programmed pvlan for dhcp server with mac " + dhcpMac); | ||
| 1576 | + } | ||
| 1577 | + } else if (cmd.getType() == PvlanSetupCommand.Type.VM) { | ||
| 1578 | + Script script = new Script(_ovsPvlanVmPath, _timeout, s_logger); | ||
| 1579 | + script.add(opr, "-b", _guestBridgeName, | ||
| 1580 | + "-p", primaryPvlan, "-i", isolatedPvlan, "-v", vmMac); | ||
| 1581 | + result = script.execute(); | ||
| 1582 | + if (result != null) { | ||
| 1583 | + s_logger.warn("Failed to program pvlan for vm with mac " + vmMac); | ||
| 1584 | + return new Answer(cmd, false, result); | ||
| 1585 | + } else { | ||
| 1586 | + s_logger.info("Programmed pvlan for vm with mac " + vmMac); | ||
| 1587 | + } | ||
| 1588 | + } | ||
| 1589 | + } catch (LibvirtException e) { | ||
| 1590 | + // TODO Auto-generated catch block | ||
| 1591 | + e.printStackTrace(); | ||
| 1592 | + } | ||
| 1593 | + return new Answer(cmd, true, result); | ||
| 1594 | + } | ||
| 1595 | + | ||
| 1520 | 1596 | private void VifHotPlug(Connect conn, String vmName, String vlanId, | |
| 1521 | 1597 | String macAddr) throws InternalErrorException, LibvirtException { | |
| 1522 | 1598 | NicTO nicTO = new NicTO(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -76,10 +76,12 @@ public InterfaceDef plug(NicTO nic, String guestOsType) | |||
| 76 | 76 | } | |
| 77 | 77 | else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch) { | |
| 78 | 78 | logicalSwitchUuid = nic.getBroadcastUri().getSchemeSpecificPart(); | |
| 79 | + } else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Pvlan) { | ||
| 80 | + vlanId = NetUtils.getPrimaryPvlanFromUri(nic.getBroadcastUri()); | ||
| 79 | 81 | } | |
| 80 | 82 | String trafficLabel = nic.getName(); | |
| 81 | 83 | if (nic.getType() == Networks.TrafficType.Guest) { | |
| 82 | - if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan | ||
| 84 | + if ((nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan || nic.getBroadcastType() == Networks.BroadcastDomainType.Pvlan) | ||
| 83 | 85 | && !vlanId.equalsIgnoreCase("untagged")) { | |
| 84 | 86 | if(trafficLabel != null && !trafficLabel.isEmpty()) { | |
| 85 | 87 | s_logger.debug("creating a vlan dev and bridge for guest traffic per traffic label " + trafficLabel); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -83,6 +83,7 @@ | |||
| 83 | 83 | import com.cloud.agent.api.PoolEjectCommand; | |
| 84 | 84 | import com.cloud.agent.api.PrepareForMigrationAnswer; | |
| 85 | 85 | import com.cloud.agent.api.PrepareForMigrationCommand; | |
| 86 | + import com.cloud.agent.api.PvlanSetupCommand; | ||
| 86 | 87 | import com.cloud.agent.api.ReadyAnswer; | |
| 87 | 88 | import com.cloud.agent.api.ReadyCommand; | |
| 88 | 89 | import com.cloud.agent.api.RebootAnswer; | |
@@ -614,6 +615,8 @@ public Answer executeRequest(Command cmd) { | |||
| 614 | 615 | return execute((NetworkRulesVmSecondaryIpCommand)cmd); | |
| 615 | 616 | } else if (clazz == ScaleVmCommand.class) { | |
| 616 | 617 | return execute((ScaleVmCommand) cmd); | |
| 618 | + } else if (clazz == PvlanSetupCommand.class) { | ||
| 619 | + return execute((PvlanSetupCommand) cmd); | ||
| 617 | 620 | } else { | |
| 618 | 621 | return Answer.createUnsupportedCommandAnswer(cmd); | |
| 619 | 622 | } | |
@@ -1030,6 +1033,11 @@ protected Network getNetwork(Connection conn, NicTO nic) throws XenAPIException, | |||
| 1030 | 1033 | } else if (nic.getBroadcastType() == BroadcastDomainType.Lswitch) { | |
| 1031 | 1034 | // Nicira Logical Switch | |
| 1032 | 1035 | return network.getNetwork(); | |
| 1036 | + } else if (nic.getBroadcastType() == BroadcastDomainType.Pvlan) { | ||
| 1037 | + URI broadcastUri = nic.getBroadcastUri(); | ||
| 1038 | + assert broadcastUri.getScheme().equals(BroadcastDomainType.Pvlan.scheme()); | ||
| 1039 | + long vlan = Long.parseLong(NetUtils.getPrimaryPvlanFromUri(broadcastUri)); | ||
| 1040 | + return enableVlanNetwork(conn, vlan, network); | ||
| 1033 | 1041 | } | |
| 1034 | 1042 | ||
| 1035 | 1043 | throw new CloudRuntimeException("Unable to support this type of network broadcast domain: " + nic.getBroadcastUri()); | |
@@ -1065,7 +1073,7 @@ protected VIF createVif(Connection conn, String vmName, VM vm, NicTO nic) throws | |||
| 1065 | 1073 | vifr = vif.getRecord(conn); | |
| 1066 | 1074 | s_logger.debug("Created a vif " + vifr.uuid + " on " + nic.getDeviceId()); | |
| 1067 | 1075 | } | |
| 1068 | - | ||
| 1076 | + | ||
| 1069 | 1077 | return vif; | |
| 1070 | 1078 | } | |
| 1071 | 1079 | ||
@@ -1476,6 +1484,55 @@ private void cleanUpTmpDomVif(Connection conn) { | |||
| 1476 | 1484 | } | |
| 1477 | 1485 | } | |
| 1478 | 1486 | } | |
| 1487 | + | ||
| 1488 | + private Answer execute(PvlanSetupCommand cmd) { | ||
| 1489 | + Connection conn = getConnection(); | ||
| 1490 | + | ||
| 1491 | + String primaryPvlan = cmd.getPrimary(); | ||
| 1492 | + String isolatedPvlan = cmd.getIsolated(); | ||
| 1493 | + String op = cmd.getOp(); | ||
| 1494 | + String dhcpName = cmd.getDhcpName(); | ||
| 1495 | + String dhcpMac = cmd.getDhcpMac(); | ||
| 1496 | + String dhcpIp = cmd.getDhcpIp(); | ||
| 1497 | + String vmMac = cmd.getVmMac(); | ||
| 1498 | + String networkTag = cmd.getNetworkTag(); | ||
| 1499 | + | ||
| 1500 | + XsLocalNetwork nw = null; | ||
| 1501 | + String nwNameLabel = null; | ||
| 1502 | + try { | ||
| 1503 | + nw = getNativeNetworkForTraffic(conn, TrafficType.Guest, networkTag); | ||
| 1504 | + nwNameLabel = nw.getNetwork().getNameLabel(conn); | ||
| 1505 | + } catch (XenAPIException e) { | ||
| 1506 | + s_logger.warn("Fail to get network", e); | ||
| 1507 | + return new Answer(cmd, false, e.toString()); | ||
| 1508 | + } catch (XmlRpcException e) { | ||
| 1509 | + s_logger.warn("Fail to get network", e); | ||
| 1510 | + return new Answer(cmd, false, e.toString()); | ||
| 1511 | + } | ||
| 1512 | + | ||
| 1513 | + String result = null; | ||
| 1514 | + if (cmd.getType() == PvlanSetupCommand.Type.DHCP) { | ||
| 1515 | + result = callHostPlugin(conn, "ovs-pvlan", "setup-pvlan-dhcp", "op", op, "nw-label", nwNameLabel, | ||
| 1516 | + "primary-pvlan", primaryPvlan, "isolated-pvlan", isolatedPvlan, "dhcp-name", dhcpName, | ||
| 1517 | + "dhcp-ip", dhcpIp, "dhcp-mac", dhcpMac); | ||
| 1518 | + if (result == null || result.isEmpty() || !Boolean.parseBoolean(result)) { | ||
| 1519 | + s_logger.warn("Failed to program pvlan for dhcp server with mac " + dhcpMac); | ||
| 1520 | + return new Answer(cmd, false, result); | ||
| 1521 | + } else { | ||
| 1522 | + s_logger.info("Programmed pvlan for dhcp server with mac " + dhcpMac); | ||
| 1523 | + } | ||
| 1524 | + } else if (cmd.getType() == PvlanSetupCommand.Type.VM) { | ||
| 1525 | + result = callHostPlugin(conn, "ovs-pvlan", "setup-pvlan-vm", "op", op, "nw-label", nwNameLabel, | ||
| 1526 | + "primary-pvlan", primaryPvlan, "isolated-pvlan", isolatedPvlan, "vm-mac", vmMac); | ||
| 1527 | + if (result == null || result.isEmpty() || !Boolean.parseBoolean(result)) { | ||
| 1528 | + s_logger.warn("Failed to program pvlan for vm with mac " + vmMac); | ||
| 1529 | + return new Answer(cmd, false, result); | ||
| 1530 | + } else { | ||
| 1531 | + s_logger.info("Programmed pvlan for vm with mac " + vmMac); | ||
| 1532 | + } | ||
| 1533 | + } | ||
| 1534 | + return new Answer(cmd, true, result); | ||
| 1535 | + } | ||
| 1479 | 1536 | ||
| 1480 | 1537 | @Override | |
| 1481 | 1538 | public StartAnswer execute(StartCommand cmd) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments