Skip to content

Commit 86800e3

Browse files
committed
Adds listing of schedules for associated volumes
Resolves softlayer#902
1 parent 1ccda8f commit 86800e3

5 files changed

Lines changed: 174 additions & 0 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
"""List scheduled snapshots of a specific volume"""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
import SoftLayer
6+
from SoftLayer.CLI import environment
7+
from SoftLayer.CLI import formatting
8+
9+
10+
@click.command()
11+
@click.argument('volume_id')
12+
@environment.pass_env
13+
def cli(env, volume_id):
14+
"""Lists snapshot schedules for a given volume"""
15+
16+
block_manager = SoftLayer.BlockStorageManager(env.client)
17+
18+
snapshot_schedules = block_manager.list_volume_schedules(volume_id)
19+
20+
table = formatting.Table(['id',
21+
'active',
22+
'type',
23+
'replication',
24+
'date_created',
25+
'minute',
26+
'hour',
27+
'day',
28+
'week',
29+
'day_of_week',
30+
'date_of_month',
31+
'month_of_year',
32+
'maximum_snapshots',
33+
])
34+
35+
for schedule in snapshot_schedules:
36+
37+
if 'REPLICATION' in schedule['type']['keyname']:
38+
replication = '*'
39+
else:
40+
replication = formatting.blank()
41+
42+
schedule_type = schedule['type']['keyname'].replace('REPLICATION_', '')
43+
schedule_type = schedule_type.replace('SNAPSHOT_', '')
44+
45+
property_list = ['MINUTE', 'HOUR', 'DAY', 'WEEK',
46+
'DAY_OF_WEEK', 'DAY_OF_MONTH',
47+
'MONTH_OF_YEAR', 'SNAPSHOT_LIMIT']
48+
49+
schedule_properties = []
50+
for prop_key in property_list:
51+
item = formatting.blank()
52+
for schedule_property in schedule.get('properties', []):
53+
if schedule_property['type']['keyname'] == prop_key:
54+
if schedule_property['value'] == '-1':
55+
item = '*'
56+
else:
57+
item = schedule_property['value']
58+
break
59+
schedule_properties.append(item)
60+
61+
table_row = [
62+
schedule['id'],
63+
'*' if schedule['active'] else '',
64+
schedule_type,
65+
replication,
66+
schedule['createDate']]
67+
table_row.extend(schedule_properties)
68+
69+
table.add_row(table_row)
70+
71+
env.fout(table)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
"""List scheduled snapshots of a specific volume"""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
import SoftLayer
6+
from SoftLayer.CLI import environment
7+
from SoftLayer.CLI import formatting
8+
9+
10+
@click.command()
11+
@click.argument('volume_id')
12+
@environment.pass_env
13+
def cli(env, volume_id):
14+
"""Lists snapshot schedules for a given volume"""
15+
16+
file_manager = SoftLayer.FileStorageManager(env.client)
17+
18+
snapshot_schedules = file_manager.list_volume_schedules(volume_id)
19+
20+
table = formatting.Table(['id',
21+
'active',
22+
'type',
23+
'replication',
24+
'date_created',
25+
'minute',
26+
'hour',
27+
'day',
28+
'week',
29+
'day_of_week',
30+
'date_of_month',
31+
'month_of_year',
32+
'maximum_snapshots',
33+
])
34+
35+
for schedule in snapshot_schedules:
36+
37+
if 'REPLICATION' in schedule['type']['keyname']:
38+
replication = '*'
39+
else:
40+
replication = formatting.blank()
41+
42+
schedule_type = schedule['type']['keyname'].replace('REPLICATION_', '')
43+
schedule_type = schedule_type.replace('SNAPSHOT_', '')
44+
45+
property_list = ['MINUTE', 'HOUR', 'DAY', 'WEEK',
46+
'DAY_OF_WEEK', 'DAY_OF_MONTH',
47+
'MONTH_OF_YEAR', 'SNAPSHOT_LIMIT']
48+
49+
schedule_properties = []
50+
for prop_key in property_list:
51+
item = formatting.blank()
52+
for schedule_property in schedule.get('properties', []):
53+
if schedule_property['type']['keyname'] == prop_key:
54+
if schedule_property['value'] == '-1':
55+
item = '*'
56+
else:
57+
item = schedule_property['value']
58+
break
59+
schedule_properties.append(item)
60+
61+
table_row = [
62+
schedule['id'],
63+
'*' if schedule['active'] else '',
64+
schedule_type,
65+
replication,
66+
schedule['createDate']]
67+
table_row.extend(schedule_properties)
68+
69+
table.add_row(table_row)
70+
71+
env.fout(table)

SoftLayer/CLI/routes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
('block:snapshot-delete', 'SoftLayer.CLI.block.snapshot.delete:cli'),
7373
('block:snapshot-disable', 'SoftLayer.CLI.block.snapshot.disable:cli'),
7474
('block:snapshot-enable', 'SoftLayer.CLI.block.snapshot.enable:cli'),
75+
('block:snapshot-schedule-list',
76+
'SoftLayer.CLI.block.snapshot.schedule_list:cli'),
7577
('block:snapshot-list', 'SoftLayer.CLI.block.snapshot.list:cli'),
7678
('block:snapshot-order', 'SoftLayer.CLI.block.snapshot.order:cli'),
7779
('block:snapshot-restore', 'SoftLayer.CLI.block.snapshot.restore:cli'),
@@ -98,6 +100,8 @@
98100
('file:snapshot-delete', 'SoftLayer.CLI.file.snapshot.delete:cli'),
99101
('file:snapshot-disable', 'SoftLayer.CLI.file.snapshot.disable:cli'),
100102
('file:snapshot-enable', 'SoftLayer.CLI.file.snapshot.enable:cli'),
103+
('file:snapshot-schedule-list',
104+
'SoftLayer.CLI.file.snapshot.schedule_list:cli'),
101105
('file:snapshot-list', 'SoftLayer.CLI.file.snapshot.list:cli'),
102106
('file:snapshot-order', 'SoftLayer.CLI.file.snapshot.order:cli'),
103107
('file:snapshot-restore', 'SoftLayer.CLI.file.snapshot.restore:cli'),

SoftLayer/managers/block.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,20 @@ def disable_snapshots(self, volume_id, schedule_type):
474474
return self.client.call('Network_Storage', 'disableSnapshots',
475475
schedule_type, id=volume_id)
476476

477+
def list_volume_schedules(self, volume_id):
478+
"""Lists schedules for a given volume
479+
480+
:param integer volume_id: The id of the volume
481+
:return: Returns list of schedules assigned to a given volume
482+
"""
483+
volume_detail = self.client.call(
484+
'Network_Storage',
485+
'getObject',
486+
id=volume_id,
487+
mask='schedules[type,properties[type]]')
488+
489+
return utils.lookup(volume_detail, 'schedules')
490+
477491
def restore_from_snapshot(self, volume_id, snapshot_id):
478492
"""Restores a specific volume from a snapshot
479493

SoftLayer/managers/file.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,20 @@ def disable_snapshots(self, volume_id, schedule_type):
394394
return self.client.call('Network_Storage', 'disableSnapshots',
395395
schedule_type, id=volume_id)
396396

397+
def list_volume_schedules(self, volume_id):
398+
"""Lists schedules for a given volume
399+
400+
:param integer volume_id: The id of the volume
401+
:return: Returns list of schedules assigned to a given volume
402+
"""
403+
volume_detail = self.client.call(
404+
'Network_Storage',
405+
'getObject',
406+
id=volume_id,
407+
mask='schedules[type,properties[type]]')
408+
409+
return utils.lookup(volume_detail, 'schedules')
410+
397411
def order_snapshot_space(self, volume_id, capacity, tier,
398412
upgrade, **kwargs):
399413
"""Orders snapshot space for the given file volume.

0 commit comments

Comments
 (0)