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

« back to all changes in this revision

Viewing changes to heat/engine/resources/openstack/manila/share_network.py

  • Committer: Package Import Robot
  • Author(s): Corey Bryant
  • Date: 2015-08-19 08:11:50 UTC
  • mfrom: (1.1.27)
  • Revision ID: package-import@ubuntu.com-20150819081150-m969fd35xn8bdmfu
Tags: 1:5.0.0~b2-0ubuntu1
* New upstream milestone for OpenStack Liberty.
* d/control: Align (build-)depends with upstream.
* d/p/fix-requirements.patch: Dropped. No longer needed.
* d/p/fixup-assert-regex.patch: Rebased.
* d/rules: Remove .eggs directory in override_dh_auto_clean.

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 import resource
 
20
from heat.engine import support
 
21
 
 
22
 
 
23
class ManilaShareNetwork(resource.Resource):
 
24
    """
 
25
    Stores network information that will be used by share servers,
 
26
    where shares are hosted.
 
27
    """
 
28
 
 
29
    support_status = support.SupportStatus(version='5.0.0')
 
30
 
 
31
    PROPERTIES = (
 
32
        NAME, NEUTRON_NETWORK, NEUTRON_SUBNET, NOVA_NETWORK,
 
33
        DESCRIPTION, SECURITY_SERVICES,
 
34
    ) = (
 
35
        'name', 'neutron_network', 'neutron_subnet', 'nova_network',
 
36
        'description', 'security_services',
 
37
    )
 
38
 
 
39
    ATTRIBUTES = (
 
40
        SEGMENTATION_ID, CIDR, IP_VERSION, NETWORK_TYPE,
 
41
    ) = (
 
42
        'segmentation_id', 'cidr', 'ip_version', 'network_type',
 
43
    )
 
44
 
 
45
    properties_schema = {
 
46
        NAME: properties.Schema(
 
47
            properties.Schema.STRING,
 
48
            _('Name of the share network.'),
 
49
            update_allowed=True
 
50
        ),
 
51
        NEUTRON_NETWORK: properties.Schema(
 
52
            properties.Schema.STRING,
 
53
            _('Neutron network id.'),
 
54
            update_allowed=True,
 
55
            constraints=[constraints.CustomConstraint('neutron.network')]
 
56
        ),
 
57
        NEUTRON_SUBNET: properties.Schema(
 
58
            properties.Schema.STRING,
 
59
            _('Neutron subnet id.'),
 
60
            update_allowed=True,
 
61
            constraints=[constraints.CustomConstraint('neutron.subnet')]
 
62
        ),
 
63
        NOVA_NETWORK: properties.Schema(
 
64
            properties.Schema.STRING,
 
65
            _('Nova network id.'),
 
66
            update_allowed=True,
 
67
            constraints=[constraints.CustomConstraint('nova.network')]
 
68
        ),
 
69
        DESCRIPTION: properties.Schema(
 
70
            properties.Schema.STRING,
 
71
            _('Share network description.'),
 
72
            update_allowed=True
 
73
        ),
 
74
        SECURITY_SERVICES: properties.Schema(
 
75
            properties.Schema.LIST,
 
76
            _('A list of security services IDs or names.'),
 
77
            schema=properties.Schema(
 
78
                properties.Schema.STRING
 
79
            ),
 
80
            update_allowed=True,
 
81
            default=[]
 
82
        )
 
83
    }
 
84
 
 
85
    attributes_schema = {
 
86
        SEGMENTATION_ID: attributes.Schema(
 
87
            _('VLAN ID for VLAN networks or tunnel-id for GRE/VXLAN '
 
88
              'networks.'),
 
89
            type=attributes.Schema.STRING
 
90
        ),
 
91
        CIDR: attributes.Schema(
 
92
            _('CIDR of subnet.'),
 
93
            type=attributes.Schema.STRING
 
94
        ),
 
95
        IP_VERSION: attributes.Schema(
 
96
            _('Version of IP address.'),
 
97
            type=attributes.Schema.STRING
 
98
        ),
 
99
        NETWORK_TYPE: attributes.Schema(
 
100
            _('The physical mechanism by which the virtual network is '
 
101
              'implemented.'),
 
102
            type=attributes.Schema.STRING
 
103
        ),
 
104
    }
 
105
 
 
106
    default_client_name = 'manila'
 
107
 
 
108
    def _request_network(self):
 
109
        return self.client().share_networks.get(self.resource_id)
 
110
 
 
111
    def _resolve_attribute(self, name):
 
112
        network = self._request_network()
 
113
        return getattr(network, name, None)
 
114
 
 
115
    def validate(self):
 
116
        super(ManilaShareNetwork, self).validate()
 
117
        if (self.properties[self.NEUTRON_NETWORK] and
 
118
                self.properties[self.NOVA_NETWORK]):
 
119
            raise exception.ResourcePropertyConflict(self.NEUTRON_NETWORK,
 
120
                                                     self.NOVA_NETWORK)
 
121
 
 
122
        if (self.properties[self.NOVA_NETWORK] and
 
123
                self.properties[self.NEUTRON_SUBNET]):
 
124
            raise exception.ResourcePropertyConflict(self.NEUTRON_SUBNET,
 
125
                                                     self.NOVA_NETWORK)
 
126
 
 
127
    def handle_create(self):
 
128
        network = self.client().share_networks.create(
 
129
            name=self.properties[self.NAME],
 
130
            neutron_net_id=self.properties[self.NEUTRON_NETWORK],
 
131
            neutron_subnet_id=self.properties[self.NEUTRON_SUBNET],
 
132
            nova_net_id=self.properties[self.NOVA_NETWORK],
 
133
            description=self.properties[self.DESCRIPTION])
 
134
        self.resource_id_set(network.id)
 
135
 
 
136
        for service in self.properties.get(self.SECURITY_SERVICES):
 
137
            self.client().share_networks.add_security_service(
 
138
                self.resource_id,
 
139
                self.client_plugin().get_security_service(service).id)
 
140
 
 
141
    def handle_update(self, json_snippet=None, tmpl_diff=None, prop_diff=None):
 
142
        if self.SECURITY_SERVICES in prop_diff:
 
143
            services = prop_diff.pop(self.SECURITY_SERVICES)
 
144
            s_curr = set([self.client_plugin().get_security_service(s).id
 
145
                          for s in self.properties.get(
 
146
                         self.SECURITY_SERVICES)])
 
147
            s_new = set([self.client_plugin().get_security_service(s).id
 
148
                        for s in services])
 
149
            for service in s_curr - s_new:
 
150
                self.client().share_networks.remove_security_service(
 
151
                    self.resource_id, service)
 
152
            for service in s_new - s_curr:
 
153
                self.client().share_networks.add_security_service(
 
154
                    self.resource_id, service)
 
155
 
 
156
        if prop_diff:
 
157
            self.client().share_networks.update(
 
158
                self.resource_id,
 
159
                name=prop_diff.get(self.NAME),
 
160
                neutron_net_id=prop_diff.get(self.NEUTRON_NETWORK),
 
161
                neutron_subnet_id=prop_diff.get(self.NEUTRON_SUBNET),
 
162
                nova_net_id=prop_diff.get(self.NOVA_NETWORK),
 
163
                description=prop_diff.get(self.DESCRIPTION))
 
164
 
 
165
    def handle_delete(self):
 
166
        try:
 
167
            self.client().share_networks.delete(self.resource_id)
 
168
        except Exception as ex:
 
169
            self.client_plugin().ignore_not_found(ex)
 
170
 
 
171
 
 
172
def resource_mapping():
 
173
    return {'OS::Manila::ShareNetwork': ManilaShareNetwork}