Skip to content

Commit 0800ae6

Browse files
Merge pull request #866 from sunilvrajput/sunil-sl-master
STAAS (File and Block) Hourly billing changes
2 parents fc0a44a + 879dd19 commit 0800ae6

File tree

13 files changed

+526
-82
lines changed

13 files changed

+526
-82
lines changed

SoftLayer/CLI/block/duplicate.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,23 @@
4949
type=int,
5050
help='The size of snapshot space to order for the duplicate. '
5151
'***If no snapshot space size is specified, the snapshot '
52-
'space size of the origin volume will be used.***\n'
52+
'space size of the origin block volume will be used.***\n'
5353
'Input "0" for this parameter to order a duplicate volume '
5454
'with no snapshot space.')
55+
@click.option('--billing',
56+
type=click.Choice(['hourly', 'monthly']),
57+
default='monthly',
58+
help="Optional parameter for Billing rate (default to monthly)")
5559
@environment.pass_env
5660
def cli(env, origin_volume_id, origin_snapshot_id, duplicate_size,
57-
duplicate_iops, duplicate_tier, duplicate_snapshot_size):
61+
duplicate_iops, duplicate_tier, duplicate_snapshot_size, billing):
5862
"""Order a duplicate block storage volume."""
5963
block_manager = SoftLayer.BlockStorageManager(env.client)
6064

65+
hourly_billing_flag = False
66+
if billing.lower() == "hourly":
67+
hourly_billing_flag = True
68+
6169
if duplicate_tier is not None:
6270
duplicate_tier = float(duplicate_tier)
6371

@@ -68,7 +76,8 @@ def cli(env, origin_volume_id, origin_snapshot_id, duplicate_size,
6876
duplicate_size=duplicate_size,
6977
duplicate_iops=duplicate_iops,
7078
duplicate_tier_level=duplicate_tier,
71-
duplicate_snapshot_size=duplicate_snapshot_size
79+
duplicate_snapshot_size=duplicate_snapshot_size,
80+
hourly_billing_flag=hourly_billing_flag
7281
)
7382
except ValueError as ex:
7483
raise exceptions.ArgumentError(str(ex))

SoftLayer/CLI/block/order.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,27 @@
5656
'storage_as_a_service',
5757
'enterprise',
5858
'performance']))
59+
@click.option('--billing',
60+
type=click.Choice(['hourly', 'monthly']),
61+
default='monthly',
62+
help="Optional parameter for Billing rate (default to monthly)")
5963
@environment.pass_env
6064
def cli(env, storage_type, size, iops, tier, os_type,
61-
location, snapshot_size, service_offering):
65+
location, snapshot_size, service_offering, billing):
6266
"""Order a block storage volume."""
6367
block_manager = SoftLayer.BlockStorageManager(env.client)
6468
storage_type = storage_type.lower()
6569

70+
hourly_billing_flag = False
71+
if billing.lower() == "hourly":
72+
hourly_billing_flag = True
73+
74+
if hourly_billing_flag and service_offering != 'storage_as_a_service':
75+
raise exceptions.CLIAbort(
76+
'Hourly billing is only available for the storage_as_a_service '
77+
'service offering'
78+
)
79+
6680
if storage_type == 'performance':
6781
if iops is None:
6882
raise exceptions.CLIAbort(
@@ -87,7 +101,8 @@ def cli(env, storage_type, size, iops, tier, os_type,
87101
iops=iops,
88102
os_type=os_type,
89103
snapshot_size=snapshot_size,
90-
service_offering=service_offering
104+
service_offering=service_offering,
105+
hourly_billing_flag=hourly_billing_flag
91106
)
92107
except ValueError as ex:
93108
raise exceptions.ArgumentError(str(ex))
@@ -107,7 +122,8 @@ def cli(env, storage_type, size, iops, tier, os_type,
107122
tier_level=float(tier),
108123
os_type=os_type,
109124
snapshot_size=snapshot_size,
110-
service_offering=service_offering
125+
service_offering=service_offering,
126+
hourly_billing_flag=hourly_billing_flag
111127
)
112128
except ValueError as ex:
113129
raise exceptions.ArgumentError(str(ex))

SoftLayer/CLI/file/duplicate.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,23 @@
4545
type=int,
4646
help='The size of snapshot space to order for the duplicate. '
4747
'***If no snapshot space size is specified, the snapshot '
48-
'space size of the origin volume will be used.***\n'
48+
'space size of the origin file volume will be used.***\n'
4949
'Input "0" for this parameter to order a duplicate volume '
5050
'with no snapshot space.')
51+
@click.option('--billing',
52+
type=click.Choice(['hourly', 'monthly']),
53+
default='monthly',
54+
help="Optional parameter for Billing rate (default to monthly)")
5155
@environment.pass_env
5256
def cli(env, origin_volume_id, origin_snapshot_id, duplicate_size,
53-
duplicate_iops, duplicate_tier, duplicate_snapshot_size):
57+
duplicate_iops, duplicate_tier, duplicate_snapshot_size, billing):
5458
"""Order a duplicate file storage volume."""
5559
file_manager = SoftLayer.FileStorageManager(env.client)
5660

61+
hourly_billing_flag = False
62+
if billing.lower() == "hourly":
63+
hourly_billing_flag = True
64+
5765
if duplicate_tier is not None:
5866
duplicate_tier = float(duplicate_tier)
5967

@@ -64,7 +72,8 @@ def cli(env, origin_volume_id, origin_snapshot_id, duplicate_size,
6472
duplicate_size=duplicate_size,
6573
duplicate_iops=duplicate_iops,
6674
duplicate_tier_level=duplicate_tier,
67-
duplicate_snapshot_size=duplicate_snapshot_size
75+
duplicate_snapshot_size=duplicate_snapshot_size,
76+
hourly_billing_flag=hourly_billing_flag
6877
)
6978
except ValueError as ex:
7079
raise exceptions.ArgumentError(str(ex))

SoftLayer/CLI/file/order.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,27 @@
4444
'storage_as_a_service',
4545
'enterprise',
4646
'performance']))
47+
@click.option('--billing',
48+
type=click.Choice(['hourly', 'monthly']),
49+
default='monthly',
50+
help="Optional parameter for Billing rate (default to monthly)")
4751
@environment.pass_env
4852
def cli(env, storage_type, size, iops, tier,
49-
location, snapshot_size, service_offering):
53+
location, snapshot_size, service_offering, billing):
5054
"""Order a file storage volume."""
5155
file_manager = SoftLayer.FileStorageManager(env.client)
5256
storage_type = storage_type.lower()
5357

58+
hourly_billing_flag = False
59+
if billing.lower() == "hourly":
60+
hourly_billing_flag = True
61+
62+
if hourly_billing_flag and service_offering != 'storage_as_a_service':
63+
raise exceptions.CLIAbort(
64+
'Hourly billing is only available for the storage_as_a_service '
65+
'service offering'
66+
)
67+
5468
if storage_type == 'performance':
5569
if iops is None:
5670
raise exceptions.CLIAbort(
@@ -74,7 +88,8 @@ def cli(env, storage_type, size, iops, tier,
7488
size=size,
7589
iops=iops,
7690
snapshot_size=snapshot_size,
77-
service_offering=service_offering
91+
service_offering=service_offering,
92+
hourly_billing_flag=hourly_billing_flag
7893
)
7994
except ValueError as ex:
8095
raise exceptions.ArgumentError(str(ex))
@@ -93,7 +108,8 @@ def cli(env, storage_type, size, iops, tier,
93108
size=size,
94109
tier_level=float(tier),
95110
snapshot_size=snapshot_size,
96-
service_offering=service_offering
111+
service_offering=service_offering,
112+
hourly_billing_flag=hourly_billing_flag
97113
)
98114
except ValueError as ex:
99115
raise exceptions.ArgumentError(str(ex))

SoftLayer/fixtures/SoftLayer_Network_Storage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
}],
1111
'cancellationDate': '',
1212
'categoryCode': 'storage_as_a_service',
13+
'hourlyFlag': None,
1314
'id': 454,
1415
'location': {'id': 449500}
1516
},

SoftLayer/managers/block.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,10 @@ def order_replicant_volume(self, volume_id, snapshot_schedule,
234234
:return: Returns a SoftLayer_Container_Product_Order_Receipt
235235
"""
236236

237-
block_mask = 'billingItem[activeChildren],storageTierLevel,osType,'\
238-
'staasVersion,hasEncryptionAtRest,snapshotCapacityGb,'\
239-
'schedules,hourlySchedule,dailySchedule,weeklySchedule,'\
237+
block_mask = 'billingItem[activeChildren,hourlyFlag],'\
238+
'storageTierLevel,osType,staasVersion,'\
239+
'hasEncryptionAtRest,snapshotCapacityGb,schedules,'\
240+
'hourlySchedule,dailySchedule,weeklySchedule,'\
240241
'storageType[keyName],provisionedIops'
241242
block_volume = self.get_block_volume_details(volume_id,
242243
mask=block_mask)
@@ -261,7 +262,8 @@ def order_replicant_volume(self, volume_id, snapshot_schedule,
261262
def order_duplicate_volume(self, origin_volume_id, origin_snapshot_id=None,
262263
duplicate_size=None, duplicate_iops=None,
263264
duplicate_tier_level=None,
264-
duplicate_snapshot_size=None):
265+
duplicate_snapshot_size=None,
266+
hourly_billing_flag=False):
265267
"""Places an order for a duplicate block volume.
266268
267269
:param origin_volume_id: The ID of the origin volume to be duplicated
@@ -270,10 +272,12 @@ def order_duplicate_volume(self, origin_volume_id, origin_snapshot_id=None,
270272
:param duplicate_iops: The IOPS per GB for the duplicate volume
271273
:param duplicate_tier_level: Tier level for the duplicate volume
272274
:param duplicate_snapshot_size: Snapshot space size for the duplicate
275+
:param hourly_billing_flag: Billing type, monthly (False)
276+
or hourly (True), default to monthly.
273277
:return: Returns a SoftLayer_Container_Product_Order_Receipt
274278
"""
275279

276-
block_mask = 'id,billingItem[location],snapshotCapacityGb,'\
280+
block_mask = 'id,billingItem[location,hourlyFlag],snapshotCapacityGb,'\
277281
'storageType[keyName],capacityGb,originalVolumeSize,'\
278282
'provisionedIops,storageTierLevel,osType[keyName],'\
279283
'staasVersion,hasEncryptionAtRest'
@@ -288,7 +292,8 @@ def order_duplicate_volume(self, origin_volume_id, origin_snapshot_id=None,
288292

289293
order = storage_utils.prepare_duplicate_order_object(
290294
self, origin_volume, duplicate_iops, duplicate_tier_level,
291-
duplicate_size, duplicate_snapshot_size, 'block'
295+
duplicate_size, duplicate_snapshot_size, 'block',
296+
hourly_billing_flag
292297
)
293298

294299
order['osFormatType'] = {'keyName': os_type}
@@ -308,7 +313,8 @@ def delete_snapshot(self, snapshot_id):
308313

309314
def order_block_volume(self, storage_type, location, size, os_type,
310315
iops=None, tier_level=None, snapshot_size=None,
311-
service_offering='storage_as_a_service'):
316+
service_offering='storage_as_a_service',
317+
hourly_billing_flag=False):
312318
"""Places an order for a block volume.
313319
314320
:param storage_type: 'performance' or 'endurance'
@@ -321,10 +327,12 @@ def order_block_volume(self, storage_type, location, size, os_type,
321327
if snapshot space should also be ordered (None if not ordered)
322328
:param service_offering: Requested offering package to use in the order
323329
('storage_as_a_service', 'enterprise', or 'performance')
330+
:param hourly_billing_flag: Billing type, monthly (False)
331+
or hourly (True), default to monthly.
324332
"""
325333
order = storage_utils.prepare_volume_order_object(
326334
self, storage_type, location, size, iops, tier_level,
327-
snapshot_size, service_offering, 'block'
335+
snapshot_size, service_offering, 'block', hourly_billing_flag
328336
)
329337

330338
order['osFormatType'] = {'keyName': os_type}
@@ -352,8 +360,9 @@ def order_snapshot_space(self, volume_id, capacity, tier,
352360
:param boolean upgrade: Flag to indicate if this order is an upgrade
353361
:return: Returns a SoftLayer_Container_Product_Order_Receipt
354362
"""
355-
block_mask = 'id,billingItem[location],storageType[keyName],'\
356-
'storageTierLevel,provisionedIops,staasVersion,hasEncryptionAtRest'
363+
block_mask = 'id,billingItem[location,hourlyFlag],'\
364+
'storageType[keyName],storageTierLevel,provisionedIops,'\
365+
'staasVersion,hasEncryptionAtRest'
357366
block_volume = self.get_block_volume_details(volume_id,
358367
mask=block_mask,
359368
**kwargs)
@@ -376,7 +385,7 @@ def cancel_snapshot_space(self, volume_id,
376385

377386
block_volume = self.get_block_volume_details(
378387
volume_id,
379-
mask='mask[id,billingItem[activeChildren]]')
388+
mask='mask[id,billingItem[activeChildren,hourlyFlag]]')
380389

381390
if 'activeChildren' not in block_volume['billingItem']:
382391
raise exceptions.SoftLayerError(
@@ -394,6 +403,9 @@ def cancel_snapshot_space(self, volume_id,
394403
raise exceptions.SoftLayerError(
395404
'No snapshot space found to cancel')
396405

406+
if utils.lookup(block_volume, 'billingItem', 'hourlyFlag'):
407+
immediate = True
408+
397409
return self.client['Billing_Item'].cancelItem(
398410
immediate,
399411
True,
@@ -456,9 +468,12 @@ def cancel_block_volume(self, volume_id,
456468
"""
457469
block_volume = self.get_block_volume_details(
458470
volume_id,
459-
mask='mask[id,billingItem[id]]')
471+
mask='mask[id,billingItem[id,hourlyFlag]]')
460472
billing_item_id = block_volume['billingItem']['id']
461473

474+
if utils.lookup(block_volume, 'billingItem', 'hourlyFlag'):
475+
immediate = True
476+
462477
return self.client['Billing_Item'].cancelItem(
463478
immediate,
464479
True,

0 commit comments

Comments
 (0)