yakumo.nova.v2.key_pair

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

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

     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 key pairs 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      ('name', 'name', mapper.Noop),
    28      ('fingerprint', 'fingerprint', mapper.Noop),
    29      ('public_key', 'public_key', mapper.Noop),
    30      ('user', 'user_id', mapper.Resource('user')),
    31      ('created_at', 'created_at', mapper.DateTime),
    32      ('updated_at', 'updated_at', mapper.DateTime),
    33      ('deleted_at', 'deleted_at', mapper.DateTime),
    34      ('is_deleted', 'deleted', mapper.Noop),
    35  ]
    36
    37
    38 -class Resource(base.Resource):
    39      """Resource class for key pairs in Compute API v2"""
    40
    41
    42 -class Manager(base.Manager):
    43      """Manager class for key pairs in Compute API v2"""
    44
    45      resource_class = Resource
    46      service_type = 'compute'
    47      _attr_mapping = ATTRIBUTE_MAPPING
    48      _hidden_methods = ["update"]
    49      _id_attr = 'name'
    50      _json_resource_key = 'keypair'
    51      _json_resources_key = 'keypairs'
    52      _url_resource_path = '/os-keypairs'
    53
    54 -    def create(self, name=UNDEF, public_key=UNDEF):
    55          """
    56          Register a SSH public key
    57
    58          @keyword name: Key name
    59          @type name: str
    60          @keyword public_key: content of SSH public key
    61          @type public_key: str
    62          @return: Registered key
    63          @rtype: yakumo.nova.v2.key_pair.Resource
    64          """
    65          return super(Manager, self).create(name=name, public_key=public_key)
    66
    67 -    def _find_gen(self, **kwargs):
    68          ret = self._http.get(self._url_resource_list_path)
    69          for x in ret[self._json_resources_key]:
    70              ret = self.get(x[self._json_resource_key]['name'])
    71              for k, v in kwargs.items():
    72                  if getattr(ret, k, None) != v:
    73                      break
    74              else:
    75                  yield ret
    76