def connect_to_cb(cloud_name) : ''' TBD ''' home = os.environ["HOME"] username = pwd.getpwuid(os.getuid())[0] api_file_name = "/tmp/cb_api_" + username if os.access(api_file_name, os.F_OK) : try : _fd = open(api_file_name, 'r') _api_conn_info = _fd.read() _fd.close() print _msg = "#" * 75 _msg += "\nFound CB API connection information in \"" + api_file_name + "\"\n" _msg += "#" * 75 print _msg sleep(3) except : _msg = "Unable to open file containing API connection information " _msg += "(" + api_file_name + ")." print _msg exit(4) else : _msg = "Unable to locate file containing API connection information " _msg += "(" + api_file_name + ")." print _msg exit(4) _path_set = False for _location in [ os.path.abspath(path[0] + "/../"), home ]: for _path, _dirs, _files in os.walk(_location): for _filename in fnmatch.filter(_files, "code_instrumentation.py") : if _path.count("/lib/auxiliary") : _path_set = _path.replace("/lib/auxiliary",'') path.append(_path_set) break if _path_set : break if not _path_set : _msg = "Unable to find CB's client API library" print _msg exit(4) else : _msg = "#" * 75 _msg += "\nCB API client library found in \"" + _path + "\".\n" _msg += "#" * 75 print _msg sleep(3) #from lib.api.api_service_client import * from lib.api.api_service_client import APIException,APINoSuchMetricException,APINoDataException,makeTimestamp,APIVM, APIClient _msg = "\nConnecting to API daemon (" + _api_conn_info + ")...\n" print _msg api = APIClient(_api_conn_info) _msg = "#" * 75 _msg += "\nChecking connection to cloud \"" + cloud_name + "\"..." print _msg, _cloud_not_found = True for _cld in api.cldlist() : if _cld["name"] == cloud_name : _cloud_not_found = False if _cloud_not_found : print "Unable to find cloud \"" + str(cloud_name) + "\"" exit(1) api.hostlist(cloud_name) print "OK" print "#" * 75 return api
def connect_to_cb(cloud_name): ''' TBD ''' home = os.environ["HOME"] username = pwd.getpwuid(os.getuid())[0] api_file_name = "/tmp/cb_api_" + username if os.access(api_file_name, os.F_OK): try: _fd = open(api_file_name, 'r') _api_conn_info = _fd.read() _fd.close() print _msg = "#" * 75 _msg += "\nFound CB API connection information in \"" + api_file_name + "\"\n" _msg += "#" * 75 print _msg sleep(3) except: _msg = "Unable to open file containing API connection information " _msg += "(" + api_file_name + ")." print _msg exit(4) else: _msg = "Unable to locate file containing API connection information " _msg += "(" + api_file_name + ")." print _msg exit(4) _path_set = False for _location in [os.path.abspath(path[0] + "/../"), home]: for _path, _dirs, _files in os.walk(_location): for _filename in fnmatch.filter(_files, "code_instrumentation.py"): if _path.count("/lib/auxiliary"): _path_set = _path.replace("/lib/auxiliary", '') path.append(_path_set) break if _path_set: break if not _path_set: _msg = "Unable to find CB's client API library" print _msg exit(4) else: _msg = "#" * 75 _msg += "\nCB API client library found in \"" + _path + "\".\n" _msg += "#" * 75 print _msg sleep(3) #from lib.api.api_service_client import * from lib.api.api_service_client import APIException, APINoSuchMetricException, APINoDataException, makeTimestamp, APIVM, APIClient _msg = "\nConnecting to API daemon (" + _api_conn_info + ")...\n" print _msg api = APIClient(_api_conn_info) _msg = "#" * 75 _msg += "\nChecking connection to cloud \"" + cloud_name + "\"..." print _msg, _cloud_not_found = True for _cld in api.cldlist(): if _cld["name"] == cloud_name: _cloud_not_found = False if _cloud_not_found: print "Unable to find cloud \"" + str(cloud_name) + "\"" exit(1) api.hostlist(cloud_name) print "OK" print "#" * 75 return api