yakumo.neutron.v2.network

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

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

      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 networks 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  ATTRIBUTE_MAPPING = [
     26      ('id', 'id', mapper.Noop),
     27      ('name', 'name', mapper.Noop),
     28      ('status', 'status', mapper.Noop),
     29      ('subnets', 'subnets',
     30       mapper.List(mapper.Resource('neutron.subnet'))),
     31      ('project', 'tenant_id', mapper.Resource('project')),
     32      ('is_shared', 'shared', mapper.Noop),
     33      ('is_enabled', 'admin_state_up', mapper.Noop),
     34      ('is_external', 'router:external', mapper.Noop),
     35      ('is_secured', 'port_security_enabled', mapper.Noop),
     36      ('segments', 'segments', mapper.Noop),
     37      ('provider_physical_network', 'provider:physical_network',
     38       mapper.Noop),
     39      ('provider_network_type', 'provider:network_type', mapper.Noop),
     40      ('provider_segmentation_id', 'segmentation_id', mapper.Noop),
     41      ('vlan_transparent', 'vlan_transparent', mapper.Noop),
     42  ]
     43
     44
     45 -class Resource(base.Resource):
     46      """Resource class for networks in Networking V2 API"""
     47
     48      _stable_state = ['ACTIVE', 'DOWN', 'INACTIVE', 'ERROR']
     49
     50 -    def update(self, name=UNDEF, is_shared=UNDEF, is_enabled=UNDEF,
     51                 is_external=UNDEF, is_port_security_enabled=UNDEF,
     52                 segments=UNDEF, provider_physical_network=UNDEF,
     53                 provider_network_type=UNDEF,
     54                 provider_segmentation_id=UNDEF):
     55          """
     56          Update properties of a network
     57
     58          @keyword name: Network name
     59          @type name: str
     60          @keyword is_shared: Whether the network is shared
     61          @type is_shared: bool
     62          @keyword is_enabled: Whether the network is enabled
     63          @type is_enabled: bool
     64          @keyword is_external: Wehter the network is external
     65          @type is_external: bool
     66          @keyword is_port_security_enabled: Whether the network is secured
     67          @type is_port_security_enabled: bool
     68          @keyword segments: Segments
     69          @type segments: str
     70          @keyword provider_physical_network: (Provider) physical network
     71          @type provider_physical_network: str
     72          @keyword provider_network_type: (Provider) network type
     73          @type provider_network_type: str
     74          @keyword provider_segmentation_id: (Provider) segmentation ID
     75          @type provider_segmentation_id: int
     76          @rtype: None
     77          """
     78          super(Resource, self).update(
     79              name=name,
     80              is_shared=is_shared,
     81              is_enabled=is_enabled,
     82              is_external=is_external,
     83              is_port_security_enabled=is_port_security_enabled,
     84              segments=segments,
     85              provider_physical_network=provider_physical_network,
     86              provider_network_type=provider_network_type,
     87              provider_segmentation_id=provider_segmentation_id)
     88
     89
     90 -class Manager(base.Manager):
     91      """Manager class for networks in Networking V2 API"""
     92
     93      resource_class = Resource
     94      service_type = 'network'
     95      _attr_mapping = ATTRIBUTE_MAPPING
     96      _json_resource_key = 'network'
     97      _json_resources_key = 'networks'
     98      _url_resource_path = '/v2.0/networks'
     99
    100 -    def create(self, name=UNDEF, project=UNDEF, is_shared=UNDEF,
    101                 is_enabled=UNDEF, is_external=UNDEF,
    102                 is_port_security_enabled=UNDEF, segments=UNDEF,
    103                 provider_physical_network=UNDEF, provider_network_type=UNDEF,
    104                 provider_segmentation_id=UNDEF, vlan_transparent=UNDEF):
    105          """
    106          Create a network
    107
    108          @keyword name: Network name
    109          @type name: str
    110          @keyword project: Project
    111          @type project: yakumo.project.Resource
    112          @keyword is_shared: Whether the network is shared
    113          @type is_shared: bool
    114          @keyword is_enabled: Whether the network is enabled
    115          @type is_enabled: bool
    116          @keyword is_external: Wehter the network is external
    117          @type is_external: bool
    118          @keyword is_port_security_enabled: Whether the network is secured
    119          @type is_port_security_enabled: bool
    120          @keyword segments: Segments
    121          @type segments: str
    122          @keyword provider_physical_network: (Provider) physical network
    123          @type provider_physical_network: str
    124          @keyword provider_network_type: (Provider) network type
    125          @type provider_network_type: str
    126          @keyword provider_segmentation_id: (Provider) segmentation ID
    127          @type provider_segmentation_id: int
    128          @keyword vlan_transparent: (Provider) VLAN transparent
    129          @type vlan_transparent: int
    130          @return: Created network
    131          @rtype: yakumo.neutron.v2.network.Resource
    132          """
    133          return super(Manager, self).create(
    134              name=name,
    135              is_shared=is_shared,
    136              project=project,
    137              is_enabled=is_enabled,
    138              is_external=is_external,
    139              is_port_security_enabled=is_port_security_enabled,
    140              segments=segments,
    141              provider_physical_network=provider_physical_network,
    142              provider_network_type=provider_network_type,
    143              provider_segmentation_id=provider_segmentation_id,
    144              vlan_transparent=vlan_transparent)
    145