Exemplo n.º 1
0
def cli(env, identifier):
    """View details of a placement group.

    IDENTIFIER can be either the Name or Id of the placement group you want to view
    """
    manager = PlacementManager(env.client)
    group_id = helpers.resolve_id(manager.resolve_ids, identifier,
                                  'placement_group')
    result = manager.get_object(group_id)
    table = formatting.Table(
        ["Id", "Name", "Backend Router", "Rule", "Created"])

    table.add_row([
        result['id'], result['name'], result['backendRouter']['hostname'],
        result['rule']['name'], result['createDate']
    ])
    guest_table = formatting.Table([
        "Id", "FQDN", "Primary IP", "Backend IP", "CPU", "Memory",
        "Provisioned", "Transaction"
    ])
    for guest in result['guests']:
        guest_table.add_row([
            guest.get('id'),
            guest.get('fullyQualifiedDomainName'),
            guest.get('primaryIpAddress'),
            guest.get('primaryBackendIpAddress'),
            guest.get('maxCpu'),
            guest.get('maxMemory'),
            guest.get('provisionDate'),
            formatting.active_txn(guest)
        ])

    env.fout(table)
    env.fout(guest_table)
Exemplo n.º 2
0
def cli(env):
    """List options for creating a placement group."""
    manager = PlacementManager(env.client)

    routers = manager.get_routers()
    env.fout(get_router_table(routers))

    rules = manager.get_all_rules()
    env.fout(get_rule_table(rules))
def cli(env):
    """List options for creating a placement group."""
    manager = PlacementManager(env.client)

    routers = manager.get_routers()
    env.fout(get_router_table(routers))

    rules = manager.get_all_rules()
    env.fout(get_rule_table(rules))
Exemplo n.º 4
0
def cli(env):
    """List placement groups."""
    manager = PlacementManager(env.client)
    result = manager.list()
    table = formatting.Table(
        ["Id", "Name", "Backend Router", "Rule", "Guests", "Created"],
        title="Placement Groups")
    for group in result:
        table.add_row([
            group['id'], group['name'], group['backendRouter']['hostname'],
            group['rule']['name'], group['guestCount'], group['createDate']
        ])

    env.fout(table)
Exemplo n.º 5
0
def cli(env, **args):
    """Create a placement group."""
    manager = PlacementManager(env.client)
    backend_router_id = helpers.resolve_id(manager.get_backend_router_id_from_hostname,
                                           args.get('backend_router'),
                                           'backendRouter')
    rule_id = helpers.resolve_id(manager.get_rule_id_from_name, args.get('rule'), 'Rule')
    placement_object = {
        'name': args.get('name'),
        'backendRouterId': backend_router_id,
        'ruleId': rule_id
    }

    result = manager.create(placement_object)
    click.secho("Successfully created placement group: ID: %s, Name: %s" % (result['id'], result['name']), fg='green')
Exemplo n.º 6
0
def cli(env):
    """List placement groups."""
    manager = PlacementManager(env.client)
    result = manager.list()
    table = formatting.Table(
        ["Id", "Name", "Backend Router", "Rule", "Guests", "Created"],
        title="Placement Groups")
    for group in result:
        table.add_row([
            utils.lookup(group, 'id'),
            utils.lookup(group, 'name'),
            utils.lookup(group, 'backendRouter', 'hostname'),
            utils.lookup(group, 'rule', 'name'),
            utils.lookup(group, 'guestCount'),
            utils.lookup(group, 'createDate')
        ])

    env.fout(table)
Exemplo n.º 7
0
def cli(env, identifier, purge):
    """Delete a placement group.

    Placement Group MUST be empty before you can delete it.

    IDENTIFIER can be either the Name or Id of the placement group you want to view
    """
    manager = PlacementManager(env.client)
    group_id = helpers.resolve_id(manager.resolve_ids, identifier,
                                  'placement_group')

    if purge:
        placement_group = manager.get_object(group_id)
        guest_list = ', '.join([
            guest['fullyQualifiedDomainName']
            for guest in placement_group['guests']
        ])
        if len(placement_group['guests']) < 1:
            raise exceptions.CLIAbort(
                'No virtual servers were found in placement group %s' %
                identifier)

        click.secho("You are about to delete the following guests!\n%s" %
                    guest_list,
                    fg='red')
        if not (env.skip_confirmations or formatting.confirm(
                "This action will cancel all guests! Continue?")):
            raise exceptions.CLIAbort('Aborting virtual server order.')
        vm_manager = VSManager(env.client)
        for guest in placement_group['guests']:
            click.secho("Deleting %s..." % guest['fullyQualifiedDomainName'])
            vm_manager.cancel_instance(guest['id'])
        return

    click.secho("You are about to delete the following placement group! %s" %
                identifier,
                fg='red')
    if not (env.skip_confirmations or formatting.confirm(
            "This action will cancel the placement group! Continue?")):
        raise exceptions.CLIAbort('Aborting virtual server order.')
    cancel_result = manager.delete(group_id)
    if cancel_result:
        click.secho("Placement Group %s has been canceld." % identifier,
                    fg='green')
Exemplo n.º 8
0
def cli(env):
    """List placement groups."""
    manager = PlacementManager(env.client)
    result = manager.list()
    table = formatting.Table(
        ["Id", "Name", "Backend Router", "Rule", "Guests", "Created"],
        title="Placement Groups"
    )
    for group in result:
        table.add_row([
            group['id'],
            group['name'],
            group['backendRouter']['hostname'],
            group['rule']['name'],
            group['guestCount'],
            group['createDate']
        ])

    env.fout(table)
Exemplo n.º 9
0
def cli(env, identifier):
    """View details of a placement group.

    IDENTIFIER can be either the Name or Id of the placement group you want to view
    """
    manager = PlacementManager(env.client)
    group_id = helpers.resolve_id(manager.resolve_ids, identifier, 'placement_group')
    result = manager.get_object(group_id)
    table = formatting.Table(["Id", "Name", "Backend Router", "Rule", "Created"])

    table.add_row([
        result['id'],
        result['name'],
        result['backendRouter']['hostname'],
        result['rule']['name'],
        result['createDate']
    ])
    guest_table = formatting.Table([
        "Id",
        "FQDN",
        "Primary IP",
        "Backend IP",
        "CPU",
        "Memory",
        "Provisioned",
        "Transaction"
    ])
    for guest in result['guests']:
        guest_table.add_row([
            guest.get('id'),
            guest.get('fullyQualifiedDomainName'),
            guest.get('primaryIpAddress'),
            guest.get('primaryBackendIpAddress'),
            guest.get('maxCpu'),
            guest.get('maxMemory'),
            guest.get('provisionDate'),
            formatting.active_txn(guest)
        ])

    env.fout(table)
    env.fout(guest_table)
Exemplo n.º 10
0
 def set_up(self):
     self.manager = PlacementManager(self.client)
Exemplo n.º 11
0
class VSPlacementManagerTests(testing.TestCase):
    def set_up(self):
        self.manager = PlacementManager(self.client)

    def test_list(self):
        self.manager.list()
        self.assert_called_with('SoftLayer_Account',
                                'getPlacementGroups',
                                mask=mock.ANY)

    def test_list_mask(self):
        mask = "mask[id]"
        self.manager.list(mask)
        self.assert_called_with('SoftLayer_Account',
                                'getPlacementGroups',
                                mask=mask)

    def test_create(self):
        placement_object = {
            'backendRouter': 1234,
            'name': 'myName',
            'ruleId': 1
        }
        self.manager.create(placement_object)
        self.assert_called_with('SoftLayer_Virtual_PlacementGroup',
                                'createObject',
                                args=(placement_object, ))

    def test_get_object(self):
        self.manager.get_object(1234)
        self.assert_called_with('SoftLayer_Virtual_PlacementGroup',
                                'getObject',
                                identifier=1234,
                                mask=mock.ANY)

    def test_get_object_with_mask(self):
        mask = "mask[id]"
        self.manager.get_object(1234, mask)
        self.assert_called_with('SoftLayer_Virtual_PlacementGroup',
                                'getObject',
                                identifier=1234,
                                mask=mask)

    def test_delete(self):
        self.manager.delete(1234)
        self.assert_called_with('SoftLayer_Virtual_PlacementGroup',
                                'deleteObject',
                                identifier=1234)

    def test_get_id_from_name(self):
        self.manager._get_id_from_name('test')
        _filter = {'placementGroups': {'name': {'operation': 'test'}}}
        self.assert_called_with('SoftLayer_Account',
                                'getPlacementGroups',
                                filter=_filter,
                                mask="mask[id, name]")

    def test_get_rule_id_from_name(self):
        result = self.manager.get_rule_id_from_name('SPREAD')
        self.assertEqual(result[0], 1)
        result = self.manager.get_rule_id_from_name('SpReAd')
        self.assertEqual(result[0], 1)

    def test_get_rule_id_from_name_failure(self):
        result = self.manager.get_rule_id_from_name('SPREAD1')
        self.assertEqual(result, [])

    def test_router_search(self):
        result = self.manager.get_backend_router_id_from_hostname(
            'bcr01a.ams01')
        self.assertEqual(result[0], 117917)
        result = self.manager.get_backend_router_id_from_hostname(
            'bcr01A.AMS01')
        self.assertEqual(result[0], 117917)

    def test_router_search_failure(self):
        result = self.manager.get_backend_router_id_from_hostname('1234.ams01')
        self.assertEqual(result, [])