def test_do_or_die(self, raw_input_mock):
        confirmed = '37347373737'
        raw_input_mock.return_value = confirmed
        result = formatting.no_going_back(confirmed)
        self.assertTrue(result)

        # no_going_back should cast int's to str()
        confirmed = '4712309182309'
        raw_input_mock.return_value = confirmed
        result = formatting.no_going_back(int(confirmed))
        self.assertTrue(result)

        confirmed = None
        raw_input_mock.return_value = ''
        result = formatting.no_going_back(confirmed)
        self.assertFalse(result)
Esempio n. 2
0
    def test_do_or_die(self, raw_input_mock):
        confirmed = "37347373737"
        raw_input_mock.return_value = confirmed
        result = formatting.no_going_back(confirmed)
        self.assertTrue(result)

        # no_going_back should cast int's to str()
        confirmed = "4712309182309"
        raw_input_mock.return_value = confirmed
        result = formatting.no_going_back(int(confirmed))
        self.assertTrue(result)

        confirmed = None
        raw_input_mock.return_value = ""
        result = formatting.no_going_back(confirmed)
        self.assertFalse(result)
Esempio n. 3
0
def cli(env, identifier):
    """Cancel all virtual guests of the dedicated host immediately.

       Use the 'slcli vs cancel' command to cancel an specific guest
    """

    dh_mgr = SoftLayer.DedicatedHostManager(env.client)

    host_id = helpers.resolve_id(dh_mgr.resolve_ids, identifier,
                                 'dedicated host')

    if not (env.skip_confirmations or formatting.no_going_back(host_id)):
        raise exceptions.CLIAbort('Aborted')

    table = formatting.Table(['id', 'server name', 'status'])

    result = dh_mgr.cancel_guests(host_id)

    if result:
        for status in result:
            table.add_row([status['id'], status['fqdn'], status['status']])

        env.fout(table)
    else:
        click.secho('There is not any guest into the dedicated host %s' %
                    host_id,
                    fg='red')
Esempio n. 4
0
def cli(env, identifier):
    """Remove SSL certificate."""

    manager = SoftLayer.SSLManager(env.client)
    if env.skip_confirmations or formatting.no_going_back('yes'):
        manager.remove_certificate(identifier)
    raise exceptions.CLIAbort("Aborted.")
Esempio n. 5
0
    def test_do_or_die(self, prompt_mock):
        confirmed = '37347373737'
        prompt_mock.return_value = confirmed
        result = formatting.no_going_back(confirmed)
        self.assertTrue(result)

        # no_going_back should cast int's to str()
        confirmed = '4712309182309'
        prompt_mock.return_value = confirmed
        result = formatting.no_going_back(int(confirmed))
        self.assertTrue(result)

        confirmed = None
        prompt_mock.return_value = ''
        result = formatting.no_going_back(confirmed)
        self.assertFalse(result)
def cli(env, identifier):
    """Cancel all virtual guests of the dedicated host immediately.

       Use the 'slcli vs cancel' command to cancel an specific guest
    """

    dh_mgr = SoftLayer.DedicatedHostManager(env.client)

    host_id = helpers.resolve_id(dh_mgr.resolve_ids, identifier, 'dedicated host')

    if not (env.skip_confirmations or formatting.no_going_back(host_id)):
        raise exceptions.CLIAbort('Aborted')

    table = formatting.Table(['id', 'server name', 'status'])

    result = dh_mgr.cancel_guests(host_id)

    if result:
        for status in result:
            table.add_row([
                status['id'],
                status['fqdn'],
                status['status']
            ])

        env.fout(table)
    else:
        click.secho('There is not any guest into the dedicated host %s' % host_id, fg='red')
Esempio n. 7
0
 def execute(self, args):
     vsi = SoftLayer.VSManager(self.client)
     vs_id = helpers.resolve_id(vsi.resolve_ids, args.get('<identifier>'),
                                'VS')
     if args['--really'] or formatting.no_going_back(vs_id):
         vsi.cancel_instance(vs_id)
     else:
         raise exceptions.CLIAbort('Aborted')
Esempio n. 8
0
def cli(env, volume_id, reason, immediate):
    """Cancel an existing block storage volume."""

    block_storage_manager = SoftLayer.BlockStorageManager(env.client)

    if not (env.skip_confirmations or formatting.no_going_back(volume_id)):
        raise exceptions.CLIAbort('Aborted')

    block_storage_manager.cancel_block_volume(volume_id, reason, immediate)
Esempio n. 9
0
def cli(env, identifier):
    """Cancel virtual servers."""

    vsi = SoftLayer.VSManager(env.client)
    vs_id = helpers.resolve_id(vsi.resolve_ids, identifier, 'VS')
    if not (env.skip_confirmations or formatting.no_going_back(vs_id)):
        raise exceptions.CLIAbort('Aborted')

    vsi.cancel_instance(vs_id)
Esempio n. 10
0
def cli(env, identifier):
    """Permanently removes an SSH key."""
    mgr = SoftLayer.SshKeyManager(env.client)

    key_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'SshKey')
    if env.skip_confirmations or formatting.no_going_back(key_id):
        mgr.delete_key(key_id)
    else:
        raise exceptions.CLIAbort('Aborted')
Esempio n. 11
0
def cli(env, record_id):
    """Add resource record."""

    manager = SoftLayer.DNSManager(env.client)

    if not (env.skip_confirmations or formatting.no_going_back('yes')):
        raise exceptions.CLIAbort("Aborted.")

    manager.delete_record(record_id)
Esempio n. 12
0
def cli(env, identifier):
    """Permanently removes an SSH key."""
    mgr = SoftLayer.SshKeyManager(env.client)

    key_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'SshKey')
    if not (env.skip_confirmations or formatting.no_going_back(key_id)):
        raise exceptions.CLIAbort('Aborted')

    mgr.delete_key(key_id)
Esempio n. 13
0
    def execute(self, args):
        mgr = SoftLayer.SshKeyManager(self.client)

        key_id = helpers.resolve_id(mgr.resolve_ids, args.get('<identifier>'),
                                    'SshKey')
        if args['--really'] or formatting.no_going_back(key_id):
            mgr.delete_key(key_id)
        else:
            raise exceptions.CLIAbort('Aborted')
    def execute(self, args):
        manager = SoftLayer.DNSManager(self.client)
        zone_id = helpers.resolve_id(manager.resolve_ids, args['<zone>'],
                                     name='zone')

        if args['--really'] or formatting.no_going_back(args['<zone>']):
            manager.delete_zone(zone_id)
        else:
            raise exceptions.CLIAbort("Aborted.")
Esempio n. 15
0
 def execute(self, args):
     vsi = SoftLayer.VSManager(self.client)
     vs_id = helpers.resolve_id(vsi.resolve_ids,
                                args.get('<identifier>'),
                                'VS')
     if args['--really'] or formatting.no_going_back(vs_id):
         vsi.cancel_instance(vs_id)
     else:
         raise exceptions.CLIAbort('Aborted')
Esempio n. 16
0
def cli(env, identifier):
    """Cancel virtual servers."""

    vsi = SoftLayer.VSManager(env.client)
    vs_id = helpers.resolve_id(vsi.resolve_ids, identifier, 'VS')
    if env.skip_confirmations or formatting.no_going_back(vs_id):
        vsi.cancel_instance(vs_id)
    else:
        raise exceptions.CLIAbort('Aborted')
def cli(env, record_id):
    """Remove resource record."""

    manager = SoftLayer.DNSManager(env.client)

    if not (env.skip_confirmations or formatting.no_going_back('yes')):
        raise exceptions.CLIAbort("Aborted.")

    manager.delete_record(record_id)
Esempio n. 18
0
def cli(env, identifier, immediate, comment, reason):
    """Cancel a dedicated server."""

    mgr = SoftLayer.HardwareManager(env.client)
    hw_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'hardware')

    if not (env.skip_confirmations or formatting.no_going_back(hw_id)):
        raise exceptions.CLIAbort('Aborted')

    mgr.cancel_hardware(hw_id, reason, comment, immediate)
Esempio n. 19
0
def cli(env, identifier, reason, immediate):
    """Cancel an existing iSCSI account."""

    iscsi_mgr = SoftLayer.ISCSIManager(env.client)
    iscsi_id = helpers.resolve_id(iscsi_mgr.resolve_ids, identifier, 'iSCSI')

    if env.skip_confirmations or formatting.no_going_back(iscsi_id):
        iscsi_mgr.cancel_iscsi(iscsi_id, reason, immediate)
    else:
        raise exceptions.CLIAbort('Aborted')
Esempio n. 20
0
    def execute(self, args):
        mgr = SoftLayer.SshKeyManager(self.client)

        key_id = helpers.resolve_id(mgr.resolve_ids,
                                    args.get('<identifier>'),
                                    'SshKey')
        if args['--really'] or formatting.no_going_back(key_id):
            mgr.delete_key(key_id)
        else:
            raise exceptions.CLIAbort('Aborted')
Esempio n. 21
0
    def execute(self, args):
        manager = SoftLayer.DNSManager(self.client)
        zone_id = helpers.resolve_id(manager.resolve_ids,
                                     args['<zone>'],
                                     name='zone')

        if args['--really'] or formatting.no_going_back(args['<zone>']):
            manager.delete_zone(zone_id)
        else:
            raise exceptions.CLIAbort("Aborted.")
Esempio n. 22
0
    def execute(self, args):
        mgr = SoftLayer.NetworkManager(self.client)
        global_ip_id = helpers.resolve_id(mgr.resolve_global_ip_ids,
                                          args.get('<identifier>'),
                                          name='global ip')

        if args['--really'] or formatting.no_going_back(global_ip_id):
            mgr.cancel_global_ip(global_ip_id)
        else:
            raise exceptions.CLIAbort('Aborted')
Esempio n. 23
0
def cli(env, zone):
    """Delete zone."""

    manager = SoftLayer.DNSManager(env.client)
    zone_id = helpers.resolve_id(manager.resolve_ids, zone, name='zone')

    if not (env.skip_confirmations or formatting.no_going_back(zone)):
        raise exceptions.CLIAbort("Aborted.")

    manager.delete_zone(zone_id)
Esempio n. 24
0
    def execute(self, args):
        mgr = SoftLayer.NetworkManager(self.client)
        global_ip_id = helpers.resolve_id(mgr.resolve_global_ip_ids,
                                          args.get('<identifier>'),
                                          name='global ip')

        if args['--really'] or formatting.no_going_back(global_ip_id):
            mgr.cancel_global_ip(global_ip_id)
        else:
            raise exceptions.CLIAbort('Aborted')
Esempio n. 25
0
def cli(env, identifier, reason, immediate):
    """Cancel an existing iSCSI account."""

    iscsi_mgr = SoftLayer.ISCSIManager(env.client)
    iscsi_id = helpers.resolve_id(iscsi_mgr.resolve_ids, identifier, 'iSCSI')

    if env.skip_confirmations or formatting.no_going_back(iscsi_id):
        iscsi_mgr.cancel_iscsi(iscsi_id, reason, immediate)
    else:
        raise exceptions.CLIAbort('Aborted')
Esempio n. 26
0
    def execute(self, args):
        iscsi_mgr = SoftLayer.ISCSIManager(self.client)
        iscsi_id = helpers.resolve_id(iscsi_mgr.resolve_ids, args.get("<identifier>"), "iSCSI")

        immediate = args.get("--immediate", False)

        reason = args.get("--reason")
        if args["--really"] or formatting.no_going_back(iscsi_id):
            iscsi_mgr.cancel_iscsi(iscsi_id, reason, immediate)
        else:
            raise exceptions.CLIAbort("Aborted")
Esempio n. 27
0
def cli(env, identifier):
    """Cancel global IP."""

    mgr = SoftLayer.NetworkManager(env.client)
    global_ip_id = helpers.resolve_id(mgr.resolve_global_ip_ids, identifier,
                                      name='global ip')

    if env.skip_confirmations or formatting.no_going_back(global_ip_id):
        mgr.cancel_global_ip(global_ip_id)
    else:
        raise exceptions.CLIAbort('Aborted')
Esempio n. 28
0
def cli(env, identifier):
    """Cancel a subnet."""

    mgr = SoftLayer.NetworkManager(env.client)
    subnet_id = helpers.resolve_id(mgr.resolve_subnet_ids, identifier,
                                   name='subnet')

    if not (env.skip_confirmations or formatting.no_going_back(subnet_id)):
        raise exceptions.CLIAbort('Aborted')

    mgr.cancel_subnet(subnet_id)
Esempio n. 29
0
def cli(env, identifier):
    """Cancel a subnet."""

    mgr = SoftLayer.NetworkManager(env.client)
    subnet_id = helpers.resolve_id(mgr.resolve_subnet_ids, identifier,
                                   name='subnet')

    if env.skip_confirmations or formatting.no_going_back(subnet_id):
        mgr.cancel_subnet(subnet_id)
    else:
        raise exceptions.CLIAbort('Aborted')
Esempio n. 30
0
def cli(env, identifier):
    """Cancel global IP."""

    mgr = SoftLayer.NetworkManager(env.client)
    global_ip_id = helpers.resolve_id(mgr.resolve_global_ip_ids, identifier,
                                      name='global ip')

    if not (env.skip_confirmations or formatting.no_going_back(global_ip_id)):
        raise exceptions.CLIAbort('Aborted')

    mgr.cancel_global_ip(global_ip_id)
Esempio n. 31
0
def cli(env, identifier, immediate, comment, reason):
    """Cancel a dedicated server."""

    mgr = SoftLayer.HardwareManager(env.client)
    hw_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'hardware')

    if not comment and not env.skip_confirmations:
        comment = env.input("(Optional) Add a cancellation comment:")

    if env.skip_confirmations or formatting.no_going_back(hw_id):
        mgr.cancel_hardware(hw_id, reason, comment, immediate)
    else:
        raise exceptions.CLIAbort('Aborted')
Esempio n. 32
0
def cli(env, identifier):
    """Cancel a dedicated host server immediately"""

    mgr = SoftLayer.DedicatedHostManager(env.client)

    host_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'dedicated host')

    if not (env.skip_confirmations or formatting.no_going_back(host_id)):
        raise exceptions.CLIAbort('Aborted')

    mgr.cancel_host(host_id)

    click.secho('Dedicated Host %s was cancelled' % host_id, fg='green')
Esempio n. 33
0
 def execute(self, args):
     hardware = SoftLayer.HardwareManager(self.client)
     hardware_id = helpers.resolve_id(
         hardware.resolve_ids, args.get('<identifier>'), 'hardware')
     keys = []
     if args.get('--key'):
         for key in args.get('--key'):
             resolver = SoftLayer.SshKeyManager(self.client).resolve_ids
             key_id = helpers.resolve_id(resolver, key, 'SshKey')
             keys.append(key_id)
     if args['--really'] or formatting.no_going_back(hardware_id):
         hardware.reload(hardware_id, args['--postinstall'], keys)
     else:
         raise exceptions.CLIAbort('Aborted')
Esempio n. 34
0
 def execute(self, args):
     hardware = SoftLayer.HardwareManager(self.client)
     hardware_id = helpers.resolve_id(hardware.resolve_ids,
                                      args.get('<identifier>'), 'hardware')
     keys = []
     if args.get('--key'):
         for key in args.get('--key'):
             resolver = SoftLayer.SshKeyManager(self.client).resolve_ids
             key_id = helpers.resolve_id(resolver, key, 'SshKey')
             keys.append(key_id)
     if args['--really'] or formatting.no_going_back(hardware_id):
         hardware.reload(hardware_id, args['--postinstall'], keys)
     else:
         raise exceptions.CLIAbort('Aborted')
Esempio n. 35
0
    def execute(self, args):
        iscsi_mgr = SoftLayer.ISCSIManager(self.client)
        iscsi_id = helpers.resolve_id(
            iscsi_mgr.resolve_ids,
            args.get('<identifier>'),
            'iSCSI')

        immediate = args.get('--immediate', False)

        reason = args.get('--reason')
        if args['--really'] or formatting.no_going_back(iscsi_id):
            iscsi_mgr.cancel_iscsi(iscsi_id, reason, immediate)
        else:
            raise exceptions.CLIAbort('Aborted')
Esempio n. 36
0
def cli(env, identifier, postinstall, key):
    """Reload operating system on a virtual server."""

    vsi = SoftLayer.VSManager(env.client)
    vs_id = helpers.resolve_id(vsi.resolve_ids, identifier, 'VS')
    keys = []
    if key:
        for single_key in key:
            resolver = SoftLayer.SshKeyManager(env.client).resolve_ids
            key_id = helpers.resolve_id(resolver, single_key, 'SshKey')
            keys.append(key_id)
    if not (env.skip_confirmations or formatting.no_going_back(vs_id)):
        raise exceptions.CLIAbort('Aborted')

    vsi.reload_instance(vs_id, postinstall, keys)
Esempio n. 37
0
    def execute(self, args):
        mgr = SoftLayer.HardwareManager(self.client)
        hw_id = helpers.resolve_id(
            mgr.resolve_ids, args.get('<identifier>'), 'hardware')

        comment = args.get('--comment')

        if not comment and not args['--really']:
            comment = self.env.input("(Optional) Add a cancellation comment:")

        reason = args.get('--reason')

        if args['--really'] or formatting.no_going_back(hw_id):
            mgr.cancel_hardware(hw_id, reason, comment)
        else:
            raise exceptions.CLIAbort('Aborted')
Esempio n. 38
0
    def execute(self, args):
        mgr = SoftLayer.HardwareManager(self.client)
        hw_id = helpers.resolve_id(mgr.resolve_ids, args.get('<identifier>'),
                                   'hardware')

        comment = args.get('--comment')

        if not comment and not args['--really']:
            comment = self.env.input("(Optional) Add a cancellation comment:")

        reason = args.get('--reason')

        if args['--really'] or formatting.no_going_back(hw_id):
            mgr.cancel_hardware(hw_id, reason, comment)
        else:
            raise exceptions.CLIAbort('Aborted')
Esempio n. 39
0
def cli(env, identifier, postinstall, key, lvm):
    """Reload operating system on a server."""

    hardware = SoftLayer.HardwareManager(env.client)
    hardware_id = helpers.resolve_id(hardware.resolve_ids, identifier,
                                     'hardware')
    key_list = []
    if key:
        for single_key in key:
            resolver = SoftLayer.SshKeyManager(env.client).resolve_ids
            key_id = helpers.resolve_id(resolver, single_key, 'SshKey')
            key_list.append(key_id)
    if not (env.skip_confirmations or formatting.no_going_back(hardware_id)):
        raise exceptions.CLIAbort('Aborted')

    hardware.reload(hardware_id, postinstall, key_list, lvm)
Esempio n. 40
0
def cli(env, identifier, postinstall, key):
    """Reload operating system on a server."""

    hardware = SoftLayer.HardwareManager(env.client)
    hardware_id = helpers.resolve_id(hardware.resolve_ids,
                                     identifier,
                                     'hardware')
    key_list = []
    if key:
        for single_key in key:
            resolver = SoftLayer.SshKeyManager(env.client).resolve_ids
            key_id = helpers.resolve_id(resolver, single_key, 'SshKey')
            key_list.append(key_id)
    if env.skip_confirmations or formatting.no_going_back(hardware_id):
        hardware.reload(hardware_id, postinstall, key_list)
    else:
        raise exceptions.CLIAbort('Aborted')
Esempio n. 41
0
def cli(env, volume_id, reason, immediate):
    """Cancel an existing block storage volume."""

    block_storage_manager = SoftLayer.BlockStorageManager(env.client)

    if not (env.skip_confirmations or formatting.no_going_back(volume_id)):
        raise exceptions.CLIAbort("Aborted")

    cancelled = block_storage_manager.cancel_block_volume(volume_id, reason, immediate)

    if cancelled:
        if immediate:
            click.echo("Block volume with id %s has been marked" " for immediate cancellation" % volume_id)
        else:
            click.echo("Block volume with id %s has been marked" " for cancellation" % volume_id)
    else:
        click.echo("Unable to cancel block volume %s" % volume_id)
Esempio n. 42
0
    def execute(self, args):
        manager = SoftLayer.DNSManager(self.client)
        zone_id = helpers.resolve_id(manager.resolve_ids,
                                     args['<zone>'],
                                     name='zone')

        if args['--id']:
            records = [{'id': args['--id']}]
        else:
            records = manager.get_records(zone_id, host=args['<record>'])

        if args['--really'] or formatting.no_going_back('yes'):
            table = formatting.Table(['record'])
            for result in records:
                manager.delete_record(result['id'])
                table.add_row([result['id']])

            return table
        raise exceptions.CLIAbort("Aborted.")
Esempio n. 43
0
def cli(env, volume_id, reason, immediate):
    """Cancel an existing file storage volume."""

    file_storage_manager = SoftLayer.FileStorageManager(env.client)

    if not (env.skip_confirmations or formatting.no_going_back(volume_id)):
        raise exceptions.CLIAbort('Aborted')

    cancelled = file_storage_manager.cancel_file_volume(
        volume_id, reason, immediate)

    if cancelled:
        if immediate:
            click.echo('File volume with id %s has been marked'
                       ' for immediate cancellation' % volume_id)
        else:
            click.echo('File volume with id %s has been marked'
                       ' for cancellation' % volume_id)
    else:
        click.echo('Unable to cancle file volume %s' % volume_id)
Esempio n. 44
0
def cli(env, volume_id, reason, immediate):
    """Cancel an existing file storage volume."""

    file_storage_manager = SoftLayer.FileStorageManager(env.client)

    if not (env.skip_confirmations or formatting.no_going_back(volume_id)):
        raise exceptions.CLIAbort('Aborted')

    cancelled = file_storage_manager.cancel_file_volume(volume_id,
                                                        reason, immediate)

    if cancelled:
        if immediate:
            click.echo('File volume with id %s has been marked'
                       ' for immediate cancellation' % volume_id)
        else:
            click.echo('File volume with id %s has been marked'
                       ' for cancellation' % volume_id)
    else:
        click.echo('Unable to cancle file volume %s' % volume_id)
    def execute(self, args):
        manager = SoftLayer.DNSManager(self.client)
        zone_id = helpers.resolve_id(manager.resolve_ids, args['<zone>'],
                                     name='zone')

        if args['--id']:
            records = [{'id': args['--id']}]
        else:
            records = manager.get_records(
                zone_id,
                host=args['<record>'])

        if args['--really'] or formatting.no_going_back('yes'):
            table = formatting.Table(['record'])
            for result in records:
                manager.delete_record(result['id'])
                table.add_row([result['id']])

            return table
        raise exceptions.CLIAbort("Aborted.")
Esempio n. 46
0
def cli(env, volume_id, reason, immediate):
    """Cancel existing snapshot space for a given volume."""

    block_storage_manager = SoftLayer.BlockStorageManager(env.client)

    if not (env.skip_confirmations or formatting.no_going_back(volume_id)):
        raise exceptions.CLIAbort('Aborted')

    cancelled = block_storage_manager.cancel_snapshot_space(
        volume_id, reason, immediate)

    if cancelled:
        if immediate:
            click.echo('Block volume with id %s has been marked'
                       ' for immediate snapshot cancellation' % volume_id)
        else:
            click.echo('Block volume with id %s has been marked'
                       ' for snapshot cancellation' % volume_id)
    else:
        click.echo('Unable to cancel snapshot space for block volume %s'
                   % volume_id)
Esempio n. 47
0
def cli(env, identifier):
    """Cancel network VLAN."""

    mgr = SoftLayer.NetworkManager(env.client)

    if not (env.skip_confirmations or formatting.no_going_back(identifier)):
        raise exceptions.CLIAbort('Aborted')

    reasons = mgr.get_cancel_failure_reasons(identifier)
    if len(reasons) > 0:
        raise exceptions.CLIAbort(reasons)
    item = mgr.get_vlan(identifier).get('billingItem')
    if item:
        if mgr.cancel_item(item.get('id'),
                           True,
                           'Cancel by cli command',
                           'Cancel by cli command'):
            env.fout("VLAN {} was cancelled.".format(identifier))
    else:
        raise exceptions.CLIAbort(
            "VLAN is an automatically assigned and free of charge VLAN,"
            " it will automatically be removed from your account when it is empty")
Esempio n. 48
0
 def execute(self, args):
     manager = SoftLayer.SSLManager(self.client)
     if args['--really'] or formatting.no_going_back('yes'):
         manager.remove_certificate(args['<id>'])
     raise exceptions.CLIAbort("Aborted.")