Exemple #1
0
    def post(self, request):
        lic_file = request.FILES['license_file']
        lic_file_content = lic_file.read()

        try:
            dummy_lic = License(
                license_file=lic_file_content,
                file_name="uploaded via webfrontend",
            )
            reader = LicenseFileReader(dummy_lic,
                                       log_com=request.xml_response.log)
        except LicenseFileReader.InvalidLicenseFile as e:
            request.xml_response.error(str(e), logger=logger)
        else:
            if License.objects.license_exists(lic_file_content):
                request.xml_response.warn(
                    "This license file has already been uploaded")
            else:
                local_cluster_id = device_variable.objects.get_cluster_id()
                file_cluster_ids = reader.get_referenced_cluster_ids()
                if local_cluster_id not in file_cluster_ids:
                    msg = "\n".join([
                        "This license file contains licenses for the following clusters: {}"
                        .format(", ".join(file_cluster_ids)),
                        "This cluster has the id {}.".format(local_cluster_id),
                    ])
                    request.xml_response.error(msg)
                else:
                    dummy_lic.save()
                    request.xml_response.info(
                        "Successfully uploaded license file: {}".format(
                            str(dummy_lic)))
Exemple #2
0
 def license_exists(self, lic_content):
     from initat.cluster.backbone.license_file_reader import LicenseFileReader
     _pure_content = LicenseFileReader.get_pure_data(lic_content)
     _present = False
     # only compare with the latest version ? ToDo, Fixme
     for value in self.values_list("license_file", flat=True):
         _loc_pc = LicenseFileReader.get_pure_data(value)
         if _loc_pc == _pure_content:
             _present = True
             break
     return _present
Exemple #3
0
    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
Exemple #4
0
    def _license_readers(self):
        from initat.cluster.backbone.license_file_reader import LicenseFileReader
        readers = []
        for file_content, file_name in self.values_list(
                'license_file', 'file_name'):
            try:
                readers.append(LicenseFileReader(file_content, file_name))
            except LicenseFileReader.InvalidLicenseFile as e:
                logger.info("Invalid license file in database {}: {}".format(
                    file_name, e))

        return readers
Exemple #5
0
    def post(self, request):
        lic_file = request.FILES['license_file']
        lic_file_content = lic_file.read()

        try:
            reader = LicenseFileReader(lic_file_content)
        except LicenseFileReader.InvalidLicenseFile as e:
            request.xml_response.error(unicode(e), logger=logger)
        else:
            if License.objects.license_exists(lic_file_content):
                request.xml_response.warn(
                    "This license file has already been uploaded")
            else:
                local_cluster_id = device_variable.objects.get_cluster_id()
                file_cluster_ids = reader.get_referenced_cluster_ids()
                if local_cluster_id not in file_cluster_ids:
                    msg = "\n".join([
                        u"This license file contains licenses for the following clusters: {}"
                        .format(", ".join(file_cluster_ids)),
                        u"This cluster has the id {}.".format(
                            local_cluster_id),
                    ])
                    request.xml_response.error(msg)
                else:
                    new_lic = License(file_name=lic_file.name,
                                      license_file=lic_file_content)
                    new_lic.save()
                    request.xml_response.info(
                        "Successfully uploaded license file: {}".format(
                            unicode(new_lic)))

                    srv_com = server_command.srv_command(
                        command="check_license_violations")
                    contact_server(request,
                                   icswServiceEnum.cluster_server,
                                   srv_com,
                                   timeout=60,
                                   log_error=True,
                                   log_result=False)
Exemple #6
0
 def get_valid_parameters(self):
     from initat.cluster.backbone.license_file_reader import LicenseFileReader
     # fix for above problem: build a map dict where only the latest license files
     # are referenced
     merged_maps = LicenseFileReader.merge_license_maps(
         self._license_readers)
     # import pprint
     # pprint.pprint(merged_maps)
     res = {}
     for _struct in merged_maps.values():
         # pprint.pprint(_struct)
         res.update(_struct["reader"].get_valid_parameters())
     return res
Exemple #7
0
    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
Exemple #8
0
 def get_valid_licenses(self):
     """
     Returns all licenses which are active (and should be displayed to the user)
     Problem: if you upload multiple license files (== license-packs) with the
     same name / UUID the system will return the any valid licenses and not the one
     from the latest files
     Quick fix: delete previous license files
     """
     from initat.cluster.backbone.license_file_reader import LicenseFileReader
     # fix for above problem: build a map dict where only the latest license files
     # are referenced
     merged_maps = LicenseFileReader.merge_license_maps(
         self._license_readers)
     # import pprint
     # pprint.pprint(merged_maps)
     return [
         lic for lic in set().union(*[
             _struct["reader"].get_valid_licenses()
             for _struct in merged_maps.values()
         ])
     ]
Exemple #9
0
 def get_license_packages(self):
     """Returns license packages in custom format."""
     from initat.cluster.backbone.license_file_reader import LicenseFileReader
     return LicenseFileReader.get_license_packages(self._license_readers)
Exemple #10
0
 def __unicode__(self):
     from initat.cluster.backbone.license_file_reader import LicenseFileReader
     _reader = LicenseFileReader(self.license_file, self.file_name)
     return _reader.license_info()
Exemple #11
0
 def get_raw_license_info(self, lic_obj):
     from initat.cluster.backbone.license_file_reader import LicenseFileReader
     return LicenseFileReader(lic_obj).raw_license_info