Skip to content

Commit

Permalink
Fix a backwards compatibility issue with multi-vdc API ping (#274)
Browse files Browse the repository at this point in the history
* Fix endpoint list bug in non-multi-vdc ping

* add logging
  • Loading branch information
padthaitofuhot committed Jun 20, 2017
1 parent bcf6399 commit a613ad1
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 7 deletions.
34 changes: 29 additions & 5 deletions ui/ecsconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
# it is provided by or on behalf of EMC.

"""
adsf
This script configures various ECS structures according to the
deployment map in deploy.yml.
"""

import logging
Expand All @@ -21,7 +22,7 @@
import click
import tui
import tui.tools
from tui.tools import o, die
from tui.tools import o, die, logobj
import time
import simplejson
from sarge import Capture, run, shell_format, capture_both, get_both
Expand All @@ -40,6 +41,14 @@
# Helpers
"""

DEBUG = True


def debug(msg):
if DEBUG:
o(msg)


"""
# Config
"""
Expand Down Expand Up @@ -69,21 +78,26 @@ def api_set_endpoint(self, api_endpoint):
"""
Sets the API endpoint to use. default is random endpoint
"""
logging.debug(self.__class__.__name__ + ': ' + sys._getframe().f_code.co_name)
logobj(api_endpoint)
self.api_endpoint = api_endpoint

def api_set_timeout(self, timeout):
"""
Sets the API timeout to <timeout> seconds
:param timeout: <timeout> seconds
"""
logging.debug(self.__class__.__name__ + ': ' + sys._getframe().f_code.co_name)
logobj(timeout)
self.api_timeout = timeout

def _api_get_client(self):
"""
Returns an instance of ecsclient.client.Client
"""
logging.debug(self.__class__.__name__ + ': ' + sys._getframe().f_code.co_name)
url = "{0}://{1}:{2}".format(API_PROTOCOL, self.api_endpoint, API_PORT)

logobj(url)
return Client('3',
username=self.ecs.get_root_user(),
password=self.ecs.get_root_pass(),
Expand All @@ -96,6 +110,7 @@ def api_reset(self):
"""
Resets the APIAdminClient instance
"""
logging.debug(self.__class__.__name__ + ': ' + sys._getframe().f_code.co_name)
try:
self.api_client.authentication.logout()
except Exception:
Expand All @@ -115,13 +130,15 @@ def diag_dt_get(self):
unknown_dt_num
unready_dt_num
"""
logging.debug(self.__class__.__name__ + ': ' + sys._getframe().f_code.co_name)
dt_diag_client = tui.ECSDiag(self.api_endpoint)
return dt_diag_client.get_dt_status()

def diag_dt_ready(self, footprint='small'):
"""
Returns True of no dt unready and dt unknown, False otherwise
"""
logging.debug(self.__class__.__name__ + ': ' + sys._getframe().f_code.co_name)
dt_data = self.diag_dt_get()
if dt_data['unknown_dt_num'] > 0 \
or dt_data['total_dt_num'] < self.ecs.get_dt_total(footprint) \
Expand All @@ -135,6 +152,7 @@ def diag_dt_status_text(self, dt_data=None):
Get a status string
:return: dt status string
"""
logging.debug(self.__class__.__name__ + ': ' + sys._getframe().f_code.co_name)
dt_string = None

if dt_data is None:
Expand All @@ -159,6 +177,7 @@ def wait_for_dt_ready(self):
"""
Loops until DT are ready or else timeout
"""
logging.debug(self.__class__.__name__ + ': ' + sys._getframe().f_code.co_name)
tries = DIAGNOSTIC_RETRIES
timeout = time.time() + DIAGNOSTIC_TIMEOUT
while tries >= 0:
Expand All @@ -172,6 +191,7 @@ def wait_for_dt_ready(self):
return False

def api_task_get_status(self, task_id):
logging.debug(self.__class__.__name__ + ': ' + sys._getframe().f_code.co_name)
pass

def get_vdc_id_by_name(self, vdc_name):
Expand All @@ -180,6 +200,7 @@ def get_vdc_id_by_name(self, vdc_name):
:param vdc_name: name of the deploy.yml VDC
:return: VDC ID
"""
logging.debug(self.__class__.__name__ + ': ' + sys._getframe().f_code.co_name)
return self.api_client.vdc.get(name=vdc_name)['id']

def get_vdc_secret_by_name(self, vdc_name):
Expand All @@ -188,6 +209,7 @@ def get_vdc_secret_by_name(self, vdc_name):
:param vdc_name: name of the deploy.yml VDC
:return: VDC Secret Key
"""
logging.debug(self.__class__.__name__ + ': ' + sys._getframe().f_code.co_name)
self.api_set_endpoint(self.ecs.get_vdc_endpoint(vdc_name))
self.api_reset()
return self.api_client.vdc.get_local_secret_key()['key']
Expand Down Expand Up @@ -313,8 +335,10 @@ def do_ping():
for vdc in vdc_list:
o('\t{}: {}'.format(vdc, conf.ecs.get_vdc_endpoint(vdc)))
endpoint_list = [conf.ecs.get_vdc_endpoint(vdc) for vdc in vdc_list]
logobj(endpoint_list)
else:
endpoint_list = conf.ecs.get_vdc_endpoint(conf.ecs.get_vdc_primary())
endpoint_list = [conf.ecs.get_vdc_endpoint(conf.ecs.get_vdc_primary())]
logobj(endpoint_list)

for endpoint in endpoint_list:
conf.api_set_endpoint(endpoint)
Expand Down Expand Up @@ -549,7 +573,7 @@ def create(self, name, description, node_id, storage_pool_id):

def add_one(name):
vdc_name = conf.ecs.get_sp_vdc(name)
o('Creating Storage Pool {}/{}'.format(vdc_name, name))
o('Creating Storage Pool: {}/{}'.format(vdc_name, name))

# Set the correct endpoint for this VDC/SP combo
conf.api_set_endpoint(conf.ecs.get_vdc_endpoint(vdc_name))
Expand Down

0 comments on commit a613ad1

Please sign in to comment.