yakumo.nova.v2.network

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

# Source Code for Module yakumo.nova.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 Compute API v2
     18  """
     19
     20  from yakumo import base
     21  from yakumo.constant import UNDEF
     22  from yakumo import mapper
     23  from yakumo import utils
     24
     25
     26  ATTRIBUTE_MAPPING = [
     27      ('id', 'id', mapper.Noop),
     28      ('bridge', 'bridge', mapper.Noop),
     29      ('bridge_interface', 'bridge_interface', mapper.Noop),
     30      ('broadcast', 'broadcast', mapper.Noop),
     31      ('cidr', 'cidr', mapper.Noop),
     32      ('cidr_v6', 'cidr_v6', mapper.Noop),
     33      ('dhcp_server', 'dhcp_server', mapper.Noop),
     34      ('dhcp_start', 'dhcp_start', mapper.Noop),
     35      ('dns1', 'dns1', mapper.Noop),
     36      ('dns2', 'dns2', mapper.Noop),
     37      ('gateway', 'gateway', mapper.Noop),
     38      ('gateway_v6', 'gateway_v6', mapper.Noop),
     39      ('host', 'host', mapper.Noop),
     40      ('name', 'label', mapper.Noop),
     41      ('mtu', 'mtu', mapper.Noop),
     42      ('netmask', 'netmask', mapper.Noop),
     43      ('netmask_v6', 'netmask_v6', mapper.Noop),
     44      ('priority', 'priority', mapper.Noop),
     45      ('rxtx_base', 'rxtx_base', mapper.Noop),
     46      ('vlan', 'vlan', mapper.Noop),
     47      ('vpn_private_address', 'vpn_private_address', mapper.Noop),
     48      ('vpn_public_address', 'vpn_public_address', mapper.Noop),
     49      ('vpn_public_port', 'vpn_public_port', mapper.Noop),
     50      ('project', 'project_id', mapper.Resource('project')),
     51      ('created_at', 'created_at', mapper.DateTime),
     52      ('deleted_at', 'deleted_at', mapper.DateTime),
     53      ('updated_at', 'updated_at', mapper.DateTime),
     54      ('is_deleted', 'deleted', mapper.Noop),
     55      ('is_dhcp_enabled', 'enable_dhcp', mapper.Noop),
     56      ('is_injected', 'injected', mapper.Noop),
     57      ('is_address_shared', 'share_address', mapper.Noop),
     58      ('is_multi_host', 'multi_host', mapper.Noop),
     59  ]
     60
     61
     62 -class Resource(base.Resource):
     63      """Resource class for networks in Compute API v2"""
     64
     65 -    def associate(self):
     66          """
     67          Associate a network
     68
     69          @rtype: None
     70          """
     71          self._http.post(self._url_resource_path, 'add',
     72                          data=dict(id=self._id))
     73
     74 -    def disassociate(self):
     75          """
     76          Disassociate a network
     77
     78          @rtype: None
     79          """
     80          self._http.post(self._url_resource_path, self._id, 'action',
     81                          data=dict(disassociate=None))
     82
     83 -    def associate_host(self, host=None):
     84          """
     85          Associate a host to a network
     86
     87          @keyword host: UUID of a host (required)
     88          @type host: str
     89          @rtype: None
     90          """
     91          self._http.post(self._url_resource_path, self._id, 'action',
     92                          data=dict(associate_host=host))
     93
     94 -    def disassociate_host(self, host=None):
     95          """
     96          Disassociate a host to a network
     97
     98          @keyword host: UUID of a host (required)
     99          @type host: str
    100          @rtype: None
    101          """
    102          self._http.post(self._url_resource_path, self._id, 'action',
    103                          data=dict(disassociate_host=host))
    104
    105 -    def disassociate_project(self, project=None):
    106          """
    107          Disassociate a host to a network
    108
    109          @keyword project: Project
    110          @type project: yakumo.project.Resource
    111          @rtype: None
    112          """
    113          self._http.post(self._url_resource_path, self._id, 'action',
    114                          data=dict(disassociate_project=project.get_id()))
    115
    116
    117 -class Manager(base.Manager):
    118      """Manager class for networks in Compute API v2"""
    119
    120      resource_class = Resource
    121      service_type = 'compute'
    122      _attr_mapping = ATTRIBUTE_MAPPING
    123      _hidden_methods = ["update"]
    124      _json_resource_key = 'network'
    125      _json_resources_key = 'networks'
    126      _url_resource_path = '/os-networks'
    127
    128 -    def create(self, bridge=UNDEF, bridge_interface=UNDEF, broadcast=UNDEF,
    129                 cidr=UNDEF, cidr_v6=UNDEF, dhcp_server=UNDEF, dhcp_start=UNDEF,
    130                 dns1=UNDEF, dns2=UNDEF, is_dhcp_enabled=UNDEF, gateway=UNDEF,
    131                 gateway_v6=UNDEF, host=UNDEF, is_injected=UNDEF, name=UNDEF,
    132                 mtu=UNDEF, is_multi_host=UNDEF, is_address_shared=UNDEF,
    133                 netmask=UNDEF, netmask_v6=UNDEF, priority=UNDEF, project=UNDEF,
    134                 rxtx_base=UNDEF, updated_at=UNDEF, vlan=UNDEF,
    135                 vpn_private_address=UNDEF, vpn_public_address=UNDEF,
    136                 vpn_public_port=UNDEF):
    137          """
    138          Create a network
    139
    140          @keyword bridge: VIFs on this network are connected to this bridge
    141          @type bridge: str
    142          @keyword bridge_interface: The bridge is connected to this interface
    143          @type bridge_interface: str
    144          @keyword broadcast: The broadcast address
    145          @type broadcast: str
    146          @keyword cidr: IPv4 subnet
    147          @type cidr: str
    148          @keyword cidr_v6: IPv6 subnet
    149          @type cidr_v6: str
    150          @keyword dhcp_server: DHCP server address
    151          @type dhcp_server: str
    152          @keyword dhcp_start: DHCP starting address
    153          @type dhcp_start: str
    154          @keyword dns1: First DNS
    155          @type dns1: str
    156          @keyword dns2: Second DNS
    157          @type dns2: str
    158          @keyword is_dhcp_enabled: enable DHCP
    159          @type is_dhcp_enabled: str
    160          @keyword is_injected: Injected flag
    161          @type is_injected: str
    162          @keyword is_multi_host: Multi host
    163          @type is_multi_host: str
    164          @keyword is_address_shared: Share Address
    165          @type is_address_shared: str
    166          @keyword gateway: IPv4 gateway
    167          @type gateway: str
    168          @keyword gateway_v6: IPv6 gateway
    169          @type gateway_v6: str
    170          @keyword host: Network host
    171          @type host: str
    172          @keyword mtu: MTU
    173          @type mtu: int
    174          @keyword name: Network label
    175          @type name: str
    176          @keyword netmask: IPv4 netmask
    177          @type netmask: str
    178          @keyword netmask_v6: IPv6 netmask
    179          @type netmask_v6: str
    180          @keyword priority: Network priority
    181          @type priority: str
    182          @keyword project: Project
    183          @type project: yakumo.project.Resource
    184          @keyword rxtx_base: RXTX base factor value for the network
    185          @type rxtx_base: str
    186          @keyword vlan: VLAN ID
    187          @type vlan: int
    188          @keyword vpn_private_address: VPN private address
    189          @type vpn_private_address: str
    190          @keyword vpn_public_address: VPN public address
    191          @type vpn_public_address: str
    192          @keyword vpn_public_port: VPN public port
    193          @type vpn_public_port: int
    194          @return: Created network
    195          @rtype: yakumo.nova.v2.network.Resource
    196          """
    197          return super(Manager, self).create(
    198              bridge=bridge,
    199              bridge_interface=bridge_interface,
    200              broadcast=broadcast,
    201              cidr=cidr,
    202              cidr_v6=cidr_v6,
    203              dhcp_server=dhcp_server,
    204              dhcp_start=dhcp_start,
    205              dns1=dns1,
    206              dns2=dns2,
    207              gateway=gateway,
    208              gateway_v6=gateway_v6,
    209              host=host,
    210              name=name,
    211              mtu=mtu,
    212              is_dhcp_enabled=is_dhcp_enabled,
    213              is_injected=is_injected,
    214              is_multi_host=is_multi_host,
    215              is_address_shared=is_address_shared,
    216              netmask=netmask,
    217              netmask_v6=netmask_v6,
    218              priority=priority,
    219              project=project,
    220              rxtx_base=rxtx_base,
    221              vlan=vlan,
    222              vpn_private_address=vpn_private_address,
    223              vpn_public_address=vpn_public_address,
    224              vpn_public_port=vpn_public_port)
    225