mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			129 lines
		
	
	
		
			3.9 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			129 lines
		
	
	
		
			3.9 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| #!/usr/bin/env python
 | |
| # Copyright 2012 Citrix Systems, Inc. Licensed under the
 | |
| # Apache License, Version 2.0 (the "License"); you may not use this
 | |
| # file except in compliance with the License.  Citrix Systems, Inc.
 | |
| # reserves all rights not expressly granted by 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.
 | |
| # 
 | |
| # Automatically generated by addcopyright.py at 04/03/2012
 | |
| 
 | |
| '''
 | |
| # Experimental state of scripts 
 | |
| #    * Need to be reviewed
 | |
| #    * Only a sandbox
 | |
| '''
 | |
| 
 | |
| from ConfigParser import SafeConfigParser
 | |
| from optparse import OptionParser
 | |
| from configGenerator import *
 | |
| import random
 | |
| 
 | |
| 
 | |
| def getGlobalSettings(config):
 | |
|    for k, v in dict(config.items('globals')).iteritems():
 | |
|         cfg = configuration()
 | |
|         cfg.name = k
 | |
|         cfg.value = v
 | |
|         yield cfg
 | |
| 
 | |
| 
 | |
| def describeResources(config):
 | |
|     zs = cloudstackConfiguration()
 | |
| 
 | |
|     z = zone()
 | |
|     z.dns1 = config.get('environment', 'dns')
 | |
|     z.internaldns1 = config.get('environment', 'dns')
 | |
|     z.name = 'Sandbox-%s'%(config.get('environment', 'hypervisor'))
 | |
|     z.networktype = 'Advanced'
 | |
|     z.guestcidraddress = '10.1.1.0/24'
 | |
|     z.vlan = config.get('cloudstack','guest.vlan')
 | |
| 
 | |
|     p = pod()
 | |
|     p.name = 'POD0'
 | |
|     p.gateway = config.get('cloudstack', 'private.gateway')
 | |
|     p.startip =  config.get('cloudstack', 'private.pod.startip')
 | |
|     p.endip =  config.get('cloudstack', 'private.pod.endip')
 | |
|     p.netmask = '255.255.255.0'
 | |
| 
 | |
|     v = iprange()
 | |
|     v.gateway = config.get('cloudstack', 'public.gateway')
 | |
|     v.startip = config.get('cloudstack', 'public.vlan.startip')
 | |
|     v.endip = config.get('cloudstack', 'public.vlan.endip') 
 | |
|     v.netmask = '255.255.255.0'
 | |
|     v.vlan = config.get('cloudstack', 'public.vlan')
 | |
|     z.ipranges.append(v)
 | |
| 
 | |
|     c = cluster()
 | |
|     c.clustername = 'C0'
 | |
|     c.hypervisor = config.get('environment', 'hypervisor')
 | |
|     c.clustertype = 'CloudManaged'
 | |
| 
 | |
|     h = host()
 | |
|     h.username = 'root'
 | |
|     h.password = 'password'
 | |
|     h.url = 'http://%s'%(config.get('cloudstack', 'host'))
 | |
|     c.hosts.append(h)
 | |
| 
 | |
|     ps = primaryStorage()
 | |
|     ps.name = 'PS0'
 | |
|     ps.url = config.get('cloudstack', 'pool')
 | |
|     c.primaryStorages.append(ps)
 | |
| 
 | |
|     p.clusters.append(c)
 | |
|     z.pods.append(p)
 | |
| 
 | |
|     secondary = secondaryStorage()
 | |
|     secondary.url = config.get('cloudstack', 'secondary')
 | |
|     z.secondaryStorages.append(secondary)
 | |
| 
 | |
|     '''Add zone'''
 | |
|     zs.zones.append(z)
 | |
| 
 | |
|     '''Add mgt server'''
 | |
|     mgt = managementServer()
 | |
|     mgt.mgtSvrIp = config.get('environment', 'mshost')
 | |
|     zs.mgtSvr.append(mgt)
 | |
| 
 | |
|     '''Add a database'''
 | |
|     db = dbServer()
 | |
|     db.dbSvr = config.get('environment', 'database')
 | |
|     zs.dbSvr = db
 | |
| 
 | |
|     '''Add some configuration'''
 | |
|     [zs.globalConfig.append(cfg) for cfg in getGlobalSettings(config)]
 | |
| 
 | |
|     ''''add loggers'''
 | |
|     testClientLogger = logger()
 | |
|     testClientLogger.name = 'TestClient'
 | |
|     testClientLogger.file = '/var/log/testclient.log'
 | |
| 
 | |
|     testCaseLogger = logger()
 | |
|     testCaseLogger.name = 'TestCase'
 | |
|     testCaseLogger.file = '/var/log/testcase.log'
 | |
| 
 | |
|     zs.logger.append(testClientLogger)
 | |
|     zs.logger.append(testCaseLogger)
 | |
|     return zs
 | |
| 
 | |
| 
 | |
| if __name__ == '__main__':
 | |
|     parser = OptionParser()
 | |
|     parser.add_option('-i', '--input', action='store', default='setup.properties', \
 | |
|                       dest='input', help='file containing environment setup information')
 | |
|     parser.add_option('-o', '--output', action='store', default='./sandbox.cfg', \
 | |
|                       dest='output', help='path where environment json will be generated')
 | |
| 
 | |
| 
 | |
|     (opts, args) = parser.parse_args()
 | |
| 
 | |
|     cfg_parser = SafeConfigParser()
 | |
|     cfg_parser.read(opts.input)
 | |
| 
 | |
|     cfg = describeResources(cfg_parser)
 | |
|     generate_setup_config(cfg, opts.output)
 |