Ejemplo n.º 1
0
def cli(env, volume_id, snapshot_schedule, location, tier):
    """Order a file storage replica volume."""
    file_manager = SoftLayer.FileStorageManager(env.client)

    if tier is not None:
        tier = float(tier)

    try:
        order = file_manager.order_replicant_volume(
            volume_id,
            snapshot_schedule=snapshot_schedule,
            location=location,
            tier=tier,
        )
    except ValueError as ex:
        raise exceptions.ArgumentError(str(ex))

    if 'placedOrder' in order.keys():
        click.echo("Order #{0} placed successfully!".format(
            order['placedOrder']['id']))
        for item in order['placedOrder']['items']:
            click.echo(" > %s" % item['description'])
    else:
        click.echo("Order could not be placed! Please verify your options " +
                   "and try again.")
Ejemplo n.º 2
0
def cli(env, volume_id, capacity, tier, upgrade):
    """Order snapshot space for a file storage volume."""
    file_manager = SoftLayer.FileStorageManager(env.client)

    if tier is not None:
        tier = float(tier)

    try:
        order = file_manager.order_snapshot_space(volume_id,
                                                  capacity=capacity,
                                                  tier=tier,
                                                  upgrade=upgrade)
    except ValueError as ex:
        raise exceptions.ArgumentError(str(ex))

    if 'placedOrder' in order.keys():
        click.echo("Order #{0} placed successfully!".format(
            order['placedOrder']['id']))
        for item in order['placedOrder']['items']:
            click.echo(" > %s" % item['description'])
        if 'status' in order['placedOrder'].keys():
            click.echo(" > Order status: %s" % order['placedOrder']['status'])
    else:
        click.echo("Order could not be placed! Please verify your options " +
                   "and try again.")
Ejemplo n.º 3
0
def cli(env, volume_id, new_size, new_iops, new_tier):
    """Modify an existing file storage volume."""
    file_manager = SoftLayer.FileStorageManager(env.client)

    if new_tier is not None:
        new_tier = float(new_tier)

    try:
        order = file_manager.order_modified_volume(
            volume_id,
            new_size=new_size,
            new_iops=new_iops,
            new_tier_level=new_tier,
        )
    except ValueError as ex:
        raise exceptions.ArgumentError(str(ex))

    if 'placedOrder' in order.keys():
        click.echo("Order #{0} placed successfully!".format(
            order['placedOrder']['id']))
        for item in order['placedOrder']['items']:
            click.echo(" > %s" % item['description'])
    else:
        click.echo(
            "Order could not be placed! Please verify your options and try again."
        )
Ejemplo n.º 4
0
def cli(env, origin_volume_id, origin_snapshot_id, duplicate_size,
        duplicate_iops, duplicate_tier, duplicate_snapshot_size, billing):
    """Order a duplicate file storage volume."""
    file_manager = SoftLayer.FileStorageManager(env.client)

    hourly_billing_flag = False
    if billing.lower() == "hourly":
        hourly_billing_flag = True

    if duplicate_tier is not None:
        duplicate_tier = float(duplicate_tier)

    try:
        order = file_manager.order_duplicate_volume(
            origin_volume_id,
            origin_snapshot_id=origin_snapshot_id,
            duplicate_size=duplicate_size,
            duplicate_iops=duplicate_iops,
            duplicate_tier_level=duplicate_tier,
            duplicate_snapshot_size=duplicate_snapshot_size,
            hourly_billing_flag=hourly_billing_flag
        )
    except ValueError as ex:
        raise exceptions.ArgumentError(str(ex))

    if 'placedOrder' in order.keys():
        click.echo("Order #{0} placed successfully!".format(
            order['placedOrder']['id']))
        for item in order['placedOrder']['items']:
            click.echo(" > %s" % item['description'])
    else:
        click.echo("Order could not be placed! Please verify your options " +
                   "and try again.")
Ejemplo n.º 5
0
def cli(env, snapshot_id):
    """Deletes a snapshot on a given volume"""
    file_storage_manager = SoftLayer.FileStorageManager(env.client)
    deleted = file_storage_manager.delete_snapshot(snapshot_id)

    if deleted:
        click.echo('Snapshot %s deleted' % snapshot_id)
Ejemplo n.º 6
0
def cli(env, volume_id, schedule_type, retention_count, minute, hour,
        day_of_week):
    """Enables snapshots for a given volume on the specified schedule"""
    file_manager = SoftLayer.FileStorageManager(env.client)

    valid_schedule_types = {'INTERVAL', 'HOURLY', 'DAILY', 'WEEKLY'}
    valid_days = {
        'SUNDAY', 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY',
        'SATURDAY'
    }

    if schedule_type not in valid_schedule_types:
        raise exceptions.CLIAbort(
            '--schedule-type must be INTERVAL, HOURLY, ' +
            'DAILY, or WEEKLY, not ' + schedule_type)

    if schedule_type == 'INTERVAL' and (minute < 30 or minute > 59):
        raise exceptions.CLIAbort('--minute value must be between 30 and 59')
    if minute < 0 or minute > 59:
        raise exceptions.CLIAbort('--minute value must be between 0 and 59')
    if hour < 0 or hour > 23:
        raise exceptions.CLIAbort('--hour value must be between 0 and 23')
    if day_of_week not in valid_days:
        raise exceptions.CLIAbort(
            '--day_of_week value must be a valid day (ex: SUNDAY)')

    enabled = file_manager.enable_snapshots(volume_id, schedule_type,
                                            retention_count, minute, hour,
                                            day_of_week)

    if enabled:
        click.echo('%s snapshots have been enabled for volume %s' %
                   (schedule_type, volume_id))
Ejemplo n.º 7
0
def cli(env, volume_id, snapshot_id):
    """Restore file volume using a given snapshot"""
    file_manager = SoftLayer.FileStorageManager(env.client)
    success = file_manager.restore_from_snapshot(volume_id, snapshot_id)

    if success:
        click.echo('File volume %s is being restored using snapshot %s' %
                   (volume_id, snapshot_id))
Ejemplo n.º 8
0
def cli(env, volume_id):
    """Lists snapshot schedules for a given volume"""

    file_manager = SoftLayer.FileStorageManager(env.client)

    snapshot_schedules = file_manager.list_volume_schedules(volume_id)

    table = formatting.Table(['id',
                              'active',
                              'type',
                              'replication',
                              'date_created',
                              'minute',
                              'hour',
                              'day',
                              'week',
                              'day_of_week',
                              'date_of_month',
                              'month_of_year',
                              'maximum_snapshots'])

    for schedule in snapshot_schedules:

        if 'REPLICATION' in schedule['type']['keyname']:
            replication = '*'
        else:
            replication = formatting.blank()

        file_schedule_type = schedule['type']['keyname'].replace('REPLICATION_', '')
        file_schedule_type = file_schedule_type.replace('SNAPSHOT_', '')

        property_list = ['MINUTE', 'HOUR', 'DAY', 'WEEK',
                         'DAY_OF_WEEK', 'DAY_OF_MONTH',
                         'MONTH_OF_YEAR', 'SNAPSHOT_LIMIT']

        schedule_properties = []
        for prop_key in property_list:
            item = formatting.blank()
            for schedule_property in schedule.get('properties', []):
                if schedule_property['type']['keyname'] == prop_key:
                    if schedule_property['value'] == '-1':
                        item = '*'
                    else:
                        item = schedule_property['value']
                    break
            schedule_properties.append(item)

        table_row = [
            schedule['id'],
            '*' if schedule.get('active', '') else '',
            file_schedule_type,
            replication,
            schedule.get('createDate', '')
        ]
        table_row.extend(schedule_properties)
        table.add_row(table_row)

    env.fout(table)
Ejemplo n.º 9
0
def cli(env, storage_type, size, iops, tier, os_type, location, snapshot_size):
    """Order a file storage volume."""
    file_manager = SoftLayer.FileStorageManager(env.client)
    storage_type = storage_type.lower()

    if storage_type == 'performance':
        if iops is None:
            raise exceptions.CLIAbort(
                'Option --iops required with Performance')

        if iops < 100 or iops > 6000:
            raise exceptions.CLIAbort(
                'Option --iops must be between 100 and 6000, inclusive')

        if iops % 100 != 0:
            raise exceptions.CLIAbort(
                'Option --iops must be a multiple of 100')

        if snapshot_size is not None:
            raise exceptions.CLIAbort(
                'Option --snapshot-size not allowed for performance volumes.'
                ' Snapshots are only available for endurance storage.')

        try:
            order = file_manager.order_file_volume(
                storage_type='performance_storage_nfs',
                location=location,
                size=size,
                iops=iops,
                os_type=os_type)
        except ValueError as ex:
            raise exceptions.ArgumentError(str(ex))

    if storage_type == 'endurance':
        if tier is None:
            raise exceptions.CLIAbort(
                'Option --tier required with Endurance in IOPS/GB '
                '[0.25,2,4,10]')

        try:
            order = file_manager.order_file_volume(
                storage_type='storage_service_enterprise',
                location=location,
                size=size,
                tier_level=float(tier),
                os_type=os_type,
                snapshot_size=snapshot_size)
        except ValueError as ex:
            raise exceptions.ArgumentError(str(ex))

    if 'placedOrder' in order.keys():
        click.echo("Order #{0} placed successfully!".format(
            order['placedOrder']['id']))
        for item in order['placedOrder']['items']:
            click.echo(" > %s" % item['description'])
    else:
        click.echo("Order could not be placed! Please verify your options " +
                   "and try again.")
Ejemplo n.º 10
0
def cli(env, volume_id, enable):
    """Enables/Disables snapshot space usage threshold warning for a given volume"""
    file_manager = SoftLayer.FileStorageManager(env.client)

    status = file_manager.set_volume_snapshot_notification(volume_id, enable)
    if status:
        click.echo(
            'Snapshots space usage threshold warning notification has bee set to %s for volume %s'
            % (enable, volume_id))
Ejemplo n.º 11
0
def cli(env, volume_id):
    """Failback a file volume from the given replicant volume."""
    file_storage_manager = SoftLayer.FileStorageManager(env.client)

    success = file_storage_manager.failback_from_replicant(volume_id)

    if success:
        click.echo("Failback from replicant is now in progress.")
    else:
        click.echo("Failback operation could not be initiated.")
Ejemplo n.º 12
0
def cli(env, volume_id, notes):
    """Creates a snapshot on a given volume"""
    file_storage_manager = SoftLayer.FileStorageManager(env.client)
    snapshot = file_storage_manager.create_snapshot(volume_id, notes=notes)

    if 'id' in snapshot:
        click.echo('New snapshot created with id: %s' % snapshot['id'])
    else:
        click.echo('Error occurred while creating snapshot.\n'
                   'Ensure volume is not failed over or in another '
                   'state which prevents taking snapshots.')
Ejemplo n.º 13
0
def cli(env, volume_id, replicant_id, immediate):
    """Failover a file volume to the given replicant volume."""
    file_storage_manager = SoftLayer.FileStorageManager(env.client)

    success = file_storage_manager.failover_to_replicant(
        volume_id, replicant_id, immediate)

    if success:
        click.echo("Failover to replicant is now in progress.")
    else:
        click.echo("Failover operation could not be initiated.")
Ejemplo n.º 14
0
def cli(env, volume_id, note):
    """Set note for an existing file storage volume."""
    file_manager = SoftLayer.FileStorageManager(env.client)
    file_volume_id = helpers.resolve_id(file_manager.resolve_ids, volume_id, 'File Storage')

    result = file_manager.volume_set_note(file_volume_id, note)

    if result:
        click.echo("Set note successfully!")

    else:
        click.echo("Note could not be set! Please verify your options and try again.")
Ejemplo n.º 15
0
def cli(env, sortby, columns, datacenter, username, storage_type, order):
    """List file storage."""
    file_manager = SoftLayer.FileStorageManager(env.client)
    file_volumes = file_manager.list_file_volumes(datacenter=datacenter,
                                                  username=username,
                                                  storage_type=storage_type,
                                                  order=order,
                                                  mask=columns.mask())

    table = storage_utils.build_output_table(env, file_volumes, columns,
                                             sortby)
    env.fout(table)
Ejemplo n.º 16
0
def cli(env, sortby):
    """List number of block storage volumes limit per datacenter."""
    file_manager = SoftLayer.FileStorageManager(env.client)
    file_volumes = file_manager.list_file_volume_limit()

    table = formatting.KeyValueTable(DEFAULT_COLUMNS)
    table.sortby = sortby
    for volume in file_volumes:
        datacenter_name = volume['datacenterName']
        maximum_available_count = volume['maximumAvailableCount']
        provisioned_count = volume['provisionedCount']
        table.add_row([datacenter_name, maximum_available_count, provisioned_count])
    env.fout(table)
Ejemplo n.º 17
0
def cli(env, volume_id, schedule_type):
    """Disables snapshots on the specified schedule for a given volume"""

    if (schedule_type not in ['INTERVAL', 'HOURLY', 'DAILY', 'WEEKLY']):
        raise exceptions.CLIAbort(
            '--schedule_type must be INTERVAL, HOURLY, DAILY, or WEEKLY')

    file_manager = SoftLayer.FileStorageManager(env.client)
    disabled = file_manager.disable_snapshots(volume_id, schedule_type)

    if disabled:
        click.echo('%s snapshots have been disabled for volume %s'
                   % (schedule_type, volume_id))
Ejemplo n.º 18
0
def cli(env, volume_id, sortby, columns):
    """List file storage snapshots."""
    file_manager = SoftLayer.FileStorageManager(env.client)
    snapshots = file_manager.get_file_volume_snapshot_list(volume_id,
                                                           mask=columns.mask())

    table = formatting.Table(columns.columns)
    table.sortby = sortby

    for snapshot in snapshots:
        table.add_row(
            [value or formatting.blank() for value in columns.row(snapshot)])

    env.fout(table)
Ejemplo n.º 19
0
def cli(env, volume_id):
    """Get snapshots space usage threshold warning flag setting for a given volume"""

    file_manager = SoftLayer.FileStorageManager(env.client)
    enabled = file_manager.get_volume_snapshot_notification_status(volume_id)

    if enabled == 0:
        click.echo(
            "Disabled: Snapshots space usage threshold is disabled for volume {}"
            .format(volume_id))
    else:
        click.echo(
            "Enabled: Snapshots space usage threshold is enabled for volume {}"
            .format(volume_id))
Ejemplo n.º 20
0
def cli(env, sortby, columns, datacenter, username, storage_type):
    """List file storage."""
    file_manager = SoftLayer.FileStorageManager(env.client)
    file_volumes = file_manager.list_file_volumes(datacenter=datacenter,
                                                  username=username,
                                                  storage_type=storage_type,
                                                  mask=columns.mask())

    table = formatting.Table(columns.columns)
    table.sortby = sortby

    for file_volume in file_volumes:
        table.add_row([
            value or formatting.blank() for value in columns.row(file_volume)
        ])

    env.fout(table)
def cli(env, volume_id):
    """Get status for split or move completed percentage of a given file duplicate volume."""
    table = formatting.Table(['Username', 'Active Conversion Start Timestamp', 'Completed Percentage'])

    file_manager = SoftLayer.FileStorageManager(env.client)

    value = file_manager.convert_dupe_status(volume_id)

    table.add_row(
        [
            value['volumeUsername'],
            value['activeConversionStartTime'],
            value['deDuplicateConversionPercentage']
        ]
    )

    env.fout(table)
Ejemplo n.º 22
0
def cli(env, volume_id, hardware_id, virtual_id, ip_address_id, ip_address,
        subnet_id):
    """Revokes authorization for hosts accessing a given volume"""
    file_manager = SoftLayer.FileStorageManager(env.client)
    ip_address_id_list = list(ip_address_id)

    # Convert actual IP Addresses to their SoftLayer ids
    if ip_address is not None:
        network_manager = SoftLayer.NetworkManager(env.client)
        for ip_address_value in ip_address:
            ip_address_object = network_manager.ip_lookup(ip_address_value)
            ip_address_id_list.append(ip_address_object['id'])

    file_manager.deauthorize_host_to_volume(volume_id, hardware_id, virtual_id,
                                            ip_address_id_list, subnet_id)

    # If no exception was raised, the command succeeded
    click.echo('Access to %s was revoked for the specified hosts' % volume_id)
Ejemplo n.º 23
0
def cli(env, columns, sortby, volume_id):
    """List ACLs."""
    file_manager = SoftLayer.FileStorageManager(env.client)
    access_list = file_manager.get_file_volume_access_list(
        volume_id=volume_id)
    table = formatting.Table(columns.columns)
    table.sortby = sortby

    for key, type_name in [('allowedVirtualGuests', 'VIRTUAL'),
                           ('allowedHardware', 'HARDWARE'),
                           ('allowedSubnets', 'SUBNET'),
                           ('allowedIpAddresses', 'IP')]:
        for obj in access_list.get(key, []):
            obj['type'] = type_name
            table.add_row([value or formatting.blank()
                           for value in columns.row(obj)])

    env.fout(table)
Ejemplo n.º 24
0
def cli(env, columns, sortby, volume_id):
    """List suitable replication datacenters for the given volume."""
    file_storage_manager = SoftLayer.FileStorageManager(env.client)

    legal_centers = file_storage_manager.get_replication_locations(volume_id)

    if not legal_centers:
        click.echo("No data centers compatible for replication.")
    else:
        table = formatting.KeyValueTable(columns.columns)
        table.sortby = sortby
        for legal_center in legal_centers:
            table.add_row([
                value or formatting.blank()
                for value in columns.row(legal_center)
            ])

        env.fout(table)
Ejemplo n.º 25
0
def cli(env, columns, sortby, volume_id):
    """List existing replicant volumes for a file volume."""
    file_storage_manager = SoftLayer.FileStorageManager(env.client)

    legal_volumes = file_storage_manager.get_replication_partners(volume_id)

    if not legal_volumes:
        click.echo("There are no replication partners for the given volume.")
    else:
        table = formatting.Table(columns.columns)
        table.sortby = sortby

        for legal_volume in legal_volumes:
            table.add_row([
                value or formatting.blank()
                for value in columns.row(legal_volume)
            ])

        env.fout(table)
Ejemplo n.º 26
0
def cli(env, volume_id, replicant_id):
    """Failover an inaccessible file volume to its available replicant volume."""
    file_storage_manager = SoftLayer.FileStorageManager(env.client)

    click.secho("""WARNING : Failover an inaccessible file volume to its available replicant volume."""
                """If a volume (with replication) becomes inaccessible due to a disaster event,"""
                """this method can be used to immediately failover to an available replica in another location."""
                """This method does not allow for failback via the API."""
                """To failback to the original volume after using this method, open a support ticket."""
                """If you wish to test failover, use replica-failover instead.""", fg='red')

    if not formatting.confirm('Are you sure you want to continue?'):
        raise exceptions.CLIAbort('Aborted.')

    file_storage_manager.disaster_recovery_failover_to_replicant(
        volume_id,
        replicant_id
    )

    click.echo("Disaster Recovery Failover to replicant is now in progress.")
Ejemplo n.º 27
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)
Ejemplo n.º 28
0
def cli(env, sortby, datacenter):
    """List number of file storage volumes per datacenter."""
    file_manager = SoftLayer.FileStorageManager(env.client)
    mask = "mask[serviceResource[datacenter[name]],"\
           "replicationPartners[serviceResource[datacenter[name]]]]"
    file_volumes = file_manager.list_file_volumes(datacenter=datacenter,
                                                  mask=mask)

    datacenters = {}
    for volume in file_volumes:
        service_resource = volume['serviceResource']
        if 'datacenter' in service_resource:
            datacenter_name = service_resource['datacenter']['name']
            if datacenter_name not in datacenters.keys():  # pylint: disable=consider-iterating-dictionary
                datacenters[datacenter_name] = 1
            else:
                datacenters[datacenter_name] += 1

    table = formatting.KeyValueTable(DEFAULT_COLUMNS)
    table.sortby = sortby
    for key, value in datacenters.items():
        table.add_row([key, value])
    env.fout(table)
Ejemplo n.º 29
0
def cli(env, volume_id, hardware_id, virtual_id, ip_address_id, ip_address,
        subnet_id):
    """Authorizes hosts to access a given volume"""
    file_manager = SoftLayer.FileStorageManager(env.client)
    ip_address_id_list = list(ip_address_id)

    # Convert actual IP Addresses to their SoftLayer ids
    if ip_address is not None:
        network_manager = SoftLayer.NetworkManager(env.client)
        for ip_address_value in ip_address:
            ip_address_object = network_manager.ip_lookup(ip_address_value)
            if ip_address_object == "":
                click.echo(
                    "IP Address not found on your account. Please confirm IP and try again."
                )
                raise exceptions.ArgumentError('Incorrect IP Address')
            ip_address_id_list.append(ip_address_object['id'])

    file_manager.authorize_host_to_volume(volume_id, hardware_id, virtual_id,
                                          ip_address_id_list, subnet_id)

    # If no exception was raised, the command succeeded
    click.echo('The specified hosts were authorized to access %s' % volume_id)
Ejemplo n.º 30
0
def cli(env, volume_id, snapshot_id):
    """Refresh a duplicate volume with a snapshot from its parent."""
    file_manager = SoftLayer.FileStorageManager(env.client)
    resp = file_manager.refresh_dupe(volume_id, snapshot_id)

    click.echo(resp)