0

SoftLayer API 経由で仮想サーバーを注文する際に、「監視からの自動再起動」を有効にする方法を探しています。

私の使い方では、APIが「監視からの自動再起動」を設定するオプションを提供すると望ましい

client['Virtual_Guest'].createObject({ 'hostname': 'myhost', 'domain': 'yukaary.craft.com', 'startCpus': 1, 'maxMemory': 1024, 'datacenter': {"name": "tok02"}, 'privateNetworkOnlyFlag': 'true', 'hourlyBillingFlag': 'true', 'operatingSystemReferenceCode': 'UBUNTU_LATEST', 'localDiskFlag': 'false', 'serviceAddon': {'response': 'reboot'} })

申し訳ありませんが、これは PHP ではなく Python です。

既存の質問と sldn サイトの両方を検索していますが、現時点では手がかりがありません。

4

2 に答える 2

0

これを行う方法を見つけました。

これは、既存のサーバーの注文テンプレートから変更されたサンプル注文です: client['Virtual_Guest'].getOrderTemplate("HOURLY", id=12345678).

order.json { "preTaxSetup": "0", "storageGroups": [], "postTaxRecurring": "0.111", "billingOrderItemId": "", "presetId": "", "prices": [ {"id": 52123}, {"id": 1800}, {"id": 2202}, {"id": 57731}, {"id": 56679}, {"id": 57}, {"id": 13945}, {"id": 273}, {"id": 21}, {"id": 52265}, {"id": 905}, {"id": 57755}, {"id": 420}, {"id": 418} ], "sendQuoteEmailFlag": "", "packageId": 46, "useHourlyPricing": true, "preTaxRecurringMonthly": "0", "message": "", "virtualGuests": [{"domain": "yukaary.craft.net", "hostname": "test"}], "preTaxRecurring": "0.111", "primaryDiskPartitionId": 1, "taxCompletedFlag": true, "isManagedOrder": 0, "imageTemplateId": "", "postTaxRecurringMonthly": "0", "resourceGroupTemplateId": "", "postTaxSetup": "0", "sshKeys": [{"sshKeyIds":[012345]}], "location": 449604, "stepId": "", "proratedInitialCharge": "0", "totalRecurringTax": 0, "paymentType": "", "resourceGroupId": "", "sourceVirtualGuestId": "", "bigDataOrderFlag": false, "extendedHardwareTesting": "", "preTaxRecurringHourly": "0.111", "monitoringAgentConfigurationTemplateGroupId": "", "postTaxRecurringHourly": "0.111", "currencyShortName": "USD", "proratedOrderTotal": "0", "serverCoreCount": 4, "privateCloudOrderFlag": false, "totalSetupTax": "0", "quantity": 1 }

  • tok02 データセンター用に調整されています。

次に、仮想サーバーを注文しました

client['Product_Order'].placeOrder(order)

サーバーは、「監視パッケージ - プレミアム アプリケーション」および「監視からの自動再起動」オプションを使用して作成されました。

于 2016-01-15T09:50:06.980 に答える
0

create オブジェクトを使用して addoms を構成することはできません。placeOrder メソッドを使用して、注文で希望するアイテムの価格を注文で指定する必要があります。

softlayer での注文方法の詳細については、このドキュメントを参照して ください http://sldn.softlayer.com/blog/bpotter/Going-Further-SoftLayer-API-Python-Client-Part-3

この例が役に立ちますように (Python を使用しています)。ポータルに表示されるような名前と値を使用して、注文するオプションを設定できます。

"""
Order a new VSI.

Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/verifyOrder
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getSshKeys
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getItemPrices
http://sldn.softlayer.com/reference/services/SoftLayer_Location/getDatacenters
http://sldn.softlayer.com/reference/services/SoftLayer_Network_Vlan/getVlanForIpAddress
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Item_Price

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

import SoftLayer
import json

location = "AMS01"
quantity = 1
# If you want the VSI hourly pricing
# set the value as True
useHourlyPricing = False

# The configuration of the VSI
# The values and names are the same like
# the ones displayed in the portal.
configuration = {
    "COMPUTING INSTANCE": "2 x 2.0 GHz Cores",
    "RAM": "4 GB",
    "OPERATING SYSTEM": "CentOS 7.x - Minimal Install (64 bit)",
    "FIRST DISK": "25 GB (SAN)",
    "PUBLIC BANDWIDTH": "250 GB Bandwidth",
    "UPLINK PORT SPEEDS": "100 Mbps Public & Private Network Uplinks",
    "MONITORING": "Host Ping",
    "RESPONSE": "Automated Notification",
    "Primary IP Addresses": "1 IP Address",
    "Remote Management": "Reboot / Remote Console",
    "Notification": "Email and Ticket",
    "VPN Management - Private Network": "Unlimited SSL VPN Users & 1 PPTP VPN User per account",
    "Vulnerability Assessments & Management": "Nessus Vulnerability Assessment & Reporting"
}

# Specifies the hostname and domain we want for our VSI.
# If you set quantity greater than 1 then you
# need to define one hostname/domain pair per VSI you wish to order.
virtualGuest = [
    {
        "domain": "softlayer.ibm.com",
        "hostname": "VM1",
        # The vlan configuration for the VSI if you do not wish to configure
        # the vlans just comment the lines.
        # set the any IP address which belongs to the VLAN you wish to configure in the VSI
        "backendVlanIp": "10.68.117.193",
        "frontedVLAN": "159.122.23.225"
    }
]

# The post install script to apply.
# Leave in empty if you do not wish to apply an script in the provisioning.
postInstallScript = ""

# The list of ssh keys to apply to the VSI.
# Set the label names of the ssh keys like in the portal
# Leave in empty if you do not wish to apply any ssh key.
sshKeys = ["labkey", "matt-sl-test"]


PACKAGE = 46
client = SoftLayer.Client()
orderService = client['SoftLayer_Product_Order']
accountService = client['SoftLayer_Account']
packageService = client['SoftLayer_Product_Package']
locationService = client['SoftLayer_Location']
valnService = client['SoftLayer_Network_Vlan']

try:
    location = locationService.getDatacenters(filter={"name": {"operation": location.lower()}})
except SoftLayer.SoftLayerAPIError as e:
    print("Unable to get the datacenter. " % (e.faultCode, e.faultString))
    exit(0)

try:
    pricesPackage = packageService.getItemPrices(id=PACKAGE, mask="mask[categories, item]")
except SoftLayer.SoftLayerAPIError as e:
    print("Unable to get the item prices. " % (e.faultCode, e.faultString))
    exit(0)

# Getting the item prices for the order.
prices = []
for item in configuration.keys():
    for price in pricesPackage:
        added = False
        if 'categories' in price:
            for category in price['categories']:
                if category['name'].strip().upper() == item.strip().upper() and \
                   price['item']['description'].strip().upper() == configuration[item].strip().upper() and \
                   price['locationGroupId'] == "":
                    prices.append(price)
                    added = True
                    break
            if added:
                break
    if not added:
        print("There is no price for the item: " + item + "- " + configuration[item])
        exit(0)

vsis = []
for vsi in virtualGuest:
    guest = {}
    if 'domain' in vsi:
        guest['domain'] = vsi['domain']
    if 'hostname' in vsi:
        guest['hostname'] = vsi['hostname']
    if 'backendVlanIp' in vsi:
        try:
            backend = valnService.getVlanForIpAddress(vsi['backendVlanIp'])
            guest['primaryBackendNetworkComponent'] = {}
            guest['primaryBackendNetworkComponent']['networkVlan'] = backend
        except SoftLayer.SoftLayerAPIError as e:
            print("Unable to get the backend Vlan. " % (e.faultCode, e.faultString))
    if 'frontedVLAN' in vsi:
        try:
            fronted = valnService.getVlanForIpAddress(vsi['frontedVLAN'])
            guest['primaryNetworkComponent'] = {}
            guest['primaryNetworkComponent']['networkVlan'] = fronted
        except SoftLayer.SoftLayerAPIError as e:
            print("Unable to get the fronted Vlan. " % (e.faultCode, e.faultString))
    vsis.append(guest)


orderData = {
    "prices": prices,
    "packageId": PACKAGE,
    "location": location[0]['id'],
    'hardware': vsis,
    'useHourlyPricing': useHourlyPricing
}

if postInstallScript:
    orderData['provisionScripts'] = [postInstallScript]

if len(sshKeys) > 0:
    objectfilter = {"sshKeys": {"label": {"operation": "in", "options": [{"name": "data", "value": sshKeys}]}}}
    try:
        sshs = accountService.getSshKeys(filter=objectfilter, mask="mask[id]")
    except SoftLayer.SoftLayerAPIError as e:
        print("Unable to get the ssh keys. " % (e.faultCode, e.faultString))
    if len(sshs) > 0:
        orderData['sshKeys'] = []
        sshKeyIds = {}
        sshKeyIds['sshKeyIds'] = []
        for ssh in sshs:
            sshKeyIds['sshKeyIds'].append(ssh['id'])
        orderData['sshKeys'].append(sshKeyIds)
    else:
        print("None ssh key was found")

try:
    # When you are ready to order the VSI
    # change verifyOrder() method by placeOrder() method.
    result = orderService.verifyOrder(orderData)
    print(json.dumps(result, sort_keys=True, indent=2, separators=(',', ': ')))
except SoftLayer.SoftLayerAPIError as e:
    print("Unable to create the order. "
          % (e.faultCode, e.faultString))
于 2016-01-15T12:36:27.890 に答える