Add Designate apis as mistral actions

Implement designate actions in Mistral, useful for automating the designate tasks

Change-Id: Id6f9d1c7a29530068be453a7c8c1fc607af23e91
Implements: blueprint designate-api-actions
This commit is contained in:
ravikiran 2016-05-12 06:38:05 -04:00
parent 627145b311
commit 42ca859c27
8 changed files with 100 additions and 2 deletions

View File

@ -41,6 +41,7 @@ Nikolay Mahotkin <nmakhotkin@mirantis.com>
Noa Koffman <noa.koffman@alcatel-lucent.com>
Oleksii Chuprykov <ochuprykov@mirantis.com>
Pierre-Arthur MATHIEU <pierre-arthur.mathieu@hp.com>
Ravikiran Kommalapati <ravikiran.k@att.com>
Ray Chen <chenrano2002@gmail.com>
Renat Akhmerov <rakhmerov@mirantis.com>
Renat Akhmerov <renat.akhmerov@gmail.com>

View File

@ -20,7 +20,7 @@ from mistral.actions.openstack.action_generator import base
SUPPORTED_MODULES = [
'Nova', 'Glance', 'Keystone', 'Heat', 'Neutron', 'Cinder', 'Ceilometer',
'Trove', 'Ironic', 'Baremetal Introspection', 'Swift', 'Zaqar', 'Barbican',
'Mistral'
'Mistral', 'Designate'
]

View File

@ -17,6 +17,7 @@ import functools
from barbicanclient import client as barbicanclient
from ceilometerclient.v2 import client as ceilometerclient
from cinderclient.v2 import client as cinderclient
from designateclient import client as designateclient
from glanceclient.v2 import client as glanceclient
from heatclient.v1 import client as heatclient
from ironic_inspector_client import v1 as ironic_inspector_client
@ -570,3 +571,39 @@ class BarbicanAction(base.OpenStackAction):
entity.store()
return entity._get_formatted_entity()
class DesignateAction(base.OpenStackAction):
_client_class = designateclient.Client
def _get_client(self):
ctx = context.ctx()
LOG.debug("Designate action security context: %s" % ctx)
designate_endpoint = keystone_utils.get_endpoint_for_project(
service_type='dns'
)
designate_url = keystone_utils.format_url(
designate_endpoint.url,
{'tenant_id': ctx.project_id}
)
client = self._client_class(
1,
ctx.user_name,
ctx.auth_token,
project_id=ctx.project_id,
auth_url=designate_url,
region_name=designate_endpoint.region
)
client.client.auth_token = ctx.auth_token
client.client.management_url = designate_url
return client
@classmethod
def _get_fake_client(cls):
return cls._client_class()

View File

@ -1084,5 +1084,38 @@
"workflows_list": "workflows.list",
"workflows_update": "workflows.update",
"workflows_validate": "workflows.validate"
},
"designate": {
"_comment": "It uses designateclient.v1.",
"diagnostics_ping": "diagnostics.ping",
"domain_create ": "domain.create",
"domain_delete": "domain.delete",
"domain_get": "domain.get",
"domain_list": "domain.list",
"domain_servers_list": "domain.servers_list",
"domain_update": "domain.update",
"quota_get": "quota.get",
"quota_reset": "quota.reset",
"quota_update": "quota.update",
"record_create": "record.create",
"record_delete": "record.delete",
"record_get": "record.get",
"record_list": "record.list",
"record_update": "record.update",
"report_count_all": "report.count_all",
"report_count_domains": "report.count_domains",
"report_count_records": "report.count_records",
"report_count_tenants": "report.count_tenats",
"report_tenant_domains": "report.tenant_domains",
"report_tenants_all": "report.tenant_all",
"server_create": "server.create",
"server_delete": "server.delete",
"server_get": "server.get",
"server_list": "server.list",
"server_update": "server.update",
"sync_all": "sync.all",
"sync_domain": "sync.domain",
"sync_record": "sync.record",
"touch_domain": "touch.domain"
}
}

View File

@ -32,6 +32,7 @@ MODULE_MAPPING = {
'zaqar': ['zaqar.queue_messages', actions.ZaqarAction],
'barbican': ['barbican.orders_list', actions.BarbicanAction],
'mistral': ['mistral.workflows_get', actions.MistralAction],
'designate': ['designate.domain_list', actions.DesignateAction],
}
EXTRA_MODULES = ['neutron', 'swift', 'zaqar']

View File

@ -187,3 +187,15 @@ class OpenStackActionTest(base.BaseTestCase):
self.assertTrue(mocked().orders_list.called)
mocked().orders_list.assert_called_once_with(limit=5)
@mock.patch.object(actions.DesignateAction, '_get_client')
def test_designate_action(self, mocked):
method_name = "domain.get"
action_class = actions.DesignateAction
action_class.client_method_name = method_name
params = {'domain': 'example.com'}
action = action_class(**params)
action.run()
self.assertTrue(mocked().domain.get.called)
mocked().domain.get.assert_called_once_with(domain="example.com")

View File

@ -25,6 +25,7 @@ pecan>=1.0.0 # BSD
python-barbicanclient>=4.0.0 # Apache-2.0
python-ceilometerclient>=2.2.1 # Apache-2.0
python-cinderclient>=1.6.0 # Apache-2.0
python-designateclient>=1.5.0 # Apache-2.0
python-glanceclient>=2.0.0 # Apache-2.0
python-heatclient>=0.6.0 # Apache-2.0
python-keystoneclient!=1.8.0,!=2.1.0,>=1.6.0 # Apache-2.0

View File

@ -23,6 +23,7 @@ from barbicanclient import client as barbicanclient
from ceilometerclient.v2 import client as ceilometerclient
from cinderclient.openstack.common.apiclient import base as cinder_base
from cinderclient.v2 import client as cinderclient
from designateclient import client as designateclient
from glanceclient.v2 import client as glanceclient
from heatclient.openstack.common.apiclient import base as heat_base
from heatclient.v1 import client as heatclient
@ -127,6 +128,11 @@ CEILOMETER_NAMESPACE_LIST = [
'resources', 'samples', 'statistics', 'trait_descriptions', 'traits'
]
DESIGNATE_NAMESPACE_LIST = [
'diagnostics', 'domain', 'quota', 'record', 'report_count',
'report_tenant', 'server', 'sync', 'touch'
]
def get_nova_client(**kwargs):
return novaclient.Client(2)
@ -171,6 +177,10 @@ def get_barbican_client(**kwargs):
)
def get_designate_client(**kwargs):
return designateclient.Client(1)
CLIENTS = {
'nova': get_nova_client,
'heat': get_heat_client,
@ -182,6 +192,7 @@ CLIENTS = {
'ironic': get_ironic_client,
'barbican': get_barbican_client,
'mistral': get_mistral_client,
'designate': get_designate_client
# 'neutron': get_nova_client
# 'baremetal_introspection': ...
# 'swift': ...
@ -198,6 +209,7 @@ BASE_MANAGERS = {
'ironic': BASE_IRONIC_MANAGER,
'barbican': BASE_BARBICAN_MANAGER,
'mistral': BASE_MISTRAL_MANAGER,
'designate': None,
# 'neutron': BASE_NOVA_MANAGER
# 'baremetal_introspection': ...
# 'swift': ...
@ -205,7 +217,8 @@ BASE_MANAGERS = {
}
NAMESPACES = {
'glance': GLANCE_NAMESPACE_LIST,
'ceilometer': CEILOMETER_NAMESPACE_LIST
'ceilometer': CEILOMETER_NAMESPACE_LIST,
'designate': DESIGNATE_NAMESPACE_LIST
}
ALLOWED_ATTRS = ['service_catalog', 'catalog']
FORBIDDEN_METHODS = [