Skip to content

Commit 7d0df32

Browse files
Ian Southamwilderrodrigues
authored andcommitted
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
1 parent 08d2e10 commit 7d0df32

12 files changed

Lines changed: 116 additions & 23 deletions

File tree

core/src/com/cloud/agent/resource/virtualnetwork/facade/AbstractConfigItemFacade.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ public abstract class AbstractConfigItemFacade {
6363
private static Hashtable<Class<? extends NetworkElementCommand>, AbstractConfigItemFacade> flyweight = new Hashtable<Class<? extends NetworkElementCommand>, AbstractConfigItemFacade>();
6464

6565
static {
66-
gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
66+
gson = new GsonBuilder()
67+
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
68+
.disableHtmlEscaping()
69+
.create();
6770

6871
flyweight.put(SetPortForwardingRulesVpcCommand.class, new SetPortForwardingRulesVpcConfigItem());
6972
flyweight.put(SetPortForwardingRulesCommand.class, new SetPortForwardingRulesConfigItem());
@@ -114,4 +117,4 @@ protected List<ConfigItem> generateConfigItems(final ConfigBase configuration) {
114117
}
115118

116119
public abstract List<ConfigItem> generateConfig(NetworkElementCommand cmd);
117-
}
120+
}

systemvm/patches/debian/config/opt/cloud/bin/configure.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from cs.CsFile import CsFile
3838
from cs.CsAddress import CsAddress
3939
from cs.CsApp import CsApache, CsPasswdSvc, CsDnsmasq
40+
from cs.CsMonitor import CsMonitor
4041

4142

4243
class CsPassword(CsDataBag):
@@ -87,10 +88,7 @@ def __init__(self, obj, fw):
8788

8889
def create(self):
8990
for cidr in self.rule['cidr']:
90-
self.add_rule()
91-
if self.ip != '':
92-
# Always append default drop
93-
self.fw.append(["mangle", "", "-A FIREWALL_%s -j DROP" % self.ip])
91+
self.add_rule(cidr)
9492

9593
def add_rule(self, cidr):
9694
icmp_type = ''
@@ -567,8 +565,12 @@ def main(argv):
567565
nf = CsNetfilters()
568566
nf.compare(config.get_fw())
569567

570-
dh = CsDataBag("dhcpentry")
571-
dhcp = CsDhcp(dh.get_bag(), config.get_cmdline())
568+
dhcp = CsDhcp("dhcpentry", config)
569+
dhcp.process()
570+
571+
mon = CsMonitor("monitorservice", config)
572+
mon.process()
573+
572574

573575
if __name__ == "__main__":
574576
main(sys.argv)

systemvm/patches/debian/config/opt/cloud/bin/cs/CsAddress.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ def fw_router(self):
300300
self.fw.append(["mangle", "",
301301
"-A PREROUTING -i %s -m state --state NEW " % self.dev +
302302
"-j CONNMARK --set-xmark 0x%s/0xffffffff" % self.dnum])
303+
self.fw.append(["mangle", "", "-A FIREWALL_%s -j DROP" % self.address['public_ip']])
303304

304305
self.fw.append(["filter", "", "-A INPUT -d 224.0.0.18/32 -j ACCEPT"])
305306
self.fw.append(["filter", "", "-A INPUT -d 225.0.0.50/32 -j ACCEPT"])

systemvm/patches/debian/config/opt/cloud/bin/cs/CsConfig.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ def get_level(self):
5151
def is_vpc(self):
5252
return self.cl.get_type() == "vpcrouter"
5353

54+
def get_domain(self):
55+
return self.cl.get_domain()
56+
5457
def get_format(self):
5558
return self.__LOG_FORMAT
5659

systemvm/patches/debian/config/opt/cloud/bin/cs/CsDatabag.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ def get_type(self):
6868
else:
6969
return "unknown"
7070

71+
def get_domain(self):
72+
if "domain" in self.dbag['config']:
73+
return self.dbag['config']['domain']
74+
else:
75+
return "cloudnine.internal"
76+
7177
def get_vpccidr(self):
7278
if "vpccidr" in self.dbag['config']:
7379
return self.dbag['config']['vpccidr']

systemvm/patches/debian/config/opt/cloud/bin/cs/CsDhcp.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import logging
1919
from netaddr import *
2020
from CsGuestNetwork import CsGuestNetwork
21+
from cs.CsDatabag import CsDataBag
2122

2223
NO_PRELOAD = False
2324
LEASES = "/var/lib/misc/dnsmasq.leases"
@@ -27,16 +28,16 @@
2728
CLOUD_CONF = "/etc/dnsmasq.d/cloud.conf"
2829

2930

30-
class CsDhcp(object):
31+
class CsDhcp(CsDataBag):
3132
""" Manage dhcp entries """
3233

33-
def __init__(self, dbag, cl):
34-
dnsmasq = CsDnsMasq()
35-
for item in dbag:
34+
def process(self):
35+
dnsmasq = CsDnsMasq(self.config)
36+
for item in self.dbag:
3637
if item == "id":
3738
continue
38-
dnsmasq.add(dbag[item])
39-
dnsmasqb4 = CsDnsMasq(NO_PRELOAD)
39+
dnsmasq.add(self.dbag[item])
40+
dnsmasqb4 = CsDnsMasq(self.config, NO_PRELOAD)
4041
dnsmasqb4.parse_hosts()
4142
dnsmasqb4.parse_dnsmasq()
4243
if not dnsmasq.compare_hosts(dnsmasqb4):
@@ -55,10 +56,11 @@ def __init__(self, dbag, cl):
5556

5657
class CsDnsMasq(object):
5758

58-
def __init__(self, preload=True):
59+
def __init__(self, config, preload=True):
5960
self.list = []
6061
self.hosts = []
6162
self.leases = []
63+
self.config = config
6264
self.updated = False
6365
self.devinfo = CsHelper.get_device_info()
6466
self.devs = []
@@ -108,7 +110,7 @@ def configure_server(self):
108110
self.updated = self.updated | CsHelper.addifmissing(CLOUD_CONF, line)
109111
# Next add the domain
110112
# if this is a guest network get it there otherwise use the value in resolv.conf
111-
gn = CsGuestNetwork(device)
113+
gn = CsGuestNetwork(device, self.cl)
112114
line = "dhcp-option=tag:interface-%s,15,%s" % (device, gn.get_domain())
113115
self.updated = self.updated | CsHelper.addifmissing(CLOUD_CONF, line)
114116
if self.updated:

systemvm/patches/debian/config/opt/cloud/bin/cs/CsGuestNetwork.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919

2020

2121
class CsGuestNetwork:
22-
def __init__(self, device):
22+
def __init__(self, device, config):
2323
self.data = {}
2424
self.guest = True
2525
db = DataBag()
2626
db.setKey("guestnetwork")
2727
db.load()
2828
dbag = db.getDataBag()
29+
self.config = config
2930
if device in dbag.keys() and len(dbag[device]) != 0:
3031
self.data = dbag[device][0]
3132
else:
@@ -37,7 +38,7 @@ def is_guestnetwork(self):
3738
def get_domain(self):
3839
domain = "cloudnine.internal"
3940
if not self.guest:
40-
return CsHelper.get_domain()
41+
return self.config.get_domain()
4142

4243
if 'domain_name' in self.data:
4344
return self.data['domain_name']
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
import logging
18+
from cs.CsDatabag import CsDataBag
19+
from CsFile import CsFile
20+
21+
MON_CONFIG = "/etc/monitor.conf"
22+
23+
24+
class CsMonitor(CsDataBag):
25+
""" Manage dhcp entries """
26+
27+
def process(self):
28+
if "config" not in self.dbag:
29+
return
30+
procs = [x.strip() for x in self.dbag['config'].split(',')]
31+
file = CsFile(MON_CONFIG)
32+
for proc in procs:
33+
bits = [x for x in proc.split(':')]
34+
if len(bits) < 5:
35+
continue
36+
for i in range(0, 4):
37+
file.add(bits[i], -1)
38+
file.commit()
39+
cron = CsFile("/etc/cron.d/process")
40+
cron.add("SHELL=/bin/bash", 0)
41+
cron.add("PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin", 1)
42+
cron.add("*/3 * * * * root /usr/bin/python /root/monitorServices.py", -1)
43+
cron.commit()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
18+
from pprint import pprint
19+
from netaddr import *
20+
21+
22+
def merge(dbag, data):
23+
24+
if "config" in data:
25+
dbag['config'] = data["config"]
26+
return dbag

systemvm/patches/debian/config/opt/cloud/bin/merge.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import cs_vmp
2727
import cs_network_acl
2828
import cs_firewallrules
29+
import cs_monitorservice
2930
import cs_vmdata
3031
import cs_dhcp
3132
import cs_forwardingrules
@@ -105,6 +106,8 @@ def process(self):
105106
dbag = self.process_network_acl(self.db.getDataBag())
106107
elif self.qFile.type == 'firewallrules':
107108
dbag = self.process_firewallrules(self.db.getDataBag())
109+
elif self.qFile.type == 'monitorservice':
110+
dbag = self.process_monitorservice(self.db.getDataBag())
108111
elif self.qFile.type == 'vmdata':
109112
dbag = self.processVmData(self.db.getDataBag())
110113
elif self.qFile.type == 'dhcpentry':
@@ -147,6 +150,9 @@ def process_network_acl(self, dbag):
147150
def process_firewallrules(self, dbag):
148151
return cs_firewallrules.merge(dbag, self.qFile.data)
149152

153+
def process_monitorservice(self, dbag):
154+
return cs_monitorservice.merge(dbag, self.qFile.data)
155+
150156
def processVMpassword(self, dbag):
151157
return cs_vmp.merge(dbag, self.qFile.data)
152158

0 commit comments

Comments
 (0)