yakumo.nova.v2.floating_ip_bulk

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

# Source Code for Module yakumo.nova.v2.floating_ip_bulk

     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 floating IP bulks 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      ('ip', 'address', mapper.Noop),
    28      ('ip_range', 'ip_range', mapper.Noop),
    29      ('server', 'instance_uuid', mapper.Resource('nova.server')),
    30      ('interface', 'interface', mapper.Noop),
    31      ('project', 'project_id', mapper.Resource('project')),
    32  ]
    33
    34
    35 -class Resource(base.Resource):
    36      """Resource class for floating IP bulks in Compute API v2"""
    37
    38
    39 -class Manager(base.Manager):
    40      """Manager class for floating IP bulks in Compute API v2"""
    41
    42      resource_class = Resource
    43      service_type = 'compute'
    44      _attr_mapping = ATTRIBUTE_MAPPING
    45      _hidden_methods = ["update"]
    46      _id_attr = 'ip'
    47      _json_resource_key = 'floating_ip_info'
    48      _json_resources_key = 'floating_ip_info'
    49      _url_resource_path = '/os-floating-ips-bulk'
    50
    51 -    def find_gen(self, host=None):
    52          """
    53          Bulk-get floating IPs
    54
    55          :param host=: hostname (str)
    56          """
    57          ret = self._http.get(self._url_resource_path, host)
    58          for x in ret.get('floating_ip_info'):
    59              attrs = self._json2attr(x)
    60              yield self.resource_class(self, **attrs)
    61
    62 -    def create(self, pool=UNDEF, ip_range=UNDEF, interface=UNDEF):
    63          """
    64          Bulk-create floating IPs
    65
    66          @keyword pool: Pool name (str, required)
    67          @type pool: Pool name (str, required)
    68          @keyword ip_range: CIDR like '192.168.1.0/24' (str, required)
    69          @type ip_range: CIDR like '192.168.1.0/24' (str, required)
    70          @keyword interface: Interface name like 'eth0' (str)
    71          @type interface: Interface name like 'eth0' (str)
    72          @rtype: None
    73          """
    74          self._http.post(self._url_resource_path,
    75                          data=utils.get_json_body(
    76                              "floating_ips_bulk_create",
    77                              ip_range=ip_range,
    78                              pool=pool,
    79                              interface=interface))
    80
    81 -    def delete(self, ip_range=None):
    82          """
    83          Bulk-create floating IPs
    84
    85          @keyword ip_range: CIDR like '192.168.1.0/24' (required)
    86          @type ip_range: str
    87          @rtype: None
    88          """
    89          self._http.put(self._url_resource_path, 'delete',
    90                         data=dict(ip_range=ip_range))
    91