use try except to judge whether to import provider_client

this is cherry pick from https://review.openstack.org/#/c/415812/17

Change-Id: Ia118eccd5c7a0e4288ec92f72753a6b1c3785188
This commit is contained in:
Zhou Ya 2017-01-23 10:57:56 +08:00
parent 3240484de4
commit efc4661c7b
2 changed files with 43 additions and 12 deletions

View File

@ -20,12 +20,14 @@ import copy
import subprocess
import time
import re
import os
import commands
from oslo_config import cfg
from oslo_log import log as logging
from webob.exc import HTTPBadRequest
from daisy.api import common
import threading
from oslo_utils import importutils
from daisy import i18n
import json
@ -500,6 +502,7 @@ class OSInstall():
self.max_parallel_os_num = int(CONF.max_parallel_os_number)
self.cluster_hosts_install_timeout = (
self.max_parallel_os_num / 4 + 2) * 60 * (12 * self.time_step)
self.providerclient = utils.get_provider_client
def _set_boot_or_power_state(self, host_detail, action):
user = host_detail['ipmi_user']
@ -720,7 +723,6 @@ class OSInstall():
kwargs['nova_lv_size'] = 0
rc, error = install_os(**kwargs)
if rc != 0:
install_os_description = error
LOG.info(
_("install os config failed because of '%s'" % error))
host_status = {'os_status': host_os_status['INSTALL_FAILED'],
@ -845,6 +847,27 @@ class OSInstall():
host_status['messages'] = "OS installed successfully"
# wait for nicfix script complete
time.sleep(10)
self._set_disk_start_mode(host_detail)
# node state: in use
node_state = 'true'
path = os.path.join(os.path.abspath(os.path.dirname(
os.path.realpath(__file__))), 'ext')
path_split = path.split("/")
new_path = []
for name in path_split:
if name != "api":
new_path.append(name)
path = "/".join(new_path)
path = os.getcwd() + "/api/v1/ext"
for root, dirs, names in os.walk(path):
filename = 'router.py'
if filename in names:
ext_name = root.split(path)[1].strip('/')
ext_func = "%s.api.hosts" % ext_name
extension = importutils.import_module(
'daisy.api.v1.ext',
ext_func)
extension.update_host_state(host_detail, node_state)
host_management_ip = daisy_cmn.get_management_ip(host_detail,
False)
if host_management_ip:
@ -1134,17 +1157,6 @@ def upgrade(self, req, cluster_id, version_id, version_patch_id,
if daisy_cmn.get_local_deployment_ip(host_ip):
LOG.exception("%s host os upgrade by hand" % host_ip)
continue
if update_object == "vplat":
target_host_os = _get_host_os_version(
host_ip, host_meta['root_pwd'])
if _cmp_os_version(update_file, target_host_os, host_ip) == -1:
LOG.warn(
_("new os version is lower than or equal to "
"host %s, don't need to upgrade!" % host_ip))
host_meta['messages'] = "New os version is lower than" \
" or equal to host %s." % host_ip
daisy_cmn.update_db_host_status(req, host_id, host_meta)
continue
host_set = set()
host_set.add(host_ip)
unreached_hosts = daisy_cmn.check_ping_hosts(host_set, 5)
@ -1181,6 +1193,15 @@ def upgrade_os(req, version_id, version_patch_id, update_script,
for host_info in upgrade_hosts:
host_id = host_info.keys()[0]
host_ip = host_info.values()[0]
host_detail = daisy_cmn.get_host_detail(req, host_id)
if update_object == "vplat":
target_host_os = _get_host_os_version(
host_ip, host_detail['root_pwd'])
if _cmp_os_version(update_file, target_host_os, host_ip) == -1:
LOG.warn(
_("new os version is lower than or equal to "
"host %s, don't need to upgrade!" % host_ip))
continue
host_meta['os_progress'] = 10
host_meta['os_status'] = host_os_status['UPDATING']
host_meta['messages'] = "os updating,begin copy iso"

View File

@ -50,6 +50,10 @@ from webob import exc
from daisy.common import exception
from daisy import i18n
try:
from providerclient.v1 import client as provider_client
except ImportError:
pass
CONF = cfg.CONF
@ -1202,3 +1206,9 @@ def get_numa_node_from_cpus(numa, str_cpus):
numa_nodes = list(set(numa_nodes))
numa_nodes.sort()
return numa_nodes
def get_provider_client(provider_ip):
endpoint = "http://" + provider_ip + ":8089"
args = {'version': 1.0, 'endpoint': endpoint}
return provider_client.Client(**args)