Ejemplo n.º 1
0
    def launch(self):
        # We are active only if the hosting driver is scaleway
        hostingctxmgr = get_hostingdrivermgr()
        if not hostingctxmgr.is_driver_active('azure'):
            self.set_not_eligible('This server is not hosted on Azure')
            return False

        hostingctx = hostingctxmgr.get_driver('azure')
        # Now we have our scaleway code, we can dump info from it

        meta_data = hostingctx.get_meta_data()

        return meta_data
Ejemplo n.º 2
0
    def launch(self):

        # We are active only if the hosting driver is scaleway
        hostingctxmgr = get_hostingdrivermgr()
        if not hostingctxmgr.is_driver_active('synology'):
            self.set_not_eligible('This server is not a synology NAS')
            return False

        hostingctx = hostingctxmgr.get_driver('synology')
        # Now we have our scaleway code, we can dump info from it

        meta_data = hostingctx.get_meta_data()

        res = meta_data.copy()

        # Try to get as SNMP if available
        self.logger.debug('META %s' % res)

        for (k, c) in self.oids.items():
            oid, name_mapping = c
            self.logger.debug('GET => %s ' % k)
            v = self._get_snmp_value(oid)
            final_value = self._get_transformed_value(v, key_name=k)
            # Take the name from a mappign if available, else take the raw key name
            saved_name = name_mapping if name_mapping is not None else k
            self.logger.debug('Get OID %s => %s' % (saved_name, final_value))
            res[saved_name] = final_value

        # Disk ones (we will zip them)
        disk_ids = self._get_snmp_value(self.disks_oids['diskID'])
        disk_models = self._get_snmp_value(self.disks_oids['diskModel'])
        disk_status = self._get_snmp_value(self.disks_oids['diskStatus'])
        disk_temps = self._get_snmp_value(self.disks_oids['diskTemp'])

        disks_entry = {}

        if disk_ids is not None:
            for (idx, disk_id) in enumerate(disk_ids):
                disk_model = disk_models[idx]
                disk_statu = disk_status[idx]
                final_disk_status = self._get_transformed_value(
                    disk_statu, key_name='diskStatus')
                disk_temp = disk_temps[idx]
                disks_entry[disk_id] = {
                    'model': disk_model,
                    'status': final_disk_status,
                    'temperature': disk_temp
                }
            res['disks'] = disks_entry

        return res
Ejemplo n.º 3
0
def hosting_driver_is_active(driver_name):
    """**hosting_driver_is_active(driver_name)** -> return True if this hosting driver is active.

<code>
    Example:
        hosting_driver_is_active('ec2')

    Returns:
        True
</code>
    """
    
    hostingctxmgr = get_hostingdrivermgr()
    return hostingctxmgr.is_driver_active(driver_name)
Ejemplo n.º 4
0
    def launch(self):
        logger = self.logger

        logger.debug('getSystem: start')
        res = {}

        res['hostname'] = platform.node()
        res['fqdn'] = socket.getfqdn()

        res['os'] = {}
        res['os']['name'] = platform.system().lower()
        res['os']['platform'] = sys.platform
        res['architecture'] = platform.uname()[-1]
        # Lazy load multiprocessing
        from multiprocessing import cpu_count
        res['cpu_count'] = cpu_count()
        res['cpu_model_name'] = ''
        res['cpu_mhz'] = 0

        systepacketmgr = get_systepacketmgr()
        # Linux, directly ask python
        if res['os']['name'] == 'linux':
            (distname, version, _id) = systepacketmgr.get_distro()
            linux = {}
            res['os']['linux'] = linux
            linux['distribution'] = distname  # .lower()
            linux['version'] = version  # .lower()
            linux['id'] = _id  # .lower()
            # Maybe version is directly an int, get it
            _version = linux['version']
            _major = None
            _minor = None
            # something like 7.2
            if '.' in _version:
                elts = _version.split('.')  # no limit, if 8.0.1, will give 8.0
                try:
                    _major = int(elts[0])
                    _minor = int(elts[1])
                except ValueError:
                    pass
            else:
                try:
                    _major = int(_version)
                    _minor = 0
                except ValueError:
                    pass
            linux['major_version'] = _major
            linux['minor_version'] = _minor

            # Also get CPU info
            with open('/proc/cpuinfo', 'r') as f:
                buf = f.read()
                lines = buf.splitlines()
                for line in lines:
                    if ':' not in line:
                        continue
                    key, value = line.split(':', 1)
                    if key.startswith('model name'):
                        res['cpu_model_name'] = value.strip()
                    if key.startswith('cpu MHz'):
                        res['cpu_mhz'] = int(float(value.strip()))

        # Windows, get data from Win32_OperatingSystem
        if os.name == 'nt':
            win = {}
            res['windows'] = win
            _os = wmiaccess.get_table_where('Win32_OperatingSystem',
                                            {'Primary': 1})
            # only the first entry
            _os = _os[0]
            props = [
                'Caption', 'ServicePackMajorVersion',
                'ServicePackMinorVersion', 'SerialNumber', 'OSArchitecture',
                'MUILanguages', 'CSDVersion'
            ]
            for prop in props:
                win[prop.lower()] = getattr(_os, prop)

            # Also get server roles
            win['features'] = []
            try:
                _features = wmiaccess.get_table_where('Win32_ServerFeature')
            except AttributeError:  # maybe the Win32_ServerFeature is missing
                _features = []
            for f in _features:
                win['features'].append(f.Name)
            win['features'].sort()

        if hasattr(os, 'getlogin'):
            try:
                res['user'] = os.getlogin()
            except OSError:  # some background daemon can have problem on ancien os
                if pwd is not None:
                    res['user'] = pwd.getpwuid(os.geteuid()).pw_name
            if hasattr(os, 'getuid'):  # windows python 3 do not have it
                res['uid'] = os.getuid()
                res['gid'] = os.getgid()

        # Get public & local address, and directly from the hosting driver as it already does the job
        hostingdrvmgr = get_hostingdrivermgr()
        res['public_ip'] = hostingdrvmgr.get_public_address()
        res['local_ip'] = hostingdrvmgr.get_local_address()

        logger.debug('getsystem: completed, returning')
        return res