Skip to content

Commit f1d0b7f

Browse files
Nilo LisboaNilo Lisboa
authored andcommitted
Order fixed
Implemented replica-locations and replica-partners for improved Experience when replicating or looking up information on replicants.
1 parent 12dac31 commit f1d0b7f

File tree

13 files changed

+433
-2
lines changed

13 files changed

+433
-2
lines changed

SoftLayer/CLI/block/order.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def cli(env, storage_type, size, iops, tier, os_type,
7979
order = block_manager.order_block_volume(
8080
storage_type='performance_storage_iscsi',
8181
location=location,
82-
size=size,
82+
size=int(size),
8383
iops=iops,
8484
os_type=os_type
8585
)
@@ -97,7 +97,7 @@ def cli(env, storage_type, size, iops, tier, os_type,
9797
order = block_manager.order_block_volume(
9898
storage_type='storage_service_enterprise',
9999
location=location,
100-
size=size,
100+
size=int(size),
101101
tier_level=float(tier),
102102
os_type=os_type,
103103
snapshot_size=snapshot_size
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"""List suitable replication datacenters for the given volume."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
import SoftLayer
6+
from SoftLayer.CLI import columns as column_helper
7+
from SoftLayer.CLI import environment
8+
from SoftLayer.CLI import formatting
9+
10+
COLUMNS = [
11+
column_helper.Column('ID', ('id',), mask="id"),
12+
column_helper.Column('Long Name', ('longName',), mask="longName"),
13+
column_helper.Column('Short Name', ('name',), mask="name"),
14+
]
15+
16+
DEFAULT_COLUMNS = [
17+
'ID',
18+
'Long Name',
19+
'Short Name',
20+
]
21+
22+
23+
@click.command()
24+
@click.argument('volume-id')
25+
@click.option('--sortby', help='Column to sort by', default='Long Name')
26+
@click.option('--columns',
27+
callback=column_helper.get_formatter(COLUMNS),
28+
help='Columns to display. Options: {0}'.format(
29+
', '.join(column.name for column in COLUMNS)),
30+
default=','.join(DEFAULT_COLUMNS))
31+
@environment.pass_env
32+
def cli(env, columns, sortby, volume_id):
33+
"""List suitable replication datacenters for the given volume."""
34+
block_storage_manager = SoftLayer.BlockStorageManager(env.client)
35+
36+
legal_centers = block_storage_manager.get_replication_locations(
37+
volume_id
38+
)
39+
40+
if not legal_centers:
41+
click.echo("No data centers compatible for replication.")
42+
else:
43+
table = formatting.KeyValueTable(columns.columns)
44+
table.sortby = sortby
45+
for legal_center in legal_centers:
46+
table.add_row([value or formatting.blank()
47+
for value in columns.row(legal_center)])
48+
49+
env.fout(table)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"""List existing replicant volumes for a block volume."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
import SoftLayer
6+
from SoftLayer.CLI import columns as column_helper
7+
from SoftLayer.CLI import environment
8+
from SoftLayer.CLI import formatting
9+
10+
COLUMNS = [
11+
column_helper.Column('ID', ('id',)),
12+
column_helper.Column('Username', ('username',), mask="username"),
13+
column_helper.Column('Account ID', ('accountId',), mask="accountId"),
14+
column_helper.Column('Capacity (GB)', ('capacityGb',), mask="capacityGb"),
15+
column_helper.Column('Hardware ID', ('hardwareId',), mask="hardwareId"),
16+
column_helper.Column('Guest ID', ('guestId',), mask="guestId"),
17+
column_helper.Column('Host ID', ('hostId',), mask="hostId"),
18+
]
19+
20+
DEFAULT_COLUMNS = [
21+
'ID',
22+
'Username',
23+
'Account ID',
24+
'Capacity (GB)',
25+
'Hardware ID',
26+
'Guest ID',
27+
'Host ID'
28+
]
29+
30+
31+
@click.command()
32+
@click.argument('volume-id')
33+
@click.option('--sortby', help='Column to sort by', default='Username')
34+
@click.option('--columns',
35+
callback=column_helper.get_formatter(COLUMNS),
36+
help='Columns to display. Options: {0}'.format(
37+
', '.join(column.name for column in COLUMNS)),
38+
default=','.join(DEFAULT_COLUMNS))
39+
@environment.pass_env
40+
def cli(env, columns, sortby, volume_id):
41+
"""List existing replicant volumes for a block volume."""
42+
block_storage_manager = SoftLayer.BlockStorageManager(env.client)
43+
44+
legal_volumes = block_storage_manager.get_replication_partners(
45+
volume_id
46+
)
47+
48+
if not legal_volumes:
49+
click.echo("There are no replication partners for the given volume.")
50+
else:
51+
table = formatting.Table(columns.columns)
52+
table.sortby = sortby
53+
for legal_volume in legal_volumes:
54+
table.add_row([value or formatting.blank()
55+
for value in columns.row(legal_volume)])
56+
57+
env.fout(table)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"""List suitable replication datacenters for the given volume."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
import SoftLayer
6+
from SoftLayer.CLI import columns as column_helper
7+
from SoftLayer.CLI import environment
8+
from SoftLayer.CLI import formatting
9+
10+
COLUMNS = [
11+
column_helper.Column('ID', ('id',), mask="id"),
12+
column_helper.Column('Long Name', ('longName',), mask="longName"),
13+
column_helper.Column('Short Name', ('name',), mask="name"),
14+
]
15+
16+
DEFAULT_COLUMNS = [
17+
'ID',
18+
'Long Name',
19+
'Short Name',
20+
]
21+
22+
23+
@click.command()
24+
@click.argument('volume-id')
25+
@click.option('--sortby', help='Column to sort by', default='Long Name')
26+
@click.option('--columns',
27+
callback=column_helper.get_formatter(COLUMNS),
28+
help='Columns to display. Options: {0}'.format(
29+
', '.join(column.name for column in COLUMNS)),
30+
default=','.join(DEFAULT_COLUMNS))
31+
@environment.pass_env
32+
def cli(env, columns, sortby, volume_id):
33+
"""List suitable replication datacenters for the given volume."""
34+
file_storage_manager = SoftLayer.FileStorageManager(env.client)
35+
36+
legal_centers = file_storage_manager.get_replication_locations(
37+
volume_id
38+
)
39+
40+
if not legal_centers:
41+
click.echo("No data centers compatible for replication.")
42+
else:
43+
table = formatting.KeyValueTable(columns.columns)
44+
table.sortby = sortby
45+
for legal_center in legal_centers:
46+
table.add_row([value or formatting.blank()
47+
for value in columns.row(legal_center)])
48+
49+
env.fout(table)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
"""List existing replicant volumes for a file volume."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
import SoftLayer
6+
from SoftLayer.CLI import columns as column_helper
7+
from SoftLayer.CLI import environment
8+
from SoftLayer.CLI import formatting
9+
10+
COLUMNS = [
11+
column_helper.Column('ID', ('id',)),
12+
column_helper.Column('Username', ('username',), mask="username"),
13+
column_helper.Column('Account ID', ('accountId',), mask="accountId"),
14+
column_helper.Column('Capacity (GB)', ('capacityGb',), mask="capacityGb"),
15+
column_helper.Column('Hardware ID', ('hardwareId',), mask="hardwareId"),
16+
column_helper.Column('Guest ID', ('guestId',), mask="guestId"),
17+
column_helper.Column('Host ID', ('hostId',), mask="hostId"),
18+
]
19+
20+
# In-line comment to avoid similarity flag with block version
21+
22+
DEFAULT_COLUMNS = [
23+
'ID',
24+
'Username',
25+
'Account ID',
26+
'Capacity (GB)',
27+
'Hardware ID',
28+
'Guest ID',
29+
'Host ID'
30+
]
31+
32+
33+
@click.command()
34+
@click.argument('volume-id')
35+
@click.option('--sortby', help='Column to sort by', default='Username')
36+
@click.option('--columns',
37+
callback=column_helper.get_formatter(COLUMNS),
38+
help='Columns to display. Options: {0}'.format(
39+
', '.join(column.name for column in COLUMNS)),
40+
default=','.join(DEFAULT_COLUMNS))
41+
@environment.pass_env
42+
def cli(env, columns, sortby, volume_id):
43+
"""List existing replicant volumes for a file volume."""
44+
file_storage_manager = SoftLayer.FileStorageManager(env.client)
45+
46+
legal_volumes = file_storage_manager.get_replication_partners(
47+
volume_id
48+
)
49+
50+
if not legal_volumes:
51+
click.echo("There are no replication partners for the given volume.")
52+
else:
53+
table = formatting.Table(columns.columns)
54+
table.sortby = sortby
55+
56+
for legal_volume in legal_volumes:
57+
table.add_row([value or formatting.blank()
58+
for value in columns.row(legal_volume)])
59+
60+
env.fout(table)

SoftLayer/CLI/routes.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@
6363
('block:replica-failback', 'SoftLayer.CLI.block.replication.failback:cli'),
6464
('block:replica-failover', 'SoftLayer.CLI.block.replication.failover:cli'),
6565
('block:replica-order', 'SoftLayer.CLI.block.replication.order:cli'),
66+
('block:replica-partners', 'SoftLayer.CLI.block.replication.partners:cli'),
67+
('block:replica-locations',
68+
'SoftLayer.CLI.block.replication.locations:cli'),
6669
('block:snapshot-cancel', 'SoftLayer.CLI.block.snapshot.cancel:cli'),
6770
('block:snapshot-create', 'SoftLayer.CLI.block.snapshot.create:cli'),
6871
('block:snapshot-delete', 'SoftLayer.CLI.block.snapshot.delete:cli'),
@@ -83,6 +86,8 @@
8386
('file:replica-failback', 'SoftLayer.CLI.file.replication.failback:cli'),
8487
('file:replica-failover', 'SoftLayer.CLI.file.replication.failover:cli'),
8588
('file:replica-order', 'SoftLayer.CLI.file.replication.order:cli'),
89+
('file:replica-partners', 'SoftLayer.CLI.file.replication.partners:cli'),
90+
('file:replica-locations', 'SoftLayer.CLI.file.replication.locations:cli'),
8691
('file:snapshot-cancel', 'SoftLayer.CLI.file.snapshot.cancel:cli'),
8792
('file:snapshot-create', 'SoftLayer.CLI.file.snapshot.create:cli'),
8893
('file:snapshot-delete', 'SoftLayer.CLI.file.snapshot.delete:cli'),

SoftLayer/fixtures/SoftLayer_Network_Storage.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,16 @@
8484
'id': 1784,
8585
'username': 'TEST_REP_1',
8686
'serviceResourceBackendIpAddress': '10.3.174.79',
87+
'nasType': 'ISCSI_REPLICANT',
88+
'createDate': '2017:50:15-04:00',
8789
'serviceResource': {'datacenter': {'name': 'wdc01'}},
8890
'replicationSchedule': {'type': {'keyname': 'REPLICATION_HOURLY'}},
8991
}, {
9092
'id': 1785,
9193
'username': 'TEST_REP_2',
9294
'serviceResourceBackendIpAddress': '10.3.177.84',
95+
'nasType': 'ISCSI_REPLICANT',
96+
'createDate': '2017:50:15-04:00',
9397
'serviceResource': {'datacenter': {'name': 'dal01'}},
9498
'replicationSchedule': {'type': {'keyname': 'REPLICATION_DAILY'}},
9599
}],
@@ -102,6 +106,41 @@
102106
'snapshotSizeBytes': '42',
103107
}]
104108

109+
getReplicationPartners = [{
110+
'id': 1784,
111+
'accountId': 3000,
112+
'capacityGb': 20,
113+
'username': 'TEST_REP_1',
114+
'serviceResourceBackendIpAddress': '10.3.174.79',
115+
'nasType': 'ISCSI_REPLICANT',
116+
'hostId': None,
117+
'guestId': None,
118+
'hardwareId': None,
119+
'createDate': '2017:50:15-04:00',
120+
'serviceResource': {'datacenter': {'name': 'wdc01'}},
121+
'replicationSchedule': {'type': {'keyname': 'REPLICATION_HOURLY'}},
122+
}, {
123+
'id': 1785,
124+
'accountId': 3001,
125+
'capacityGb': 20,
126+
'username': 'TEST_REP_2',
127+
'serviceResourceBackendIpAddress': '10.3.177.84',
128+
'nasType': 'ISCSI_REPLICANT',
129+
'hostId': None,
130+
'guestId': None,
131+
'hardwareId': None,
132+
'createDate': '2017:50:15-04:00',
133+
'serviceResource': {'datacenter': {'name': 'dal01'}},
134+
'replicationSchedule': {'type': {'keyname': 'REPLICATION_DAILY'}},
135+
}]
136+
137+
getValidReplicationTargetDatacenterLocations = [{
138+
'id': 12345,
139+
'longName': 'Dallas 05',
140+
'name': 'dal05'
141+
}]
142+
143+
105144
deleteObject = True
106145
allowAccessFromHostList = True
107146
removeAccessFromHostList = True

SoftLayer/managers/block.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,26 @@ def deauthorize_host_to_volume(self, volume_id,
195195
return self.client.call('Network_Storage', 'removeAccessFromHostList',
196196
host_templates, id=volume_id, **kwargs)
197197

198+
def get_replication_partners(self, volume_id):
199+
"""Acquires list of replicant volumes pertaining to the given volume.
200+
201+
:param volume_id: The ID of the primary volume to be replicated
202+
:return: Returns an array of SoftLayer_Location objects
203+
"""
204+
return self.client.call('Network_Storage',
205+
'getReplicationPartners',
206+
id=volume_id)
207+
208+
def get_replication_locations(self, volume_id):
209+
"""Acquires list of the datacenters to which a volume can be replicated.
210+
211+
:param volume_id: The ID of the primary volume to be replicated
212+
:return: Returns an array of SoftLayer_Network_Storage objects
213+
"""
214+
return self.client.call('Network_Storage',
215+
'getValidReplicationTargetDatacenterLocations',
216+
id=volume_id)
217+
198218
def order_replicant_volume(self, volume_id, snapshot_schedule,
199219
location, tier=None, os_type=None):
200220
"""Places an order for a replicant block volume.

SoftLayer/managers/file.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,26 @@ def order_replicant_volume(self, volume_id, snapshot_schedule,
220220

221221
return self.client.call('Product_Order', 'placeOrder', order)
222222

223+
def get_replication_partners(self, volume_id):
224+
"""Acquires list of replicant volumes pertaining to the given volume.
225+
226+
:param volume_id: The ID of the primary volume to be replicated
227+
:return: Returns an array of SoftLayer_Location objects
228+
"""
229+
return self.client.call('Network_Storage',
230+
'getReplicationPartners',
231+
id=volume_id)
232+
233+
def get_replication_locations(self, volume_id):
234+
"""Acquires list of the datacenters to which a volume can be replicated.
235+
236+
:param volume_id: The ID of the primary volume to be replicated
237+
:return: Returns an array of SoftLayer_Network_Storage objects
238+
"""
239+
return self.client.call('Network_Storage',
240+
'getValidReplicationTargetDatacenterLocations',
241+
id=volume_id)
242+
223243
def delete_snapshot(self, snapshot_id):
224244
"""Deletes the specified snapshot object.
225245

0 commit comments

Comments
 (0)