Skip to content

Commit ab646c9

Browse files
Merge branch 'master' into issue1683
2 parents 98222e0 + cdf590a commit ab646c9

File tree

13 files changed

+250
-93
lines changed

13 files changed

+250
-93
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ jobs:
4646
- name: Publish 📦 to Test PyPI
4747
uses: pypa/gh-action-pypi-publish@master
4848
with:
49-
password: ${{ secrets.CGALLO_TEST_PYPI }}
50-
repository_url: https://test.pypi.org/legacy/
49+
user: __token__
50+
password: ${{ secrets.CGALLO_PYPI }}
51+
repository_url: https://pypi.org/legacy/
5152

SoftLayer/CLI/block/options.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"""List all options for ordering a block storage."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
6+
import SoftLayer
7+
from SoftLayer.CLI.command import SLCommand
8+
from SoftLayer.CLI import environment
9+
from SoftLayer.CLI import formatting
10+
11+
PACKAGE_STORAGE = 759
12+
13+
14+
@click.command(cls=SLCommand)
15+
@environment.pass_env
16+
def cli(env):
17+
"""List all options for ordering a block storage"""
18+
19+
order_manager = SoftLayer.OrderingManager(env.client)
20+
items = order_manager.get_items(PACKAGE_STORAGE)
21+
datacenters = order_manager.get_regions(PACKAGE_STORAGE)
22+
23+
iops_table = formatting.Table(['Id', 'Description', 'KeyName'], title='IOPS')
24+
snapshot_table = formatting.Table(['Id', 'Description', 'KeyName'], title='Snapshot')
25+
storage_table = formatting.Table(['Id', 'Description', 'KeyName'], title='Storage')
26+
datacenter_table = formatting.Table(['Id', 'Description', 'KeyName'], title='Datacenter')
27+
28+
for datacenter in datacenters:
29+
datacenter_table.add_row([datacenter['location']['locationId'],
30+
datacenter.get('description'),
31+
datacenter['keyname']])
32+
33+
for item in items:
34+
if item['itemCategory']['categoryCode'] == 'performance_storage_space':
35+
storage_table.add_row([item.get('id'), item.get('description'),
36+
item.get('keyName')])
37+
38+
if item['itemCategory']['categoryCode'] == 'storage_tier_level':
39+
iops_table.add_row([item.get('id'), item.get('description'),
40+
item.get('keyName')])
41+
42+
if item['itemCategory']['categoryCode'] == 'storage_snapshot_space':
43+
snapshot_table.add_row([item.get('id'), item.get('description'),
44+
item.get('keyName')])
45+
46+
env.fout(datacenter_table)
47+
env.fout(iops_table)
48+
env.fout(storage_table)
49+
env.fout(snapshot_table)

SoftLayer/CLI/object_storage/list_endpoints.py

Lines changed: 78 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,95 @@
22
# :license: MIT, see LICENSE for more details.
33

44
import click
5-
65
import SoftLayer
76
from SoftLayer.CLI import environment
87
from SoftLayer.CLI import formatting
8+
from SoftLayer import utils
99

1010

1111
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
12+
@click.argument('identifier')
1213
@environment.pass_env
13-
def cli(env):
14+
def cli(env, identifier):
1415
"""List object storage endpoints."""
1516

1617
mgr = SoftLayer.ObjectStorageManager(env.client)
17-
endpoints = mgr.list_endpoints()
18+
endpoints = mgr.list_endpoints(identifier)
19+
20+
final_end_points = []
1821

19-
table = formatting.Table(['datacenter', 'public', 'private'])
22+
table = formatting.Table(['Location/Region', 'Url', 'EndPoint Type', 'Public/Private', 'Legacy'])
23+
table.align['Location/Region'] = 'l'
24+
table.align['Url'] = 'l'
2025
for endpoint in endpoints:
21-
table.add_row([
22-
endpoint['datacenter']['name'],
23-
endpoint['public'],
24-
endpoint['private'],
25-
])
26+
data = {
27+
'Location/Region': location_region(endpoint),
28+
'Url': endpoint['url'],
29+
'EndPoint Type': end_point_return(endpoint['region']),
30+
'Public/Private': public_private(endpoint['type']),
31+
'Legacy': endpoint['legacy']
32+
}
33+
final_end_points.append(data)
34+
35+
final_end_points = sort_endpoint(final_end_points)
36+
table = add_array_to_table(table, final_end_points)
2637

2738
env.fout(table)
39+
40+
41+
def add_array_to_table(table, array_datas):
42+
"""Add an array to a table"""
43+
for array in array_datas:
44+
table.add_row([array['Location/Region'],
45+
array['Url'],
46+
array['EndPoint Type'],
47+
array['Public/Private'],
48+
array['Legacy']])
49+
return table
50+
51+
52+
def end_point_return(endpoint):
53+
"""Returns end point type"""
54+
if endpoint == 'singleSite':
55+
return 'Single Site'
56+
if endpoint == 'regional':
57+
return 'Region'
58+
return 'Cross Region'
59+
60+
61+
def public_private(data):
62+
"""Returns public or private in capital letter"""
63+
if data == 'public':
64+
return 'Public'
65+
return 'Private'
66+
67+
68+
def location_region(endpoint):
69+
"""Returns location if it exists otherwise region"""
70+
if utils.lookup(endpoint, 'location'):
71+
return endpoint['location']
72+
return endpoint['region']
73+
74+
75+
def sort_endpoint(endpoints):
76+
"""Sort the all endpoints for public or private"""
77+
first_data = 0
78+
endpoint_type = ''
79+
if len(endpoints) > 0:
80+
endpoint_type = endpoints[first_data]['EndPoint Type']
81+
public = []
82+
private = []
83+
array_final = []
84+
for endpoint in endpoints:
85+
if endpoint['EndPoint Type'] != endpoint_type:
86+
endpoint_type = endpoint['EndPoint Type']
87+
array_final = array_final + public + private
88+
public.clear()
89+
private.clear()
90+
if endpoint['Public/Private'] == 'Public':
91+
public.append(endpoint)
92+
else:
93+
private.append(endpoint)
94+
95+
array_final = array_final + public + private
96+
return array_final

SoftLayer/CLI/order/item_list.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@
88
from SoftLayer.managers import ordering
99
from SoftLayer.utils import lookup
1010

11-
COLUMNS = ['category', 'keyName', 'description', 'priceId']
12-
COLUMNS_ITEM_PRICES = ['keyName', 'priceId', 'Hourly', 'Monthly', 'Restriction']
13-
COLUMNS_ITEM_PRICES_LOCATION = ['keyName', 'priceId', 'Hourly', 'Monthly', 'Restriction']
11+
COLUMNS = ['Category', 'KeyName', 'Description', 'Price Id']
12+
COLUMNS_ITEM_PRICES = ['KeyName', 'Price Id', 'Hourly', 'Monthly', 'Restriction']
13+
COLUMNS_ITEM_PRICES_LOCATION = ['KeyName', 'Price Id', 'Hourly', 'Monthly', 'Restriction']
1414

1515

1616
@click.command(cls=SLCommand)
1717
@click.argument('package_keyname')
1818
@click.option('--keyword', '-k', help="A word (or string) used to filter item names.")
1919
@click.option('--category', '-c', help="Category code to filter items by")
20-
@click.option('--prices', '-p', is_flag=True, help='Use --prices to list the server item prices, and to list the '
21-
'Item Prices by location, add it to the --prices option using '
22-
'location KeyName, e.g. --prices AMSTERDAM02')
20+
@click.option('--prices', '-p', is_flag=True,
21+
help='Use --prices to list the server item prices, and to list the '
22+
'Item Prices by location, add it to the --prices option using '
23+
'location KeyName, e.g. --prices AMSTERDAM02')
2324
@click.argument('location', required=False)
2425
@environment.pass_env
2526
def cli(env, package_keyname, keyword, category, prices, location=None):
@@ -66,7 +67,7 @@ def cli(env, package_keyname, keyword, category, prices, location=None):
6667
for item in sorted_items[category_name]:
6768
table_items_detail.add_row([category_name, item['keyName'], item['description'], get_price(item)])
6869
tables.append(table_items_detail)
69-
env.fout(formatting.listing(tables, separator='\n'))
70+
env.fout(tables)
7071

7172

7273
def sort_items(items):

SoftLayer/CLI/routes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
('block:volume-limits', 'SoftLayer.CLI.block.limit:cli'),
126126
('block:volume-refresh', 'SoftLayer.CLI.block.refresh:cli'),
127127
('block:volume-convert', 'SoftLayer.CLI.block.convert:cli'),
128+
('block:volume-options', 'SoftLayer.CLI.block.options:cli'),
128129
('block:volume-set-note', 'SoftLayer.CLI.block.set_note:cli'),
129130
('block:object-list', 'SoftLayer.CLI.block.object_list:cli'),
130131
('block:object-storage-detail', 'SoftLayer.CLI.block.object_storage_detail:cli'),
Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1 @@
1-
getDataCenters = [
2-
{
3-
"id": 358694,
4-
"longName": "London 2",
5-
"name": "lon02"
6-
},
7-
{
8-
"id": 168642,
9-
"longName": "San Jose 1",
10-
"name": "sjc01"
11-
}]
12-
getDatacenters = [{'id': 1854895, "longName": "Dallas 13", 'name': 'dal13', 'regions': [{'keyname': 'DALLAS13'}]}]
1+
getDatacenters = [{'id': 1854895, 'longName': 'dallas 13', 'name': 'dal13', 'regions': [{'keyname': 'DALLAS13'}]}]

SoftLayer/managers/object_storage.py

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
id,username,notes,vendorName,serviceResource
1414
]'''
1515

16-
ENDPOINT_MASK = '''mask(SoftLayer_Network_Storage_Hub_Swift)[
17-
id,storageNodes[id,backendIpAddress,frontendIpAddress,datacenter]
18-
]'''
19-
2016

2117
class ObjectStorageManager(utils.IdentifierMixin, object):
2218
"""Manager for SoftLayer Object Storage accounts.
@@ -40,26 +36,10 @@ def list_accounts(self, object_mask=None, object_filter=None, limit=10):
4036
filter=object_filter,
4137
limit=limit)
4238

43-
def list_endpoints(self):
39+
def list_endpoints(self, identifier):
4440
"""Lists the known object storage endpoints."""
45-
_filter = {
46-
'hubNetworkStorage': {'vendorName': {'operation': 'Swift'}},
47-
}
48-
endpoints = []
49-
network_storage = self.client.call('Account',
50-
'getHubNetworkStorage',
51-
mask=ENDPOINT_MASK,
52-
limit=1,
53-
filter=_filter)
54-
if network_storage:
55-
for node in network_storage['storageNodes']:
56-
endpoints.append({
57-
'datacenter': node['datacenter'],
58-
'public': node['frontendIpAddress'],
59-
'private': node['backendIpAddress'],
60-
})
61-
62-
return endpoints
41+
42+
return self.client.call('SoftLayer_Network_Storage_Hub_Cleversafe_Account', 'getEndpoints', id=identifier)
6343

6444
def create_credential(self, identifier):
6545
"""Create object storage credential.

SoftLayer/managers/ordering.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,6 @@ def get_items(self, package_id, storage_filter=None):
731731
def get_regions(self, package_id):
732732
"""returns the all regions.
733733
734-
735734
:param int package_id: The package for which to get the items.
736735
"""
737736
return self.client.call('SoftLayer_Product_Package', 'getRegions', id=package_id)

docs/cli/block.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ Block Commands
8383
:prog: block volume-count
8484
:show-nested:
8585

86+
.. click:: SoftLayer.CLI.block.options:cli
87+
:prog: block volume-options
88+
:show-nested:
89+
8690
.. click:: SoftLayer.CLI.block.detail:cli
8791
:prog: block volume-detail
8892
:show-nested:

tests/CLI/modules/block_tests.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,11 @@ def test_dep_dupe_convert(self):
792792

793793
self.assert_no_fail(result)
794794

795+
def test_volume_options(self):
796+
result = self.run_command(['block', 'volume-options'])
797+
798+
self.assert_no_fail(result)
799+
795800
@mock.patch('SoftLayer.BlockStorageManager.volume_set_note')
796801
def test_volume_set_note(self, set_note):
797802
set_note.return_value = True

0 commit comments

Comments
 (0)