Rebase network resources to resource2 (4)

Change-Id: I9e224849ebcc438652d4a6b96b795b91c5375ec2
This commit is contained in:
tengqm 2016-12-08 08:44:38 -05:00
parent 20b6040890
commit 076ec4adc8
14 changed files with 65 additions and 92 deletions

View File

@ -11,7 +11,7 @@
# under the License.
from openstack.network import network_service
from openstack import resource
from openstack import resource2 as resource
class AutoAllocatedTopology(resource.Resource):
@ -22,11 +22,13 @@ class AutoAllocatedTopology(resource.Resource):
# Capabilities
allow_create = False
allow_retrieve = True
allow_get = True
allow_update = False
allow_delete = True
allow_list = False
# NOTE: this resource doesn't support list or query
# Properties
#: Project ID
#: If project is not specified the topology will be created
@ -34,7 +36,7 @@ class AutoAllocatedTopology(resource.Resource):
#: Will return in error if resources have not been configured correctly
#: To use this feature auto-allocated-topology, subnet_allocation,
#: external-net and router extensions must be enabled and set up.
project_id = resource.prop('tenant_id')
project_id = resource.Body('tenant_id')
class ValidateTopology(AutoAllocatedTopology):
@ -43,4 +45,5 @@ class ValidateTopology(AutoAllocatedTopology):
#: Validate requirements before running (Does not return topology)
#: Will return "Deployment error:" if the resources required have not
#: been correctly set up.
dry_run = resource.prop('dry_run')
dry_run = resource.Body('dry_run')
project_id = resource.URI('project')

View File

@ -11,7 +11,7 @@
# under the License.
from openstack.network import network_service
from openstack import resource
from openstack import resource2 as resource
class QoSBandwidthLimitRule(resource.Resource):
@ -22,28 +22,18 @@ class QoSBandwidthLimitRule(resource.Resource):
# capabilities
allow_create = True
allow_retrieve = True
allow_get = True
allow_update = True
allow_delete = True
allow_list = True
# Properties
#: QoS bandwidth limit rule id.
id = resource.prop('id')
#: The ID of the QoS policy who owns rule.
qos_policy_id = resource.prop('qos_policy_id')
qos_policy_id = resource.URI('qos_policy_id')
#: Maximum bandwidth in kbps.
max_kbps = resource.prop('max_kbps')
max_kbps = resource.Body('max_kbps')
#: Maximum burst bandwidth in kbps.
max_burst_kbps = resource.prop('max_burst_kbps')
max_burst_kbps = resource.Body('max_burst_kbps')
# NOTE(ralonsoh): to be implemented in bug 1560961
#: Traffic direction from the tenant point of view ('egress', 'ingress').
# direction = resource.prop('direction')
@classmethod
def _get_create_body(cls, attrs):
# Exclude qos_policy_id from attrs since it is not expected by QoS API.
if 'qos_policy_id' in attrs:
attrs.pop('qos_policy_id')
return {cls.resource_key: attrs}

View File

@ -11,7 +11,7 @@
# under the License.
from openstack.network import network_service
from openstack import resource
from openstack import resource2 as resource
class QoSDSCPMarkingRule(resource.Resource):
@ -22,23 +22,13 @@ class QoSDSCPMarkingRule(resource.Resource):
# capabilities
allow_create = True
allow_retrieve = True
allow_get = True
allow_update = True
allow_delete = True
allow_list = True
# Properties
#: QoS DSCP marking rule id.
id = resource.prop('id')
#: The ID of the QoS policy who owns rule.
qos_policy_id = resource.prop('qos_policy_id')
qos_policy_id = resource.URI('qos_policy_id')
#: DSCP mark field.
dscp_mark = resource.prop('dscp_mark')
@classmethod
def _get_create_body(cls, attrs):
# Exclude qos_policy_id from attrs since it is not expected by QoS API.
if 'qos_policy_id' in attrs:
attrs.pop('qos_policy_id')
return {cls.resource_key: attrs}
dscp_mark = resource.Body('dscp_mark')

View File

@ -11,7 +11,7 @@
# under the License.
from openstack.network import network_service
from openstack import resource
from openstack import resource2 as resource
class QoSMinimumBandwidthRule(resource.Resource):
@ -22,25 +22,15 @@ class QoSMinimumBandwidthRule(resource.Resource):
# capabilities
allow_create = True
allow_retrieve = True
allow_get = True
allow_update = True
allow_delete = True
allow_list = True
# Properties
#: QoS minimum bandwidth rule id.
id = resource.prop('id')
#: The ID of the QoS policy who owns rule.
qos_policy_id = resource.prop('qos_policy_id')
qos_policy_id = resource.URI('qos_policy_id')
#: Minimum bandwidth in kbps.
min_kbps = resource.prop('min_kbps')
min_kbps = resource.Body('min_kbps')
#: Traffic direction from the tenant point of view. Valid values: 'egress'
direction = resource.prop('direction')
@classmethod
def _get_create_body(cls, attrs):
# Exclude qos_policy_id from attrs since it is not expected by QoS API.
if 'qos_policy_id' in attrs:
attrs.pop('qos_policy_id')
return {cls.resource_key: attrs}
direction = resource.Body('direction')

View File

@ -11,7 +11,7 @@
# under the License.
from openstack.network import network_service
from openstack import resource
from openstack import resource2 as resource
class QoSRuleType(resource.Resource):
@ -22,11 +22,11 @@ class QoSRuleType(resource.Resource):
# capabilities
allow_create = False
allow_retrieve = False
allow_get = False
allow_update = False
allow_delete = False
allow_list = True
# Properties
#: QoS rule type name.
type = resource.prop('type')
type = resource.Body('type')

View File

@ -11,7 +11,7 @@
# under the License.
from openstack.network import network_service
from openstack import resource
from openstack import resource2 as resource
class ServiceProfile(resource.Resource):
@ -22,19 +22,24 @@ class ServiceProfile(resource.Resource):
# capabilities
allow_create = True
allow_retrieve = True
allow_get = True
allow_update = True
allow_delete = True
allow_list = True
_query_mapping = resource.QueryParameters(
'description', 'driver',
is_enabled='enabled',
project_id='tenant_id'
)
# Properties
#: Description of the service flavor profile.
description = resource.prop('description')
description = resource.Body('description')
#: Provider Driver for the service flavor profile
driver = resource.prop('driver')
driver = resource.Body('driver')
#: Sets enabled flag
is_enabled = resource.prop('enabled', type=bool)
is_enabled = resource.Body('enabled', type=bool)
#: Metainformation of the service flavor profile
metainfo = resource.prop('metainfo')
meta_info = resource.Body('metainfo')
#: The owner project ID
project_id = resource.prop('tenant_id')
project_id = resource.Body('tenant_id')

View File

@ -11,7 +11,7 @@
# under the License.
from openstack.network import network_service
from openstack import resource
from openstack import resource2 as resource
class ServiceProvider(resource.Resource):
@ -21,15 +21,20 @@ class ServiceProvider(resource.Resource):
# Capabilities
allow_create = False
allow_retrieve = False
allow_get = False
allow_update = False
allow_delete = False
allow_list = True
_query_mapping = resource.QueryParameters(
'service_type', 'name',
is_default='default'
)
# Properties
#: Service type (FIREWALL, FLAVORS, METERING, QOS, etc..)
service_type = resource.prop('service_type')
service_type = resource.Body('service_type')
#: Name of the service type
name = resource.prop('name')
name = resource.Body('name')
#: The default value of service type
is_default = resource.prop('default', type=bool)
is_default = resource.Body('default', type=bool)

View File

@ -15,7 +15,7 @@ import testtools
from openstack.network.v2 import auto_allocated_topology
EXAMPLE = {
'project_id': '1',
'tenant_id': '1',
'dry_run': False,
}
@ -27,11 +27,11 @@ class TestAutoAllocatedTopology(testtools.TestCase):
self.assertEqual('auto_allocated_topology', topo.resource_key)
self.assertEqual('/auto-allocated-topology', topo.base_path)
self.assertFalse(topo.allow_create)
self.assertTrue(topo.allow_retrieve)
self.assertTrue(topo.allow_get)
self.assertFalse(topo.allow_update)
self.assertTrue(topo.allow_delete)
self.assertFalse(topo.allow_list)
def test_make_it(self):
topo = auto_allocated_topology.AutoAllocatedTopology(EXAMPLE)
self.assertEqual(EXAMPLE['project_id'], topo.project_id)
topo = auto_allocated_topology.AutoAllocatedTopology(**EXAMPLE)
self.assertEqual(EXAMPLE['tenant_id'], topo.project_id)

View File

@ -36,13 +36,13 @@ class TestQoSBandwidthLimitRule(testtools.TestCase):
sot.base_path)
self.assertEqual('network', sot.service.service_type)
self.assertTrue(sot.allow_create)
self.assertTrue(sot.allow_retrieve)
self.assertTrue(sot.allow_get)
self.assertTrue(sot.allow_update)
self.assertTrue(sot.allow_delete)
self.assertTrue(sot.allow_list)
def test_make_it(self):
sot = qos_bandwidth_limit_rule.QoSBandwidthLimitRule(EXAMPLE)
sot = qos_bandwidth_limit_rule.QoSBandwidthLimitRule(**EXAMPLE)
self.assertEqual(EXAMPLE['id'], sot.id)
self.assertEqual(EXAMPLE['qos_policy_id'], sot.qos_policy_id)
self.assertEqual(EXAMPLE['max_kbps'], sot.max_kbps)

View File

@ -32,13 +32,13 @@ class TestQoSDSCPMarkingRule(testtools.TestCase):
sot.base_path)
self.assertEqual('network', sot.service.service_type)
self.assertTrue(sot.allow_create)
self.assertTrue(sot.allow_retrieve)
self.assertTrue(sot.allow_get)
self.assertTrue(sot.allow_update)
self.assertTrue(sot.allow_delete)
self.assertTrue(sot.allow_list)
def test_make_it(self):
sot = qos_dscp_marking_rule.QoSDSCPMarkingRule(EXAMPLE)
sot = qos_dscp_marking_rule.QoSDSCPMarkingRule(**EXAMPLE)
self.assertEqual(EXAMPLE['id'], sot.id)
self.assertEqual(EXAMPLE['qos_policy_id'], sot.qos_policy_id)
self.assertEqual(EXAMPLE['dscp_mark'], sot.dscp_mark)

View File

@ -10,8 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import copy
import testtools
import uuid
@ -36,22 +34,14 @@ class TestQoSMinimumBandwidthRule(testtools.TestCase):
sot.base_path)
self.assertEqual('network', sot.service.service_type)
self.assertTrue(sot.allow_create)
self.assertTrue(sot.allow_retrieve)
self.assertTrue(sot.allow_get)
self.assertTrue(sot.allow_update)
self.assertTrue(sot.allow_delete)
self.assertTrue(sot.allow_list)
def test_make_it(self):
sot = qos_minimum_bandwidth_rule.QoSMinimumBandwidthRule(EXAMPLE)
sot = qos_minimum_bandwidth_rule.QoSMinimumBandwidthRule(**EXAMPLE)
self.assertEqual(EXAMPLE['id'], sot.id)
self.assertEqual(EXAMPLE['qos_policy_id'], sot.qos_policy_id)
self.assertEqual(EXAMPLE['min_kbps'], sot.min_kbps)
self.assertEqual(EXAMPLE['direction'], sot.direction)
def test_create_body(self):
params = copy.deepcopy(EXAMPLE)
body = (qos_minimum_bandwidth_rule.QoSMinimumBandwidthRule.
_get_create_body(params))
reference = copy.deepcopy(EXAMPLE)
reference.pop('qos_policy_id')
self.assertEqual(reference, body['minimum_bandwidth_rule'])

View File

@ -28,11 +28,11 @@ class TestQoSRuleType(testtools.TestCase):
self.assertEqual('/qos/rule-types', sot.base_path)
self.assertEqual('network', sot.service.service_type)
self.assertFalse(sot.allow_create)
self.assertFalse(sot.allow_retrieve)
self.assertFalse(sot.allow_get)
self.assertFalse(sot.allow_update)
self.assertFalse(sot.allow_delete)
self.assertTrue(sot.allow_list)
def test_make_it(self):
sot = qos_rule_type.QoSRuleType(EXAMPLE)
sot = qos_rule_type.QoSRuleType(**EXAMPLE)
self.assertEqual(EXAMPLE['type'], sot.type)

View File

@ -35,18 +35,18 @@ class TestServiceProfile(testtools.TestCase):
self.assertEqual('service_profiles', service_profiles.resources_key)
self.assertEqual('/service_profiles', service_profiles.base_path)
self.assertTrue(service_profiles.allow_create)
self.assertTrue(service_profiles.allow_retrieve)
self.assertTrue(service_profiles.allow_get)
self.assertTrue(service_profiles.allow_update)
self.assertTrue(service_profiles.allow_delete)
self.assertTrue(service_profiles.allow_list)
def test_make_it(self):
service_profiles = service_profile.ServiceProfile(EXAMPLE)
service_profiles = service_profile.ServiceProfile(**EXAMPLE)
self.assertEqual(EXAMPLE['driver'], service_profiles.driver)
def test_make_it_with_optional(self):
service_profiles = service_profile.ServiceProfile(
EXAMPLE_WITH_OPTIONAL)
**EXAMPLE_WITH_OPTIONAL)
self.assertEqual(EXAMPLE_WITH_OPTIONAL['description'],
service_profiles.description)
self.assertEqual(EXAMPLE_WITH_OPTIONAL['driver'],
@ -54,6 +54,6 @@ class TestServiceProfile(testtools.TestCase):
self.assertEqual(EXAMPLE_WITH_OPTIONAL['enabled'],
service_profiles.is_enabled)
self.assertEqual(EXAMPLE_WITH_OPTIONAL['metainfo'],
service_profiles.metainfo)
service_profiles.meta_info)
self.assertEqual(EXAMPLE_WITH_OPTIONAL['tenant_id'],
service_profiles.tenant_id)
service_profiles.project_id)

View File

@ -31,13 +31,13 @@ class TestServiceProvider(testtools.TestCase):
self.assertEqual('/service-providers', sot.base_path)
self.assertEqual('network', sot.service.service_type)
self.assertFalse(sot.allow_create)
self.assertFalse(sot.allow_retrieve)
self.assertFalse(sot.allow_get)
self.assertFalse(sot.allow_update)
self.assertFalse(sot.allow_delete)
self.assertTrue(sot.allow_list)
def test_make_it(self):
sot = service_provider.ServiceProvider(EXAMPLE)
sot = service_provider.ServiceProvider(**EXAMPLE)
self.assertEqual(EXAMPLE['service_type'], sot.service_type)
self.assertEqual(EXAMPLE['name'], sot.name)
self.assertEqual(EXAMPLE['default'], sot.is_default)