Skip to content

Commit 5442df2

Browse files
author
Prasanna Santhanam
committed
devcloud-kvm: marvin deployment config generator for devcloud-kvm
The devcloud-kvm.py script will take the kvm.properties file to generate an advanced zone configuration with two physical networks with traffic labels for 'guest' and 'public' traffic going on 'eth0' and 'eth1' respectively. To generate config: $ python devcloud-kvm.py -i kvm.properties -o devcloud-kvm-advanced.cfg Signed-off-by: Prasanna Santhanam <tsp@apache.org>
1 parent 8d3cbc8 commit 5442df2

3 files changed

Lines changed: 402 additions & 0 deletions

File tree

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
{
2+
"zones": [
3+
{
4+
"localstorageenabled": "true",
5+
"name": "Devcloud-KVM",
6+
"guestcidraddress": "10.1.1.0/24",
7+
"dns1": "8.8.8.8",
8+
"physical_networks": [
9+
{
10+
"name": "eth0",
11+
"providers": [
12+
{
13+
"broadcastdomainrange": "ZONE",
14+
"name": "VirtualRouter"
15+
},
16+
{
17+
"broadcastdomainrange": "ZONE",
18+
"name": "VpcVirtualRouter"
19+
}
20+
],
21+
"broadcastdomainrange": "Zone",
22+
"vlan": "3900-3919",
23+
"traffictypes": [
24+
{
25+
"kvm": "kvm-guest",
26+
"typ": "Guest"
27+
},
28+
{
29+
"typ": "Management"
30+
}
31+
],
32+
"tags": [
33+
"devcloud-guest"
34+
]
35+
},
36+
{
37+
"name": "eth1",
38+
"providers": [
39+
{
40+
"broadcastdomainrange": "ZONE",
41+
"name": "VirtualRouter"
42+
},
43+
{
44+
"broadcastdomainrange": "ZONE",
45+
"name": "VpcVirtualRouter"
46+
}
47+
],
48+
"broadcastdomainrange": "Zone",
49+
"vlan": "3920-3939",
50+
"traffictypes": [
51+
{
52+
"kvm": "kvm-public",
53+
"typ": "Public"
54+
}
55+
],
56+
"tags": [
57+
"devcloud-public"
58+
]
59+
}
60+
],
61+
"ipranges": [
62+
{
63+
"startip": "10.0.3.100",
64+
"endip": "10.0.3.199",
65+
"netmask": "255.255.255.0",
66+
"vlan": "31",
67+
"gateway": "10.0.3.2"
68+
}
69+
],
70+
"networktype": "Advanced",
71+
"pods": [
72+
{
73+
"endip": "192.168.56.249",
74+
"name": "POD0",
75+
"startip": "192.168.56.200",
76+
"netmask": "255.255.255.0",
77+
"clusters": [
78+
{
79+
"clustername": "C0",
80+
"hypervisor": "KVM",
81+
"hosts": [
82+
{
83+
"username": "root",
84+
"url": "http://192.168.56.10",
85+
"password": "password"
86+
}
87+
],
88+
"clustertype": "CloudManaged",
89+
"primaryStorages": [
90+
{
91+
"url": "nfs://192.168.56.10/opt/storage/primary",
92+
"name": "PS0"
93+
}
94+
]
95+
}
96+
],
97+
"gateway": "192.168.56.1"
98+
}
99+
],
100+
"internaldns1": "8.8.8.8",
101+
"secondaryStorages": [
102+
{
103+
"url": "nfs://192.168.56.10/opt/storage/secondary"
104+
}
105+
]
106+
}
107+
],
108+
"dbSvr": {
109+
"dbSvr": "127.0.0.1",
110+
"passwd": "cloud",
111+
"db": "cloud",
112+
"port": 3306,
113+
"user": "cloud"
114+
},
115+
"logger": [
116+
{
117+
"name": "TestClient",
118+
"file": "testclient.log"
119+
},
120+
{
121+
"name": "TestCase",
122+
"file": "testcase.log"
123+
}
124+
],
125+
"globalConfig": [
126+
{
127+
"name": "storage.cleanup.interval",
128+
"value": "300"
129+
},
130+
{
131+
"name": "instance.name",
132+
"value": "vm"
133+
},
134+
{
135+
"name": "workers",
136+
"value": "10"
137+
},
138+
{
139+
"name": "vm.op.wait.interval",
140+
"value": "5"
141+
},
142+
{
143+
"name": "account.cleanup.interval",
144+
"value": "600"
145+
},
146+
{
147+
"name": "guest.domain.suffix",
148+
"value": "devcloud.kvm"
149+
},
150+
{
151+
"name": "expunge.delay",
152+
"value": "60"
153+
},
154+
{
155+
"name": "vm.allocation.algorithm",
156+
"value": "random"
157+
},
158+
{
159+
"name": "expunge.interval",
160+
"value": "60"
161+
},
162+
{
163+
"name": "expunge.workers",
164+
"value": "3"
165+
},
166+
{
167+
"name": "secstorage.allowed.internal.sites",
168+
"value": "10.147.28.0/24"
169+
},
170+
{
171+
"name": "check.pod.cidrs",
172+
"value": "true"
173+
}
174+
],
175+
"mgtSvr": [
176+
{
177+
"mgtSvrIp": "127.0.0.1",
178+
"passwd": "password",
179+
"user": "root",
180+
"port": 8096
181+
}
182+
]
183+
}

tools/devcloud-kvm/devcloud-kvm.py

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
#!/usr/bin/env python
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
'''
19+
############################################################
20+
# Experimental state of scripts
21+
# * Need to be reviewed
22+
# * Only a sandbox
23+
############################################################
24+
'''
25+
import random
26+
import marvin
27+
from ConfigParser import SafeConfigParser
28+
from optparse import OptionParser
29+
from marvin.configGenerator import *
30+
31+
32+
def getGlobalSettings(config):
33+
for k, v in dict(config.items('globals')).iteritems():
34+
cfg = configuration()
35+
cfg.name = k
36+
cfg.value = v
37+
yield cfg
38+
39+
40+
def describeDevcloudKvmResources(config):
41+
zs = cloudstackConfiguration()
42+
43+
z = zone()
44+
z.dns1 = config.get('environment', 'dns')
45+
z.internaldns1 = config.get('environment', 'dns')
46+
z.name = 'Devcloud-%s'%(config.get('cloudstack', 'hypervisor'))
47+
z.networktype = 'Advanced'
48+
z.guestcidraddress = '10.1.1.0/24'
49+
z.localstorageenabled = 'true'
50+
51+
vpcprovider = provider()
52+
vpcprovider.name = 'VpcVirtualRouter'
53+
54+
pn = physical_network()
55+
pn.name = "eth0"
56+
pn.vlan = config.get('cloudstack', 'pnet.vlan')
57+
pn.tags = ["devcloud-guest"]
58+
pn.traffictypes = [traffictype("Guest", {"kvm" :"kvm-guest" }), traffictype("Management")]
59+
pn.providers.append(vpcprovider)
60+
61+
pn2 = physical_network()
62+
pn2.name = "eth1"
63+
pn2.vlan = config.get('cloudstack', 'pnet2.vlan')
64+
pn2.tags = ["devcloud-public"]
65+
pn2.traffictypes = [traffictype("Public", {"kvm" : "kvm-public"})]
66+
pn2.providers.append(vpcprovider)
67+
68+
z.physical_networks.append(pn)
69+
z.physical_networks.append(pn2)
70+
71+
p = pod()
72+
p.name = 'POD0'
73+
p.gateway = config.get('cloudstack', 'private.gateway')
74+
p.startip = config.get('cloudstack', 'private.pod.startip')
75+
p.endip = config.get('cloudstack', 'private.pod.endip')
76+
p.netmask = config.get('cloudstack', 'private.netmask')
77+
78+
v = iprange()
79+
v.gateway = config.get('cloudstack', 'public.gateway')
80+
v.startip = config.get('cloudstack', 'public.vlan.startip')
81+
v.endip = config.get('cloudstack', 'public.vlan.endip')
82+
v.netmask = config.get('cloudstack', 'public.netmask')
83+
v.vlan = config.get('cloudstack', 'public.vlan')
84+
z.ipranges.append(v)
85+
86+
c = cluster()
87+
c.clustername = 'C0'
88+
c.hypervisor = config.get('cloudstack', 'hypervisor')
89+
c.clustertype = 'CloudManaged'
90+
91+
h = host()
92+
h.username = 'root'
93+
h.password = config.get('cloudstack', 'host.password')
94+
h.url = 'http://%s'%(config.get('cloudstack', 'host'))
95+
c.hosts.append(h)
96+
97+
ps = primaryStorage()
98+
ps.name = 'PS0'
99+
ps.url = config.get('cloudstack', 'primary.pool')
100+
c.primaryStorages.append(ps)
101+
102+
p.clusters.append(c)
103+
z.pods.append(p)
104+
105+
secondary = secondaryStorage()
106+
secondary.url = config.get('cloudstack', 'secondary.pool')
107+
z.secondaryStorages.append(secondary)
108+
109+
'''Add zone'''
110+
zs.zones.append(z)
111+
112+
'''Add mgt server'''
113+
mgt = managementServer()
114+
mgt.mgtSvrIp = config.get('environment', 'mshost')
115+
mgt.user = config.get('environment', 'mshost.user')
116+
mgt.passwd = config.get('environment', 'mshost.passwd')
117+
zs.mgtSvr.append(mgt)
118+
119+
'''Add a database'''
120+
db = dbServer()
121+
db.dbSvr = config.get('environment', 'mysql.host')
122+
db.user = config.get('environment', 'mysql.cloud.user')
123+
db.passwd = config.get('environment', 'mysql.cloud.passwd')
124+
zs.dbSvr = db
125+
126+
'''Add some configuration'''
127+
[zs.globalConfig.append(cfg) for cfg in getGlobalSettings(config)]
128+
129+
''''add loggers'''
130+
testClientLogger = logger()
131+
testClientLogger.name = 'TestClient'
132+
testClientLogger.file = 'testclient.log'
133+
134+
testCaseLogger = logger()
135+
testCaseLogger.name = 'TestCase'
136+
testCaseLogger.file = 'testcase.log'
137+
138+
zs.logger.append(testClientLogger)
139+
zs.logger.append(testCaseLogger)
140+
return zs
141+
142+
143+
if __name__ == '__main__':
144+
parser = OptionParser()
145+
parser.add_option('-i', '--input', action='store', default='setup.properties', \
146+
dest='input', help='file containing environment setup information')
147+
parser.add_option('-o', '--output', action='store', default='./devcloud-kvm-advanced.cfg', \
148+
dest='output', help='path where environment json will be generated')
149+
150+
151+
(opts, args) = parser.parse_args()
152+
153+
cfg_parser = SafeConfigParser()
154+
cfg_parser.read(opts.input)
155+
156+
cfg = describeDevcloudKvmResources(cfg_parser)
157+
generate_setup_config(cfg, opts.output)

0 commit comments

Comments
 (0)