【问题标题】:SoftLayer API: Order Virtual Server with specific VLANSoftLayer API:订购具有特定 VLAN 的虚拟服务器
【发布时间】:2016-04-11 13:46:41
【问题描述】:

我使用此代码列出我帐户中可用的 VLAN

require 'softlayer_api'
require 'pp'

client = SoftLayer::Client.new
account_service = client[:Account]

object_filter = {'networkVlans': {'primaryRouter': {'datacenter': {'name': 'tor01'}}}}
object_mask = 'mask[id,name,primaryRouter[id,datacenter[id,name]]]'

vlans = account_service.object_mask(object_mask).getNetworkVlans(object_filter)

vlans.each { |vlan| pp plan }

我明白了

{"id"=>999999,
 "name"=>"VLAN1",
 "primaryRouter"=>
  {"id"=>777777, "datacenter"=>{"id"=>448994, "name"=>"tor01"}}}
{"id"=>888888,
 "name"=>"VLAN2",
 "primaryRouter"=>
  {"id"=>666666, "datacenter"=>{"id"=>448994, "name"=>"tor01"}}}

当我使用例如888888 在虚拟服务器顺序中,尽管显式设置了值,但仍为服务器配置了默认 VLAN:

server_order = SoftLayer::VirtualServerOrder_Package.new(client)
server_order.datacenter = SoftLayer::Datacenter.datacenter_named 'tor01', client

server_order.hostname = 'hostname'
server_order.domain = 'domain.com'
# See code below to list out all vlan ids for the current account
server_order.private_vlan_id = 888888
server_order.public_vlan_id = 999999
server_order.hourly = true
server_order.configuration_options = config_options

server_order.place_order!()

我错过了什么?订购服务器时如何显式设置 VLAN id?

【问题讨论】:

    标签: api ibm-cloud-infrastructure


    【解决方案1】:

    目前使用VirtualServerOrder_Package class指定vlan存在问题

    我已打开一个问题来跟踪此问题:https://github.com/softlayer/softlayer-ruby/issues/111

    但是,您可以使用以下脚本来订购虚拟服务器,指定 vlan(它不使用 VirtualServerOrder_Package 类来订购)。看看下面的脚本:

    # Order Virtual Guest
    #
    # Important manual pages:
    # http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder
    # http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order
    # http://sldn.softlayer.com/reference/datatypes/SoftLayer_Hardware
    # http://sldn.softlayer.com/reference/services/SoftLayer_Product_Item_Price/
    #
    # License: http://sldn.softlayer.com/article/License
    # Author: SoftLayer Technologies, Inc.<sldn@softlayer.com>
    
    require 'rubygems'
    require 'softlayer_api'
    require 'json'
    
    # Your SoftLayer API username.
    USERNAME = 'set me'
    
    # Your SoftLayer API key.
    API_KEY = 'set me'
    
    # The number of servers you wish to order in this configuration.
    quantity = 1
    
    # Where you'd like your new server provisioned.
    # This can either be the id of the datacenter you wish your new server to be
    # provisioned in or the string 'FIRST_AVAILABLE' if you have no preference
    # where your server is provisioned.
    # Location id 3     = Dallas
    # Location id 18171 = Seattle
    # Location id 37473 = Washington, D.C.
    location = '138124' # Dallas 5
    
    # The id of the SoftLayer_Product_Package you wish to order.
    package_id = 46
    
    # Build a skeleton SoftLayer_Hardware object to define hostname, domain, public and private vlan.
    virtualGuests = [
      {
        'hostname' => 'test', # The hostname of the server you wish to order.
        'domain' => 'example.org', # The domain name of the server you wish to order.
        'primaryNetworkComponent' => { "networkVlan" => { "id" =>  971077}}, # public vlan id
        'primaryBackendNetworkComponent' => {'networkVlan'=> {""=> 971075}} # private vlan id
      }
    ]
    
    # Build a skeleton SoftLayer_Product_Item_Price objects. These objects contain
    # much more than ids, but SoftLayer's ordering system only needs the price's id
    # to know what you want to order.
    
    # Every item in SoftLayer's product catalog is assigned an id. Use these ids
    # to tell the SoftLayer API which options you want in your new server. Use
    # the getActivePackages() method in the SoftLayer_Account API service to get
    # a list of available item and price options per available package.
    prices = [
      { 'id' => 1640 }, # 1 x 2.0 GHz Core
      { 'id' => 1644 }, # 1 GB RAM
      { 'id' => 13940 }, # CentOS 6.x - LAMP Install (32 bit)
      { 'id' => 2202 }, # 25 GB (SAN)
      { 'id' => 50241 }, # 5000 GB Bandwidth
      { 'id' => 273 }, # 100 Mbps Public & Private Network Uplinks
      { 'id' => 2302 }, # Monitoring Package - Basic
      { 'id' => 55 }, # Host Ping
      { 'id' => 58 }, # Automated Notification
      { 'id' => 420}, # Unlimited SSL VPN Users & 1 PPTP VPN User per account
      { 'id' => 418 }, # Nessus Vulnerability Assessment & Reporting
      { 'id' => 21}, # 1 IP Address
      { 'id' => 57}, # Email and Ticket
      { 'id' => 905}, # Reboot / Remote Console
      {'id' => 14022} # International Services
    ]
    
    # Build a skeleton SoftLayer_Container_Product_Order_Virtual_Guest object
    # containing the order you wish to place.
    order_template = {
      'quantity' => quantity,
      'location' => location,
      'packageId' => package_id,
      'prices' => prices,
      'hardware' => virtualGuests
    }
    
    # Declare the API client to use the SoftLayer_Product_Order API service
    client = SoftLayer::Client.new(username: USERNAME, api_key: API_KEY)
    product_order_service = client.service_named('SoftLayer_Product_Order')
    begin
      # verifyOrder() will check your order for errors. Replace this with a call to
      # placeOrder() when you're ready to order. Both calls return a receipt object
      # that you can use for your records.
      #
      # Once your order is placed it'll go through SoftLayer's provisioning process.
      # When it's done you'll have a new SoftLayer_Virtual_Guest object and CCI ready
      # to use.
      receipt = product_order_service.verifyOrder(order_template)
      puts receipt
    rescue StandardError => exception
      puts "There was an error in your order: #{exception}"
    end
    

    如果您有任何问题、疑问或需要更多帮助来下订单,请告诉我,

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多