~ubuntu-branches/ubuntu/saucy/heat/saucy-updates

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-08 15:23:59 UTC
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: package-import@ubuntu.com-20130808152359-187gmaw0nx1oduxy
Tags: upstream-2013.2~b2.a186.g2b4b248
ImportĀ upstreamĀ versionĀ 2013.2~b2.a186.g2b4b248

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
#
 
4
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
5
#    not use this file except in compliance with the License. You may obtain
 
6
#    a copy of the License at
 
7
#
 
8
#         http://www.apache.org/licenses/LICENSE-2.0
 
9
#
 
10
#    Unless required by applicable law or agreed to in writing, software
 
11
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
12
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
13
#    License for the specific language governing permissions and limitations
 
14
#    under the License.
 
15
 
 
16
from heat.engine import clients
 
17
from heat.openstack.common import log as logging
 
18
from heat.engine.resources.neutron import neutron
 
19
from heat.engine import scheduler
 
20
 
 
21
if clients.neutronclient is not None:
 
22
    from neutronclient.common.exceptions import NeutronClientException
 
23
 
 
24
logger = logging.getLogger(__name__)
 
25
 
 
26
 
 
27
class Net(neutron.NeutronResource):
 
28
    properties_schema = {'name': {'Type': 'String'},
 
29
                         'value_specs': {'Type': 'Map',
 
30
                                         'Default': {}},
 
31
                         'admin_state_up': {'Default': True,
 
32
                                            'Type': 'Boolean'}}
 
33
    attributes_schema = {
 
34
        "id": "the unique identifier for this network",
 
35
        "status": "the status of the network",
 
36
        "name": "the name of the network",
 
37
        "subnets": "subnets of this network",
 
38
        "admin_state_up": "the administrative status of the network",
 
39
        "tenant_id": "the tenant owning this network"
 
40
    }
 
41
 
 
42
    def handle_create(self):
 
43
        props = self.prepare_properties(
 
44
            self.properties,
 
45
            self.physical_resource_name())
 
46
        net = self.neutron().create_network({'network': props})['network']
 
47
        self.resource_id_set(net['id'])
 
48
 
 
49
    def _show_resource(self):
 
50
        return self.neutron().show_network(
 
51
            self.resource_id)['network']
 
52
 
 
53
    def check_create_complete(self, *args):
 
54
        attributes = self._show_resource()
 
55
        return self.is_built(attributes)
 
56
 
 
57
    def handle_delete(self):
 
58
        client = self.neutron()
 
59
        try:
 
60
            client.delete_network(self.resource_id)
 
61
        except NeutronClientException as ex:
 
62
            if ex.status_code != 404:
 
63
                raise ex
 
64
        else:
 
65
            return scheduler.TaskRunner(self._confirm_delete)()
 
66
 
 
67
 
 
68
def resource_mapping():
 
69
    if clients.neutronclient is None:
 
70
        return {}
 
71
 
 
72
    return {
 
73
        'OS::Neutron::Net': Net,
 
74
        'OS::Quantum::Net': Net,
 
75
    }