Remove all codes about Heat

Change-Id: Ibf773e8e63f56a1f9eb1aa0ff38e718e4e750355
Implements: blueprint remove-heat
This commit is contained in:
zengchen 2017-05-20 17:28:09 +08:00
parent 0d6867dc8a
commit 9947cb40e2
10 changed files with 1 additions and 512 deletions

View File

@ -43,7 +43,6 @@ DEFAULT_EXTRA_SPECS="'snapshot_support=True create_share_from_snapshot_support=T
DEVSTACK_LOCAL_CONFIG+="API_WORKERS=4"
DEVSTACK_LOCAL_CONFIG+=$'\n'"VOLUME_BACKING_FILE_SIZE=20490M"
DEVSTACK_LOCAL_CONFIG+=$'\n'"enable_plugin karbor git://git.openstack.org/openstack/karbor"
DEVSTACK_LOCAL_CONFIG+=$'\n'"enable_plugin heat git://git.openstack.org/openstack/heat"
DEVSTACK_LOCAL_CONFIG+=$'\n'"enable_plugin manila git://git.openstack.org/openstack/manila"
DEVSTACK_LOCAL_CONFIG+=$'\n'"MANILA_OPTGROUP_generic1_driver_handles_share_servers=False"
DEVSTACK_LOCAL_CONFIG+=$'\n'"MANILA_USE_SERVICE_INSTANCE_PASSWORD=True"

View File

@ -8,7 +8,6 @@ ADMIN_PASSWORD=password
enable_plugin karbor https://git.openstack.org/openstack/karbor master
enable_plugin karbor-dashboard https://git.openstack.org/openstack/karbor-dashboard master
enable_plugin heat https://git.openstack.org/openstack/heat master
#run the services you want to use
ENABLED_SERVICES=rabbit,mysql,key
@ -17,7 +16,6 @@ ENABLED_SERVICES+=,placement-api
ENABLED_SERVICES+=,neutron,q-svc,q-agt,q-dhcp,q-meta
ENABLED_SERVICES+=,cinder,g-api,g-reg
ENABLED_SERVICES+=,c-api,c-vol,c-sch,c-bak,horizon
ENABLED_SERVICES+=,heat,h-api,h-api-cfn,h-api-cw,h-eng
ENABLED_SERVICES+=,manila,m-api,m-sch,m-shr,m-dat
#Add the karbor services
@ -44,4 +42,3 @@ MANILA_OPTGROUP_generic1_driver_handles_share_servers=False
MANILA_USE_SERVICE_INSTANCE_PASSWORD=True
MANILA_DEFAULT_SHARE_TYPE_EXTRA_SPECS="snapshot_support=True create_share_from_snapshot_support=True mount_snapshot_support=True driver_handles_share_servers=False"
SHARE_DRIVER=manila.share.drivers.lvm.LVMShareDriver

View File

@ -247,8 +247,6 @@ class RestoresController(wsgi.Controller):
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")
if restore_auth is not None:
if not isinstance(restore_auth, dict):

View File

@ -28,7 +28,6 @@ import karbor.services.operationengine.manager
import karbor.services.operationengine.operations.base as base
import karbor.services.protection.clients.cinder
import karbor.services.protection.clients.glance
import karbor.services.protection.clients.heat
import karbor.services.protection.clients.manila
import karbor.services.protection.clients.neutron
import karbor.services.protection.clients.nova
@ -57,9 +56,6 @@ _opts = [
('glance_client', list(itertools.chain(
karbor.common.config.service_client_opts,
karbor.services.protection.clients.glance.glance_client_opts))),
('heat_client', list(itertools.chain(
karbor.common.config.service_client_opts,
karbor.services.protection.clients.heat.heat_client_opts))),
('manila_client', list(itertools.chain(
karbor.common.config.service_client_opts,
karbor.services.protection.clients.manila.manila_client_opts))),

View File

@ -1,113 +0,0 @@
# 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 heatclient import client as hc
from keystoneclient.v3 import client as kc_v3
from oslo_config import cfg
from oslo_log import log as logging
from karbor.common import config
from karbor.services.protection.clients import utils
LOG = logging.getLogger(__name__)
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',
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.'),
]
CONFIG_GROUP = '%s_client' % SERVICE
CONF = cfg.CONF
CONF.register_opts(config.service_client_opts, group=CONFIG_GROUP)
CONF.register_opts(heat_client_opts, group=CONFIG_GROUP)
CONF.set_default('service_name', 'heat', CONFIG_GROUP)
CONF.set_default('service_type', 'orchestration', CONFIG_GROUP)
KEYSTONECLIENT_VERSION = (3, 0)
HEATCLIENT_VERSION = '1'
def create(context, conf, **kwargs):
cfg.CONF.register_opts(heat_client_opts, group=CONFIG_GROUP)
client_config = conf[CONFIG_GROUP]
if kwargs.get("auth_url", None):
return _create_client_with_auth_url(context, client_config, **kwargs)
else:
return _create_client_with_tenant(context, client_config, **kwargs)
def _create_client_with_auth_url(context, client_config, **kwargs):
auth_url = kwargs["auth_url"]
username = kwargs["username"]
password = kwargs["password"]
tenant_name = context.project_name
cacert = client_config.heat_ca_cert_file
insecure = client_config.heat_auth_insecure
LOG.debug('Creating heat client with auth url %s.', auth_url)
try:
keystone = kc_v3.Client(version=KEYSTONECLIENT_VERSION,
username=username,
tenant_name=tenant_name,
password=password,
auth_url=auth_url)
auth_token = keystone.auth_token
heat_endpoint = ''
services = keystone.service_catalog.catalog['catalog']
for service in services:
if service['name'] == 'heat':
endpoints = service['endpoints']
for endpoint in endpoints:
if endpoint['interface'] == 'public':
heat_endpoint = endpoint['url']
heat = hc.Client(HEATCLIENT_VERSION, endpoint=heat_endpoint,
token=auth_token, cacert=cacert, insecure=insecure)
return heat
except Exception:
LOG.error('Creating heat client with url %s.', auth_url)
raise
def _create_client_with_tenant(context, client_config, **kwargs):
url = utils.get_url(SERVICE, context, client_config,
append_project_fmt='%(url)s/%(project)s', **kwargs)
LOG.debug('Creating heat client with url %s.', url)
if kwargs.get('session'):
return hc.Client(HEATCLIENT_VERSION, session=kwargs.get('session'),
endpoint=url)
args = {
'endpoint': url,
'token': context.auth_token,
'cacert': client_config.heat_ca_cert_file,
'insecure': client_config.heat_auth_insecure,
}
return hc.Client(HEATCLIENT_VERSION, **args)

View File

@ -10,20 +10,14 @@
# License for the specific language governing permissions and limitations
# under the License.
from oslo_config import cfg
from oslo_log import log as logging
from oslo_service import loopingcall
from oslo_utils import timeutils
from oslo_utils import uuidutils
from taskflow import task
from karbor.common import constants
from karbor.services.protection import client_factory
from karbor.services.protection.flows import utils
from karbor.services.protection import resource_flow
from karbor.services.protection import restore_heat
from taskflow import task
sync_status_opts = [
cfg.IntOpt('sync_status_interval',
@ -68,111 +62,8 @@ class CompleteRestoreTask(task.Task):
utils.update_operation_log(context, operation_log, update_fields)
class CreateHeatTask(task.Task):
default_provides = ['heat_client', 'heat_template']
def execute(self, context, heat_conf):
LOG.info('Creating Heat template. Target: "%s"'
% heat_conf.get('auth_url', '(None)'))
heat_client = client_factory.ClientFactory.create_client(
'heat', context=context, **heat_conf)
heat_template = restore_heat.HeatTemplate()
return (heat_client, heat_template)
class CreateStackTask(task.Task):
default_provides = 'stack_id'
def execute(self, heat_client, heat_template):
stack_name = "restore_%s" % uuidutils.generate_uuid()
if heat_template.len() == 0:
LOG.info('Not creating Heat stack, no resources in template')
return None
LOG.info('Creating Heat stack, stack_name: %s', stack_name)
try:
body = heat_client.stacks.create(
stack_name=stack_name,
template=heat_template.to_dict())
LOG.debug('Created stack with id: %s', body['stack']['id'])
return body['stack']['id']
except Exception:
LOG.error("use heat to create stack failed")
raise
class SyncRestoreStatusTask(task.Task):
def execute(self, stack_id, heat_client, restore):
if stack_id is None:
LOG.info('Not syncing Heat stack status, stack is empty')
return
LOG.info('Syncing Heat stack status, stack_id: %s', stack_id)
self._restore = restore
sync_status_loop = loopingcall.FixedIntervalLoopingCall(
self._sync_status, heat_client, stack_id)
sync_status_loop.start(interval=CONF.sync_status_interval)
sync_status_loop.wait()
def _sync_status(self, heat_client, stack_id):
try:
stack = heat_client.stacks.get(stack_id)
except Exception:
LOG.debug('Heat error getting stack, stack_id: %s', stack_id)
raise
stack_status = getattr(stack, 'stack_status')
if stack_status == 'CREATE_IN_PROGRESS':
LOG.debug('Heat stack status: in progress, stack_id: %s',
stack_id)
elif stack_status == 'CREATE_COMPLETE':
LOG.info('Heat stack status: complete, stack_id: %s', stack_id)
self._update_resource_status(heat_client, stack_id)
raise loopingcall.LoopingCallDone()
else:
LOG.info('Heat stack status: failure, stack_id: %s', stack_id)
self._update_resource_status(heat_client, stack_id)
raise
def _update_resource_status(self, heat_client, stack_id):
LOG.debug('Updating resources status from heat stack (stack_id: %s)',
stack_id)
try:
resources = heat_client.resources.list(stack_id)
for resource in resources:
heat_to_karbor_map = {
'CREATE_COMPLETE': constants.RESOURCE_STATUS_AVAILABLE,
'CREATE_IN_PROGRESS': constants.RESOURCE_STATUS_RESTORING,
'CREATE_FAILED': constants.RESOURCE_STATUS_ERROR,
}
reason = resource.resource_status_reason if (
resource.resource_status == 'CREATE_FAILED'
) else None
self._restore.update_resource_status(
resource.resource_type,
resource.physical_resource_id,
heat_to_karbor_map[resource.resource_status],
reason,
)
self._restore.save()
except Exception as e:
LOG.warning('Unable to update resources status from heat stack. '
'Reason: %s', e)
def get_flow(context, workflow_engine, checkpoint, provider, restore,
restore_auth):
target = restore.get('restore_target', None)
heat_conf = {}
if target is not None:
heat_conf["auth_url"] = target
if restore_auth is not None:
auth_type = restore_auth.get("type", None)
if auth_type == "password":
heat_conf["username"] = restore_auth["username"]
heat_conf["password"] = restore_auth["password"]
resource_graph = checkpoint.resource_graph
operation_log = utils.create_operation_log_restore(context, restore)
parameters = restore.parameters
@ -191,10 +82,7 @@ def get_flow(context, workflow_engine, checkpoint, provider, restore,
workflow_engine.add_tasks(
restore_flow,
InitiateRestoreTask(),
CreateHeatTask(inject={'context': context, 'heat_conf': heat_conf}),
resources_task_flow,
CreateStackTask(),
SyncRestoreStatusTask(),
CompleteRestoreTask()
)
flow_engine = workflow_engine.get_engine(

View File

@ -1,92 +0,0 @@
# 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.
import datetime
import yaml
from karbor.exception import InvalidOriginalId
from oslo_log import log as logging
from oslo_serialization import jsonutils
LOG = logging.getLogger(__name__)
class HeatResource(object):
def __init__(self, resource_id, type):
super(HeatResource, self).__init__()
self.resource_id = resource_id
self._type = type
self._properties = {}
def set_property(self, key, value):
self._properties[key] = value
def to_dict(self):
resource_dict = {
self.resource_id: {
"type": self._type,
"properties": self._properties
}
}
return resource_dict
class HeatTemplate(object):
heat_template_version = str(datetime.date(2015, 10, 15))
description = "karbor restore template"
def __init__(self):
super(HeatTemplate, self).__init__()
self._resources = []
self._original_id_resource_map = {}
self._original_id_parameter_map = {}
def put_resource(self, original_id, heat_resource):
self._resources.append(heat_resource)
self._original_id_resource_map[original_id] = heat_resource.resource_id
def put_parameter(self, original_id, parameter):
self._original_id_parameter_map[original_id] = parameter
def get_resource_reference(self, original_id):
if original_id in self._original_id_resource_map:
return {
"get_resource": (self._original_id_resource_map[original_id])
}
elif original_id in self._original_id_parameter_map:
return self._original_id_parameter_map[original_id]
else:
LOG.error("The reference is not found, original_id:%s",
original_id)
raise InvalidOriginalId
def len(self):
return len(self._resources)
def to_dict(self):
resources_dict = {}
for resource in self._resources:
resource_id = resource.resource_id
resource_dict = resource.to_dict()
resources_dict[resource_id] = resource_dict[resource_id]
template_dict = {
"heat_template_version": self.heat_template_version,
"description": self.description,
"resources": resources_dict
}
return yaml.load(jsonutils.dumps(template_dict))
def dump_to_yaml_file(self, file_name):
with open(file_name, "w") as f:
yaml.dump(yaml.load(jsonutils.dumps(self.to_dict())),
f,
default_flow_style=False)

View File

@ -1,182 +0,0 @@
# 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.
import datetime
import tempfile
import yaml
from karbor.services.protection.restore_heat import HeatResource
from karbor.services.protection.restore_heat import HeatTemplate
from karbor.tests import base
class HeatResourceTest(base.TestCase):
def setUp(self):
super(HeatResourceTest, self).setUp()
fake_resource_id = "restore_123456"
fake_resource_type = "OS::Cinder::Volume"
self.heat_resource = HeatResource(fake_resource_id, fake_resource_type)
def test_set_property(self):
key = "volume_type"
value = "lvmdriver-1"
self.heat_resource.set_property(key, value)
self.assertEqual({"volume_type": "lvmdriver-1"},
self.heat_resource._properties)
def test_to_dict(self):
properties = {
"volume_type": "lvmdriver-1",
"size": 1
}
for key, value in properties.items():
self.heat_resource.set_property(key, value)
resource_dict = self.heat_resource.to_dict()
target_dict = {
"restore_123456": {
"type": "OS::Cinder::Volume",
"properties": {
"volume_type": "lvmdriver-1",
"size": 1
}
}
}
self.assertEqual(target_dict, resource_dict)
def tearDown(self):
super(HeatResourceTest, self).tearDown()
class HeatTemplateTest(base.TestCase):
def setUp(self):
super(HeatTemplateTest, self).setUp()
self.heat_template = HeatTemplate()
def test_put_resource(self):
fake_original_id = "123456"
fake_resource_id = "restore_123456"
fake_resource_type = "OS::Cinder::Volume"
heat_resource = HeatResource(fake_resource_id, fake_resource_type)
properties = {
"volume_type": "lvmdriver-1",
"size": 1
}
for key, value in properties.items():
heat_resource.set_property(key, value)
self.heat_template.put_resource(fake_original_id, heat_resource)
self.assertEqual(1, len(self.heat_template._resources))
self.assertEqual(
fake_resource_id,
self.heat_template._original_id_resource_map[fake_original_id]
)
def test_put_parameter(self):
fake_original_id = "123456"
fake_parameter = "restored_123456"
self.heat_template.put_parameter(fake_original_id, fake_parameter)
self.assertEqual(1, len(self.heat_template._original_id_parameter_map))
self.assertEqual(
fake_parameter,
self.heat_template._original_id_parameter_map[fake_original_id]
)
def test_get_resource_reference(self):
fake_original_id = "123456"
fake_resource_id = "restore_123456"
fake_resource_type = "OS::Cinder::Volume"
heat_resource = HeatResource(fake_resource_id, fake_resource_type)
properties = {
"volume_type": "lvmdriver-1",
"size": 1
}
for key, value in properties.items():
heat_resource.set_property(key, value)
self.heat_template.put_resource(fake_original_id, heat_resource)
reference = self.heat_template.get_resource_reference(fake_original_id)
self.assertEqual({"get_resource": "restore_123456"}, reference)
fake_original_id = '23456'
fake_parameter = 'restored_23456'
self.heat_template.put_parameter(fake_original_id, fake_parameter)
reference = self.heat_template.get_resource_reference(fake_original_id)
self.assertEqual(fake_parameter, reference)
def test_to_dict(self):
fake_original_id = "123456"
fake_resource_id = "restore_123456"
fake_resource_type = "OS::Cinder::Volume"
heat_resource = HeatResource(fake_resource_id, fake_resource_type)
properties = {
"volume_type": "lvmdriver-1",
"size": 1
}
for key, value in properties.items():
heat_resource.set_property(key, value)
self.heat_template.put_resource(fake_original_id, heat_resource)
fake_original_id_2 = '23456'
fake_parameter = 'restored_23456'
self.heat_template.put_parameter(fake_original_id_2, fake_parameter)
template_dict = self.heat_template.to_dict()
target_dict = {
"heat_template_version": str(datetime.date(2015, 10, 15)),
"description": "karbor restore template",
"resources": {
"restore_123456": {
"type": "OS::Cinder::Volume",
"properties": {
"volume_type": "lvmdriver-1",
"size": 1
}
}
}
}
self.assertEqual(target_dict, template_dict)
def test_dump_to_yaml_file(self):
fake_original_id = "123456"
temp_dir = tempfile.mkdtemp()
temp_file = temp_dir + "/template.yaml"
fake_resource_id = "restore_123456"
fake_resource_type = "OS::Cinder::Volume"
heat_resource = HeatResource(fake_resource_id, fake_resource_type)
properties = {
"volume_type": "lvmdriver-1",
"size": 1
}
for key, value in properties.items():
heat_resource.set_property(key, value)
self.heat_template.put_resource(fake_original_id, heat_resource)
self.heat_template.dump_to_yaml_file(temp_file)
with open(temp_file, "r") as f:
template_dict = yaml.load(f)
target_dict = {
"heat_template_version": str(datetime.date(2015, 10, 15)),
"description": "karbor restore template",
"resources": {
"restore_123456": {
"type": "OS::Cinder::Volume",
"properties": {
"volume_type": "lvmdriver-1",
"size": 1
}
}
}
}
self.assertEqual(target_dict, template_dict)

View File

@ -40,6 +40,5 @@ taskflow>=2.7.0 # Apache-2.0
WebOb>=1.7.1 # MIT
oslo.i18n!=3.15.2,>=2.1.0 # Apache-2.0
python-swiftclient>=3.2.0 # Apache-2.0
python-heatclient>=1.6.1 # Apache-2.0
python-karborclient>=0.6.0 # Apache-2.0
abclient>=0.2.3 # Apache-2.0

View File

@ -18,7 +18,6 @@ python-novaclient>=9.0.0 # Apache-2.0
python-cinderclient>=3.1.0 # Apache-2.0
python-karborclient>=0.6.0 # Apache-2.0
python-neutronclient>=6.3.0 # Apache-2.0
python-heatclient>=1.6.1 # Apache-2.0
python-troveclient>=2.2.0 # Apache-2.0
reno!=2.3.1,>=1.8.0 # Apache-2.0
openstackdocstheme>=1.16.0 # Apache-2.0