marvin_refactor: network data factory

network can create isolated guest and shared guest networks. the network
object will inturn use the default networkofferings which are
auto-enabeld by their postgenerators

Signed-off-by: Prasanna Santhanam <tsp@apache.org>
This commit is contained in:
Prasanna Santhanam 2013-09-07 11:02:18 +05:30
parent 6dc259ea88
commit c632fadee5
2 changed files with 91 additions and 1 deletions

View File

@ -0,0 +1,48 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# 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
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import factory
from marvin.legacy.utils import random_gen
from marvin.factory.network import NetworkFactory
from marvin.factory.data.networkoffering import DefaultIsolatedNetworkOfferingWithSourceNatServiceFactory
from marvin.factory.data.networkoffering import DefaultSharedNetworkOfferingFactory
class GuestIsolatedNetworkFactory(NetworkFactory):
displaytext = factory.Sequence(lambda n: 'GuestIsolatedNetwork-%s' % random_gen())
name = factory.Sequence(lambda n: 'GuestIsolatedNetwork-%s' % random_gen())
networkoffering =\
factory.SubFactory(
DefaultIsolatedNetworkOfferingWithSourceNatServiceFactory,
apiclient=factory.SelfAttribute('..apiclient'),
name=factory.Sequence(lambda n: 'GuestIsolatedNetworkOffering-%s' % random_gen()),
)
networkofferingid = factory.LazyAttribute(lambda no: no.networkoffering.id if no.networkoffering else no.networkoffering)
zoneid = None
class SharedNetworkFactory(NetworkFactory):
displaytext = factory.Sequence(lambda n: 'SharedNetwork-%s' % random_gen())
name = factory.Sequence(lambda n: 'SharedNetwork-%d' % random_gen())
networkoffering = \
factory.SubFactory(
DefaultSharedNetworkOfferingFactory,
apiclient=factory.SelfAttribute('..apiclient'),
name=factory.Sequence(lambda n: 'SharedNetworkOffering-%s' % random_gen())
)
networkofferingid = factory.LazyAttribute(lambda no: no.networkoffering.id if not no.networkoffering else no.networkoffering)
zoneid = None

View File

@ -17,7 +17,7 @@
import factory
from marvin.factory.networkoffering import NetworkOfferingFactory
from marvin.utils import random_gen
from marvin.legacy.utils import random_gen
class DefaultIsolatedNetworkOfferingWithSourceNatServiceFactory(NetworkOfferingFactory):
@ -43,6 +43,12 @@ class DefaultIsolatedNetworkOfferingWithSourceNatServiceFactory(NetworkOfferingF
'provider': 'VirtualRouter'
}
)
# enable the offering post generation
factory.PostGenerationMethodCall('update',
factory.SelfAttribute('..apiclient'),
id=factory.SelfAttribute('..id'),
state='Enabled')
class DefaultSharedNetworkOfferingWithSGServiceFactory(NetworkOfferingFactory):
@ -71,3 +77,39 @@ class DefaultSharedNetworkOfferingWithSGServiceFactory(NetworkOfferingFactory):
'provider': provider
}
)
# enable the offering post generation
factory.PostGenerationMethodCall('update',
factory.SelfAttribute('..apiclient'),
id=factory.SelfAttribute('..id'),
state='Enabled')
class DefaultSharedNetworkOfferingFactory(NetworkOfferingFactory):
displaytext = factory.Sequence(lambda n : "DefaultSharedNetworkOfferingFactory-%d" % n)
name = factory.Sequence(lambda n : "DefaultSharedNetworkOfferingFactory-%d" % n)
availability = "Optional"
supportedservices = "Dns,Dhcp,UserData"
guestiptype = "Shared"
traffictype = "GUEST"
specifyVlan = True
specifyIpRanges = True
isPersistent = False
conserveMode = True
serviceProviderList = []
for service in map(lambda l: l.strip(' '), supportedservices.split(',')):
serviceProviderList.append(
{
'service': service,
'provider': 'VirtualRouter'
}
)
# enable the offering post generation
factory.PostGenerationMethodCall('update',
factory.SelfAttribute('..apiclient'),
id=factory.SelfAttribute('..id'),
state='Enabled')