mirror of https://github.com/apache/cloudstack.git
Switch ip associations to new model and update the recipes
This commit is contained in:
parent
183b248c4e
commit
0027db6cd1
|
|
@ -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<ConfigItem> generateConfig(IpAssocCommand cmd) {
|
||||
LinkedList<ConfigItem> cfg = new LinkedList<>();
|
||||
// Reuse the IpAddressTO model
|
||||
ConfigItem ipAssociationsFile = new FileConfigItem(VRScripts.CONFIG_PERSIST_LOCATION, VRScripts.IP_ASSOCIATION_CONFIG, gson.toJson(cmd.getIpAddresses()));
|
||||
List<IpAddress> ips = new LinkedList<IpAddress>();
|
||||
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue