"Fossies" - the Fresh Open Source Software Archive

Member "tacker-2.0.0/tacker/vnfm/infra_drivers/openstack/heat_client.py" (16 Oct 2019, 3184 Bytes) of package /linux/misc/openstack/tacker-2.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "heat_client.py" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 0.9.0_vs_1.0.0.

    1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
    2 # not use this file except in compliance with the License. You may obtain
    3 # a copy of the License at
    4 #
    5 #      http://www.apache.org/licenses/LICENSE-2.0
    6 #
    7 # Unless required by applicable law or agreed to in writing, software
    8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   10 # License for the specific language governing permissions and limitations
   11 # under the License.
   12 
   13 import sys
   14 
   15 from heatclient import exc as heatException
   16 from oslo_log import log as logging
   17 
   18 from tacker.common import clients
   19 from tacker.extensions import vnfm
   20 
   21 LOG = logging.getLogger(__name__)
   22 
   23 
   24 class HeatClient(object):
   25     def __init__(self, auth_attr, region_name=None):
   26         # context, password are unused
   27         self.heat = clients.OpenstackClients(auth_attr, region_name).heat
   28         self.stacks = self.heat.stacks
   29         self.resource_types = self.heat.resource_types
   30         self.resources = self.heat.resources
   31 
   32     def create(self, fields):
   33         fields = fields.copy()
   34         fields.update({
   35             'timeout_mins': 10,
   36             'disable_rollback': True})
   37         if 'password' in fields.get('template', {}):
   38             fields['password'] = fields['template']['password']
   39 
   40         try:
   41             return self.stacks.create(**fields)
   42         except heatException.HTTPException:
   43             type_, value, tb = sys.exc_info()
   44             raise vnfm.HeatClientException(msg=value)
   45 
   46     def delete(self, stack_id):
   47         try:
   48             self.stacks.delete(stack_id)
   49         except heatException.HTTPNotFound:
   50             LOG.warning("Stack %(stack)s created by service chain driver is "
   51                         "not found at cleanup", {'stack': stack_id})
   52 
   53     def get(self, stack_id):
   54         return self.stacks.get(stack_id)
   55 
   56     def update(self, stack_id, **kwargs):
   57         return self.stacks.update(stack_id, **kwargs)
   58 
   59     def resource_attr_support(self, resource_name, property_name):
   60         resource = self.resource_types.get(resource_name)
   61         return property_name in resource['attributes']
   62 
   63     def resource_get_list(self, stack_id, nested_depth=0):
   64         return self.heat.resources.list(stack_id,
   65                                         nested_depth=nested_depth)
   66 
   67     def resource_signal(self, stack_id, rsc_name):
   68         return self.heat.resources.signal(stack_id, rsc_name)
   69 
   70     def resource_get(self, stack_id, rsc_name):
   71         return self.heat.resources.get(stack_id, rsc_name)
   72 
   73     def resource_event_list(self, stack_id, rsc_name, **kwargs):
   74         return self.heat.events.list(stack_id, rsc_name, **kwargs)
   75 
   76     def resource_metadata(self, stack_id, rsc_name):
   77         return self.heat.resources.metadata(stack_id, rsc_name)
   78 
   79     def resource_mark_unhealthy(self, stack_id, resource_name,
   80                                 mark_unhealthy, resource_status_reason):
   81         return self.heat.resources.mark_unhealthy(stack_id, resource_name,
   82                                                   mark_unhealthy,
   83                                                   resource_status_reason)