Beispiel #1
0
    async def info(self):
        """
        Returns basic system information.
        """
        uptime = (await (await Popen(
            "env -u TZ uptime | awk -F', load averages:' '{ print $1 }'",
            stdout=subprocess.PIPE,
            shell=True,
        )).communicate())[0].decode().strip()

        serial = (await (await Popen(
            ['dmidecode', '-s', 'system-serial-number'],
            stdout=subprocess.PIPE,
        )).communicate())[0].decode().strip() or None

        product = (await (await Popen(
            ['dmidecode', '-s', 'system-product-name'],
            stdout=subprocess.PIPE,
        )).communicate())[0].decode().strip() or None

        license = get_license()[0]
        if license:
            license = {
                "contract_type":
                ContractType(license.contract_type).name.upper(),
                "contract_end": license.contract_end,
            }

        return {
            'version':
            self.version(),
            'hostname':
            socket.gethostname(),
            'physmem':
            sysctl.filter('hw.physmem')[0].value,
            'model':
            sysctl.filter('hw.model')[0].value,
            'cores':
            sysctl.filter('hw.ncpu')[0].value,
            'loadavg':
            os.getloadavg(),
            'uptime':
            uptime,
            'system_serial':
            serial,
            'system_product':
            product,
            'license':
            license,
            'boottime':
            datetime.fromtimestamp(
                struct.unpack('l',
                              sysctl.filter('kern.boottime')[0].value[:8])[0]),
            'datetime':
            datetime.utcnow(),
            'timezone':
            (await self.middleware.call('datastore.config',
                                        'system.settings'))['stg_timezone'],
        }
Beispiel #2
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
Beispiel #3
0
 async def __get_license(self):
     licenseobj = get_license()[0]
     if not licenseobj:
         return
     license = {
         "system_serial": licenseobj.system_serial,
         "system_serial_ha": licenseobj.system_serial_ha,
         "contract_type":
         ContractType(licenseobj.contract_type).name.upper(),
         "contract_end": licenseobj.contract_end,
         "features": [],
     }
     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 (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