簡體   English   中英

使用Softlayer Python API創建數據塊后如何獲取數據塊存儲信息

[英]How to get block storage info after creating it with softlayer Python API

現在,我可以使用softlayer Python API創建塊存儲,命令如下:

客戶端['SoftLayer_Product_Order']。placeOrder(orderData)

可以執行此命令,響應如下所示:

{'orderId': 11999815, 'placedOrder': {'status': 'PENDING_AUTO_APPROVAL', 'account': {'companyName': 'xxxxxx', 'id': 323716, 'brandId': 11246}, 'orderQuoteId': '', 'userRecordId': 426607, 'orderTypeId': 4, 'items': [{'itemId': 5936, 'setupFee': '0', 'promoCodeId': '', 'recurringFee': '0', 'description': 'Endurance Storage', 'laborFee': '0', 'oneTimeFee': '0', 'itemPriceId': '45064', 'children': [{'itemId': 5944, 'setupFee': '0', 'promoCodeId': '', 'recurringFee': '0', 'description': 'Block Storage', 'laborFee': '0', 'oneTimeFee': '0', 'itemPriceId': '45104', 'categoryCode': 'storage_block', 'parentId': 171180595, 'id': 171180597}, {'itemId': 5940, 'setupFee': '0', 'promoCodeId': '', 'recurringFee': '0', 'description': '2 IOPS per GB', 'laborFee': '0', 'oneTimeFee': '0', 'itemPriceId': '45084', 'categoryCode': 'storage_tier_level', 'parentId': 171180595, 'id': 171180599}, {'itemId': 5138, 'setupFee': '0', 'promoCodeId': '', 'recurringFee': '36.25', 'description': '250 GB Storage Space', 'laborFee': '0', 'oneTimeFee': '0', 'itemPriceId': '45254', 'categoryCode': 'performance_storage_space', 'parentId': 171180595, 'id': 171180601}, {'itemId': 6028, 'setupFee': '0', 'promoCodeId': '', 'recurringFee': '.36', 'description': '5 GB Storage Space (Snapshot Space)', 'laborFee': '0', 'oneTimeFee': '0', 'itemPriceId': '46136', 'categoryCode': 'storage_snapshot_space', 'parentId': 171180595, 'id': 171180603}], 'categoryCode': 'storage_service_enterprise', 'parentId': '', 'id': 171180595}, {'itemId': 5944, 'setupFee': '0', 'promoCodeId': '', 'recurringFee': '0', 'description': 'Block Storage', 'laborFee': '0', 'oneTimeFee': '0', 'itemPriceId': '45104', 'categoryCode': 'storage_block', 'parentId': 171180595, 'id': 171180597}, {'itemId': 5940, 'setupFee': '0', 'promoCodeId': '', 'recurringFee': '0', 'description': '2 IOPS per GB', 'laborFee': '0', 'oneTimeFee': '0', 'itemPriceId': '45084', 'categoryCode': 'storage_tier_level', 'parentId': 171180595, 'id': 171180599}, {'itemId': 5138, 'setupFee': '0', 'promoCodeId': '', 'recurringFee': '36.25', 'description': '250 GB Storage Space', 'laborFee': '0', 'oneTimeFee': '0', 'itemPriceId': '45254', 'categoryCode': 'performance_storage_space', 'parentId': 171180595, 'id': 171180601}, {'itemId': 6028, 'setupFee': '0', 'promoCodeId': '', 'recurringFee': '.36', 'description': '5 GB Storage Space (Snapshot Space)', 'laborFee': '0', 'oneTimeFee': '0', 'itemPriceId': '46136', 'categoryCode': 'storage_snapshot_space', 'parentId': 171180595, 'id': 171180603}], 'accountId': 323716, 'userRecord': {'username': 'xxxx', 'lastName': 'xxxx', 'id': 426607, 'firstName': 'xxxx', 'accountId': xxxx}, 'id': 11999815, 'presaleEventId': ''}, 'orderDate': '2017-01-04T00:42:21-08:00', 'orderDetails': {'preTaxSetup': '0', 'storageGroups': [], 'postTaxRecurring': '36.61', 'billingOrderItemId': '', 'presetId': '', 'prices': [{'itemId': 5936, 'setupFee': '0', 'recurringFee': '0', 'laborFee': '0', 'oneTimeFee': '0', 'item': {'thirdPartyPolicyAssignments': [], 'capacity': '0', 'description': 'Endurance Storage', 'bundle': [], 'keyName': 'CODENAME_PRIME_STORAGE_SERVICE', 'units': 'N/A', 'id': 5936}, 'id': 45064, 'categories': [{'categoryCode': 'storage_service_enterprise', 'id': 394, 'name': 'Endurance'}]}, {'itemId': 5944, 'setupFee': '0', 'recurringFee': '0', 'laborFee': '0', 'oneTimeFee': '0', 'item': {'thirdPartyPolicyAssignments': [], 'capacity': '0', 'description': 'Block Storage', 'bundle': [], 'keyName': 'BLOCK_STORAGE_2', 'units': 'N/A', 'id': 5944}, 'id': 45104, 'categories': [{'categoryCode': 'storage_block', 'id': 398, 'name': 'Block Storage'}]}, {'itemId': 5940, 'setupFee': '0', 'recurringFee': '0', 'laborFee': '0', 'oneTimeFee': '0', 'item': {'thirdPartyPolicyAssignments': [], 'capacity': '0', 'description': '2 IOPS per GB', 'bundle': [], 'keyName': 'READHEAVY_TIER', 'units': 'N/A', 'id': 5940}, 'id': 45084, 'categories': [{'categoryCode': 'storage_tier_level', 'id': 396, 'name': 'Storage Tier Level'}]}, {'itemId': 5138, 'setupFee': '0', 'recurringFee': '36.25', 'laborFee': '0', 'oneTimeFee': '0', 'item': {'thirdPartyPolicyAssignments': [], 'capacity': '250', 'description': '250 GB Storage Space', 'bundle': [], 'keyName': '250_GB_PERFORMANCE_STORAGE_SPACE', 'units': 'GB', 'id': 5138}, 'id': 45254, 'categories': [{'categoryCode': 'performance_storage_space', 'id': 382, 'name': 'Storage Space'}]}, {'itemId': 6028, 'setupFee': '0', 'recurringFee': '.36', 'laborFee': '0', 'oneTimeFee': '0', 'item': {'thirdPartyPolicyAssignments': [], 'capacity': '5', 'description': '5 GB Storage Space', 'bundle': [], 'keyName': '5_GB_STORAGE_SPACE', 'units': 'GB', 'id': 6028}, 'id': 46136, 'categories': [{'categoryCode': 'storage_snapshot_space', 'id': 402, 'name': 'Storage Snapshot Space'}]}], 'sendQuoteEmailFlag': '', 'packageId': 240, 'useHourlyPricing': False, 'preTaxRecurringMonthly': '36.61', 'message': '', 'preTaxRecurring': '36.61', 'billingInformation': {'billingNameFirst': 'xxxxx', 'billingPostalCode': 'xxxxxx', 'billingPhoneVoice': 'xxxxx', 'billingNameCompany': 'xxxxxx', 'billingAddressLine1': 'xxxxx', 'cardExpirationMonth': '', 'billingNameLast': 'Urbisci', 'cardExpirationYear': '', 'billingState': 'xxxx', 'billingCountryCode': 'xxxx', 'billingEmail': 'xxxxxx', 'taxExempt': 0, 'billingCity': 'San Jose'}, 'primaryDiskPartitionId': '', 'locationObject': {'id': 1004995, 'name': 'sjc03', 'longName': 'San Jose 3'}, 'taxCompletedFlag': True, 'isManagedOrder': '', 'originVolumeScheduleId': '', 'imageTemplateId': '', 'postTaxRecurringMonthly': '36.61', 'resourceGroupTemplateId': '', 'postTaxSetup': '0', 'sshKeys': [], 'location': '1004995', 'stepId': '', 'proratedInitialCharge': '33.07', 'totalRecurringTax': '0', 'originVolumeId': '', 'osFormatType': {'createDate': '', 'keyName': 'LINUX', 'id': 12}, 'paymentType': 'ADD_TO_BALANCE', 'resourceGroupId': '', 'sourceVirtualGuestId': '', 'bigDataOrderFlag': False, 'properties': [], 'extendedHardwareTesting': '', 'preTaxRecurringHourly': '0', 'postTaxRecurringHourly': '0', 'taxCacheHash': '97601ef55aa1f213ad046476769b64f57ce4d1ab', 'currencyShortName': 'USD', 'itemCategoryQuestionAnswers': [], 'containerSplHash': '000000001fe660de00007f62a57eefc9', 'proratedOrderTotal': '33.07', 'serverCoreCount': '', 'privateCloudOrderFlag': False, 'totalSetupTax': '0', 'quantity': 1}}

問題是響應沒有提供任何有用的信息來標識存儲,例如存儲ID或存儲名稱。

我知道可以獲取所有存儲信息的API:

client['SoftLayer_Account'].getIscsiNetworkStorage()

但是我無法識別我剛剛創建的那個(存儲名稱是自動的,由API創建),檢查創建的時間不是一個好主意。

來自SoftLayer_Product_Order :: placeOrder方法的響應包含一個orderId屬性

'orderId':11999815

我們可以通過此方法找到存儲,為此嘗試以下腳本:

"""
Get storage through orderId

Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getNetworkStorage
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_Storage
http://sldn.softlayer.com/article/object-filters

License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer

"""
Your SoftLayer API username and key.
"""
USERNAME = 'set me'
API_KEY = 'set me'

# Define the orderId from block storage
orderId = 11999815

# Declare a new API service object
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
accountService = client['Account']

# Define an object filter to get storage through orderId
objectFilter = {"iscsiNetworkStorage": {"billingItem": {"orderItem": {"order": {"id": {"operation": orderId}}}}}}

try:
    result = accountService.getIscsiNetworkStorage(filter=objectFilter)
    print(result)
except SoftLayer.SoftLayerAPIError as e:
    print("Error. "
          % (e.faultCode, e.faultString))

希望對您有所幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM