~ubuntu-branches/ubuntu/wily/heat/wily-proposed

« back to all changes in this revision

Viewing changes to heat/engine/resources/neutron/provider_net.py

  • Committer: Package Import Robot
  • Author(s): James Page, Corey Bryant, James Page
  • Date: 2015-03-30 11:11:18 UTC
  • mfrom: (1.1.23)
  • Revision ID: package-import@ubuntu.com-20150330111118-2qpycylx6swu4yhj
Tags: 2015.1~b3-0ubuntu1
[ Corey Bryant ]
* New upstream milestone release for OpenStack kilo:
  - d/control: Align with upstream dependencies.
  - d/p/sudoers_patch.patch: Rebased.
  - d/p/fix-requirements.patch: Rebased.

[ James Page ]
* d/p/fixup-assert-regex.patch: Tweak test to use assertRegexpMatches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
3
 
#    not use this file except in compliance with the License. You may obtain
4
 
#    a copy of the License at
5
 
#
6
 
#         http://www.apache.org/licenses/LICENSE-2.0
7
 
#
8
 
#    Unless required by applicable law or agreed to in writing, software
9
 
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10
 
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11
 
#    License for the specific language governing permissions and limitations
12
 
#    under the License.
13
 
 
14
 
from heat.common import exception
15
 
from heat.common.i18n import _
16
 
from heat.engine import attributes
17
 
from heat.engine import constraints
18
 
from heat.engine import properties
19
 
from heat.engine.resources.neutron import net
20
 
from heat.engine import support
21
 
 
22
 
 
23
 
class ProviderNet(net.Net):
24
 
 
25
 
    support_status = support.SupportStatus(version='2014.1')
26
 
 
27
 
    PROPERTIES = (
28
 
        NAME, PROVIDER_NETWORK_TYPE, PROVIDER_PHYSICAL_NETWORK,
29
 
        PROVIDER_SEGMENTATION_ID, ADMIN_STATE_UP, SHARED,
30
 
    ) = (
31
 
        'name', 'network_type', 'physical_network',
32
 
        'segmentation_id', 'admin_state_up', 'shared',
33
 
    )
34
 
 
35
 
    ATTRIBUTES = (
36
 
        STATUS, SUBNETS, SHOW,
37
 
    ) = (
38
 
        'status', 'subnets', 'show',
39
 
    )
40
 
 
41
 
    properties_schema = {
42
 
        NAME: net.Net.properties_schema[NAME],
43
 
        PROVIDER_NETWORK_TYPE: properties.Schema(
44
 
            properties.Schema.STRING,
45
 
            _('A string specifying the provider network type for the '
46
 
                'network.'),
47
 
            update_allowed=True,
48
 
            required=True,
49
 
            constraints=[
50
 
                constraints.AllowedValues(['vlan', 'flat']),
51
 
            ]
52
 
        ),
53
 
        PROVIDER_PHYSICAL_NETWORK: properties.Schema(
54
 
            properties.Schema.STRING,
55
 
            _('A string specifying physical network mapping for the '
56
 
                'network.'),
57
 
            update_allowed=True,
58
 
            required=True,
59
 
        ),
60
 
        PROVIDER_SEGMENTATION_ID: properties.Schema(
61
 
            properties.Schema.STRING,
62
 
            _('A string specifying the segmentation id for the '
63
 
                'network.'),
64
 
            update_allowed=True
65
 
        ),
66
 
        ADMIN_STATE_UP: net.Net.properties_schema[ADMIN_STATE_UP],
67
 
        SHARED: properties.Schema(
68
 
            properties.Schema.BOOLEAN,
69
 
            _('Whether this network should be shared across all tenants.'),
70
 
            default=True,
71
 
            update_allowed=True
72
 
        ),
73
 
    }
74
 
 
75
 
    attributes_schema = {
76
 
        STATUS: attributes.Schema(
77
 
            _("The status of the network.")
78
 
        ),
79
 
        SUBNETS: attributes.Schema(
80
 
            _("Subnets of this network.")
81
 
        ),
82
 
        SHOW: attributes.Schema(
83
 
            _("All attributes.")
84
 
        ),
85
 
    }
86
 
 
87
 
    def validate(self):
88
 
        '''
89
 
        Validates to ensure that segmentation_id is not there for flat
90
 
        network type.
91
 
        '''
92
 
        super(ProviderNet, self).validate()
93
 
 
94
 
        if (self.properties.get(self.PROVIDER_SEGMENTATION_ID) and
95
 
                self.properties.get(self.PROVIDER_NETWORK_TYPE) != 'vlan'):
96
 
            msg = _('segmentation_id not allowed for flat network type.')
97
 
            raise exception.StackValidationFailed(message=msg)
98
 
 
99
 
    @staticmethod
100
 
    def add_provider_extension(props, key):
101
 
        props['provider:' + key] = props.pop(key)
102
 
 
103
 
    @staticmethod
104
 
    def prepare_provider_properties(self, props):
105
 
        self.add_provider_extension(props, self.PROVIDER_NETWORK_TYPE)
106
 
 
107
 
        self.add_provider_extension(props, self.PROVIDER_PHYSICAL_NETWORK)
108
 
 
109
 
        if self.PROVIDER_SEGMENTATION_ID in props.keys():
110
 
            self.add_provider_extension(props, self.PROVIDER_SEGMENTATION_ID)
111
 
 
112
 
    def handle_create(self):
113
 
        '''
114
 
        Adds 'provider:' extension to the required properties during create.
115
 
        '''
116
 
        props = self.prepare_properties(
117
 
            self.properties,
118
 
            self.physical_resource_name())
119
 
 
120
 
        self.prepare_provider_properties(self, props)
121
 
 
122
 
        prov_net = self.neutron().create_network({'network': props})['network']
123
 
        self.resource_id_set(prov_net['id'])
124
 
 
125
 
    def handle_update(self, json_snippet, tmpl_diff, prop_diff):
126
 
        '''
127
 
        Adds 'provider:' extension to the required properties during update.
128
 
        '''
129
 
        props = self.prepare_update_properties(json_snippet)
130
 
 
131
 
        self.prepare_provider_properties(self, props)
132
 
 
133
 
        self.neutron().update_network(self.resource_id, {'network': props})
134
 
 
135
 
 
136
 
def resource_mapping():
137
 
    return {
138
 
        'OS::Neutron::ProviderNet': ProviderNet,
139
 
    }