cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seb...@apache.org
Subject [1/2] git commit: updated refs/heads/master to a401127
Date Fri, 21 Jun 2013 12:29:23 GMT
Updated Branches:
  refs/heads/master 9b70828e2 -> a401127b0


pep8 deployDatacenter


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/a65d2153
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/a65d2153
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/a65d2153

Branch: refs/heads/master
Commit: a65d2153f1a31b12cbb123109f4b4b128c26731a
Parents: 4c51c60
Author: Daan Hoogland <dhoogland@schubergphilis.com>
Authored: Fri Jun 21 11:05:55 2013 +0200
Committer: Sebastien Goasguen <runseb@gmail.com>
Committed: Fri Jun 21 08:28:18 2013 -0400

----------------------------------------------------------------------
 tools/marvin/marvin/deployDataCenter.py | 195 ++++++++++++++++-----------
 1 file changed, 114 insertions(+), 81 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a65d2153/tools/marvin/marvin/deployDataCenter.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/deployDataCenter.py b/tools/marvin/marvin/deployDataCenter.py
index d6f19b0..f38df4e 100644
--- a/tools/marvin/marvin/deployDataCenter.py
+++ b/tools/marvin/marvin/deployDataCenter.py
@@ -5,9 +5,9 @@
 # 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
@@ -24,12 +24,14 @@ from cloudstackAPI import *
 from os import path
 from optparse import OptionParser
 
+
 class deployDataCenters():
 
     def __init__(self, cfgFile):
         if not path.exists(cfgFile) \
            and not path.exists(path.abspath(cfgFile)):
-            raise IOError("config file %s not found. please specify a valid config file"%cfgFile)
+            raise IOError("config file %s not found. please \
+specify a valid config file" % cfgFile)
         self.configFile = cfgFile
 
     def addHosts(self, hosts, zoneId, podId, clusterId, hypervisor):
@@ -69,9 +71,9 @@ class deployDataCenters():
             clusterresponse = self.apiClient.addCluster(clustercmd)
             clusterId = clusterresponse[0].id
 
-            self.addHosts(cluster.hosts, zoneId, podId, clusterId,\
+            self.addHosts(cluster.hosts, zoneId, podId, clusterId,
                           cluster.hypervisor)
-            self.createPrimaryStorages(cluster.primaryStorages, zoneId, podId,\
+            self.createPrimaryStorages(cluster.primaryStorages, zoneId, podId,
                                        clusterId)
 
     def createPrimaryStorages(self, primaryStorages, zoneId, podId, clusterId):
@@ -103,12 +105,12 @@ class deployDataCenters():
             podId = createpodResponse.id
 
             if pod.guestIpRanges is not None and networkId is not None:
-                self.createVlanIpRanges("Basic", pod.guestIpRanges, zoneId,\
+                self.createVlanIpRanges("Basic", pod.guestIpRanges, zoneId,
                                         podId, networkId)
 
             self.createClusters(pod.clusters, zoneId, podId)
 
-    def createVlanIpRanges(self, mode, ipranges, zoneId, podId=None,\
+    def createVlanIpRanges(self, mode, ipranges, zoneId, podId=None,
                            networkId=None, forvirtualnetwork=None):
         if ipranges is None:
             return
@@ -142,8 +144,8 @@ class deployDataCenters():
             secondarycmd.url = secondary.url
             secondarycmd.provider = secondary.provider
             secondarycmd.details = []
-            
-            if isinstance(secondary.details, list): 
+
+            if isinstance(secondary.details, list):
                 for item in secondary.details:
                     secondarycmd.details.append(item.__dict__)
             if secondarycmd.provider == "NFS":
@@ -201,63 +203,73 @@ class deployDataCenters():
         if vlan:
             upnet.vlan = vlan
         return self.apiClient.updatePhysicalNetwork(upnet)
-    
+
     def enableProvider(self, provider_id):
-        upnetprov = \
-        updateNetworkServiceProvider.updateNetworkServiceProviderCmd()
+        upnetprov =\
+            updateNetworkServiceProvider.updateNetworkServiceProviderCmd()
         upnetprov.id = provider_id
         upnetprov.state = "Enabled"
         self.apiClient.updateNetworkServiceProvider(upnetprov)
 
     def configureProviders(self, phynetwrk, providers):
         """
-        We will enable the virtualrouter elements for all zones. Other providers 
-        like NetScalers, SRX, etc are explicitly added/configured
+        We will enable the virtualrouter elements for all zones. Other
+        providers like NetScalers, SRX, etc are explicitly added/configured
         """
-        
+
         for provider in providers:
-            pnetprov = listNetworkServiceProviders.listNetworkServiceProvidersCmd()
+            pnetprov = listNetworkServiceProviders.\
+                listNetworkServiceProvidersCmd()
             pnetprov.physicalnetworkid = phynetwrk.id
             pnetprov.state = "Disabled"
             pnetprov.name = provider.name
             pnetprovres = self.apiClient.listNetworkServiceProviders(pnetprov)
 
-            if pnetprovres and len(pnetprovres) > 0: 
+            if pnetprovres and len(pnetprovres) > 0:
                 if provider.name == 'VirtualRouter'\
                    or provider.name == 'VpcVirtualRouter':
-                    vrprov = listVirtualRouterElements.listVirtualRouterElementsCmd()
+                    vrprov = listVirtualRouterElements.\
+                        listVirtualRouterElementsCmd()
                     vrprov.nspid = pnetprovres[0].id
-                    vrprovresponse = self.apiClient.listVirtualRouterElements(vrprov)
+                    vrprovresponse = self.apiClient.\
+                        listVirtualRouterElements(vrprov)
                     vrprovid = vrprovresponse[0].id
-        
+
                     vrconfig = \
-                    configureVirtualRouterElement.configureVirtualRouterElementCmd()
+                        configureVirtualRouterElement.\
+                        configureVirtualRouterElementCmd()
                     vrconfig.enabled = "true"
                     vrconfig.id = vrprovid
                     self.apiClient.configureVirtualRouterElement(vrconfig)
                     self.enableProvider(pnetprovres[0].id)
                 elif provider.name == 'InternalLbVm':
-                    internallbprov = listInternalLoadBalancerElements.listInternalLoadBalancerElementsCmd()

+                    internallbprov = listInternalLoadBalancerElements.\
+                        listInternalLoadBalancerElementsCmd()
                     internallbprov.nspid = pnetprovres[0].id
-                    internallbresponse = self.apiClient.listInternalLoadBalancerElements(internallbprov)
+                    internallbresponse = self.apiClient.\
+                        listInternalLoadBalancerElements(internallbprov)
                     internallbid = internallbresponse[0].id
 
                     internallbconfig = \
-                            configureInternalLoadBalancerElement.configureInternalLoadBalancerElementCmd()
+                        configureInternalLoadBalancerElement.\
+                        configureInternalLoadBalancerElementCmd()
                     internallbconfig.enabled = "true"
                     internallbconfig.id = internallbid
-                    self.apiClient.configureInternalLoadBalancerElement(internallbconfig)
+                    self.apiClient.\
+                        configureInternalLoadBalancerElement(internallbconfig)
                     self.enableProvider(pnetprovres[0].id)
                 elif provider.name == 'SecurityGroupProvider':
                     self.enableProvider(pnetprovres[0].id)
             elif provider.name in ['Netscaler', 'JuniperSRX', 'F5BigIp']:
-                netprov = addNetworkServiceProvider.addNetworkServiceProviderCmd()
+                netprov = addNetworkServiceProvider.\
+                    addNetworkServiceProviderCmd()
                 netprov.name = provider.name
                 netprov.physicalnetworkid = phynetwrk.id
                 result = self.apiClient.addNetworkServiceProvider(netprov)
                 for device in provider.devices:
                     if provider.name == 'Netscaler':
-                        dev = addNetscalerLoadBalancer.addNetscalerLoadBalancerCmd()
+                        dev = addNetscalerLoadBalancer.\
+                            addNetscalerLoadBalancerCmd()
                         dev.username = device.username
                         dev.password = device.password
                         dev.networkdevicetype = device.networkdevicetype
@@ -281,20 +293,27 @@ class deployDataCenters():
                         dev.physicalnetworkid = phynetwrk.id
                         self.apiClient.addF5LoadBalancer(dev)
                     else:
-                        raise cloudstackException.InvalidParameterException("Device %s doesn't
match any know provider type"%device)
+                        raise cloudstackException.\
+                            InvalidParameterException("Device %s doesn't match\
+ any know provider type" % device)
                 self.enableProvider(result.id)
-            
+
     def addTrafficTypes(self, physical_network_id, traffictypes):
-        [self.addTrafficType(physical_network_id, traffic_type) for traffic_type in traffictypes]
+        [self.addTrafficType(physical_network_id, traffic_type)
+            for traffic_type in traffictypes]
 
     def addTrafficType(self, physical_network_id, traffictype):
         traffic_type = addTrafficType.addTrafficTypeCmd()
         traffic_type.physicalnetworkid = physical_network_id
         traffic_type.traffictype = traffictype.typ
-        traffic_type.kvmnetworklabel = traffictype.kvm if traffictype.kvm is not None else
None
-        traffic_type.xennetworklabel = traffictype.xen if traffictype.xen is not None else
None
-        traffic_type.vmwarenetworklabel = traffictype.vmware if traffictype.vmware is not
None else None
-        traffic_type.simulatorlabel = traffictype.simulator if traffictype.simulator is not
None else None
+        traffic_type.kvmnetworklabel = traffictype.kvm\
+            if traffictype.kvm is not None else None
+        traffic_type.xennetworklabel = traffictype.xen\
+            if traffictype.xen is not None else None
+        traffic_type.vmwarenetworklabel = traffictype.vmware\
+            if traffictype.vmware is not None else None
+        traffic_type.simulatorlabel = traffictype.simulator\
+            if traffictype.simulator is not None else None
         return self.apiClient.addTrafficType(traffic_type)
 
     def enableZone(self, zoneid, allocation_state="Enabled"):
@@ -322,48 +341,59 @@ class deployDataCenters():
             createzone.networktype = zone.networktype
             if zone.securitygroupenabled != "true":
                 createzone.guestcidraddress = zone.guestcidraddress
-            
+
             zoneresponse = self.apiClient.createZone(createzone)
             zoneId = zoneresponse.id
 
             for pnet in zone.physical_networks:
                 phynetwrk = self.createPhysicalNetwork(pnet, zoneId)
                 self.configureProviders(phynetwrk, pnet.providers)
-                self.updatePhysicalNetwork(phynetwrk.id, "Enabled", vlan=pnet.vlan)
+                self.updatePhysicalNetwork(phynetwrk.id, "Enabled",
+                                           vlan=pnet.vlan)
 
             if zone.networktype == "Basic":
-                listnetworkoffering = listNetworkOfferings.listNetworkOfferingsCmd()
-                listnetworkoffering.name = "DefaultSharedNetscalerEIPandELBNetworkOffering"
\
-                        if len(filter(lambda x : x.typ == 'Public', zone.physical_networks[0].traffictypes))
> 0 \
-                        else "DefaultSharedNetworkOfferingWithSGService"
-                if zone.networkofferingname  is not None:
-                   listnetworkoffering.name = zone.networkofferingname 
+                listnetworkoffering =\
+                    listNetworkOfferings.listNetworkOfferingsCmd()
+                listnetworkoffering.name =\
+                    "DefaultSharedNetscalerEIPandELBNetworkOffering" \
+                    if len(filter(lambda x:
+                                  x.typ == 'Public',
+                                  zone.physical_networks[0].
+                                  traffictypes)) > 0 \
+                    else "DefaultSharedNetworkOfferingWithSGService"
+                if zone.networkofferingname is not None:
+                    listnetworkoffering.name = zone.networkofferingname
 
                 listnetworkofferingresponse = \
-                self.apiClient.listNetworkOfferings(listnetworkoffering)
+                    self.apiClient.listNetworkOfferings(listnetworkoffering)
 
                 guestntwrk = configGenerator.network()
                 guestntwrk.displaytext = "guestNetworkForBasicZone"
                 guestntwrk.name = "guestNetworkForBasicZone"
                 guestntwrk.zoneid = zoneId
                 guestntwrk.networkofferingid = \
-                        listnetworkofferingresponse[0].id
-                        
+                    listnetworkofferingresponse[0].id
+
                 networkid = self.createnetworks([guestntwrk], zoneId)
                 self.createpods(zone.pods, zoneId, networkid)
                 if self.isEipElbZone(zone):
-                    self.createVlanIpRanges(zone.networktype, zone.ipranges, \
-                                        zoneId, forvirtualnetwork=True)
+                    self.createVlanIpRanges(zone.networktype, zone.ipranges,
+                                            zoneId, forvirtualnetwork=True)
 
-            if zone.networktype == "Advanced" and zone.securitygroupenabled != "true":
+            isFreeZone = (zone.networktype == "Advanced"
+                          and zone.securitygroupenabled != "true")
+            if ifFreeZone:
                 self.createpods(zone.pods, zoneId)
-                self.createVlanIpRanges(zone.networktype, zone.ipranges, \
+                self.createVlanIpRanges(zone.networktype, zone.ipranges,
                                         zoneId)
-            elif zone.networktype == "Advanced" and zone.securitygroupenabled == "true":
-                listnetworkoffering = listNetworkOfferings.listNetworkOfferingsCmd()
-                listnetworkoffering.name = "DefaultSharedNetworkOfferingWithSGService"
-                if zone.networkofferingname  is not None:
-                   listnetworkoffering.name = zone.networkofferingname
+            elif (zone.networktype == "Advanced"
+                  and zone.securitygroupenabled == "true"):
+                listnetworkoffering =\
+                    listNetworkOfferings.listNetworkOfferingsCmd()
+                listnetworkoffering.name =\
+                    "DefaultSharedNetworkOfferingWithSGService"
+                if zone.networkofferingname is not None:
+                    listnetworkoffering.name = zone.networkofferingname
 
                 listnetworkofferingresponse = \
                     self.apiClient.listNetworkOfferings(listnetworkoffering)
@@ -371,7 +401,8 @@ class deployDataCenters():
                 networkcmd = createNetwork.createNetworkCmd()
                 networkcmd.displaytext = "Shared SG enabled network"
                 networkcmd.name = "Shared SG enabled network"
-                networkcmd.networkofferingid = listnetworkofferingresponse[0].id
+                networkcmd.networkofferingid =\
+                    listnetworkofferingresponse[0].id
                 networkcmd.zoneid = zoneId
 
                 ipranges = zone.ipranges
@@ -388,8 +419,8 @@ class deployDataCenters():
                 self.createpods(zone.pods, zoneId, networkId)
 
             self.createSecondaryStorages(zone.secondaryStorages, zoneId)
-            self.createCacheStorages(zone.cacheStorages, zoneId)            
-            
+            self.createCacheStorages(zone.cacheStorages, zoneId)
+
             enabled = getattr(zone, 'enabled', 'True')
             if enabled == 'True' or enabled is None:
                 self.enableZone(zoneId, "Enabled")
@@ -399,9 +430,11 @@ class deployDataCenters():
                 self.updateZoneDetails(zoneId, det)
 
         return
-    
+
     def isEipElbZone(self, zone):
-        if zone.networktype == "Basic" and len(filter(lambda x : x.typ == 'Public', zone.physical_networks[0].traffictypes))
> 0:
+        if (zone.networktype == "Basic"
+            and len(filter(lambda x: x.typ == 'Public',
+                           zone.physical_networks[0].traffictypes)) > 0):
             return True
         return False
 
@@ -416,7 +449,7 @@ class deployDataCenters():
             registerUser = registerUserKeys.registerUserKeysCmd()
             registerUser.id = userId
             registerUserRes = \
-            self.testClient.getApiClient().registerUserKeys(registerUser)
+                self.testClient.getApiClient().registerUserKeys(registerUser)
 
             apiKey = registerUserRes.apikey
             securityKey = registerUserRes.secretkey
@@ -435,8 +468,8 @@ class deployDataCenters():
         try:
             self.config = configGenerator.get_setup_config(self.configFile)
         except:
-            raise cloudstackException.InvalidParameterException( \
-                            "Failed to load config %s"%self.configFile)
+            raise cloudstackException.InvalidParameterException(
+                "Failed to load config %s" % self.configFile)
 
         mgt = self.config.mgtSvr[0]
 
@@ -457,37 +490,38 @@ class deployDataCenters():
         if testClientLogFile is not None:
             testClientLogger = logging.getLogger("testclient.testengine.run")
             fh = logging.FileHandler(testClientLogFile)
-            fh.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s - %(name)s - %(message)s"))
+            fh.setFormatter(logging.
+                            Formatter("%(asctime)s - %(levelname)s - %(name)s\
+ - %(message)s"))
             testClientLogger.addHandler(fh)
             testClientLogger.setLevel(logging.INFO)
         self.testClientLogger = testClientLogger
 
         self.testClient = \
-        cloudstackTestClient.cloudstackTestClient(mgt.mgtSvrIp, mgt.port, \
-                                                  mgt.user, mgt.passwd, \
-                                                  mgt.apiKey, \
-                                                  mgt.securityKey, \
-                                            logging=self.testClientLogger)
+            cloudstackTestClient.\
+            cloudstackTestClient(mgt.mgtSvrIp, mgt.port, mgt.user, mgt.passwd,
+                                 mgt.apiKey, mgt.securityKey,
+                                 logging=self.testClientLogger)
         if mgt.apiKey is None:
             apiKey, securityKey = self.registerApiKey()
-            self.testClient = \
-            cloudstackTestClient.cloudstackTestClient(mgt.mgtSvrIp, 8080, \
-                                                      mgt.user, mgt.passwd, \
-                                                      apiKey, securityKey, \
-                                             logging=self.testClientLogger)
+            self.testClient = cloudstackTestClient.cloudstackTestClient(
+                mgt.mgtSvrIp, 8080,
+                mgt.user, mgt.passwd,
+                apiKey, securityKey,
+                logging=self.testClientLogger)
 
         """config database"""
         dbSvr = self.config.dbSvr
         if dbSvr is not None:
-          self.testClient.dbConfigure(dbSvr.dbSvr, dbSvr.port, dbSvr.user, \
-                                      dbSvr.passwd, dbSvr.db)
+            self.testClient.dbConfigure(dbSvr.dbSvr, dbSvr.port, dbSvr.user,
+                                        dbSvr.passwd, dbSvr.db)
 
         self.apiClient = self.testClient.getApiClient()
         """set hypervisor"""
         if mgt.hypervisor:
             self.apiClient.hypervisor = mgt.hypervisor
         else:
-            self.apiClient.hypervisor = "XenServer"     #Defaults to Xenserver
+            self.apiClient.hypervisor = "XenServer"  # Defaults to Xenserver
 
     def updateConfiguration(self, globalCfg):
         if globalCfg is None:
@@ -501,10 +535,9 @@ class deployDataCenters():
 
     def copyAttributesToCommand(self, source, command):
 
-        map(lambda attr : setattr(command, attr, getattr(source, attr, None)),
-                filter(lambda attr : not attr.startswith("__") and
-                    attr not in [ "required", "isAsync" ], dir(command)))
-
+        map(lambda attr: setattr(command, attr, getattr(source, attr, None)),
+            filter(lambda attr: not attr.startswith("__") and
+            attr not in ["required", "isAsync"], dir(command)))
 
     def configureS3(self, s3):
         if s3 is None:
@@ -524,7 +557,7 @@ if __name__ == "__main__":
 
     parser = OptionParser()
 
-    parser.add_option("-i", "--input", action="store", \
+    parser.add_option("-i", "--input", action="store",
                       default="./datacenterCfg", dest="input", help="the path \
                       where the json config file generated, by default is \
                       ./datacenterCfg")


Mime
View raw message