Ejemplo n.º 1
0
 def clean_license(self):
     license = self.cleaned_data.get('license', '').strip()
     try:
         License.load(license)
     except:
         raise forms.ValidationError(_('This is not a valid license.'))
     return license
Ejemplo n.º 2
0
 def clean_license(self):
     license = self.cleaned_data.get('license', '').strip()
     try:
         License.load(license)
     except:
         raise forms.ValidationError(_('This is not a valid license.'))
     return license
Ejemplo n.º 3
0
    def run(self):
        if not os.path.exists(LICENSE_FILE):
            return None
        with open(LICENSE_FILE, 'rb') as f:
            data = f.read()
        try:
            license = License.load(data)
        except:
            return [Alert(
                Alert.CRIT,
                _('Unable to decode %s license') % get_sw_name(),
            )]

        end_date = license.contract_end
        if end_date < datetime.now().date():
            return [Alert(
                Alert.CRIT,
                _('Your %s license has expired') % get_sw_name(),
            )]
        elif end_date - timedelta(days=30) < datetime.now().date():
            return [Alert(
                Alert.WARN, _(
                    'Your %(sw_name)s license is going to expire in %(date)s'
                ) % {
                    'sw_name': get_sw_name(),
                    'date': end_date,
                }
            )]
Ejemplo n.º 4
0
    def license_update(self, license):
        """
        Update license file.
        """
        try:
            License.load(license)
        except Exception:
            raise CallError('This is not a valid license.')

        with open(LICENSE_FILE, 'w+') as f:
            f.write(license)

        self.middleware.call_sync('etc.generate', 'rc')

        self.middleware.run_coroutine(
            self.middleware.call_hook('system.post_license_update'), wait=False,
        )
Ejemplo n.º 5
0
def get_license():
    if not os.path.exists(LICENSE_FILE):
        return None, 'ENOFILE'

    with open(LICENSE_FILE, 'r') as f:
        license_file = f.read().strip('\n')

    try:
        license = License.load(license_file)
    except Exception, e:
        return None, unicode(e)
Ejemplo n.º 6
0
    def license_update(self, license):
        """
        Update license file.
        """
        try:
            License.load(license)
        except Exception:
            raise CallError('This is not a valid license.')

        prev_product_type = self.middleware.call_sync('system.product_type')

        with open(LICENSE_FILE, 'w+') as f:
            f.write(license)

        self.middleware.call_sync('etc.generate', 'rc')

        SystemService.PRODUCT_TYPE = None
        if self.middleware.call_sync('system.is_enterprise'):
            Path('/data/truenas-eula-pending').touch(exist_ok=True)
        self.middleware.run_coroutine(
            self.middleware.call_hook('system.post_license_update', prev_product_type=prev_product_type), wait=False,
        )
Ejemplo n.º 7
0
    def _get_license():
        if not os.path.exists(LICENSE_FILE):
            return

        with open(LICENSE_FILE, 'r') as f:
            license_file = f.read().strip('\n')

        try:
            licenseobj = License.load(license_file)
        except Exception:
            return

        license = {
            "model": licenseobj.model,
            "system_serial": licenseobj.system_serial,
            "system_serial_ha": licenseobj.system_serial_ha,
            "contract_type": ContractType(licenseobj.contract_type).name.upper(),
            "contract_start": licenseobj.contract_start,
            "contract_end": licenseobj.contract_end,
            "legacy_contract_hardware": (
                licenseobj.contract_hardware.name.upper()
                if licenseobj.contract_type == ContractType.legacy
                else None
            ),
            "legacy_contract_software": (
                licenseobj.contract_software.name.upper()
                if licenseobj.contract_type == ContractType.legacy
                else None
            ),
            "customer_name": licenseobj.customer_name,
            "expired": licenseobj.expired,
            "features": [],
            "addhw": licenseobj.addhw,
            "addhw_detail": [
                f"{quantity} × " + (f"{LICENSE_ADDHW_MAPPING[code]} Expansion shelf" if code in LICENSE_ADDHW_MAPPING
                                    else f"<Unknown hardware {code}>")
                for quantity, code in licenseobj.addhw
            ],
        }
        for feature in licenseobj.features:
            license["features"].append(feature.name.upper())
        # Licenses issued before 2017-04-14 had a bug in the feature bit
        # for fibre channel, which means they were issued having
        # dedup+jails instead.
        if (
            Features.fibrechannel not in licenseobj.features and licenseobj.contract_start < date(2017, 4, 14) and
            Features.dedup in licenseobj.features and Features.jails in licenseobj.features
        ):
            license["features"].append(Features.fibrechannel.name.upper())
        return license