Merge "Restore: initialize heat client using current login tenant by default"
This commit is contained in:
commit
52d819a59c
|
@ -248,11 +248,15 @@ class RestoresController(wsgi.Controller):
|
||||||
" a restore.")
|
" a restore.")
|
||||||
raise exception.InvalidInput(reason=msg)
|
raise exception.InvalidInput(reason=msg)
|
||||||
|
|
||||||
|
# restore_auth and restore_target are optional
|
||||||
|
# Heat client can be initialized using current login tenant when the
|
||||||
|
# restore_target and restore_auth is not provided.
|
||||||
restore_auth = restore.get("restore_auth")
|
restore_auth = restore.get("restore_auth")
|
||||||
if not isinstance(restore_auth, dict):
|
if restore_auth is not None:
|
||||||
msg = _("restore_auth must be a dict when creating"
|
if not isinstance(restore_auth, dict):
|
||||||
" a restore.")
|
msg = _("restore_auth must be a dict when creating"
|
||||||
raise exception.InvalidInput(reason=msg)
|
" a restore.")
|
||||||
|
raise exception.InvalidInput(reason=msg)
|
||||||
|
|
||||||
restore_properties = {
|
restore_properties = {
|
||||||
'project_id': context.project_id,
|
'project_id': context.project_id,
|
||||||
|
|
|
@ -81,7 +81,7 @@ class RequestContext(context.RequestContext):
|
||||||
if s.get('type') in
|
if s.get('type') in
|
||||||
('identity', 'compute', 'object-store',
|
('identity', 'compute', 'object-store',
|
||||||
'image', 'volume', 'volumev2', 'network',
|
'image', 'volume', 'volumev2', 'network',
|
||||||
'volumev3')]
|
'volumev3', 'orchestration')]
|
||||||
else:
|
else:
|
||||||
# if list is empty or none
|
# if list is empty or none
|
||||||
self.service_catalog = []
|
self.service_catalog = []
|
||||||
|
|
|
@ -12,24 +12,60 @@
|
||||||
|
|
||||||
from heatclient import client as hc
|
from heatclient import client as hc
|
||||||
from keystoneclient.v2_0 import client as kc
|
from keystoneclient.v2_0 import client as kc
|
||||||
|
from oslo_config import cfg
|
||||||
|
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from karbor.i18n import _LE, _LI
|
from karbor.i18n import _LE, _LI
|
||||||
|
from karbor.services.protection import utils
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
SERVICE = 'heat'
|
SERVICE = 'heat'
|
||||||
|
heat_client_opts = [
|
||||||
|
cfg.StrOpt('region_id',
|
||||||
|
default='RegionOne',
|
||||||
|
help='The region id which the service belongs to.'),
|
||||||
|
cfg.StrOpt(SERVICE + '_endpoint',
|
||||||
|
help='URL of the heat endpoint.'),
|
||||||
|
cfg.StrOpt(SERVICE + '_catalog_info',
|
||||||
|
default='orchestration:heat:publicURL',
|
||||||
|
help='Info to match when looking for heat in the service '
|
||||||
|
'catalog. Format is: separated values of the form: '
|
||||||
|
'<service_type>:<service_name>:<endpoint_type> - '
|
||||||
|
'Only used if cinder_endpoint is unset'),
|
||||||
|
cfg.StrOpt(SERVICE + '_ca_cert_file',
|
||||||
|
default=None,
|
||||||
|
help='Location of the CA certificate file '
|
||||||
|
'to use for client requests in SSL connections.'),
|
||||||
|
cfg.BoolOpt(SERVICE + '_auth_insecure',
|
||||||
|
default=False,
|
||||||
|
help='Bypass verification of server certificate when '
|
||||||
|
'making SSL connection to Cinder.'),
|
||||||
|
]
|
||||||
|
|
||||||
|
cfg.CONF.register_opts(heat_client_opts, group=SERVICE + '_client')
|
||||||
|
|
||||||
KEYSTONECLIENT_VERSION = (3, 0)
|
KEYSTONECLIENT_VERSION = (3, 0)
|
||||||
HEATCLIENT_VERSION = '1'
|
HEATCLIENT_VERSION = '1'
|
||||||
|
|
||||||
|
|
||||||
def create(context, conf, **kwargs):
|
def create(context, conf, **kwargs):
|
||||||
|
cfg.CONF.register_opts(heat_client_opts, group=SERVICE + '_client')
|
||||||
|
auth_url = kwargs.get("auth_url", None)
|
||||||
|
if auth_url is not None:
|
||||||
|
return create_heat_client_with_auth_url(context, conf, **kwargs)
|
||||||
|
else:
|
||||||
|
return create_heat_client_with_tenant(context, conf)
|
||||||
|
|
||||||
|
|
||||||
|
def create_heat_client_with_auth_url(context, conf, **kwargs):
|
||||||
auth_url = kwargs["auth_url"]
|
auth_url = kwargs["auth_url"]
|
||||||
username = kwargs["username"]
|
username = kwargs["username"]
|
||||||
password = kwargs["password"]
|
password = kwargs["password"]
|
||||||
tenant_name = context.project_name
|
tenant_name = context.project_name
|
||||||
LOG.info(_LI('Creating heat client with url %s.'), auth_url)
|
cacert = conf.heat_client.heat_ca_cert_file
|
||||||
|
insecure = conf.heat_client.heat_auth_insecure
|
||||||
|
LOG.info(_LI('Creating heat client with auth url %s.'), auth_url)
|
||||||
try:
|
try:
|
||||||
keystone = kc.Client(version=KEYSTONECLIENT_VERSION,
|
keystone = kc.Client(version=KEYSTONECLIENT_VERSION,
|
||||||
username=username,
|
username=username,
|
||||||
|
@ -44,8 +80,31 @@ def create(context, conf, **kwargs):
|
||||||
if service['name'] == 'heat':
|
if service['name'] == 'heat':
|
||||||
heat_endpoint = service['endpoints'][0]['publicURL']
|
heat_endpoint = service['endpoints'][0]['publicURL']
|
||||||
heat = hc.Client(HEATCLIENT_VERSION, endpoint=heat_endpoint,
|
heat = hc.Client(HEATCLIENT_VERSION, endpoint=heat_endpoint,
|
||||||
token=auth_token)
|
token=auth_token, cacert=cacert, insecure=insecure)
|
||||||
return heat
|
return heat
|
||||||
except Exception:
|
except Exception:
|
||||||
LOG.error(_LE('Creating heat client with url %s.'), auth_url)
|
LOG.error(_LE('Creating heat client with url %s.'), auth_url)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
def create_heat_client_with_tenant(context, conf):
|
||||||
|
cacert = conf.heat_client.heat_ca_cert_file
|
||||||
|
insecure = conf.heat_client.heat_auth_insecure
|
||||||
|
|
||||||
|
conf.register_opts(heat_client_opts, group=SERVICE + '_client')
|
||||||
|
try:
|
||||||
|
url = utils.get_url(SERVICE, context, conf,
|
||||||
|
append_project_fmt='%(url)s/%(project)s')
|
||||||
|
except Exception:
|
||||||
|
LOG.error(_LE("Get heat service endpoint url failed."))
|
||||||
|
raise
|
||||||
|
|
||||||
|
try:
|
||||||
|
LOG.info(_LI('Creating heat client with url %s.'), url)
|
||||||
|
heat = hc.Client(HEATCLIENT_VERSION, endpoint=url,
|
||||||
|
token=context.auth_token, cacert=cacert,
|
||||||
|
insecure=insecure)
|
||||||
|
return heat
|
||||||
|
except Exception:
|
||||||
|
LOG.error(_LE('Creating heat client with endpoint fails.'))
|
||||||
|
raise
|
||||||
|
|
|
@ -93,16 +93,24 @@ class SyncStackStatusTask(task.Task):
|
||||||
|
|
||||||
def get_flow(context, workflow_engine, operation_type, checkpoint, provider,
|
def get_flow(context, workflow_engine, operation_type, checkpoint, provider,
|
||||||
restore, restore_auth):
|
restore, restore_auth):
|
||||||
target = restore['restore_target']
|
target = restore.get('restore_target', None)
|
||||||
auth_type = restore_auth["type"]
|
|
||||||
if auth_type == "password":
|
|
||||||
username = restore_auth["username"]
|
|
||||||
password = restore_auth["password"]
|
|
||||||
|
|
||||||
# TODO(luobin): create a heat_client
|
# TODO(luobin): create a heat_client
|
||||||
kwargs = {"auth_url": target,
|
# Initialize a heat client using current login tenant when the
|
||||||
"username": username,
|
# restore_target and restore_auth is not provided.
|
||||||
"password": password}
|
if target is not None:
|
||||||
|
username = None
|
||||||
|
password = None
|
||||||
|
if restore_auth is not None:
|
||||||
|
auth_type = restore_auth.get("type", None)
|
||||||
|
if auth_type == "password":
|
||||||
|
username = restore_auth["username"]
|
||||||
|
password = restore_auth["password"]
|
||||||
|
kwargs = {"auth_url": target,
|
||||||
|
"username": username,
|
||||||
|
"password": password}
|
||||||
|
else:
|
||||||
|
kwargs = {}
|
||||||
heat_client = ClientFactory.create_client("heat",
|
heat_client = ClientFactory.create_client("heat",
|
||||||
context=context,
|
context=context,
|
||||||
**kwargs)
|
**kwargs)
|
||||||
|
|
|
@ -70,6 +70,25 @@ class RestoresTest(karbor_base.KarborBaseTest):
|
||||||
after_num = len(restores)
|
after_num = len(restores)
|
||||||
self.assertEqual(1, after_num - before_num)
|
self.assertEqual(1, after_num - before_num)
|
||||||
|
|
||||||
|
def test_restore_create_without_target_and_auth(self):
|
||||||
|
volume = self.store(objects.Volume())
|
||||||
|
volume.create(1)
|
||||||
|
plan = self.store(objects.Plan())
|
||||||
|
plan.create(self.provider_id, [volume, ])
|
||||||
|
checkpoint = self.store(objects.Checkpoint())
|
||||||
|
checkpoint.create(self.provider_id, plan.id)
|
||||||
|
|
||||||
|
restores = self.karbor_client.restores.list()
|
||||||
|
before_num = len(restores)
|
||||||
|
|
||||||
|
restore = self.store(objects.Restore())
|
||||||
|
restore.create(self.provider_id, checkpoint.id,
|
||||||
|
None, self.parameters, None)
|
||||||
|
|
||||||
|
restores = self.karbor_client.restores.list()
|
||||||
|
after_num = len(restores)
|
||||||
|
self.assertEqual(1, after_num - before_num)
|
||||||
|
|
||||||
def test_restore_get(self):
|
def test_restore_get(self):
|
||||||
volume = self.store(objects.Volume())
|
volume = self.store(objects.Volume())
|
||||||
volume.create(1)
|
volume.create(1)
|
||||||
|
|
Loading…
Reference in New Issue