2016-11-30 92 views

回答

0

不幸的是,这是无法获取同样的结果比Control Portal进行单呼,但它使用的编程语言是可能的。

要见编程通过SoftLayer的支持语言:

看看下面的python脚本:

""" 
List OSs for VSI similar than Portal 

See below references for more details. 
Important manual pages: 
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getItemPrices 
http://sldn.softlayer.com/article/object-filters 
http://sldn.softlayer.com/article/object-Masks 

@License: http://sldn.softlayer.com/article/License 
@Author: SoftLayer Technologies, Inc. <[email protected]> 
""" 
import SoftLayer 
import datetime 
import time 

# Your SoftLayer's username and api Key 
USERNAME = 'set me' 
API_KEY = 'set me' 

# Package id 
packageId = 46 
# Datacenter 
datacenter = 'wdc04' 
# Computing INstance 
core = '1 x 2.0 GHz Core' 

# Creating service 
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY) 
packageService = client['SoftLayer_Product_Package'] 

# Declaring filters and mask to get additional information for items 
filterDatacenter = {"itemPrices": {"pricingLocationGroup": {"locations": {"name": {"operation": datacenter}}}}} 
objectMaskDatacenter = 'mask[pricingLocationGroup[locations]]' 

objectMask = 'mask[pricingLocationGroup[locations],categories,item[id, description, capacity,softwareDescription[manufacturer],availabilityAttributeCount, availabilityAttributes[attributeType]]]' 
filterInstance = { 
    'itemPrices': { 
     'categories': { 
      'categoryCode': { 
       'operation': 'os' 
      } 
     } 
    } 
} 

# Define a variable to get capacity 
coreCapacity = 0 
# To get item id information 
itemId = 0 
flag = False 
# Define the manufacturers from which you like to get information 
manufacturers = ["CentOS", "CloudLinux", "CoreOS", "Debian", "Microsoft", "Redhat", "Ubuntu"] 

# Declare time to avoid list OS expired 
now = time.strftime("%m/%d/%Y") 
nowTime = time.mktime(datetime.datetime.strptime(now, "%m/%d/%Y").timetuple()) 

try: 
    conflicts = packageService.getItemConflicts(id=packageId) 
    itemPrices = packageService.getItemPrices(id=packageId, filter=filterDatacenter, mask=objectMask) 
    if len(itemPrices) == 0: 
     filterDatacenter = {"itemPrices":{"locationGroupId":{"operation":"is null"}}} 
     itemPrices = packageService.getItemPrices(id=packageId, filter=filterDatacenter, mask=objectMask) 
    for itemPrice in itemPrices: 
     if itemPrice['item']['description'] == core: 
      itemId = itemPrice['item']['id'] 
      coreCapacity = itemPrice['item']['capacity'] 
    result = packageService.getItemPrices(id=packageId, mask=objectMask, filter=filterInstance) 
    filtered_os = [] 
    for item in result: 
     for attribute in item['item']['availabilityAttributes']: 
      expireTime = time.mktime(datetime.datetime.strptime(attribute['value'], "%m/%d/%Y").timetuple()) 
      if ((attribute['attributeType']['keyName'] == 'UNAVAILABLE_AFTER_DATE_NEW_ORDERS') and (expireTime >= nowTime)): 
       filtered_os.append(item) 
     if item['item']['availabilityAttributeCount'] == 0: 
      filtered_os.append(item) 
    for manufacturer in manufacturers: 
     print(manufacturer) 
     for itemOs in filtered_os: 
      for conflict in conflicts: 
       if (((itemOs['item']['id'] == conflict['itemId']) and (itemId == conflict['resourceTableId'])) or ((itemId == conflict['itemId']) and (itemOs['item']['id'] == conflict['resourceTableId']))): 
        flag = False 
        break 
       else: 
        flag = True 
      if flag: 
       if itemOs['item']['softwareDescription']['manufacturer'] == manufacturer: 
        if 'capacityRestrictionMinimum' in itemOs: 
         if((itemOs['capacityRestrictionMinimum'] <= coreCapacity) and (coreCapacity <= itemOs['capacityRestrictionMaximum'])): 
           print("%s Price Id: %s Item Id: %s" % (itemOs['item']['description'], itemOs['id'], itemOs['item']['id'])) 
        else: 
         print("%s Price Id: %s Item Id: %s" % (itemOs['item']['description'], itemOs['id'], itemOs['item']['id'])) 
     print("---------------------------------------------------") 
except SoftLayer.SoftLayerAPIError as e: 
    print('Unable to get Item Prices faultCode=%s, faultString=%s' 
    % (e.faultCode, e.faultString)) 

我加核心变量,因为操作系统对核心容量有限制。另外,我还添加了datecenter以获取特定数据中心的特定核心项目价格,这可能是不必要的,但您可以根据您的要求编辑此脚本。

同样的想法可以应用于其他编程语言。

我希望它有帮助,请让我知道任何疑问,意见或如果您需要进一步的帮助。


更新

我提高了剧本,我加入到检查项目之间的冲突,为了得到相同的结果为每一种能力计算实例

+0

我明白了。非常感谢〜 –

+0

我改进了脚本。在我的答案中查看**更新的**部分 –

0

有没有你正在寻找一个特定语言的例子吗?如果您使用的SoftLayer CLI可以做到这一点使用下面的命令

slcli vs create-options # For Virtual Guests 
slcli server create-options # For Bare Metal Servers 
+0

我使用python语言编程,非常感谢。 –