Skip to content

Commit a720e7e

Browse files
#1074 have config setup cehck which transport was actually entered to try getting API credentials, also added priceIds to slcli order item-list
1 parent 3a1e016 commit a720e7e

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

SoftLayer/CLI/config/setup.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from SoftLayer.CLI import environment
1111
from SoftLayer.CLI import exceptions
1212
from SoftLayer.CLI import formatting
13+
from SoftLayer import transports
1314
from SoftLayer import utils
1415

1516

@@ -22,7 +23,11 @@ def get_api_key(client, username, secret):
2223
# Try to use a client with username/api key
2324
if len(secret) == 64:
2425
try:
25-
client.auth = auth.BasicAuthentication(username, secret)
26+
# real_transport = getattr(client.transport, 'transport', transport)
27+
if isinstance(client.transport.transport, transports.RestTransport):
28+
client.auth = auth.BasicHTTPAuthentication(username, secret)
29+
else:
30+
client.auth = auth.BasicAuthentication(username, secret)
2631
client['Account'].getCurrentUser()
2732
return secret
2833
except SoftLayer.SoftLayerAPIError as ex:
@@ -103,17 +108,22 @@ def get_user_input(env):
103108
secret = env.getpass('API Key or Password', default=defaults['api_key'])
104109

105110
# Ask for which endpoint they want to use
111+
endpoint = defaults.get('endpoint_url', 'public')
106112
endpoint_type = env.input(
107-
'Endpoint (public|private|custom)', default='public')
113+
'Endpoint (public|private|custom)', default=endpoint)
108114
endpoint_type = endpoint_type.lower()
109115

110-
if endpoint_type == 'custom':
111-
endpoint_url = env.input('Endpoint URL',
112-
default=defaults['endpoint_url'])
116+
if endpoint_type == 'public':
117+
endpoint_url = SoftLayer.API_PUBLIC_ENDPOINT
113118
elif endpoint_type == 'private':
114119
endpoint_url = SoftLayer.API_PRIVATE_ENDPOINT
115120
else:
116-
endpoint_url = SoftLayer.API_PUBLIC_ENDPOINT
121+
if endpoint_type == 'custom':
122+
endpoint_url = env.input('Endpoint URL', default=endpoint)
123+
else:
124+
endpoint_url = endpoint
125+
126+
print("SETTING enpoint to %s "% endpoint_url)
117127

118128
# Ask for timeout
119129
timeout = env.input('Timeout', default=defaults['timeout'] or 0)

SoftLayer/CLI/order/item_list.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from SoftLayer.managers import ordering
88
from SoftLayer.utils import lookup
99

10-
COLUMNS = ['category', 'keyName', 'description']
10+
COLUMNS = ['category', 'keyName', 'description', 'priceId']
1111

1212

1313
@click.command()
@@ -60,7 +60,7 @@ def cli(env, package_keyname, keyword, category):
6060
categories = sorted_items.keys()
6161
for catname in sorted(categories):
6262
for item in sorted_items[catname]:
63-
table.add_row([catname, item['keyName'], item['description']])
63+
table.add_row([catname, item['keyName'], item['description'], get_price(item)])
6464
env.fout(table)
6565

6666

@@ -75,3 +75,10 @@ def sort_items(items):
7575
sorted_items[category].append(item)
7676

7777
return sorted_items
78+
79+
def get_price(item):
80+
81+
for price in item.get('prices', []):
82+
if not price.get('locationGroupId'):
83+
return price.get('id')
84+
return 0

SoftLayer/managers/ordering.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
itemCategory[id, name, categoryCode]
1717
'''
1818

19-
ITEM_MASK = '''id, keyName, description, itemCategory, categories'''
19+
ITEM_MASK = '''id, keyName, description, itemCategory, categories, prices'''
2020

2121
PACKAGE_MASK = '''id, name, keyName, isActive, type'''
2222

0 commit comments

Comments
 (0)