diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/ConfigHelper.java b/core/src/com/cloud/agent/resource/virtualnetwork/ConfigHelper.java index af5fa9a9f8d..8154d681bb5 100644 --- a/core/src/com/cloud/agent/resource/virtualnetwork/ConfigHelper.java +++ b/core/src/com/cloud/agent/resource/virtualnetwork/ConfigHelper.java @@ -56,10 +56,13 @@ import com.cloud.agent.api.routing.VmDataCommand; import com.cloud.agent.api.routing.VpnUsersCfgCommand; import com.cloud.agent.api.to.DhcpTO; import com.cloud.agent.api.to.FirewallRuleTO; +import com.cloud.agent.api.to.IpAddressTO; import com.cloud.agent.api.to.NicTO; import com.cloud.agent.api.to.PortForwardingRuleTO; import com.cloud.agent.api.to.StaticNatRuleTO; import com.cloud.agent.resource.virtualnetwork.model.GuestNetwork; +import com.cloud.agent.resource.virtualnetwork.model.IpAddress; +import com.cloud.agent.resource.virtualnetwork.model.IpAssociation; import com.cloud.agent.resource.virtualnetwork.model.NetworkACL; import com.cloud.network.HAProxyConfigurator; import com.cloud.network.LoadBalancerConfigurator; @@ -624,8 +627,17 @@ public class ConfigHelper { private static List generateConfig(IpAssocCommand cmd) { LinkedList cfg = new LinkedList<>(); - // Reuse the IpAddressTO model - ConfigItem ipAssociationsFile = new FileConfigItem(VRScripts.CONFIG_PERSIST_LOCATION, VRScripts.IP_ASSOCIATION_CONFIG, gson.toJson(cmd.getIpAddresses())); + List ips = new LinkedList(); + + for (IpAddressTO ip : cmd.getIpAddresses()) { + IpAddress ipAddress = new IpAddress(ip.getPublicIp(), ip.isSourceNat(), ip.isAdd(), ip.isOneToOneNat(), ip.isFirstIP(), ip.getVlanGateway(), ip.getVlanNetmask(), + ip.getVifMacAddress(), ip.getNicDevId(), ip.isNewNic()); + ips.add(ipAddress); + } + + IpAssociation ipAssociation = new IpAssociation(ips.toArray(new IpAddress[ips.size()])); + + ConfigItem ipAssociationsFile = new FileConfigItem(VRScripts.CONFIG_PERSIST_LOCATION, VRScripts.IP_ASSOCIATION_CONFIG, gson.toJson(ipAssociation)); cfg.add(ipAssociationsFile); ConfigItem updateIpAssociations = new ScriptConfigItem(VRScripts.UPDATE_CONFIG, VRScripts.IP_ASSOCIATION_CONFIG); diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/model/ConfigBase.java b/core/src/com/cloud/agent/resource/virtualnetwork/model/ConfigBase.java index f84a1c65397..a0baeae2aca 100644 --- a/core/src/com/cloud/agent/resource/virtualnetwork/model/ConfigBase.java +++ b/core/src/com/cloud/agent/resource/virtualnetwork/model/ConfigBase.java @@ -1,3 +1,22 @@ +// +// 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.agent.resource.virtualnetwork.model; public abstract class ConfigBase { diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/model/IpAddress.java b/core/src/com/cloud/agent/resource/virtualnetwork/model/IpAddress.java new file mode 100644 index 00000000000..5889bd28ea2 --- /dev/null +++ b/core/src/com/cloud/agent/resource/virtualnetwork/model/IpAddress.java @@ -0,0 +1,134 @@ +// +// 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.agent.resource.virtualnetwork.model; + + +public class IpAddress { + private String publicIp; + private boolean sourceNat; + private boolean add; + private boolean oneToOneNat; + private boolean firstIP; + private String gateway; + private String netmask; + private String vifMacAddress; + private Integer nicDevId; + private boolean newNic; + + public IpAddress() { + // Empty constructor for (de)serialization + } + + public IpAddress(String publicIp, boolean sourceNat, boolean add, boolean oneToOneNat, boolean firstIP, String gateway, String netmask, String vifMacAddress, + Integer nicDevId, boolean newNic) { + super(); + this.publicIp = publicIp; + this.sourceNat = sourceNat; + this.add = add; + this.oneToOneNat = oneToOneNat; + this.firstIP = firstIP; + this.gateway = gateway; + this.netmask = netmask; + this.vifMacAddress = vifMacAddress; + this.nicDevId = nicDevId; + this.newNic = newNic; + } + + public String getPublicIp() { + return publicIp; + } + + public void setPublicIp(String publicIp) { + this.publicIp = publicIp; + } + + public boolean isSourceNat() { + return sourceNat; + } + + public void setSourceNat(boolean sourceNat) { + this.sourceNat = sourceNat; + } + + public boolean isAdd() { + return add; + } + + public void setAdd(boolean add) { + this.add = add; + } + + public boolean isOneToOneNat() { + return oneToOneNat; + } + + public void setOneToOneNat(boolean oneToOneNat) { + this.oneToOneNat = oneToOneNat; + } + + public boolean isFirstIP() { + return firstIP; + } + + public void setFirstIP(boolean firstIP) { + this.firstIP = firstIP; + } + + public String getGateway() { + return gateway; + } + + public void setGateway(String gateway) { + this.gateway = gateway; + } + + public String getNetmask() { + return netmask; + } + + public void setNetmask(String netmask) { + this.netmask = netmask; + } + + public String getVifMacAddress() { + return vifMacAddress; + } + + public void setVifMacAddress(String vifMacAddress) { + this.vifMacAddress = vifMacAddress; + } + + public Integer getNicDevId() { + return nicDevId; + } + + public void setNicDevId(Integer nicDevId) { + this.nicDevId = nicDevId; + } + + public boolean isNewNic() { + return newNic; + } + + public void setNewNic(boolean newNic) { + this.newNic = newNic; + } + +} diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/model/IpAssociation.java b/core/src/com/cloud/agent/resource/virtualnetwork/model/IpAssociation.java new file mode 100644 index 00000000000..4a015a8e839 --- /dev/null +++ b/core/src/com/cloud/agent/resource/virtualnetwork/model/IpAssociation.java @@ -0,0 +1,42 @@ +// +// 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.agent.resource.virtualnetwork.model; + +public class IpAssociation extends ConfigBase { + private IpAddress[] ipAddress; + + public IpAssociation() { + setType("ips"); + } + + public IpAssociation(IpAddress[] ipAddress) { + setType("ips"); + this.ipAddress = ipAddress; + } + + public IpAddress[] getIpAddress() { + return ipAddress; + } + + public void setIpAddress(IpAddress[] ipAddress) { + this.ipAddress = ipAddress; + } + +} diff --git a/systemvm/patches/debian/config/opt/cloud/bin/merge.py b/systemvm/patches/debian/config/opt/cloud/bin/merge.py index 35f800c93e4..bd6c7368d4e 100755 --- a/systemvm/patches/debian/config/opt/cloud/bin/merge.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/merge.py @@ -55,7 +55,7 @@ class updateDataBag: self.save(dbag) def processIP(self, dbag): - for ip in self.qFile.data: + for ip in self.qFile.data["ip_address"]: dbag = cs_ip.merge(dbag, ip) return dbag @@ -89,7 +89,6 @@ class loadQueueFile: fileName = '' dpath = "/etc/cloudstack" data = {} - type = 'ips' def load(self): fn = self.dpath + '/' + self.fileName @@ -99,15 +98,16 @@ class loadQueueFile: logging.error("Could not open %s", fn) else: self.data = json.load(handle) + self.type = self.data["type"] handle.close() proc = updateDataBag(self) def setFile(self, name): self.fileName = name - def setType(self, name): - self.type = name - + def getType(self): + return self.type + def getData(self): return self.data diff --git a/systemvm/patches/debian/config/opt/cloud/bin/update_config.py b/systemvm/patches/debian/config/opt/cloud/bin/update_config.py index 63f2004afd0..60d8ddbe745 100644 --- a/systemvm/patches/debian/config/opt/cloud/bin/update_config.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/update_config.py @@ -3,6 +3,8 @@ import sys from merge import loadQueueFile import logging +import subprocess +from subprocess import PIPE logging.basicConfig(filename='/var/log/cloud.log',level=logging.DEBUG, format='%(asctime)s %(message)s') @@ -11,9 +13,20 @@ if ( len(sys.argv) != 2 ): print "Invalid usage" sys.exit(1) -# ip files -if(sys.argv[1].startswith('ip')): - qf = loadQueueFile() - qf.setType("ips") - qf.setFile(sys.argv[1]) - qf.load() +qf = loadQueueFile() +qf.setFile(sys.argv[1]) +qf.load() + +# Converge +chefrun = subprocess.Popen(["/usr/bin/chef-solo", + "-j", "/etc/chef/node.json", + "-l","fatal"], + stdout=PIPE, stderr=PIPE) +result = chefrun.wait() + +if (result != 0): + print result.stderr +else: + print "chef update completed" + +sys.exit(result) diff --git a/systemvm/patches/debian/config/var/chef/cookbooks/csip/libraries/helper.rb b/systemvm/patches/debian/config/var/chef/cookbooks/csip/libraries/helper.rb index bbb2f5bcce0..4cfce4659fc 100644 --- a/systemvm/patches/debian/config/var/chef/cookbooks/csip/libraries/helper.rb +++ b/systemvm/patches/debian/config/var/chef/cookbooks/csip/libraries/helper.rb @@ -39,7 +39,7 @@ def inConfig(ips, dev, tip) return false end ips[dev].each do |o| - oip = o['publicIp'] + '/' << IPAddr.new(o['vlanNetmask']).to_i.to_s(2).count("1").to_s + oip = o['public_ip'] + '/' << IPAddr.new(o['netmask']).to_i.to_s(2).count("1").to_s if oip == tip return true end diff --git a/systemvm/patches/debian/config/var/chef/cookbooks/csip/providers/device.rb b/systemvm/patches/debian/config/var/chef/cookbooks/csip/providers/device.rb index 2dc73bc1c57..d38ba1343e6 100755 --- a/systemvm/patches/debian/config/var/chef/cookbooks/csip/providers/device.rb +++ b/systemvm/patches/debian/config/var/chef/cookbooks/csip/providers/device.rb @@ -28,7 +28,7 @@ def load_current_resource @current_resource.object(@new_resource.object) @current_resource.exists = false if new_resource.cidrs.nil? - @current_resource.cidrs(new_resource.object['public_ip'] + '/' + IPAddr.new( new_resource.object['vlan_netmask']).to_i.to_s(2).count("1").to_s) + @current_resource.cidrs(new_resource.object['public_ip'] + '/' + IPAddr.new( new_resource.object['netmask']).to_i.to_s(2).count("1").to_s) else @current_resource.cidrs(@new_resource.cidrs) end diff --git a/systemvm/patches/debian/config/var/chef/cookbooks/csip/recipes/default.rb b/systemvm/patches/debian/config/var/chef/cookbooks/csip/recipes/default.rb index 7c9884c5d71..b61a87e0eb8 100755 --- a/systemvm/patches/debian/config/var/chef/cookbooks/csip/recipes/default.rb +++ b/systemvm/patches/debian/config/var/chef/cookbooks/csip/recipes/default.rb @@ -62,14 +62,14 @@ vr_ips.each do |name,data| type "dev" table "Table_#{name}" ip ipo['public_ip'] - mask ipo['vlan_netmask'] + mask ipo['netmask'] dev name end csip_route "#{name}-default" do type "default" table "Table_#{name}" - ip ipo['vlan_gateway'] - mask ipo['vlan_netmask'] + ip ipo['gateway'] + mask ipo['netmask'] dev name end end