From daf1aa4b926e2869b58be9975bd8c6c25f0b3fff Mon Sep 17 00:00:00 2001 From: anthony Date: Tue, 5 Jun 2012 15:38:25 -0700 Subject: [PATCH] VPC, implement plug/unplug nic --- .../xen/resource/CitrixResourceBase.java | 47 +++++++++++++++++-- .../config/etc/iptables/iptables-router | 2 - wscript | 2 +- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 2605b2e7d72..4a616331b12 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -6973,8 +6973,31 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe * @return */ private UnPlugNicAnswer execute(UnPlugNicCommand cmd) { - // TODO Auto-generated method stub - return null; + Connection conn = getConnection(); + VirtualMachineTO vmto = cmd.getVirtualMachine(); + String vmName = vmto.getName(); + try { + Set vms = VM.getByNameLabel(conn, vmName); + if ( vms == null || vms.isEmpty() ) { + return new UnPlugNicAnswer(cmd, false, "Can not find VM " + vmName); + } + VM vm = vms.iterator().next(); + NicTO nic = cmd.getNic(); + String mac = nic.getMac(); + for ( VIF vif : vm.getVIFs(conn)) { + String lmac = vif.getMAC(conn); + if ( lmac.equals(mac) ) { + vif.unplug(conn); + vif.destroy(conn); + break; + } + } + return new UnPlugNicAnswer(cmd, true, "success"); + } catch (Exception e) { + String msg = " UnPlug Nic failed due to " + e.toString(); + s_logger.warn(msg, e); + return new UnPlugNicAnswer(cmd, false, msg); + } } /** @@ -6982,8 +7005,24 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe * @return */ private PlugNicAnswer execute(PlugNicCommand cmd) { - // TODO Auto-generated method stub - return null; + Connection conn = getConnection(); + VirtualMachineTO vmto = cmd.getVirtualMachine(); + String vmName = vmto.getName(); + try { + Set vms = VM.getByNameLabel(conn, vmName); + if ( vms == null || vms.isEmpty() ) { + return new PlugNicAnswer(cmd, false, "Can not find VM " + vmName); + } + VM vm = vms.iterator().next(); + NicTO nic = cmd.getNic(); + VIF vif = createVif(conn, vmName, vm, nic); + vif.plug(conn); + return new PlugNicAnswer(cmd, true, "success"); + } catch (Exception e) { + String msg = " Plug Nic failed due to " + e.toString(); + s_logger.warn(msg, e); + return new PlugNicAnswer(cmd, false, msg); + } } /** diff --git a/patches/systemvm/debian/config/etc/iptables/iptables-router b/patches/systemvm/debian/config/etc/iptables/iptables-router index ac40ed41056..193d54fa33e 100644 --- a/patches/systemvm/debian/config/etc/iptables/iptables-router +++ b/patches/systemvm/debian/config/etc/iptables/iptables-router @@ -10,8 +10,6 @@ COMMIT -A INPUT -d 224.0.0.18/32 -j ACCEPT -A INPUT -d 225.0.0.50/32 -j ACCEPT -A INPUT -i eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT --A INPUT -i eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT --A INPUT -i eth2 -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -i eth0 -p tcp -m state --state NEW --dport 3922 -j ACCEPT diff --git a/wscript b/wscript index d38cc11efce..e41b86035e5 100644 --- a/wscript +++ b/wscript @@ -4,7 +4,7 @@ # the following two variables are used by the target "waf dist" # if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog -VERSION = '3.0.3.2012-06-05T18:30:03Z' +VERSION = '3.0.3.2012-06-05T22:35:08Z' APPNAME = 'cloud' import shutil,os