Esempio n. 1
0
    def execute(self, args):
        table = KeyValueTable(['Name', 'Value'])
        table.align['Name'] = 'r'
        table.align['Value'] = 'l'

        show_all = True
        for opt_name in self.options:
            if args.get("--" + opt_name):
                show_all = False
                break

        mgr = HardwareManager(self.client)

        bmi_options = mgr.get_bare_metal_create_options()

        if args['--all']:
            show_all = True

        if args['--datacenter'] or show_all:
            results = self.get_create_options(bmi_options, 'datacenter')[0]

            table.add_row([results[0], listing(sorted(results[1]))])

        if args['--cpu'] or args['--memory'] or show_all:
            results = self.get_create_options(bmi_options, 'cpu')
            memory_cpu_table = Table(['memory', 'cpu'])
            for result in results:
                memory_cpu_table.add_row([
                    result[0],
                    listing(
                        [item[0] for item in sorted(
                            result[1], key=lambda x: int(x[0])
                        )])])
            table.add_row(['memory/cpu', memory_cpu_table])

        if args['--os'] or show_all:
            results = self.get_create_options(bmi_options, 'os')

            for result in results:
                table.add_row([
                    result[0],
                    listing(
                        [item[0] for item in sorted(result[1])],
                        separator=linesep
                    )])

        if args['--disk'] or show_all:
            results = self.get_create_options(bmi_options, 'disk')[0]

            table.add_row([results[0], listing(
                [item[0] for item in sorted(results[1])])])

        if args['--nic'] or show_all:
            results = self.get_create_options(bmi_options, 'nic')

            for result in results:
                table.add_row([result[0], listing(
                    [item[0] for item in sorted(result[1],)])])

        return table
Esempio n. 2
0
    def execute(self, args):
        t = KeyValueTable(["Name", "Value"])
        t.align["Name"] = "r"
        t.align["Value"] = "l"

        show_all = True
        for opt_name in self.options:
            if args.get("--" + opt_name):
                show_all = False
                break

        mgr = HardwareManager(self.client)

        bmi_options = mgr.get_bare_metal_create_options()

        if args["--all"]:
            show_all = True

        if args["--datacenter"] or show_all:
            results = self.get_create_options(bmi_options, "datacenter")[0]

            t.add_row([results[0], listing(sorted(results[1]))])

        if args["--cpu"] or args["--memory"] or show_all:
            results = self.get_create_options(bmi_options, "cpu")
            memory_cpu_table = Table(["memory", "cpu"])
            for result in results:
                memory_cpu_table.add_row(
                    [result[0], listing([item[0] for item in sorted(result[1], key=lambda x: int(x[0]))])]
                )
            t.add_row(["memory/cpu", memory_cpu_table])

        if args["--os"] or show_all:
            results = self.get_create_options(bmi_options, "os")

            for result in results:
                t.add_row([result[0], listing([item[0] for item in sorted(result[1])], separator=linesep)])

        if args["--disk"] or show_all:
            results = self.get_create_options(bmi_options, "disk")[0]

            t.add_row([results[0], listing([item[0] for item in sorted(results[1])])])

        if args["--nic"] or show_all:
            results = self.get_create_options(bmi_options, "nic")

            for result in results:
                t.add_row([result[0], listing([item[0] for item in sorted(result[1])])])

        return t
    def execute(self, args):
        mgr = FirewallManager(self.client)
        fwvlans = mgr.get_firewalls()
        table = Table(['vlan', 'type', 'features'])

        dedicatedfws = [vlan['dedicatedFirewallFlag'] for vlan in fwvlans]
        for vlan in dedicatedfws:
            features = []
            if vlan['highAvailabilityFirewallFlag']:
                features.append('HA')

            if features:
                feature_list = listing(features, separator=',')
            else:
                feature_list = blank()

            table.add_row([
                vlan['vlanNumber'],
                'dedicated',
                feature_list,
            ])

        shared_vlan = [vlan['dedicatedFirewallFlag'] for vlan in fwvlans]
        for vlan in shared_vlan:
            table.add_row([vlan['vlanNumber'], 'standard', blank()])

        return table
    def execute(client, args):
        f = FirewallManager(client)
        fwvlans = f.get_firewalls()
        t = Table(['vlan', 'type', 'features'])

        dedicatedfws = filter(lambda x: x['dedicatedFirewallFlag'], fwvlans)
        for vlan in dedicatedfws:
            features = []
            if vlan['highAvailabilityFirewallFlag']:
                features.append('HA')

            if features:
                feature_list = listing(features, separator=',')
            else:
                feature_list = blank()

            t.add_row([
                vlan['vlanNumber'],
                'dedicated',
                feature_list,
            ])

        shared_vlan = filter(lambda x: not x['dedicatedFirewallFlag'], fwvlans)
        for vlan in shared_vlan:
            t.add_row([vlan['vlanNumber'], 'standard', blank()])

        return t
Esempio n. 5
0
            def add_cpus_row(cpu_options, name):
                """ Add CPU rows to the table """
                cpus = []
                for cpu_option in cpu_options:
                    cpus.append(str(cpu_option['template']['startCpus']))

                table.add_row(['cpus (%s)' % name,
                               listing(cpus, separator=',')])
Esempio n. 6
0
    def execute(self, args):
        mgr = FirewallManager(self.client)
        table = Table(['firewall id',
                       'type',
                       'features',
                       'server/vlan id'])

        fwvlans = mgr.get_firewalls()
        dedicatedfws = [firewall for firewall in fwvlans
                        if firewall['dedicatedFirewallFlag']]

        for vlan in dedicatedfws:
            features = []
            if vlan['highAvailabilityFirewallFlag']:
                features.append('HA')

            if features:
                feature_list = listing(features, separator=',')
            else:
                feature_list = blank()

            table.add_row([
                'vlan:%s' % vlan['networkVlanFirewall']['id'],
                'VLAN - dedicated',
                feature_list,
                vlan['id']
            ])

        shared_vlan = [firewall for firewall in fwvlans
                       if not firewall['dedicatedFirewallFlag']]
        for vlan in shared_vlan:
            fwls = [guest for guest in vlan['firewallGuestNetworkComponents']
                    if has_firewall_component(guest)]

            for firewall in fwls:
                table.add_row([
                    'cci:%s' % firewall['id'],
                    'CCI - standard',
                    '-',
                    firewall['guestNetworkComponent']['guest']['id']
                ])

            fwls = [server for server in vlan['firewallNetworkComponents']
                    if has_firewall_component(server)]

            for fwl in fwls:
                table.add_row([
                    'server:%s' % fwl['id'],
                    'Server - standard',
                    '-',
                    fwl['networkComponent']['downlinkComponent']['hardwareId']
                ])

        return table
    def execute(client, args):
        meta = MetadataManager()
        if args['<public>']:
            t = Table(['Name', 'Value'])
            t.align['Name'] = 'r'
            t.align['Value'] = 'l'
            network = meta.public_network()
            t.add_row([
                'mac addresses',
                listing(network['mac_addresses'], separator=',')])
            t.add_row([
                'router', network['router']])
            t.add_row([
                'vlans', listing(network['vlans'], separator=',')])
            t.add_row([
                'vlan ids',
                listing(network['vlan_ids'], separator=',')])
            return t

        if args['<private>']:
            t = Table(['Name', 'Value'])
            t.align['Name'] = 'r'
            t.align['Value'] = 'l'
            network = meta.private_network()
            t.add_row([
                'mac addresses',
                listing(network['mac_addresses'], separator=',')])
            t.add_row([
                'router', network['router']])
            t.add_row([
                'vlans', listing(network['vlans'], separator=',')])
            t.add_row([
                'vlan ids',
                listing(network['vlan_ids'], separator=',')])
            return t
Esempio n. 8
0
            def add_block_rows(disks, name):
                """ Add block rows to the table """
                simple = {}
                for disk in disks:
                    block = disk['template']['blockDevices'][0]
                    bid = block['device']

                    if bid not in simple:
                        simple[bid] = []

                    simple[bid].append(str(block['diskImage']['capacity']))

                for label in sorted(simple.keys()):
                    table.add_row(['%s disk(%s)' % (name, label),
                                   listing(simple[label], separator=',')])
Esempio n. 9
0
            def block_rows(blocks, name):
                simple = {}
                for block in blocks:
                    b = block['template']['blockDevices'][0]
                    bid = b['device']
                    size = b['diskImage']['capacity']

                    if bid not in simple:
                        simple[bid] = []

                    simple[bid].append(str(size))

                for b in sorted(simple.keys()):
                    t.add_row([
                        '%s disk(%s)' % (name, b),
                        listing(simple[b], separator=',')]
                    )
Esempio n. 10
0
 def _execute(self, _):
     return listing(MetadataManager().get('frontend_mac'), separator=',')
Esempio n. 11
0
    def execute(self, args):
        cci = CCIManager(self.client)
        result = cci.get_create_options()

        show_all = True
        for opt_name in self.options:
            if args.get("--" + opt_name):
                show_all = False
                break

        if args['--all']:
            show_all = True

        table = KeyValueTable(['Name', 'Value'])
        table.align['Name'] = 'r'
        table.align['Value'] = 'l'

        if args['--datacenter'] or show_all:
            datacenters = [dc['template']['datacenter']['name']
                           for dc in result['datacenters']]
            table.add_row(['datacenter', listing(datacenters, separator=',')])

        if args['--cpu'] or show_all:
            standard_cpu = [x for x in result['processors']
                            if not x['template'].get(
                                'dedicatedAccountHostOnlyFlag', False)]

            ded_cpu = [x for x in result['processors']
                       if x['template'].get('dedicatedAccountHostOnlyFlag',
                                            False)]

            def add_cpus_row(cpu_options, name):
                """ Add CPU rows to the table """
                cpus = []
                for cpu_option in cpu_options:
                    cpus.append(str(cpu_option['template']['startCpus']))

                table.add_row(['cpus (%s)' % name,
                               listing(cpus, separator=',')])

            add_cpus_row(ded_cpu, 'private')
            add_cpus_row(standard_cpu, 'standard')

        if args['--memory'] or show_all:
            memory = [
                str(m['template']['maxMemory']) for m in result['memory']]
            table.add_row(['memory', listing(memory, separator=',')])

        if args['--os'] or show_all:
            op_sys = [
                o['template']['operatingSystemReferenceCode'] for o in
                result['operatingSystems']]

            op_sys = sorted(op_sys)
            os_summary = set()

            for operating_system in op_sys:
                os_summary.add(operating_system[0:operating_system.find('_')])

            for summary in sorted(os_summary):
                table.add_row([
                    'os (%s)' % summary,
                    linesep.join(sorted([x for x in op_sys
                                         if x[0:len(summary)] == summary]))
                ])

        if args['--disk'] or show_all:
            local_disks = [x for x in result['blockDevices']
                           if x['template'].get('localDiskFlag', False)]

            san_disks = [x for x in result['blockDevices']
                         if not x['template'].get('localDiskFlag', False)]

            def add_block_rows(disks, name):
                """ Add block rows to the table """
                simple = {}
                for disk in disks:
                    block = disk['template']['blockDevices'][0]
                    bid = block['device']

                    if bid not in simple:
                        simple[bid] = []

                    simple[bid].append(str(block['diskImage']['capacity']))

                for label in sorted(simple.keys()):
                    table.add_row(['%s disk(%s)' % (name, label),
                                   listing(simple[label], separator=',')])

            add_block_rows(local_disks, 'local')
            add_block_rows(san_disks, 'san')

        if args['--nic'] or show_all:
            speeds = []
            for comp in result['networkComponents']:
                speed = comp['template']['networkComponents'][0]['maxSpeed']
                speeds.append(str(speed))

            speeds = sorted(speeds)

            table.add_row(['nic', listing(speeds, separator=',')])

        return table
Esempio n. 12
0
    def execute(self, args):
        cci = CCIManager(self.client)
        table = KeyValueTable(['Name', 'Value'])
        table.align['Name'] = 'r'
        table.align['Value'] = 'l'

        cci_id = resolve_id(cci.resolve_ids, args.get('<identifier>'), 'CCI')
        result = cci.get_instance(cci_id)
        result = NestedDict(result)

        table.add_row(['id', result['id']])
        table.add_row(['hostname', result['fullyQualifiedDomainName']])
        table.add_row(['status', FormattedItem(
            result['status']['keyName'] or blank(),
            result['status']['name'] or blank()
        )])
        table.add_row(['active_transaction', active_txn(result)])
        table.add_row(['state', FormattedItem(
            lookup(result, 'powerState', 'keyName'),
            lookup(result, 'powerState', 'name'),
        )])
        table.add_row(['datacenter', result['datacenter']['name'] or blank()])
        operating_system = lookup(result,
                                  'operatingSystem',
                                  'softwareLicense',
                                  'softwareDescription') or {}
        table.add_row([
            'os',
            FormattedItem(
                operating_system.get('version') or blank(),
                operating_system.get('name') or blank()
            )])
        table.add_row(['os_version',
                       operating_system.get('version') or blank()])
        table.add_row(['cores', result['maxCpu']])
        table.add_row(['memory', mb_to_gb(result['maxMemory'])])
        table.add_row(['public_ip', result['primaryIpAddress'] or blank()])
        table.add_row(['private_ip',
                       result['primaryBackendIpAddress'] or blank()])
        table.add_row(['private_only', result['privateNetworkOnlyFlag']])
        table.add_row(['private_cpu', result['dedicatedAccountHostOnlyFlag']])
        table.add_row(['created', result['createDate']])
        table.add_row(['modified', result['modifyDate']])

        vlan_table = Table(['type', 'number', 'id'])
        for vlan in result['networkVlans']:
            vlan_table.add_row([
                vlan['networkSpace'], vlan['vlanNumber'], vlan['id']])
        table.add_row(['vlans', vlan_table])

        if result.get('notes'):
            table.add_row(['notes', result['notes']])

        if args.get('--price'):
            table.add_row(['price rate',
                           result['billingItem']['recurringFee']])

        if args.get('--passwords'):
            pass_table = Table(['username', 'password'])
            for item in result['operatingSystem']['passwords']:
                pass_table.add_row([item['username'], item['password']])
            table.add_row(['users', pass_table])

        tag_row = []
        for tag in result['tagReferences']:
            tag_row.append(tag['tag']['name'])

        if tag_row:
            table.add_row(['tags', listing(tag_row, separator=',')])

        if not result['privateNetworkOnlyFlag']:
            ptr_domains = self.client['Virtual_Guest'].\
                getReverseDomainRecords(id=cci_id)

            for ptr_domain in ptr_domains:
                for ptr in ptr_domain['resourceRecords']:
                    table.add_row(['ptr', ptr['data']])

        return table
Esempio n. 13
0
            def cpus_row(c, name):
                cpus = []
                for x in c:
                    cpus.append(str(x['template']['startCpus']))

                t.add_row(['cpus (%s)' % name, listing(cpus, separator=',')])
Esempio n. 14
0
 def _execute(self, _):
     return listing(MetadataManager().get('tags'), separator=',')
Esempio n. 15
0
    def execute(cls, client, args):
        cci = CCIManager(client)
        result = cci.get_create_options()

        show_all = True
        for opt_name in cls.options:
            if args.get("--" + opt_name):
                show_all = False
                break

        if args['--all']:
            show_all = True

        t = Table(['Name', 'Value'])
        t.align['Name'] = 'r'
        t.align['Value'] = 'l'

        if args['--datacenter'] or show_all:
            datacenters = [dc['template']['datacenter']['name']
                           for dc in result['datacenters']]
            t.add_row(['datacenter', listing(datacenters, separator=',')])

        if args['--cpu'] or show_all:
            standard_cpu = filter(
                lambda x: not x['template'].get(
                    'dedicatedAccountHostOnlyFlag', False),
                result['processors'])

            ded_cpu = filter(
                lambda x: x['template'].get(
                    'dedicatedAccountHostOnlyFlag', False),
                result['processors'])

            def cpus_row(c, name):
                cpus = []
                for x in c:
                    cpus.append(str(x['template']['startCpus']))

                t.add_row(['cpus (%s)' % name, listing(cpus, separator=',')])

            cpus_row(ded_cpu, 'private')
            cpus_row(standard_cpu, 'standard')

        if args['--memory'] or show_all:
            memory = [
                str(m['template']['maxMemory']) for m in result['memory']]
            t.add_row(['memory', listing(memory, separator=',')])

        if args['--os'] or show_all:
            op_sys = [
                o['template']['operatingSystemReferenceCode'] for o in
                result['operatingSystems']]

            op_sys = sorted(op_sys)
            os_summary = set()

            for o in op_sys:
                os_summary.add(o[0:o.find('_')])

            for summary in sorted(os_summary):
                t.add_row([
                    'os (%s)' % summary,
                    linesep.join(sorted(filter(
                        lambda x: x[0:len(summary)] == summary, op_sys))
                    )
                ])

        if args['--disk'] or show_all:
            local_disks = filter(
                lambda x: x['template'].get('localDiskFlag', False),
                result['blockDevices'])

            san_disks = filter(
                lambda x: not x['template'].get('localDiskFlag', False),
                result['blockDevices'])

            def block_rows(blocks, name):
                simple = {}
                for block in blocks:
                    b = block['template']['blockDevices'][0]
                    bid = b['device']
                    size = b['diskImage']['capacity']

                    if bid not in simple:
                        simple[bid] = []

                    simple[bid].append(str(size))

                for b in sorted(simple.keys()):
                    t.add_row([
                        '%s disk(%s)' % (name, b),
                        listing(simple[b], separator=',')]
                    )

            block_rows(local_disks, 'local')
            block_rows(san_disks, 'san')

        if args['--nic'] or show_all:
            speeds = []
            for x in result['networkComponents']:
                speed = x['template']['networkComponents'][0]['maxSpeed']
                speeds.append(str(speed))

            speeds = sorted(speeds)

            t.add_row(['nic', listing(speeds, separator=',')])

        return t
Esempio n. 16
0
    def execute(client, args):
        cci = CCIManager(client)

        t = Table(['Name', 'Value'])
        t.align['Name'] = 'r'
        t.align['Value'] = 'l'

        cci_id = resolve_id(cci, args.get('<identifier>'))
        result = cci.get_instance(cci_id)
        result = NestedDict(result)

        t.add_row(['id', result['id']])
        t.add_row(['hostname', result['fullyQualifiedDomainName']])
        t.add_row(['status', result['status']['name']])
        t.add_row(['state', result['powerState']['name']])
        t.add_row(['datacenter', result['datacenter'].get('name', blank())])
        t.add_row(['cores', result['maxCpu']])
        t.add_row(['memory', mb_to_gb(result['maxMemory'])])
        t.add_row(['public_ip', result.get('primaryIpAddress', blank())])
        t.add_row(
            ['private_ip', result.get('primaryBackendIpAddress', blank())])
        t.add_row([
            'os',
            FormattedItem(
                result['operatingSystem']['softwareLicense']
                ['softwareDescription'].get('referenceCode', blank()),
                result['operatingSystem']['softwareLicense']
                ['softwareDescription'].get('name', blank())
            )])
        t.add_row(['private_only', result['privateNetworkOnlyFlag']])
        t.add_row(['private_cpu', result['dedicatedAccountHostOnlyFlag']])
        t.add_row(['created', result['createDate']])
        t.add_row(['modified', result['modifyDate']])

        if result.get('notes'):
            t.add_row(['notes', result['notes']])

        if args.get('--price'):
            t.add_row(['price rate', result['billingItem']['recurringFee']])

        if args.get('--passwords'):
            user_strs = []
            for item in result['operatingSystem']['passwords']:
                user_strs.append(
                    "%s %s" % (item['username'], item['password']))
            t.add_row(['users', listing(user_strs)])

        tag_row = []
        for tag in result['tagReferences']:
            tag_row.append(tag['tag']['name'])

        if tag_row:
            t.add_row(['tags', listing(tag_row, separator=',')])

        ptr_domains = client['Virtual_Guest'].\
            getReverseDomainRecords(id=cci_id)

        for ptr_domain in ptr_domains:
            for ptr in ptr_domain['resourceRecords']:
                t.add_row(['ptr', ptr['data']])

        return t
 def execute(client, args):
     return listing(MetadataManager().get('frontend_mac'), separator=',')
 def execute(client, args):
     return listing(MetadataManager().get('tags'), separator=',')