예제 #1
0
    def execute(self, args):
        table = Table(['Code', 'Reason'])
        table.align['Code'] = 'r'
        table.align['Reason'] = 'l'

        mgr = HardwareManager(self.client)

        for code, reason in mgr.get_cancellation_reasons().items():
            table.add_row([code, reason])

        return table
예제 #2
0
    def execute(self, args):
        table = Table(['Code', 'Chassis'])
        table.align['Code'] = 'r'
        table.align['Chassis'] = 'l'

        mgr = HardwareManager(self.client)
        chassis = mgr.get_available_dedicated_server_packages()

        for chassis in chassis:
            table.add_row([chassis[0], chassis[1]])

        return table
예제 #3
0
    def execute(client, args):
        t = Table(['Code', 'Reason'])
        t.align['Code'] = 'r'
        t.align['Reason'] = 'l'

        mgr = HardwareManager(client)
        reasons = mgr.get_cancellation_reasons().iteritems()

        for code, reason in reasons:
            t.add_row([code, reason])

        return t
예제 #4
0
    def execute(self, args):
        manager = SSLManager(self.client)

        certificates = manager.list_certs(args['--status'])

        table = Table(['id', 'common_name', 'days_until_expire', 'notes'])
        for certificate in certificates:
            table.add_row([
                certificate['id'],
                certificate['commonName'],
                certificate['validityDays'],
                certificate.get('notes', blank())
            ])
        table.sortby = args['--sortby']
        return table
예제 #5
0
    def execute(self, args):
        manager = HardwareManager(self.client)

        tags = None
        if args.get('--tags'):
            tags = [tag.strip() for tag in args.get('--tags').split(',')]

        servers = manager.list_hardware(
            hostname=args.get('--hostname'),
            domain=args.get('--domain'),
            cpus=args.get('--cpu'),
            memory=args.get('--memory'),
            datacenter=args.get('--datacenter'),
            nic_speed=args.get('--network'),
            tags=tags)

        table = Table([
            'id',
            'datacenter',
            'host',
            'cores',
            'memory',
            'primary_ip',
            'backend_ip',
            'active_transaction'
        ])
        table.sortby = args.get('--sortby') or 'host'

        for server in servers:
            server = NestedDict(server)
            table.add_row([
                server['id'],
                server['datacenter']['name'] or blank(),
                server['fullyQualifiedDomainName'],
                server['processorPhysicalCoreAmount'],
                gb(server['memoryCapacity'] or 0),
                server['primaryIpAddress'] or blank(),
                server['primaryBackendIpAddress'] or blank(),
                active_txn(server),
            ])

        return table
예제 #6
0
    def execute(self, args):
        update_with_template_args(args)
        mgr = HardwareManager(self.client)

        # Disks will be a comma-separated list. Let's make it a real list.
        if isinstance(args.get('--disk'), str):
            args['--disk'] = args.get('--disk').split(',')

        # Do the same thing for SSH keys
        if isinstance(args.get('--key'), str):
            args['--key'] = args.get('--key').split(',')

        self._validate_args(args)

        ds_options = mgr.get_dedicated_server_create_options(args['--chassis'])

        order = {
            'hostname': args['--hostname'],
            'domain': args['--domain'],
            'bare_metal': False,
            'package_id': args['--chassis'],
        }

        # Convert the OS code back into a price ID
        os_price = self._get_price_id_from_options(ds_options, 'os',
                                                   args['--os'])

        if os_price:
            order['os'] = os_price
        else:
            raise CLIAbort('Invalid operating system specified.')

        order['location'] = args['--datacenter'] or 'FIRST_AVAILABLE'
        order['server'] = args['--cpu']
        order['ram'] = self._get_price_id_from_options(ds_options, 'memory',
                                                       int(args['--memory']))
        # Set the disk sizes
        disk_prices = []
        disk_number = 0
        for disk in args.get('--disk'):
            disk_price = self._get_disk_price(ds_options, disk, disk_number)
            disk_number += 1
            if disk_price:
                disk_prices.append(disk_price)

        if not disk_prices:
            disk_prices.append(self._get_default_value(ds_options, 'disk0'))

        order['disks'] = disk_prices

        # Set the disk controller price
        if args.get('--controller'):
            dc_price = self._get_price_id_from_options(
                ds_options, 'disk_controller', args.get('--controller'))
        else:
            dc_price = self._get_price_id_from_options(ds_options,
                                                       'disk_controller',
                                                       'None')

        order['disk_controller'] = dc_price

        # Set the port speed
        port_speed = args.get('--network') or '100'

        nic_price = self._get_price_id_from_options(ds_options, 'nic',
                                                    port_speed)

        if nic_price:
            order['port_speed'] = nic_price
        else:
            raise CLIAbort('Invalid NIC speed specified.')

        if args.get('--postinstall'):
            order['post_uri'] = args.get('--postinstall')

        # Get the SSH keys
        if args.get('--key'):
            keys = []
            for key in args.get('--key'):
                key_id = resolve_id(SshKeyManager(self.client).resolve_ids,
                                    key, 'SshKey')
                keys.append(key_id)
            order['ssh_keys'] = keys

        if args.get('--vlan_public'):
            order['public_vlan'] = args['--vlan_public']

        if args.get('--vlan_private'):
            order['private_vlan'] = args['--vlan_private']

        # Do not create hardware server with --test or --export
        do_create = not (args['--export'] or args['--test'])

        output = None
        if args.get('--test'):
            result = mgr.verify_order(**order)

            table = Table(['Item', 'cost'])
            table.align['Item'] = 'r'
            table.align['cost'] = 'r'

            total = 0.0
            for price in result['prices']:
                total += float(price.get('recurringFee', 0.0))
                rate = "%.2f" % float(price['recurringFee'])

                table.add_row([price['item']['description'], rate])

            table.add_row(['Total monthly cost', "%.2f" % total])
            output = []
            output.append(table)
            output.append(FormattedItem(
                '',
                ' -- ! Prices reflected here are retail and do not '
                'take account level discounts and are not guaranteed.')
            )

        if args['--export']:
            export_file = args.pop('--export')
            export_to_template(export_file, args, exclude=['--wait', '--test'])
            return 'Successfully exported options to a template file.'

        if do_create:
            if args['--really'] or confirm(
                    "This action will incur charges on your account. "
                    "Continue?"):
                result = mgr.place_order(**order)

                table = KeyValueTable(['name', 'value'])
                table.align['name'] = 'r'
                table.align['value'] = 'l'
                table.add_row(['id', result['orderId']])
                table.add_row(['created', result['orderDate']])
                output = table
            else:
                raise CLIAbort('Aborting dedicated server order.')

        return output
예제 #7
0
    def execute(self, args):
        mgr = HardwareManager(self.client)

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

        chassis_id = args.get('<chassis_id>')

        ds_options = mgr.get_dedicated_server_create_options(chassis_id)

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

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

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

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

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

            cpu_table = Table(['id', 'description'])
            for result in sorted(results):
                cpu_table.add_row([result[1], result[0]])
            table.add_row(['cpu', cpu_table])

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

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

        if args['--os'] or show_all:
            results = self.get_create_options(ds_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(ds_options, 'disk')[0]

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

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

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

        if args['--controller'] or show_all:
            results = self.get_create_options(ds_options, 'disk_controller')[0]

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

        return table
예제 #8
0
    def execute(self, args):
        hardware = HardwareManager(self.client)

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

        hardware_id = resolve_id(
            hardware.resolve_ids, args.get('<identifier>'), 'hardware')
        result = hardware.get_hardware(hardware_id)
        result = NestedDict(result)

        table.add_row(['id', result['id']])
        table.add_row(['hostname', result['fullyQualifiedDomainName']])
        table.add_row(['status', result['hardwareStatus']['status']])
        table.add_row(['datacenter', result['datacenter']['name'] or blank()])
        table.add_row(['cores', result['processorPhysicalCoreAmount']])
        table.add_row(['memory', gb(result['memoryCapacity'])])
        table.add_row(['public_ip', result['primaryIpAddress'] or blank()])
        table.add_row(
            ['private_ip', result['primaryBackendIpAddress'] or blank()])
        table.add_row(['ipmi_ip',
                       result['networkManagementIpAddress'] or blank()])
        table.add_row([
            'os',
            FormattedItem(
                result['operatingSystem']['softwareLicense']
                ['softwareDescription']['referenceCode'] or blank(),
                result['operatingSystem']['softwareLicense']
                ['softwareDescription']['name'] or blank()
            )])
        table.add_row(['created', result['provisionDate'] or blank()])

        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'):
            user_strs = []
            for item in result['operatingSystem']['passwords']:
                user_strs.append(
                    "%s %s" % (item['username'], item['password']))
            table.add_row(['users', listing(user_strs)])

        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['Hardware_Server']\
                .getReverseDomainRecords(id=hardware_id)

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

        return table
예제 #9
0
    def execute(self, args):
        update_with_template_args(args)
        mgr = HardwareManager(self.client)

        # Disks will be a comma-separated list. Let's make it a real list.
        if isinstance(args.get('--disk'), str):
            args['--disk'] = args.get('--disk').split(',')

        # Do the same thing for SSH keys
        if isinstance(args.get('--key'), str):
            args['--key'] = args.get('--key').split(',')

        self._validate_args(args)

        ds_options = mgr.get_dedicated_server_create_options(args['--chassis'])

        order = self._process_args(args, ds_options)

        # Do not create hardware server with --test or --export
        do_create = not (args['--export'] or args['--test'])

        output = None
        if args.get('--test'):
            result = mgr.verify_order(**order)

            table = Table(['Item', 'cost'])
            table.align['Item'] = 'r'
            table.align['cost'] = 'r'

            total = 0.0
            for price in result['prices']:
                total += float(price.get('recurringFee', 0.0))
                rate = "%.2f" % float(price['recurringFee'])

                table.add_row([price['item']['description'], rate])

            table.add_row(['Total monthly cost', "%.2f" % total])
            output = []
            output.append(table)
            output.append(FormattedItem(
                '',
                ' -- ! Prices reflected here are retail and do not '
                'take account level discounts and are not guaranteed.')
            )

        if args['--export']:
            export_file = args.pop('--export')
            export_to_template(export_file, args, exclude=['--wait', '--test'])
            return 'Successfully exported options to a template file.'

        if do_create:
            if args['--really'] or confirm(
                    "This action will incur charges on your account. "
                    "Continue?"):
                result = mgr.place_order(**order)

                table = KeyValueTable(['name', 'value'])
                table.align['name'] = 'r'
                table.align['value'] = 'l'
                table.add_row(['id', result['orderId']])
                table.add_row(['created', result['orderDate']])
                output = table
            else:
                raise CLIAbort('Aborting dedicated server order.')

        return output
예제 #10
0
    def execute(self, args):
        mgr = HardwareManager(self.client)

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

        chassis_id = args.get('<chassis_id>')

        found = False
        for chassis in mgr.get_available_dedicated_server_packages():
            if chassis_id == str(chassis[0]):
                found = True
                break

        if not found:
            raise CLIAbort('Invalid chassis specified.')

        ds_options = mgr.get_dedicated_server_create_options(chassis_id)

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

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

        # Determine if this is a "Bare Metal Instance" or regular server
        bmc = False
        if chassis_id == str(mgr.get_bare_metal_package_id()):
            bmc = True

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

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

        if (args['--cpu'] or show_all) and not bmc:
            results = self.get_create_options(ds_options, 'cpu')

            cpu_table = Table(['ID', 'Description'])
            cpu_table.align['ID'] = 'r'
            cpu_table.align['Description'] = 'l'

            for result in sorted(results, key=lambda x: x[1]):
                cpu_table.add_row([result[1], result[0]])
            table.add_row(['cpu', cpu_table])

        if (args['--memory'] or show_all) and not bmc:
            results = self.get_create_options(ds_options, 'memory')[0]

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

        if bmc and (show_all or args['--memory'] or args['--cpu']):
            results = self.get_create_options(ds_options, 'server_core')
            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(ds_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(ds_options, 'disk')[0]

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

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

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

        if (args['--controller'] or show_all) and not bmc:
            results = self.get_create_options(ds_options, 'disk_controller')[0]

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

        return table