def execute(self, args):
        mgr = NetworkManager(self.client)

        t = Table([
            'id', 'identifier', 'type', 'datacenter', 'vlan id', 'IPs',
            'hardware', 'ccis',
        ])
        t.sortby = args.get('--sortby') or 'id'

        version = 0
        if args.get('--v4'):
            version = 4
        elif args.get('--v6'):
            version = 6

        subnets = mgr.list_subnets(
            datacenter=args.get('--datacenter'),
            version=version,
            identifier=args.get('--identifier'),
            subnet_type=args.get('--type'),
        )

        for subnet in subnets:
            t.add_row([
                subnet['id'],
                subnet['networkIdentifier'] + '/' + str(subnet['cidr']),
                subnet.get('subnetType', '-'),
                subnet['datacenter']['name'],
                subnet['networkVlanId'],
                subnet['ipAddressCount'],
                len(subnet['hardware']),
                len(subnet['virtualGuests']),
            ])

        return t
    def execute(self, args):
        mgr = NetworkManager(self.client)

        table = Table([
            'id', 'number', 'datacenter', 'name', 'IPs', 'hardware', 'ccis',
            'networking', 'firewall'
        ])
        table.sortby = args.get('--sortby') or 'id'

        vlans = mgr.list_vlans(
            datacenter=args.get('--datacenter'),
            vlan_number=args.get('--number'),
            name=args.get('--name'),
        )
        for vlan in vlans:
            table.add_row([
                vlan['id'],
                vlan['vlanNumber'],
                vlan['primaryRouter']['datacenter']['name'],
                vlan.get('name') or blank(),
                vlan['totalPrimaryIpAddressCount'],
                len(vlan['hardware']),
                len(vlan['virtualGuests']),
                len(vlan['networkComponents']),
                'Yes' if vlan['firewallInterfaces'] else 'No',
            ])

        return table
    def execute(client, args):
        account = client["Account"]

        neither = not any([args["--private"], args["--public"]])

        result = []
        if args["--private"] or neither:
            account = client["Account"]
            private = "privateBlockDeviceTemplateGroups"
            mask = private + "[id,accountId,name,globalIdentifier,blockDevices,parentId]"

            result += account.getObject(mask=mask)[private]

        if args["--public"] or neither:
            vgbd = client["Virtual_Guest_Block_Device_Template_Group"]
            result += vgbd.getPublicImages()

        t = Table(["id", "account", "type", "name", "guid"])
        t.sortby = "name"

        images = filter(lambda x: x["parentId"] == "", result)
        for image in images:
            t.add_row(
                [
                    image["id"],
                    image.get("accountId", "-"),
                    image.get("type", "-"),
                    image["name"].strip(),
                    image.get("globalIdentifier", "-"),
                ]
            )

        return t
    def execute(client, args):
        account = client['Account']

        neither = not any([args['--private'], args['--public']])

        results = []
        if args['--private'] or neither:
            account = client['Account']
            mask = 'id,accountId,name,globalIdentifier,blockDevices,parentId'
            r = account.getPrivateBlockDeviceTemplateGroups(mask=mask)

            results.append(r)

        if args['--public'] or neither:
            vgbd = client['Virtual_Guest_Block_Device_Template_Group']
            r = vgbd.getPublicImages()

            results.append(r)

        t = Table(['id', 'account', 'type', 'name', 'guid', ])
        t.sortby = 'name'

        for result in results:
            images = filter(lambda x: x['parentId'] == '', result)
            for image in images:
                t.add_row([
                    image['id'],
                    image.get('accountId', blank()),
                    image.get('type', blank()),
                    image['name'].strip(),
                    image.get('globalIdentifier', blank()),
                ])

        return t
    def execute(client, args):
        mgr = NetworkManager(client)

        t = Table([
            'id', 'ip', 'assigned', 'target'
        ])
        t.sortby = args.get('--sortby') or 'id'

        version = 0
        if args.get('--v4'):
            version = 4
        elif args.get('--v6'):
            version = 6

        ips = mgr.list_global_ips(version=version)

        for ip in ips:
            assigned = 'No'
            target = 'None'
            if ip.get('destinationIpAddress'):
                dest = ip['destinationIpAddress']
                assigned = 'Yes'
                target = dest['ipAddress']
                if dest.get('virtualGuest'):
                    vg = dest['virtualGuest']
                    target += ' (' + vg['fullyQualifiedDomainName'] + ')'
                elif ip['destinationIpAddress'].get('hardware'):
                    target += ' (' + \
                              dest['hardware']['fullyQualifiedDomainName'] + \
                              ')'

            t.add_row([ip['id'], ip['ipAddress']['ipAddress'], assigned,
                       target])
        return t
Beispiel #6
0
    def execute(self, args):
        manager = CDNManager(self.client)
        accounts = manager.list_accounts()

        table = Table(['id', 'account_name', 'type', 'created', 'notes'])
        for account in accounts:
            table.add_row([
                account['id'],
                account['cdnAccountName'],
                account['cdnSolutionName'],
                account['createDate'],
                account.get('cdnAccountNote', blank())
            ])

        table.sortby = args['--sortby']
        return table
Beispiel #7
0
def get_rules_table(rules):
    """ Helper to format the rules into a table

    :param list rules: A list containing the rules of the firewall
    :returns: a formatted table of the firewall rules
    """
    table = Table(['#', 'action', 'protocol', 'src_ip', 'src_mask', 'dest',
                   'dest_mask'])
    table.sortby = '#'
    for rule in rules:
        table.add_row([
            rule['orderValue'],
            rule['action'],
            rule['protocol'],
            rule['sourceIpAddress'],
            rule['sourceIpSubnetMask'],
            '%s:%s-%s' % (rule['destinationIpAddress'],
                          rule['destinationPortRangeStart'],
                          rule['destinationPortRangeEnd']),
            rule['destinationIpSubnetMask']])
    return table
Beispiel #8
0
    def execute(self, args):
        mgr = LoadBalancerManager(self.client)

        table = Table(['id', 'capacity', 'description', 'price'])

        table.sortby = 'price'
        table.align['price'] = 'r'
        table.align['capacity'] = 'r'
        table.align['id'] = 'r'

        packages = mgr.get_lb_pkgs()

        for package in packages:
            table.add_row([
                package['prices'][0]['id'],
                package.get('capacity'),
                package['description'],
                format(float(package['prices'][0]['recurringFee']), '.2f')
            ])

        return table
Beispiel #9
0
    def execute(self, args):
        cci = CCIManager(self.client)

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

        guests = cci.list_instances(
            hourly=args.get('--hourly'),
            monthly=args.get('--monthly'),
            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)

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

        for guest in guests:
            guest = NestedDict(guest)
            t.add_row([
                guest['id'],
                guest['datacenter']['name'] or blank(),
                guest['fullyQualifiedDomainName'],
                guest['maxCpu'],
                mb_to_gb(guest['maxMemory']),
                guest['primaryIpAddress'] or blank(),
                guest['primaryBackendIpAddress'] or blank(),
                active_txn(guest),
            ])

        return t
    def execute(self, args):
        mgr = NetworkManager(self.client)
        datacenters = mgr.summary_by_datacenter()

        t = Table([
            'datacenter', 'vlans', 'subnets', 'IPs', 'networking',
            'hardware', 'ccis'
        ])
        t.sortby = args.get('--sortby') or 'datacenter'

        for name, dc in datacenters.iteritems():
            t.add_row([
                name,
                dc['vlanCount'],
                dc['subnetCount'],
                dc['primaryIpCount'],
                dc['networkingCount'],
                dc['hardwareCount'],
                dc['virtualGuestCount'],
            ])

        return t
    def execute(self, args):
        mgr = NetworkManager(self.client)

        table = Table([
            'id', 'ip', 'assigned', 'target'
        ])
        table.sortby = args.get('--sortby') or 'id'

        version = 0
        if args.get('--v4'):
            version = 4
        elif args.get('--v6'):
            version = 6

        ips = mgr.list_global_ips(version=version)

        for ip_address in ips:
            assigned = 'No'
            target = 'None'
            if ip_address.get('destinationIpAddress'):
                dest = ip_address['destinationIpAddress']
                assigned = 'Yes'
                target = dest['ipAddress']
                virtual_guest = dest.get('virtualGuest')
                if virtual_guest:
                    target += (' (%s)'
                               % virtual_guest['fullyQualifiedDomainName'])
                elif ip_address['destinationIpAddress'].get('hardware'):
                    target += ' (' + \
                              dest['hardware']['fullyQualifiedDomainName'] + \
                              ')'

            table.add_row([ip_address['id'],
                           ip_address['ipAddress']['ipAddress'],
                           assigned,
                           target])
        return table
    def execute(client, args):
        cci = CCIManager(client)

        results = cci.list_instances(
            hourly=args.get('--hourly'), monthly=args.get('--monthly'))

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

        if args.get('--tags'):
            tags = [tag.strip() for tag in args.get('--tags').split(',')]
            guests = []
            for g in results:
                guest_tags = [x['tag']['name'] for x in g['tagReferences']]
                if any(_tag in tags for _tag in guest_tags):
                    guests.append(g)
        else:
            guests = results

        for guest in guests:
            t.add_row([
                guest['id'],
                guest.get('datacenter', {}).get('name', 'unknown'),
                guest['fullyQualifiedDomainName'],
                guest['maxCpu'],
                mb_to_gb(guest['maxMemory']),
                guest.get('primaryIpAddress', '-'),
                guest.get('primaryBackendIpAddress', '-'),
                guest.get('activeTransaction', {}).get(
                    'transactionStatus', {}).get('friendlyName', '<None>'),
            ])

        return t