yakumo.nova.v2.service

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

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

      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 services 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      ('host', 'host', mapper.Noop),
     29      ('binary', 'binary', mapper.Noop),
     30      ('state', 'state', mapper.Noop),
     31      ('status', 'status', mapper.Noop),
     32      ('updated_at', 'updated_at', mapper.DateTime),
     33      ('availability_zone', 'zone',
     34       mapper.Resource('nova.availability_zone')),
     35      ('disabled_reason', 'disabled_reason', mapper.Noop),
     36  ]
     37
     38
     39 -class Resource(base.Resource):
     40      """Resource class for services in Compute API v2"""
     41
     42 -    def enable(self):
     43          """
     44          Enable a service on a host
     45
     46          @rtype: None
     47          """
     48          self._manager.enable(host=self.host, binary=self.binary)
     49
     50 -    def disable(self):
     51          """
     52          Disable a service on a host
     53
     54          @rtype: None
     55          """
     56          self._manager.disable(host=self.host, binary=self.binary)
     57
     58 -    def set_disabled_reason(self, reason=None):
     59          """
     60          Set disabled reason for a service on a host
     61
     62          @keyword reason: Description
     63          @type reason: str
     64          @rtype: None
     65          """
     66          self._manager.set_disabled_reason(host=self.host, binary=self.binary,
     67                                            reason=reason)
     68
     69 -    def update(self, name=UNDEF, availability_zone=UNDEF):
     70          """
     71          Create a host aggregate
     72
     73          @keyword name: name of the host aggregate
     74          @type name: str
     75          @keyword availability_zone: name of availability zone
     76          @type availability_zone: str
     77          @rtype: None
     78          """
     79          super(Resource, self).update(
     80              name=name,
     81              availability_zone=availability_zone)
     82
     83
     84 -class Manager(base.Manager):
     85      """Manager class for services in Compute API v2"""
     86
     87      resource_class = Resource
     88      service_type = 'compute'
     89      _attr_mapping = ATTRIBUTE_MAPPING
     90      _hidden_methods = ["create"]
     91      _json_resource_key = 'service'
     92      _json_resources_key = 'services'
     93      _url_resource_path = '/os-services'
     94
     95 -    def enable(self, host=None, binary=None):
     96          """
     97          Enable a service on a host
     98
     99          @keyword host: host name (required)
    100          @type host: str
    101          @keyword binary: binary name (required)
    102          @type binary: str
    103          @rtype: None
    104          """
    105          self._http.put(self._url_resource_path, "enable",
    106                         data=dict(host=host, binary=binary))
    107
    108 -    def disable(self, host=None, binary=None):
    109          """
    110          Disable a service on a host
    111
    112          @keyword host: host name (required)
    113          @type host: str
    114          @keyword binary: binary name (required)
    115          @type binary: str
    116          @rtype: None
    117          """
    118          self._http.put(self._url_resource_path, "disable",
    119                         data=dict(host=host, binary=binary))
    120
    121 -    def set_disabled_reason(self, host=None, binary=None, reason=None):
    122          """
    123          Set disabled reason for a service on a host
    124
    125          @keyword host: host name (required)
    126          @type host: str
    127          @keyword binary: binary name (required)
    128          @type binary: str
    129          @keyword reason: description (required)
    130          @type reason: str
    131          @rtype: None
    132          """
    133          self._http.put(self._url_resource_path, "disable-log-reason",
    134                         data=dict(host=host, binary=binary,
    135                                   disabled_reason=reason))
    136