mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Lots of fixes from the testing
firewallrules implemented sperately from networkacl (ugly but best that can be done ATM) Some refactoring in CsDHCP as it made no sense to do it that way anymore processmonitoring implemented Domain not correctly sourced in VR
This commit is contained in:
parent
08d2e10cb9
commit
7d0df32560
@ -63,7 +63,10 @@ public abstract class AbstractConfigItemFacade {
|
|||||||
private static Hashtable<Class<? extends NetworkElementCommand>, AbstractConfigItemFacade> flyweight = new Hashtable<Class<? extends NetworkElementCommand>, AbstractConfigItemFacade>();
|
private static Hashtable<Class<? extends NetworkElementCommand>, AbstractConfigItemFacade> flyweight = new Hashtable<Class<? extends NetworkElementCommand>, AbstractConfigItemFacade>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
|
gson = new GsonBuilder()
|
||||||
|
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
|
||||||
|
.disableHtmlEscaping()
|
||||||
|
.create();
|
||||||
|
|
||||||
flyweight.put(SetPortForwardingRulesVpcCommand.class, new SetPortForwardingRulesVpcConfigItem());
|
flyweight.put(SetPortForwardingRulesVpcCommand.class, new SetPortForwardingRulesVpcConfigItem());
|
||||||
flyweight.put(SetPortForwardingRulesCommand.class, new SetPortForwardingRulesConfigItem());
|
flyweight.put(SetPortForwardingRulesCommand.class, new SetPortForwardingRulesConfigItem());
|
||||||
@ -114,4 +117,4 @@ public abstract class AbstractConfigItemFacade {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public abstract List<ConfigItem> generateConfig(NetworkElementCommand cmd);
|
public abstract List<ConfigItem> generateConfig(NetworkElementCommand cmd);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,6 +37,7 @@ from cs.CsRedundant import *
|
|||||||
from cs.CsFile import CsFile
|
from cs.CsFile import CsFile
|
||||||
from cs.CsAddress import CsAddress
|
from cs.CsAddress import CsAddress
|
||||||
from cs.CsApp import CsApache, CsPasswdSvc, CsDnsmasq
|
from cs.CsApp import CsApache, CsPasswdSvc, CsDnsmasq
|
||||||
|
from cs.CsMonitor import CsMonitor
|
||||||
|
|
||||||
|
|
||||||
class CsPassword(CsDataBag):
|
class CsPassword(CsDataBag):
|
||||||
@ -87,10 +88,7 @@ class CsAcl(CsDataBag):
|
|||||||
|
|
||||||
def create(self):
|
def create(self):
|
||||||
for cidr in self.rule['cidr']:
|
for cidr in self.rule['cidr']:
|
||||||
self.add_rule()
|
self.add_rule(cidr)
|
||||||
if self.ip != '':
|
|
||||||
# Always append default drop
|
|
||||||
self.fw.append(["mangle", "", "-A FIREWALL_%s -j DROP" % self.ip])
|
|
||||||
|
|
||||||
def add_rule(self, cidr):
|
def add_rule(self, cidr):
|
||||||
icmp_type = ''
|
icmp_type = ''
|
||||||
@ -567,8 +565,12 @@ def main(argv):
|
|||||||
nf = CsNetfilters()
|
nf = CsNetfilters()
|
||||||
nf.compare(config.get_fw())
|
nf.compare(config.get_fw())
|
||||||
|
|
||||||
dh = CsDataBag("dhcpentry")
|
dhcp = CsDhcp("dhcpentry", config)
|
||||||
dhcp = CsDhcp(dh.get_bag(), config.get_cmdline())
|
dhcp.process()
|
||||||
|
|
||||||
|
mon = CsMonitor("monitorservice", config)
|
||||||
|
mon.process()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main(sys.argv)
|
main(sys.argv)
|
||||||
|
|||||||
@ -300,6 +300,7 @@ class CsIP:
|
|||||||
self.fw.append(["mangle", "",
|
self.fw.append(["mangle", "",
|
||||||
"-A PREROUTING -i %s -m state --state NEW " % self.dev +
|
"-A PREROUTING -i %s -m state --state NEW " % self.dev +
|
||||||
"-j CONNMARK --set-xmark 0x%s/0xffffffff" % self.dnum])
|
"-j CONNMARK --set-xmark 0x%s/0xffffffff" % self.dnum])
|
||||||
|
self.fw.append(["mangle", "", "-A FIREWALL_%s -j DROP" % self.address['public_ip']])
|
||||||
|
|
||||||
self.fw.append(["filter", "", "-A INPUT -d 224.0.0.18/32 -j ACCEPT"])
|
self.fw.append(["filter", "", "-A INPUT -d 224.0.0.18/32 -j ACCEPT"])
|
||||||
self.fw.append(["filter", "", "-A INPUT -d 225.0.0.50/32 -j ACCEPT"])
|
self.fw.append(["filter", "", "-A INPUT -d 225.0.0.50/32 -j ACCEPT"])
|
||||||
|
|||||||
@ -51,6 +51,9 @@ class CsConfig(object):
|
|||||||
def is_vpc(self):
|
def is_vpc(self):
|
||||||
return self.cl.get_type() == "vpcrouter"
|
return self.cl.get_type() == "vpcrouter"
|
||||||
|
|
||||||
|
def get_domain(self):
|
||||||
|
return self.cl.get_domain()
|
||||||
|
|
||||||
def get_format(self):
|
def get_format(self):
|
||||||
return self.__LOG_FORMAT
|
return self.__LOG_FORMAT
|
||||||
|
|
||||||
|
|||||||
@ -68,6 +68,12 @@ class CsCmdLine(CsDataBag):
|
|||||||
else:
|
else:
|
||||||
return "unknown"
|
return "unknown"
|
||||||
|
|
||||||
|
def get_domain(self):
|
||||||
|
if "domain" in self.dbag['config']:
|
||||||
|
return self.dbag['config']['domain']
|
||||||
|
else:
|
||||||
|
return "cloudnine.internal"
|
||||||
|
|
||||||
def get_vpccidr(self):
|
def get_vpccidr(self):
|
||||||
if "vpccidr" in self.dbag['config']:
|
if "vpccidr" in self.dbag['config']:
|
||||||
return self.dbag['config']['vpccidr']
|
return self.dbag['config']['vpccidr']
|
||||||
|
|||||||
@ -18,6 +18,7 @@ import CsHelper
|
|||||||
import logging
|
import logging
|
||||||
from netaddr import *
|
from netaddr import *
|
||||||
from CsGuestNetwork import CsGuestNetwork
|
from CsGuestNetwork import CsGuestNetwork
|
||||||
|
from cs.CsDatabag import CsDataBag
|
||||||
|
|
||||||
NO_PRELOAD = False
|
NO_PRELOAD = False
|
||||||
LEASES = "/var/lib/misc/dnsmasq.leases"
|
LEASES = "/var/lib/misc/dnsmasq.leases"
|
||||||
@ -27,16 +28,16 @@ DNSMASQ_CONF = "/etc/dnsmasq.conf"
|
|||||||
CLOUD_CONF = "/etc/dnsmasq.d/cloud.conf"
|
CLOUD_CONF = "/etc/dnsmasq.d/cloud.conf"
|
||||||
|
|
||||||
|
|
||||||
class CsDhcp(object):
|
class CsDhcp(CsDataBag):
|
||||||
""" Manage dhcp entries """
|
""" Manage dhcp entries """
|
||||||
|
|
||||||
def __init__(self, dbag, cl):
|
def process(self):
|
||||||
dnsmasq = CsDnsMasq()
|
dnsmasq = CsDnsMasq(self.config)
|
||||||
for item in dbag:
|
for item in self.dbag:
|
||||||
if item == "id":
|
if item == "id":
|
||||||
continue
|
continue
|
||||||
dnsmasq.add(dbag[item])
|
dnsmasq.add(self.dbag[item])
|
||||||
dnsmasqb4 = CsDnsMasq(NO_PRELOAD)
|
dnsmasqb4 = CsDnsMasq(self.config, NO_PRELOAD)
|
||||||
dnsmasqb4.parse_hosts()
|
dnsmasqb4.parse_hosts()
|
||||||
dnsmasqb4.parse_dnsmasq()
|
dnsmasqb4.parse_dnsmasq()
|
||||||
if not dnsmasq.compare_hosts(dnsmasqb4):
|
if not dnsmasq.compare_hosts(dnsmasqb4):
|
||||||
@ -55,10 +56,11 @@ class CsDhcp(object):
|
|||||||
|
|
||||||
class CsDnsMasq(object):
|
class CsDnsMasq(object):
|
||||||
|
|
||||||
def __init__(self, preload=True):
|
def __init__(self, config, preload=True):
|
||||||
self.list = []
|
self.list = []
|
||||||
self.hosts = []
|
self.hosts = []
|
||||||
self.leases = []
|
self.leases = []
|
||||||
|
self.config = config
|
||||||
self.updated = False
|
self.updated = False
|
||||||
self.devinfo = CsHelper.get_device_info()
|
self.devinfo = CsHelper.get_device_info()
|
||||||
self.devs = []
|
self.devs = []
|
||||||
@ -108,7 +110,7 @@ class CsDnsMasq(object):
|
|||||||
self.updated = self.updated | CsHelper.addifmissing(CLOUD_CONF, line)
|
self.updated = self.updated | CsHelper.addifmissing(CLOUD_CONF, line)
|
||||||
# Next add the domain
|
# Next add the domain
|
||||||
# if this is a guest network get it there otherwise use the value in resolv.conf
|
# if this is a guest network get it there otherwise use the value in resolv.conf
|
||||||
gn = CsGuestNetwork(device)
|
gn = CsGuestNetwork(device, self.cl)
|
||||||
line = "dhcp-option=tag:interface-%s,15,%s" % (device, gn.get_domain())
|
line = "dhcp-option=tag:interface-%s,15,%s" % (device, gn.get_domain())
|
||||||
self.updated = self.updated | CsHelper.addifmissing(CLOUD_CONF, line)
|
self.updated = self.updated | CsHelper.addifmissing(CLOUD_CONF, line)
|
||||||
if self.updated:
|
if self.updated:
|
||||||
|
|||||||
@ -19,13 +19,14 @@ import CsHelper
|
|||||||
|
|
||||||
|
|
||||||
class CsGuestNetwork:
|
class CsGuestNetwork:
|
||||||
def __init__(self, device):
|
def __init__(self, device, config):
|
||||||
self.data = {}
|
self.data = {}
|
||||||
self.guest = True
|
self.guest = True
|
||||||
db = DataBag()
|
db = DataBag()
|
||||||
db.setKey("guestnetwork")
|
db.setKey("guestnetwork")
|
||||||
db.load()
|
db.load()
|
||||||
dbag = db.getDataBag()
|
dbag = db.getDataBag()
|
||||||
|
self.config = config
|
||||||
if device in dbag.keys() and len(dbag[device]) != 0:
|
if device in dbag.keys() and len(dbag[device]) != 0:
|
||||||
self.data = dbag[device][0]
|
self.data = dbag[device][0]
|
||||||
else:
|
else:
|
||||||
@ -37,7 +38,7 @@ class CsGuestNetwork:
|
|||||||
def get_domain(self):
|
def get_domain(self):
|
||||||
domain = "cloudnine.internal"
|
domain = "cloudnine.internal"
|
||||||
if not self.guest:
|
if not self.guest:
|
||||||
return CsHelper.get_domain()
|
return self.config.get_domain()
|
||||||
|
|
||||||
if 'domain_name' in self.data:
|
if 'domain_name' in self.data:
|
||||||
return self.data['domain_name']
|
return self.data['domain_name']
|
||||||
|
|||||||
43
systemvm/patches/debian/config/opt/cloud/bin/cs/CsMonitor.py
Normal file
43
systemvm/patches/debian/config/opt/cloud/bin/cs/CsMonitor.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
# 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.
|
||||||
|
import logging
|
||||||
|
from cs.CsDatabag import CsDataBag
|
||||||
|
from CsFile import CsFile
|
||||||
|
|
||||||
|
MON_CONFIG = "/etc/monitor.conf"
|
||||||
|
|
||||||
|
|
||||||
|
class CsMonitor(CsDataBag):
|
||||||
|
""" Manage dhcp entries """
|
||||||
|
|
||||||
|
def process(self):
|
||||||
|
if "config" not in self.dbag:
|
||||||
|
return
|
||||||
|
procs = [x.strip() for x in self.dbag['config'].split(',')]
|
||||||
|
file = CsFile(MON_CONFIG)
|
||||||
|
for proc in procs:
|
||||||
|
bits = [x for x in proc.split(':')]
|
||||||
|
if len(bits) < 5:
|
||||||
|
continue
|
||||||
|
for i in range(0, 4):
|
||||||
|
file.add(bits[i], -1)
|
||||||
|
file.commit()
|
||||||
|
cron = CsFile("/etc/cron.d/process")
|
||||||
|
cron.add("SHELL=/bin/bash", 0)
|
||||||
|
cron.add("PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin", 1)
|
||||||
|
cron.add("*/3 * * * * root /usr/bin/python /root/monitorServices.py", -1)
|
||||||
|
cron.commit()
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
# 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.
|
||||||
|
|
||||||
|
from pprint import pprint
|
||||||
|
from netaddr import *
|
||||||
|
|
||||||
|
|
||||||
|
def merge(dbag, data):
|
||||||
|
|
||||||
|
if "config" in data:
|
||||||
|
dbag['config'] = data["config"]
|
||||||
|
return dbag
|
||||||
@ -26,6 +26,7 @@ import cs_cmdline
|
|||||||
import cs_vmp
|
import cs_vmp
|
||||||
import cs_network_acl
|
import cs_network_acl
|
||||||
import cs_firewallrules
|
import cs_firewallrules
|
||||||
|
import cs_monitorservice
|
||||||
import cs_vmdata
|
import cs_vmdata
|
||||||
import cs_dhcp
|
import cs_dhcp
|
||||||
import cs_forwardingrules
|
import cs_forwardingrules
|
||||||
@ -105,6 +106,8 @@ class updateDataBag:
|
|||||||
dbag = self.process_network_acl(self.db.getDataBag())
|
dbag = self.process_network_acl(self.db.getDataBag())
|
||||||
elif self.qFile.type == 'firewallrules':
|
elif self.qFile.type == 'firewallrules':
|
||||||
dbag = self.process_firewallrules(self.db.getDataBag())
|
dbag = self.process_firewallrules(self.db.getDataBag())
|
||||||
|
elif self.qFile.type == 'monitorservice':
|
||||||
|
dbag = self.process_monitorservice(self.db.getDataBag())
|
||||||
elif self.qFile.type == 'vmdata':
|
elif self.qFile.type == 'vmdata':
|
||||||
dbag = self.processVmData(self.db.getDataBag())
|
dbag = self.processVmData(self.db.getDataBag())
|
||||||
elif self.qFile.type == 'dhcpentry':
|
elif self.qFile.type == 'dhcpentry':
|
||||||
@ -147,6 +150,9 @@ class updateDataBag:
|
|||||||
def process_firewallrules(self, dbag):
|
def process_firewallrules(self, dbag):
|
||||||
return cs_firewallrules.merge(dbag, self.qFile.data)
|
return cs_firewallrules.merge(dbag, self.qFile.data)
|
||||||
|
|
||||||
|
def process_monitorservice(self, dbag):
|
||||||
|
return cs_monitorservice.merge(dbag, self.qFile.data)
|
||||||
|
|
||||||
def processVMpassword(self, dbag):
|
def processVMpassword(self, dbag):
|
||||||
return cs_vmp.merge(dbag, self.qFile.data)
|
return cs_vmp.merge(dbag, self.qFile.data)
|
||||||
|
|
||||||
|
|||||||
@ -10,10 +10,10 @@ class TestCsDhcp(unittest.TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
merge.DataBag.DPATH = "."
|
merge.DataBag.DPATH = "."
|
||||||
|
|
||||||
@mock.patch('cs.CsDhcp.CsHelper')
|
# @mock.patch('cs.CsDhcp.CsHelper')
|
||||||
@mock.patch('cs.CsDhcp.CsDnsMasq')
|
# @mock.patch('cs.CsDhcp.CsDnsMasq')
|
||||||
def test_init(self, mock_cshelper, mock_dnsmasq):
|
def test_init(self):
|
||||||
csdhcp = CsDhcp({}, None)
|
csdhcp = CsDhcp("dhcpentry", {})
|
||||||
self.assertTrue(csdhcp is not None)
|
self.assertTrue(csdhcp is not None)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@ -9,7 +9,7 @@ class TestCsGuestNetwork(unittest.TestCase):
|
|||||||
merge.DataBag.DPATH = "."
|
merge.DataBag.DPATH = "."
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
csguestnetwork = CsGuestNetwork({})
|
csguestnetwork = CsGuestNetwork({}, {})
|
||||||
self.assertTrue(csguestnetwork is not None)
|
self.assertTrue(csguestnetwork is not None)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user