|
| 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