yakumo.neutron.v2.router

Package yakumo :: Package neutron :: Package v2 :: Module router |
[hide private]
[frames] | no frames]

# Source Code for Module yakumo.neutron.v2.router

      1  # Copyright 2014-2017 by Akira Yoshiyama <akirayoshiyama@gmail.com>.
      2  # All Rights Reserved.
      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  """
     17  Resource class and its manager for routers in Networking V2 API
     18  """
     19
     20  from yakumo import base
     21  from yakumo.constant import UNDEF
     22  from yakumo import mapper
     23
     24
     25  FIXED_IP_MAPPING = [
     26      ('ip_address', 'ip_address', mapper.Noop),
     27      ('subnet', 'subnet_id', mapper.Resource('subnet'))
     28  ]
     29
     30
     31  EXTERNAL_GATEWAY_INFO_MAPPING = [
     32      ('network', 'network_id', mapper.Resource('network')),
     33      ('is_snat_enabled', 'enable_snat', mapper.Noop),
     34      ('external_fixed_ips', 'external_fixed_ips',
     35       mapper.List(mapper.Dict(FIXED_IP_MAPPING)))
     36  ]
     37
     38
     39  ATTRIBUTE_MAPPING = [
     40      ('id', 'id', mapper.Noop),
     41      ('name', 'name', mapper.Noop),
     42      ('status', 'status', mapper.Noop),
     43      ('routes', 'routes', mapper.Noop),
     44      ('project', 'tenant_id', mapper.Resource('project')),
     45      ('is_enabled', 'admin_state_up', mapper.Noop),
     46      ('external_gateway_info', 'external_gateway_info',
     47       mapper.Dict(EXTERNAL_GATEWAY_INFO_MAPPING)),
     48      ('is_distributed', 'distributed', mapper.Noop),
     49      ('is_ha', 'ha', mapper.Noop),
     50  ]
     51
     52
     53 -class Resource(base.Resource):
     54      """Resource class for routers in Networking V2 API"""
     55
     56 -    def update(self, name=UNDEF, routes=UNDEF,
     57                 external_gateway_info=UNDEF, is_enabled=UNDEF):
     58          """
     59          Update properties of a router
     60
     61          @keyword name: Router name
     62          @type name: str
     63          @keyword routes: Routings
     64          @type routes: str
     65          @keyword external_gateway_info: External gateway infomation
     66          @type external_gateway_info: str
     67          @keyword is_enabled: Whether the router is enabled
     68          @type is_enabled: bool
     69          @rtype: None
     70          """
     71          super(Resource, self).update(
     72              name=name,
     73              router=router,
     74              external_gateway_info=external_gateway_info,
     75              is_enabled=is_enabled)
     76
     77 -    def add_interface(self, subnet=None, port=None):
     78          """
     79          Add an interface for router
     80
     81          Either subnet or port is required.
     82
     83          @keyword subnet: Subnet
     84          @type subnet: yakumo.neutron.v2.subnet.Resource
     85          @keyword port: Port
     86          @type port: yakumo.neutron.v2.subnet.Resource
     87          @rtype: None
     88          """
     89          if port:
     90              self._http.put(self._url_resource_path, self._id,
     91                             'add_router_interface',
     92                             data=dict(port_id=port.get_id()))
     93          elif subnet:
     94              self._http.put(self._url_resource_path, self._id,
     95                             'add_router_interface',
     96                             data=dict(subnet_id=subnet.get_id()))
     97
     98 -    def remove_interface(self, subnet=None, port=None):
     99          """
    100          Remove an interface for router
    101
    102          Either subnet or port is required.
    103
    104          @keyword subnet: Subnet
    105          @type subnet: yakumo.neutron.v2.subnet.Resource
    106          @keyword port: Port
    107          @type port: yakumo.neutron.v2.subnet.Resource
    108          @rtype: None
    109          """
    110          if port:
    111              self._http.put(self._url_resource_path, self._id,
    112                             'remove_router_interface',
    113                             data=dict(port_id=port.get_id()))
    114          elif subnet:
    115              self._http.put(self._url_resource_path, self._id,
    116                             'remove_router_interface',
    117                             data=dict(subnet_id=subnet.get_id()))
    118
    119
    120 -class Manager(base.Manager):
    121      """Manager class for routers in Networking V2 API"""
    122
    123      resource_class = Resource
    124      service_type = 'network'
    125      _attr_mapping = ATTRIBUTE_MAPPING
    126      _json_resource_key = 'router'
    127      _json_resources_key = 'routers'
    128      _url_resource_path = '/v2.0/routers'
    129
    130 -    def create(self, name=UNDEF, routes=UNDEF, is_enabled=UNDEF):
    131          """
    132          Create a router
    133
    134          @keyword name: Router name
    135          @type name: str
    136          @keyword routes: Routings
    137          @type routes: str
    138          @keyword is_enabled: Whether the router is enabled
    139          @type is_enabled: bool
    140          @return: Created router
    141          @rtype: yakumo.neutron.v2.router.Resource
    142          """
    143          return super(Manager, self).create(name=name, routes=routes,
    144                                             is_enabled=is_enabled)
    145