Skip to content

Commit c52b9f0

Browse files
Merge pull request #1488 from FernandoOjeda/ft/hw_upgrade_table
Add a table result for the hw upgrade.
2 parents 29b6931 + 0ad4846 commit c52b9f0

File tree

6 files changed

+342
-39
lines changed

6 files changed

+342
-39
lines changed

Diff for: SoftLayer/CLI/hardware/upgrade.py

+93-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# :license: MIT, see LICENSE for more details.
33

44
import click
5+
from SoftLayer import utils
56

67
import SoftLayer
78
from SoftLayer.CLI import environment
@@ -35,6 +36,9 @@ def cli(env, identifier, memory, network, drive_controller, public_bandwidth, ad
3536
"""Upgrade a Hardware Server."""
3637

3738
mgr = SoftLayer.HardwareManager(env.client)
39+
table = formatting.KeyValueTable(['name', 'value'])
40+
table.align['name'] = 'r'
41+
table.align['value'] = 'l'
3842

3943
if not any([memory, network, drive_controller, public_bandwidth, add_disk, resize_disk]):
4044
raise exceptions.ArgumentError("Must provide "
@@ -57,7 +61,92 @@ def cli(env, identifier, memory, network, drive_controller, public_bandwidth, ad
5761
disks = {'description': 'resize_disk', 'capacity': guest_disk[0], 'number': guest_disk[1]}
5862
disk_list.append(disks)
5963

60-
if not mgr.upgrade(hw_id, memory=memory, nic_speed=network, drive_controller=drive_controller,
61-
public_bandwidth=public_bandwidth, disk=disk_list, test=test):
62-
raise exceptions.CLIAbort('Hardware Server Upgrade Failed')
63-
env.fout('Successfully Upgraded.')
64+
response = mgr.upgrade(hw_id, memory=memory, nic_speed=network, drive_controller=drive_controller,
65+
public_bandwidth=public_bandwidth, disk=disk_list, test=test)
66+
67+
if response:
68+
if test:
69+
add_data_to_table(response, table)
70+
else:
71+
table.add_row(['Order Date', response.get('orderDate')])
72+
table.add_row(['Order Id', response.get('orderId')])
73+
add_data_to_table(response['orderDetails'], table)
74+
place_order_table = get_place_order_information(response)
75+
table.add_row(['Place Order Information', place_order_table])
76+
order_detail_table = get_order_detail(response)
77+
table.add_row(['Order Detail (Billing Information)', order_detail_table])
78+
79+
env.fout(table)
80+
81+
82+
def add_data_to_table(response, table):
83+
"""Add the hardware server upgrade result to the table"""
84+
table.add_row(['location', utils.lookup(response, 'locationObject', 'longName')])
85+
table.add_row(['quantity', response.get('quantity')])
86+
table.add_row(['Package Id', response.get('packageId')])
87+
table.add_row(['Currency Short Name', response.get('currencyShortName')])
88+
table.add_row(['Prorated Initial Charge', response.get('proratedInitialCharge')])
89+
table.add_row(['Prorated Order Total', response.get('proratedOrderTotal')])
90+
table.add_row(['Hourly Pricing', response.get('useHourlyPricing')])
91+
table_hardware = get_hardware_detail(response)
92+
table.add_row(['Hardware', table_hardware])
93+
table_prices = get_hardware_prices(response)
94+
table.add_row(['Prices', table_prices])
95+
96+
97+
def get_place_order_information(response):
98+
"""Get the hardware server place order information."""
99+
table_place_order = formatting.Table(['Id', 'Account Id', 'Status', 'Account CompanyName',
100+
'UserRecord FirstName', 'UserRecord LastName', 'UserRecord Username'])
101+
table_place_order.add_row([response.get('id'),
102+
response.get('accountId'),
103+
response.get('status'),
104+
utils.lookup(response, 'account', 'companyName'),
105+
utils.lookup(response, 'userRecord', 'firstName'),
106+
utils.lookup(response, 'account', 'lastName'),
107+
utils.lookup(response, 'account', 'username')])
108+
109+
return table_place_order
110+
111+
112+
def get_hardware_detail(response):
113+
"""Get the hardware server detail."""
114+
table_hardware = formatting.Table(['Account Id', 'Hostname', 'Domain'])
115+
for hardware in response['hardware']:
116+
table_hardware.add_row([hardware.get('accountId'),
117+
hardware.get('hostname'),
118+
hardware.get('domain')])
119+
120+
return table_hardware
121+
122+
123+
def get_hardware_prices(response):
124+
"""Get the hardware server prices."""
125+
table_prices = formatting.Table(['Id', 'HourlyRecurringFee', 'RecurringFee', 'Categories', 'Item Description',
126+
'Item Units'])
127+
for price in response['prices']:
128+
categories = price.get('categories')[0]
129+
table_prices.add_row([price.get('id'),
130+
price.get('hourlyRecurringFee'),
131+
price.get('recurringFee'),
132+
categories.get('name'),
133+
utils.lookup(price, 'item', 'description'),
134+
utils.lookup(price, 'item', 'units')])
135+
136+
return table_prices
137+
138+
139+
def get_order_detail(response):
140+
"""Get the hardware server order detail."""
141+
table_order_detail = formatting.Table(['Billing City', 'Billing Country Code', 'Billing Email',
142+
'Billing Name First', 'Billing Name Last', 'Billing Postal Code',
143+
'Billing State'])
144+
table_order_detail.add_row([utils.lookup(response, 'orderDetails', 'billingInformation', 'billingCity'),
145+
utils.lookup(response, 'orderDetails', 'billingInformation', 'billingCountryCode'),
146+
utils.lookup(response, 'orderDetails', 'billingInformation', 'billingEmail'),
147+
utils.lookup(response, 'orderDetails', 'billingInformation', 'billingNameFirst'),
148+
utils.lookup(response, 'orderDetails', 'billingInformation', 'billingNameLast'),
149+
utils.lookup(response, 'orderDetails', 'billingInformation', 'billingPostalCode'),
150+
utils.lookup(response, 'orderDetails', 'billingInformation', 'billingState')])
151+
152+
return table_order_detail

Diff for: SoftLayer/fixtures/SoftLayer_Product_Order.py

+148
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,154 @@
6363
'postTaxRecurring': '0.32',
6464
}
6565

66+
hardware_verifyOrder = {
67+
"currencyShortName": "USD",
68+
"hardware": [
69+
{
70+
"accountId": 1111,
71+
"domain": "testedit.com",
72+
"hostname": "test",
73+
"globalIdentifier": "81434794-af69-44d5-bb97-12312asdasdasd"
74+
}
75+
],
76+
"location": "1441195",
77+
"locationObject": {
78+
"id": 1441195,
79+
"longName": "Dallas 10",
80+
"name": "dal10"
81+
},
82+
"packageId": 911,
83+
"postTaxRecurring": "0",
84+
"postTaxRecurringHourly": "0",
85+
"postTaxRecurringMonthly": "0",
86+
"preTaxRecurring": "0",
87+
"preTaxRecurringHourly": "0",
88+
"preTaxRecurringMonthly": "0",
89+
"prices": [
90+
{
91+
"hourlyRecurringFee": "0",
92+
"id": 209391,
93+
"recurringFee": "0",
94+
"categories": [
95+
{
96+
"categoryCode": "ram",
97+
"id": 3,
98+
"name": "RAM"
99+
}
100+
],
101+
"item": {
102+
"capacity": "32",
103+
"description": "32 GB RAM",
104+
"id": 11291,
105+
"units": "GB"
106+
}
107+
}
108+
],
109+
"proratedInitialCharge": "0",
110+
"proratedOrderTotal": "0",
111+
"quantity": 1,
112+
"sendQuoteEmailFlag": None,
113+
"totalRecurringTax": "0",
114+
"useHourlyPricing": False
115+
}
116+
117+
hardware_placeOrder = {
118+
"orderDate": "2021-05-07T07:41:41-06:00",
119+
"orderDetails": {
120+
"billingInformation": {
121+
"billingAddressLine1": "4849 Alpha Rd",
122+
"billingCity": "Dallas",
123+
"billingCountryCode": "US",
124+
"billingEmail": "test.ibm.com",
125+
"billingNameCompany": "SoftLayer Internal - Development Community",
126+
"billingNameFirst": "Test",
127+
"billingNameLast": "Test",
128+
"billingPhoneVoice": "1111111",
129+
"billingPostalCode": "75244-1111",
130+
"billingState": "TX",
131+
},
132+
"currencyShortName": "USD",
133+
"hardware": [
134+
{
135+
"accountId": 1111111,
136+
"bareMetalInstanceFlag": 0,
137+
"domain": "testedit.com",
138+
"fullyQualifiedDomainName": "test.testedit.com",
139+
"hostname": "test",
140+
"globalIdentifier": "81434794-af69-44d5-bb97-1111111"
141+
}
142+
],
143+
"location": "1441195",
144+
"locationObject": {
145+
"id": 1441195,
146+
"longName": "Dallas 10",
147+
"name": "dal10"
148+
},
149+
"packageId": 911,
150+
"paymentType": "ADD_TO_BALANCE",
151+
"postTaxRecurring": "0",
152+
"postTaxRecurringHourly": "0",
153+
"postTaxRecurringMonthly": "0",
154+
"postTaxSetup": "0",
155+
"preTaxRecurring": "0",
156+
"preTaxRecurringHourly": "0",
157+
"preTaxRecurringMonthly": "0",
158+
"preTaxSetup": "0",
159+
"prices": [
160+
{
161+
"hourlyRecurringFee": "0",
162+
"id": 209391,
163+
"recurringFee": "0",
164+
"categories": [
165+
{
166+
"categoryCode": "ram",
167+
"id": 3,
168+
"name": "RAM"
169+
}
170+
],
171+
"item": {
172+
"capacity": "32",
173+
"description": "32 GB RAM",
174+
"id": 11291,
175+
"keyName": "RAM_32_GB_DDR4_2133_ECC_NON_REG",
176+
"units": "GB",
177+
}
178+
}
179+
],
180+
"proratedInitialCharge": "0",
181+
"proratedOrderTotal": "0",
182+
"quantity": 1,
183+
"totalRecurringTax": "0",
184+
"useHourlyPricing": False
185+
},
186+
"orderId": 78332111,
187+
"placedOrder": {
188+
"accountId": 1111111,
189+
"id": 1234,
190+
"status": "PENDING_UPGRADE",
191+
"account": {
192+
"brandId": 2,
193+
"companyName": "SoftLayer Internal - Development Community",
194+
"id": 1234
195+
},
196+
"items": [
197+
{
198+
"categoryCode": "ram",
199+
"description": "32 GB RAM",
200+
"id": 824199364,
201+
"recurringFee": "0"
202+
}
203+
],
204+
"userRecord": {
205+
"accountId": 1234,
206+
"firstName": "test",
207+
"id": 3333,
208+
"lastName": "test",
209+
"username": "sl1234-test"
210+
}
211+
}
212+
}
213+
66214
rsc_placeOrder = {
67215
'orderDate': '2013-08-01 15:23:45',
68216
'orderId': 1234,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
getMaintenanceWindows = [
2+
{
3+
"beginDate": "2021-05-13T16:00:00-06:00",
4+
"dayOfWeek": 4,
5+
"endDate": "2021-05-13T19:00:00-06:00",
6+
"id": 198351,
7+
"locationId": 1441195,
8+
"portalTzId": 114
9+
},
10+
{
11+
"beginDat": "2021-05-14T00:00:00-06:00",
12+
"dayOfWeek": 5,
13+
"endDate": "2021-05-14T03:00:00-06:00",
14+
"id": 189747,
15+
"locationId": 1441195,
16+
"portalTzId": 114
17+
},
18+
{
19+
"beginDate": "2021-05-14T08:00:00-06:00",
20+
"dayOfWeek": 5,
21+
"endDate": "2021-05-14T11:00:00-06:00",
22+
"id": 198355,
23+
"locationId": 1441195,
24+
"portalTzId": 114
25+
}
26+
]

Diff for: SoftLayer/managers/hardware.py

+42-9
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,8 @@ def upgrade(self, instance_id, memory=None,
834834
835835
:returns: bool
836836
"""
837+
result = None
838+
maintenance_window_id = None
837839
upgrade_prices = self._get_upgrade_prices(instance_id)
838840
prices = []
839841
data = {}
@@ -849,14 +851,26 @@ def upgrade(self, instance_id, memory=None,
849851

850852
server_response = self.get_instance(instance_id)
851853
package_id = server_response['billingItem']['package']['id']
854+
location_id = server_response['datacenter']['id']
852855

853856
maintenance_window = datetime.datetime.now(utils.UTC())
857+
maintenance_window_detail = self.get_maintenance_windows_detail(location_id)
858+
if maintenance_window_detail:
859+
maintenance_window_id = maintenance_window_detail.get('id')
860+
854861
order = {
855862
'complexType': 'SoftLayer_Container_Product_Order_Hardware_Server_Upgrade',
856-
'properties': [{
857-
'name': 'MAINTENANCE_WINDOW',
858-
'value': maintenance_window.strftime("%Y-%m-%d %H:%M:%S%z")
859-
}],
863+
'properties': [
864+
{
865+
'name': 'MAINTENANCE_WINDOW',
866+
'value': maintenance_window.strftime("%Y-%m-%d %H:%M:%S%z")
867+
},
868+
{
869+
'name': 'MAINTENANCE_WINDOW_ID',
870+
'value': str(maintenance_window_id)
871+
}
872+
873+
],
860874
'hardware': [{'id': int(instance_id)}],
861875
'packageId': package_id
862876
}
@@ -878,11 +892,30 @@ def upgrade(self, instance_id, memory=None,
878892

879893
if prices:
880894
if test:
881-
self.client['Product_Order'].verifyOrder(order)
895+
result = self.client['Product_Order'].verifyOrder(order)
882896
else:
883-
self.client['Product_Order'].placeOrder(order)
884-
return True
885-
return False
897+
result = self.client['Product_Order'].placeOrder(order)
898+
return result
899+
900+
def get_maintenance_windows_detail(self, location_id):
901+
"""Get the disks prices to be added or upgraded.
902+
903+
:param int location_id: Hardware Server location id.
904+
:return int.
905+
"""
906+
result = None
907+
begin_date_object = datetime.datetime.now()
908+
begin_date = begin_date_object.strftime("%Y-%m-%dT00:00:00.0000-06:00")
909+
end_date_object = datetime.date.today() + datetime.timedelta(days=30)
910+
end_date = end_date_object.strftime("%Y-%m-%dT00:00:00.0000-06:00")
911+
912+
result_windows = self.client['SoftLayer_Provisioning_Maintenance_Window'].getMaintenanceWindows(begin_date,
913+
end_date,
914+
location_id)
915+
if len(result_windows) > 0:
916+
result = result_windows[0]
917+
918+
return result
886919

887920
@retry(logger=LOGGER)
888921
def get_instance(self, instance_id):
@@ -893,7 +926,7 @@ def get_instance(self, instance_id):
893926
the specified instance.
894927
"""
895928
mask = [
896-
'billingItem[id,package[id,keyName],nextInvoiceChildren]'
929+
'datacenter,billingItem[id,package[id,keyName],nextInvoiceChildren]'
897930
]
898931
mask = "mask[%s]" % ','.join(mask)
899932

0 commit comments

Comments
 (0)