Source code for heat.engine.clients.os.senlin

#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from heat.common import exception
from heat.common.i18n import _
from heat.engine.clients import client_plugin
from heat.engine import constraints

from senlinclient import client
from senlinclient.common import exc

CLIENT_NAME = 'senlin'


[docs]class SenlinClientPlugin(client_plugin.ClientPlugin): service_types = [CLUSTERING] = ['clustering'] VERSION = '1' def _create(self): con = self.context args = { 'auth_url': con.auth_url, 'project_id': con.tenant_id, 'token': con.keystone_session.get_token(), 'user_id': con.user_id, 'auth_plugin': 'token', } return client.Client(self.VERSION, **args)
[docs] def generate_spec(self, spec_type, spec_props): spec = {'properties': spec_props} spec['type'], spec['version'] = spec_type.split('-') return spec
[docs] def check_action_status(self, action_id): action = self.client().get_action(action_id) if action.status == 'SUCCEEDED': return True elif action.status == 'FAILED': raise exception.ResourceInError( status_reason=action.status_reason, resource_status=action.status, ) return False
[docs] def is_not_found(self, ex): return isinstance(ex, exc.sdkexc.ResourceNotFound)
[docs] def is_bad_request(self, ex): return (isinstance(ex, exc.sdkexc.HttpException) and ex.http_status == 400)
[docs]class ProfileConstraint(constraints.BaseCustomConstraint): # If name is not unique, will raise exc.sdkexc.HttpException expected_exceptions = (exc.sdkexc.HttpException,)
[docs] def validate_with_client(self, client, profile): client.client(CLIENT_NAME).get_profile(profile)
[docs]class ClusterConstraint(constraints.BaseCustomConstraint): # If name is not unique, will raise exc.sdkexc.HttpException expected_exceptions = (exc.sdkexc.HttpException,)
[docs] def validate_with_client(self, client, value): client.client(CLIENT_NAME).get_cluster(value)
[docs]class ProfileTypeConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.StackValidationFailed,)
[docs] def validate_with_client(self, client, value): senlin_client = client.client(CLIENT_NAME) type_list = senlin_client.profile_types() names = [pt.name for pt in type_list] if value not in names: not_found_message = ( _("Unable to find senlin profile type '%(pt)s', " "available profile types are %(pts)s.") % {'pt': value, 'pts': names} ) raise exception.StackValidationFailed(message=not_found_message)
[docs]class PolicyTypeConstraint(constraints.BaseCustomConstraint): expected_exceptions = (exception.StackValidationFailed,)
[docs] def validate_with_client(self, client, value): senlin_client = client.client(CLIENT_NAME) type_list = senlin_client.policy_types() names = [pt.name for pt in type_list] if value not in names: not_found_message = ( _("Unable to find senlin policy type '%(pt)s', " "available policy types are %(pts)s.") % {'pt': value, 'pts': names} ) raise exception.StackValidationFailed(message=not_found_message)

Project Source