Пример #1
0
    def on_get(self, req, resp):
        client = req.env['sl_client']
        hardware = HardwareManager(client)

        nodes = []
        hw_items = set([
            'id',
            'hostname',
            'domain',
            'hardwareStatus',
            'globalIdentifier',
            'fullyQualifiedDomainName',
            'processorPhysicalCoreAmount',
            'memoryCapacity',
            'primaryBackendIpAddress',
            'primaryIpAddress',
            'datacenter',
        ])
        server_items = set([
            'activeTransaction[id, transactionStatus[friendlyName,name]]',
        ])

        mask = '[mask[%s],' \
               ' mask(SoftLayer_Hardware_Server)[%s]]' % \
               (','.join(hw_items),
                ','.join(server_items))
        for hw in hardware.list_hardware(mask=mask):
            nodes.append({
                "uuid": hw['id'],
                "instance_uuid": hw['id'],
                # Get the actual power state of every device??? N+1 alert!
                # "power_state": '',
                "provision_state": hw['hardwareStatus']['status'],
            })
        resp.body = {'nodes': nodes}
Пример #2
0
def global_search(search):
    client = get_client()
    match_string = '<span class="text-primary">%s</span>' % search

    term = re.compile(search, re.IGNORECASE)

    results = []

    if 'vm' in app.config['installed_blueprints']:
        cci = CCIManager(client)
        #        if hostname_regex.match(term):
        for vm in cci.list_instances():
            if term.match(vm['hostname']) or \
               term.match(vm.get('primaryIpAddress', '')):
                text = '%s (%s)' % (vm['fullyQualifiedDomainName'],
                                    vm.get('primaryIpAddress', 'No Public IP'))
                text = term.sub(match_string, text)

                results.append({
                    'label':
                    '<strong>VM:</strong> ' + text,
                    'value':
                    url_for('vm_module.view', vm_id=vm['id'])
                })
    if 'servers' in app.config['installed_blueprints']:
        hw = HardwareManager(client)

        for svr in hw.list_hardware():
            if term.match(svr['hostname']) or \
               term.match(svr.get('primaryIpAddress', '')):
                text = '%s (%s)' % (svr['fullyQualifiedDomainName'],
                                    svr.get('primaryIpAddress',
                                            'No Public IP'))
                text = term.sub(match_string, text)

                results.append({
                    'label':
                    '<strong>Server:</strong> ' + text,
                    'value':
                    url_for('server_module.view', server_id=svr['id'])
                })
    if 'sshkeys' in app.config['installed_blueprints']:
        ssh = SshKeyManager(client)

        for key in ssh.list_keys():
            if term.match(key['label']) or term.match(key['fingerprint']):
                text = '%s (%s)' % (key['label'], key['fingerprint'])
                text = term.sub(match_string, text)

                results.append({
                    'label':
                    '<strong>SSH Key:</strong> ' + text,
                    'value':
                    url_for('ssh_module.view', key_id=key['id'])
                })

    return results
Пример #3
0
def get_hardware_manager():
    return HardwareManager(get_client())