def _parseConfig(self, cfgdata): '''This method overrides the plugin base class method. It is used to parse the plugin specific configuration directives.''' for kw, args in cfgdata: if kw == "path": self.path = args elif kw == "api": self.api = args elif kw == "cloud_name": self.cloud_name = args path.insert(0, self.path) from lib.api.api_service_client import APIClient self.api = APIClient(self.api) self.api.dashboard_conn_check(self.cloud_name, check_for_vpn=True) self.msci = self.api.msci self.obj_cache = {} tzoffset = datetime.utcfromtimestamp(-1).hour - datetime.fromtimestamp( 0).hour + 1 if tzoffset == 24: tzoffset = 0 _now = int(time()) + (3600 * tzoffset) self.last_refresh = str(_now) self.expid = self.api.cldshow(self.cloud_name, "time")["experiment_id"] self.username = self.api.username self.latest_collection = {"HOST" : "latest_runtime_os_HOST_" + self.username, \ "VM" : "latest_runtime_os_VM_" + self.username} self.data_collection = {"HOST" : "runtime_os_HOST_" + self.username, \ "VM" : "runtime_os_VM_" + self.username} self.manage_collection = {"HOST" : "latest_management_HOST_" + self.username, \ "VM" : "latest_management_VM_" + self.username} _msg = "API contacted successfully. The current experiment id is \"" _msg += self.expid + "\" and the current username is \"" + self.username _msg += "\"." logging.debug(_msg)
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