yakumo.nova.v2.quota_set

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

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

      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 Quota sets 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      ('cores', 'cores', mapper.Noop),
     29      ('fixed_ips', 'fixed_ips', mapper.Noop),
     30      ('floating_ips', 'floating_ips', mapper.Noop),
     31      ('injected_file_content_bytes', 'injected_file_content_bytes',
     32       mapper.Noop),
     33      ('injected_file_path_bytes', 'injected_file_path_bytes', mapper.Noop),
     34      ('injected_files', 'injected_files', mapper.Noop),
     35      ('instances', 'instances', mapper.Noop),
     36      ('key_pairs', 'key_pairs', mapper.Noop),
     37      ('metadata_items', 'metadata_items', mapper.Noop),
     38      ('ram', 'ram', mapper.Noop),
     39      ('security_group_rules', 'security_group_rules', mapper.Noop),
     40      ('security_groups', 'security_groups', mapper.Noop),
     41      ('server_group_members', 'server_group_members', mapper.Noop),
     42      ('server_groups', 'server_groups', mapper.Noop),
     43  ]
     44
     45
     46 -class Resource(base.Resource):
     47      """Resource class for Quota sets in Compute API v2"""
     48
     49
     50 -class Manager(base.Manager):
     51      """Manager class for Quota sets in Compute API v2"""
     52
     53      resource_class = Resource
     54      service_type = 'compute'
     55      _attr_mapping = ATTRIBUTE_MAPPING
     56      _hidden_methods = ["create"]
     57      _json_resource_key = 'quota_set'
     58      _url_resource_path = '/os-quota-sets'
     59
     60 -    def get(self, project=None, user=None):
     61          """
     62          Get quota set for a project
     63
     64          @keyword project: Project (required)
     65          @type project: yakumo.project.Resource
     66          @keyword user: User
     67          @type user: yakumo.user.Resource
     68          @rtype: yakumo.nova.v2.quota_set.Resource
     69          """
     70          if project is None:
     71              project = self._project
     72          params = {}
     73          if user:
     74              params = dict(user_id=user.get_id())
     75          try:
     76              ret = self._http.get(self._url_resource_path, project._id,
     77                                   params=params)
     78              json_params = ret.get(self._json_resource_key)
     79              attrs = self._json2attr(json_params)
     80              return self.resource_class(self, **attrs)
     81          except:
     82              return None
     83
     84 -    def update(self, project=UNDEF, user=UNDEF, cores=UNDEF, fixed_ips=UNDEF,
     85                 floating_ips=UNDEF, injected_file_content_bytes=UNDEF,
     86                 injected_file_path_bytes=UNDEF, injected_files=UNDEF,
     87                 instances=UNDEF, key_pairs=UNDEF, metadata_items=UNDEF,
     88                 ram=UNDEF, security_group_rules=UNDEF, security_groups=UNDEF,
     89                 server_group_members=UNDEF, server_groups=UNDEF):
     90          """
     91          Update quota set for a project
     92
     93          @keyword project: Project object (required)
     94          @type project: yakumo.project.Resource
     95          @keyword user: User object
     96          @type user: yakumo.user.Resource
     97          @keyword cores: max number of cores
     98          @type cores: int
     99          @keyword fixed_ips: max number of fixed IPs
    100          @type fixed_ips: int
    101          @keyword floating_ips: max number of floating IPs
    102          @type floating_ips: int
    103          @keyword injected_file_content_bytes: max bytes of an injected file
    104          @type injected_file_content_bytes:int
    105          @keyword injected_file_path_bytes: max path length of an injected file
    106          @type injected_file_path_bytes: int
    107          @keyword injected_files: max number of injected files
    108          @type injected_files: int
    109          @keyword instances: max number of instances
    110          @type instances: int
    111          @keyword key_pairs: max number of key pairs
    112          @type key_pairs: int
    113          @keyword metadata_items: max number of metadata items
    114          @type metadata_items: int
    115          @keyword ram: max number of RAM
    116          @type ram: int
    117          @keyword security_group_rules: max number of security group rules
    118          @type security_group_rules: int
    119          @keyword security_groups: max number of security groups
    120          @type security_groups: int
    121          @keyword server_group_members: max number of server group members
    122          @type server_group_members: int
    123          @keyword server_groups: max number of server groups
    124          @type server_groups:int
    125          @rtype: None
    126          """
    127          if project is None:
    128              project = self._project
    129          params = {}
    130          if user:
    131              params = dict(user_id=user._id)
    132          kwargs = dict(cores=cores, fixed_ips=fixed_ips,
    133                        floating_ips=floating_ips,
    134                        injected_file_content_bytes=injected_file_content_bytes,
    135                        injected_file_path_bytes=injected_file_path_bytes,
    136                        injected_files=injected_files, instances=instances,
    137                        key_pairs=key_pairs, metadata_items=metadata_items,
    138                        ram=ram, security_group_rules=security_group_rules,
    139                        security_groups=security_groups,
    140                        server_group_members=server_group_members,
    141                        server_groups=server_groups)
    142          json_params = self._attr2json(kwargs)
    143          self._http.put(self._url_resource_path, project._id,
    144                         params=params,
    145                         data=utils.get_json_body(self._json_resource_key,
    146                                                  **json_params))
    147
    148 -    def delete(self, project=None, user=None):
    149          """
    150          Delete quota set for a project
    151
    152          @keyword project: Project
    153          @type project: yakumo.project.Resource
    154          @keyword user: User
    155          @type user: yakumo.user.Resource
    156          @rtype: None
    157          """
    158          if project is None:
    159              project = self._project
    160          params = {}
    161          if user:
    162              params = dict(user_id=user._id)
    163          self._http.delete(self._url_resource_path, project._id,
    164                            params=params)
    165
    166 -    def get_default(self, project=None):
    167          """
    168          Get default quota set for a project
    169
    170          @keyword project: Project
    171          @type project: yakumo.project.Resource
    172          @return: Default quota set
    173          @rtype: yakumo.nova.v2.quota_set.Resource
    174          """
    175          if project is None:
    176              project = self._project
    177          try:
    178              ret = self._http.get(self._url_resource_path, project._id)
    179              json_params = ret.get(self._json_resource_key)
    180              attrs = self._json2attr(json_params)
    181              return self.resource_class(self, **attrs)
    182          except:
    183              return None
    184