def register_cluster(opts): cluster_id = device_variable.objects.get_cluster_id() _dict = { 'username': opts.user, 'password': opts.password, 'cluster_name': opts.cluster_name, 'cluster_id': cluster_id, "fingerprint": hfp_tools.get_server_fp(serialize=True), } _vers = config_store.ConfigStore(VERSION_CS_NAME, quiet=True) for _df in ["database", "software", "models"]: _dict["{}_version".format(_df)] = _vers[_df] data = urllib.urlencode(_dict) try: res = urllib2.urlopen(REGISTRATION_URL, data) except urllib2.URLError as e: print("Error while accessing registration: {}".format(e)) traceback.print_exc(e) sys.exit(1) else: content = res.read() _install_license(content)
def _license_readers(self): from initat.cluster.backbone.license_file_reader import LicenseFileReader from initat.cluster.backbone.models import device_variable from initat.tools import hfp_tools if not hasattr(self, "_log_cache"): self._log_cache = [] cluster_id = device_variable.objects.get_cluster_id() cur_fp = hfp_tools.get_server_fp(serialize=True) readers = [] for lic in self.filter(Q(valid=True)): try: readers.append( LicenseFileReader( lic, cluster_id=cluster_id, current_fingerprint=cur_fp, log_com=self.cached_log, )) except LicenseFileReader.InvalidLicenseFile as e: self.cached_log( "Invalid license file in database {}: {}".format( lic.file_name, e, ), logging_tools.LOG_LEVEL_ERROR) return readers
def show_cluster_id(opts): if opts.raw: print(device_variable.objects.get_cluster_id()) else: print("") print("ClusterID: {}".format(device_variable.objects.get_cluster_id())) _vers = config_store.ConfigStore(VERSION_CS_NAME, quiet=True) for _df in ["database", "software", "models"]: print("{} version: {}".format(_df.title(), _vers[_df])) print("") if not opts.without_fp: _valid, _log = hfp_tools.server_dict_is_valid( hfp_tools.get_server_fp()) if not _valid: print(_log) else: print(_log) print("") print("Current Server Fingerprint:") print("") print(hfp_tools.get_server_fp(serialize=True))
def register_cluster(opts): cluster_id = device_variable.objects.get_cluster_id() _dict = { 'username': opts.user, 'password': opts.password, 'cluster_name': opts.cluster_name, 'cluster_id': cluster_id, "fingerprint": hfp_tools.get_server_fp(serialize=True), } _vers = config_store.ConfigStore(VERSION_CS_NAME, quiet=True) for _df in ["database", "software", "models"]: _dict["{}_version".format(_df)] = _vers[_df] data = urllib.parse.urlencode(_dict) try: res = urllib.request.urlopen(REGISTRATION_URL, data.encode("utf-8")) except urllib.error.URLError as e: print("Error while accessing registration: {}".format(e)) traceback.print_exc(e) sys.exit(1) else: content = res.read() try: content_xml = etree.fromstring(content) except: print("Error interpreting response: {}".format( process_tools.get_except_info())) sys.exit(-1) else: for message_xml in content_xml.xpath("//messages/message"): prefix = { 20: "", 30: "Warning: ", 40: "Error: " }.get(int(message_xml.get('log_level')), "") print("{}{}".format(prefix, message_xml.text)) code = int(content_xml.find("header").get("code")) if code < 40: # no error lic_file_node = content_xml.xpath( "//values/value[@name='license_file']") if len(lic_file_node): _install_license(lic_file_node[0].text) else: print("No license file found in response.") else: print("Exiting due to errors.") sys.exit(1)
def extract_fp_data(cluster_xml): def get_cluster_id(_xml): return _xml.findtext("icsw:id", namespaces=ICSW_XML_NS_MAP) fp_q = ".//icsw:hardware-finger-print/text()" fp_node = cluster_xml.xpath(fp_q, namespaces=ICSW_XML_NS_MAP) if len(fp_node): return { "info": "present", "valid": fp_node[0] == hfp_tools.get_server_fp(serialize=True) } else: return {"info": "not present", "valid": False}
def _license_readers(self): from initat.cluster.backbone.license_file_reader import LicenseFileReader from initat.cluster.backbone.models import device_variable from initat.tools import hfp_tools cluster_id = device_variable.objects.get_cluster_id() cur_fp = hfp_tools.get_server_fp(serialize=True) readers = [] for file_content, file_name in self.values_list( 'license_file', 'file_name'): try: readers.append( LicenseFileReader(file_content, file_name, cluster_id=cluster_id, current_fingerprint=cur_fp)) except LicenseFileReader.InvalidLicenseFile as e: logger.error("Invalid license file in database {}: {}".format( file_name, e)) return readers
def extract_fp_data(cluster_xml): def get_cluster_id(_xml): return _xml.findtext("icsw:id", namespaces=ICSW_XML_NS_MAP) fp_q = ".//icsw:hardware-finger-print/text()" fp_node = cluster_xml.xpath(fp_q, namespaces=ICSW_XML_NS_MAP) if len(fp_node): # print("*remote", HardwareFingerPrint.deserialize(fp_node[0].encode("ascii"), deep=True)) # print("*local ", HardwareFingerPrint.deserialize(hfp_tools.get_server_fp(serialize=True).encode("ascii"), deep=True)) return { "info": "present", "valid": fp_node[0] == hfp_tools.get_server_fp(serialize=True) } else: return { "info": "not present", "valid": False }
def current_fingerprint(self): if not self.current_fp: from initat.tools import hfp_tools self.current_fp = hfp_tools.get_server_fp(serialize=True) return self.current_fp