support redeploy

1. add redeploy interface
2. bugfix about redeploy api

Change-Id: I6780e7048b1bad90c2cda47c7b8ed9afc5b60255
Signed-off-by: baigk <baiguoku@huawei.com>
This commit is contained in:
baigk 2015-12-27 20:58:29 +08:00
parent 121d7c3e53
commit d39c2fc0c5
8 changed files with 101 additions and 4 deletions

View File

@ -17,6 +17,7 @@
import logging
from compass.actions import util
from compass.db.api import cluster as cluster_db
from compass.db.api import health_check_report as health_check_db
from compass.db.api import user as user_db
from compass.deployment.deploy_manager import DeployManager
@ -70,7 +71,7 @@ def deploy(cluster_id, hosts_id_list, username=None):
)
def redeploy(cluster_id, hosts_id_list, username=None):
def redeploy(cluster_id, username=None):
"""Deploy clusters.
:param cluster_hosts: clusters and hosts in each cluster to deploy.
@ -86,6 +87,10 @@ def redeploy(cluster_id, hosts_id_list, username=None):
adapter_info = util.ActionHelper.get_adapter_info(
adapter_id, cluster_id, user)
cluster_hosts = cluster_db.list_cluster_hosts(cluster_id, user)
hosts_id_list = [host['id'] for host in cluster_hosts]
hosts_info = util.ActionHelper.get_hosts_info(
cluster_id, hosts_id_list, user)

View File

@ -2068,6 +2068,12 @@ def take_cluster_action(cluster_id):
),
202
)
redeploy_cluster_func = _wrap_response(
functools.partial(
cluster_api.redeploy_cluster, cluster_id, user=current_user,
),
202
)
patch_cluster_func = _wrap_response(
functools.partial(
cluster_api.patch_cluster, cluster_id, user=current_user,
@ -2090,6 +2096,7 @@ def take_cluster_action(cluster_id):
remove_hosts=update_cluster_hosts_func,
review=review_cluster_func,
deploy=deploy_cluster_func,
redeploy=redeploy_cluster_func,
apply_patch=patch_cluster_func,
check_health=check_cluster_health_func
)

View File

@ -634,6 +634,11 @@ class Client(object):
data['deploy'] = deploy
return self._post('/clusters/%s/action' % cluster_id, data=data)
def redeploy_cluster(self, cluster_id, deploy={}):
data = {}
data['redeploy'] = deploy
return self._post('/clusters/%s/action' % cluster_id, data=data)
def get_cluster_state(self, cluster_id):
return self._get('/clusters/%s/state' % cluster_id)

View File

@ -1859,6 +1859,69 @@ def deploy_cluster(
}
@utils.supported_filters(optional_support_keys=['redeploy'])
@database.run_in_session()
@user_api.check_user_permission(
permission.PERMISSION_DEPLOY_CLUSTER
)
@utils.wrap_to_dict(
RESP_DEPLOY_FIELDS,
cluster=RESP_CONFIG_FIELDS,
hosts=RESP_CLUSTERHOST_FIELDS
)
def redeploy_cluster(
cluster_id, deploy={}, user=None, session=None, **kwargs
):
"""redeploy cluster.
Args:
cluster_id: cluster id.
"""
from compass.db.api import host as host_api
from compass.tasks import client as celery_client
cluster = _get_cluster(cluster_id, session=session)
check_cluster_editable(cluster, user=user)
check_cluster_validated(cluster)
utils.update_db_object(
session, cluster.state,
state='INITIALIZED',
percentage=0,
ready=False
)
for clusterhost in cluster.clusterhosts:
host = clusterhost.host
# ignore checking if underlying host is validated if
# the host is not editable.
host_api.check_host_validated(host)
utils.update_db_object(
session, host.state,
state='INITIALIZED',
percentage=0,
ready=False
)
if cluster.flavor_name:
check_clusterhost_validated(clusterhost)
utils.update_db_object(
session,
clusterhost.state,
state='INITIALIZED',
percentage=0,
ready=False
)
celery_client.celery.send_task(
'compass.tasks.redeploy_cluster',
(
user.email, cluster_id
)
)
return {
'status': 'redeploy action sent',
'cluster': cluster
}
@utils.supported_filters(optional_support_keys=['apply_patch'])
@database.run_in_session()
@user_api.check_user_permission(

View File

@ -136,8 +136,9 @@ class DeployManager(object):
"""Redeploy target system for the cluster without changing config."""
if not self.pk_installer:
logging.info("Redeploy_target_system: No installer found!")
return
self.os_installer.redeploy()
self.pk_installer.deploy()
logging.info("Start to redeploy target system.")
def redeploy(self):

View File

@ -286,8 +286,8 @@ class HostInfo(object):
class BaseConfigManager(object):
def __init__(self, adapter_info={}, cluster_info={}, hosts_info={}):
assert(adapter_info and isinstance(adapter_info, dict))
assert(cluster_info and isinstance(adapter_info, dict))
assert(hosts_info and isinstance(adapter_info, dict))
assert(cluster_info and isinstance(cluster_info, dict))
assert(hosts_info and isinstance(hosts_info, dict))
self.adapter_info = AdapterInfo(adapter_info)
self.cluster_info = ClusterInfo(cluster_info)

View File

@ -258,6 +258,9 @@ class AnsibleInstaller(PKInstaller):
return tmpl.respond()
def _create_ansible_run_env(self, env_name, ansible_run_destination):
if os.path.exists(ansible_run_destination):
shutil.rmtree(ansible_run_destination, True)
os.mkdir(ansible_run_destination)
# copy roles to run env

View File

@ -113,6 +113,19 @@ def deploy_cluster(deployer_email, cluster_id, clusterhost_ids):
logging.exception(error)
@celery.task(name='compass.tasks.redeploy_cluster')
def redeploy_cluster(deployer_email, cluster_id):
"""Redeploy the given cluster.
:param cluster_id: id of the cluster
:type cluster_id: int
"""
try:
deploy.redeploy(cluster_id, deployer_email)
except Exception as error:
logging.exception(error)
@celery.task(name='compass.tasks.patch_cluster')
def patch_cluster(patcher_email, cluster_id):
"""Patch the existing cluster.