0

我正在尝试为 iSCSI 卷(块存储)创建 Endurance 存储。我正在使用 SoftLayer api。创建删除存储的过程是什么?

4

2 回答 2

1

要创建块存储 - 耐力,您可以尝试以下脚本:

// Order Block Storage - Endurance
// This script creates an order for Block Storage - Endurance
//
// See below references for more details.
// important manual pages:
// http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order
// http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder/
// @License: http://sldn.softlayer.com/article/License
// @Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>

package main

import (
    "fmt"
    "github.com/softlayer/softlayer-go/datatypes"
    "github.com/softlayer/softlayer-go/services"
    "github.com/softlayer/softlayer-go/session"
    "github.com/softlayer/softlayer-go/sl"
    "encoding/json"
)

func main() {
  username    := "set me"
  apikey      := "set me"

  complexType := "SoftLayer_Container_Product_Order_Network_Storage_Enterprise"
  quantity    := 1
  location    := "265592"
  packageId   := 240
  osKeyName   := "LINUX"
  quote       := false

  // 1. Create a session
  sess := session.New(username, apikey)

  // 2. Get a service
  service := services.GetProductOrderService(sess)

  osFormatType := &datatypes.Network_Storage_Iscsi_OS_Type{
    KeyName: sl.String(osKeyName),    
  }

  prices := []datatypes.Product_Item_Price{
    datatypes.Product_Item_Price{ Id: sl.Int(45098) },  // Block Storage
    datatypes.Product_Item_Price{ Id: sl.Int(45058) },  // Endurance Storage
    datatypes.Product_Item_Price{ Id: sl.Int(45148) },  // 40 GB Storage Space
    datatypes.Product_Item_Price{ Id: sl.Int(45068) },  // 0.25 IOPS per GB
  }

  cpo := datatypes.Container_Product_Order {
    ComplexType   : sl.String(complexType),
    Quantity      : sl.Int(quantity),
    Location      : sl.String(location),
    PackageId     : sl.Int(packageId),         
    Prices        : prices,
  }

  cponp := datatypes.Container_Product_Order_Network_Storage_Enterprise {
    Container_Product_Order : cpo,
    OsFormatType            : osFormatType,
  }


  // 4. Invoke a method
    containerProductOrder, err := service.PlaceOrder(&cponp,&quote)
    if err != nil {
        fmt.Printf("%s\n", err)
        return
    } 

  cpoMarshed, errMarsh := json.Marshal(containerProductOrder)
  if errMarsh != nil {
    fmt.Println(errMarsh)
    return
  }

  fmt.Println(string(cpoMarshed))
}

如果您需要价格方面的帮助,此方法可以提供帮助:

价格的重要参考:

取消存储

// Cancel Storage
//
// This script cancels the storage, passing a storage billing ID to
// SoftLayer_Billing_Item::cancelService method.
//
// See below references for more details.
// Important manual pages:
// http://sldn.softlayer.com/reference/services/SoftLayer_Billing_Item/cancelService
// @License: http://sldn.softlayer.com/article/License
// @Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>

package main

import (
    "fmt"
    "github.com/softlayer/softlayer-go/services"
    "github.com/softlayer/softlayer-go/session"
)

func main() {
  username    := "set me"
  apikey      := "set me"

  storageId := 19771755

  sess := session.New(username, apikey)

  networkService := services.GetNetworkStorageService(sess)
  billingService := services.GetBillingItemService(sess)

  mask := "billingItem" 

  network, err := networkService.Id(storageId).Mask(mask).GetObject()
    if err != nil {
        fmt.Printf("%s\n", err)
        return
    } 

  result, err := billingService.Id(*network.BillingItem.Id).CancelService()
    if err != nil {
        fmt.Printf("%s\n", err)
        return
    }

  fmt.Println(result)
}

参考:


通过 storage 的 orderId 获取 storage lun 名称和目标地址

// Get Storage through orderId
//
// See below references for more details.
// Important manual pages:
// http://sldn.softlayer.com/reference/services/SoftLayer_Account/getNetworkStorage
//
// @License: http://sldn.softlayer.com/article/License
// @Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>

package main

import (
    "fmt"
    "github.com/softlayer/softlayer-go/services"
    "github.com/softlayer/softlayer-go/session"
    "encoding/json"
)

func main() {
  username    := "set me"
  apikey      := "set me"
  orderId     := "6199311"

  sess := session.New(username, apikey)

  accountService := services.GetAccountService(sess)

  filter := `{"networkStorage": {"billingItem": {"orderItem": {"order": {"id": {"operation": `+orderId+`}}}}}}`
  mask   := "username;serviceResourceBackendIpAddress"

  result, err := accountService.Mask(mask).Filter(filter).GetNetworkStorage()
    if err != nil {
        fmt.Printf("%s\n", err)
        return
    } 

  storage, errMarsh := json.Marshal(result)
  if errMarsh != nil {
    fmt.Println(errMarsh)
    return
  }

  fmt.Println(string(storage))
}


    // Get Storage through orderId
    //
    // See below references for more details.
    // Important manual pages:
    // http://sldn.softlayer.com/reference/services/SoftLayer_Account/getNetworkStorage
    //
    // @License: http://sldn.softlayer.com/article/License
    // @Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>

    package main

    import (
        "fmt"
        "github.com/softlayer/softlayer-go/services"
        "github.com/softlayer/softlayer-go/session"
        "encoding/json"
    )

    func main() {
      username    := "set me"
      apikey      := "set me"
      orderId     := "6199311"

      sess := session.New(username, apikey)

      accountService := services.GetAccountService(sess)

      filter := `{"networkStorage": {"billingItem": {"orderItem": {"order": {"id": {"operation": `+orderId+`}}}}}}`
      mask   := "username;serviceResourceBackendIpAddress"

      result, err := accountService.Mask(mask).Filter(filter).GetNetworkStorage()
        if err != nil {
            fmt.Printf("%s\n", err)
            return
        } 

      storage, errMarsh := json.Marshal(result)
      if errMarsh != nil {
        fmt.Println(errMarsh)
        return
      }

      fmt.Println(string(storage))
    }

替换:用户名、apikey 和 6199311 为您自己的信息

参考资料


获取标准价格(位置组 = null)

// Retrieve product item prices which location group is null
//
// See below references for more details.
// important manual pages:
// http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getItemPrices
//
// @License: http://sldn.softlayer.com/article/License
// @Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>

package main

import (
    "fmt"
    "github.com/softlayer/softlayer-go/services"
    "github.com/softlayer/softlayer-go/session"
    "encoding/json"
)

func main() {
  username    := "set me"
  apikey      := "set me"

  packageId   := 240

  // 1. Create a session
  sess := session.New(username, apikey)

  // 2. Get a service
  packageService := services.GetProductPackageService(sess)

  // Declare a filter to get standard prices
  filter := `{"itemPrices":{"locationGroupId":{"operation": "is null"}}}`

  packageResult, err := packageService.Id(packageId).Filter(filter).GetItemPrices()
  if err != nil {
    fmt.Print("%s\n", err)
    return
  }

  prices, errMarsh := json.Marshal(packageResult)
  if errMarsh != nil {
    fmt.Println(errMarsh)
    return
  }

  fmt.Println(string(prices))
}

检索性能存储空间的产品项目价格(标准)

// Retrieve product item prices for performance storage space
//
// See below references for more details.
// important manual pages:
// http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getItemPrices
//
// @License: http://sldn.softlayer.com/article/License
// @Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>

package main

import (
    "fmt"
    "github.com/softlayer/softlayer-go/services"
    "github.com/softlayer/softlayer-go/session"
    "encoding/json"
)

func main() {
  username    := "set me"
  apikey      := "set me"

  packageId   := 240

  // 1. Create a session
  sess := session.New(username, apikey)

  // 2. Get a service
  packageService := services.GetProductPackageService(sess)

  // Declare a filter to get standard prices
  filter := `{"itemPrices":{"item":{"capacity":{"operation":40}}, "attributes":{"value":{"operation":300}}, "locationGroupId":{"operation": "is null"}, "categories":{"categoryCode":{"operation":"performance_storage_space"}}}}`

  packageResult, err := packageService.Id(packageId).Filter(filter).GetItemPrices()
  if err != nil {
    fmt.Print("%s\n", err)
    return
  }

  prices, errMarsh := json.Marshal(packageResult)
  if errMarsh != nil {
    fmt.Println(errMarsh)
    return
  }

  fmt.Println(string(prices))
}

SoftLayer_Account/getObject 不使用 softlayer-go

也许这样的事情可以帮助你:

我试过了,我创建了以下脚本来从SoftLayer_Account::getObject响应中获取部分数据:

package main

import (
    "encoding/json"
    "fmt"
    "log"
    "net/http"
)

type Account struct {
    Id int `json:"id"`
    Address1 string `json:"address1"`
    FirstName string `json:"firstName"`
}

func main() {

    url := fmt.Sprintf("https://username:apiKey@api.softlayer.com/rest/v3/SoftLayer_Account/getObject")

    req, err := http.NewRequest("GET", url, nil)
    if err != nil {
        log.Fatal("NewRequest: ", err)
        return
    }

    client := &http.Client{}

    resp, err := client.Do(req)
    if err != nil {
        log.Fatal("Do: ", err)
        return
    }

    defer resp.Body.Close()

    var record Account

    // Use json.Decode for reading streams of JSON data
    if err := json.NewDecoder(resp.Body).Decode(&record); err != nil {
        log.Println(err)
    }

    fmt.Println("Response = ", record)
    fmt.Println("FirstName = ", record.FirstName)

}

用您的凭据替换:用户名apiKey

据我了解 Golang,有必要定义响应的结构(我不确定,但这是我成功解码响应的唯一方法)请参阅脚本中的类型 Account 结构,您可以查看以下数据类型(结构)为此,在 softlayer-go 中,要清楚地了解这一点:

于 2017-02-08T14:43:29.613 回答
0

SoftLayer_Product_Order::verifyOrder - 没有 softlayer-go 的 POST 请求

最后我找到了一种简单的方法来解码响应:),这里是SoftLayer_Product_Order::verifyOrder的发布请求,我在jsonStr中定义了 json,如您所见:

// Verify Order for VSI
//
// This script verifies an order for vsi
//
// important manual pages:
// http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/verifyOrder
// http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder
//
// @License: http://sldn.softlayer.com/article/License
// @Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>


package main

import (
    "fmt"
    "net/http"
    "bytes"
    "io/ioutil"
)


func main() {
    url := "https://username:apiKey@api.softlayer.com/rest/v3/SoftLayer_Product_Order/verifyOrder"
    fmt.Println("URL:>", url)

    // Define the json to send
    var jsonStr = []byte(`{"parameters":[{"location":"AMSTERDAM","packageId":46,"quantity":1,"hardware":[{"domain":"softlayer.com","hostname":"rcvtest"}],"prices":[{"id":50231},{"id":52135},{"id":51639},{"id":51569},{"id":52363},{"id":61019},{"id":55},{"id":57},{"id":175777},{"id":273},{"id":21},{"id":51481},{"id":905},{"id":58},{"id":420},{"id":418}]}]}`)
    req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
    req.Header.Set("Content-Type", "application/json")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }

    defer resp.Body.Close()

    fmt.Println("response Status:", resp.Status)
    fmt.Println("response Headers:", resp.Header)
    body, _ := ioutil.ReadAll(resp.Body)
    fmt.Println("response Body:", string(body))
}

Replace : username 和 apiKey 在请求中用你自己的信息


SoftLayer_Account::getVirtualGuests - 带有对象过滤器和对象掩码的脚本

这里有一个在SoftLayer_Account::getVirtualGuests方法的请求中定义了 objectFilter 和 objectMasks 的脚本,用于获取虚拟客人:

// This script get virtual guest through id using object filter and mask
//
// important manual pages:
// http://sldn.softlayer.com/reference/services/SoftLayer_Account/getVirtualGuests
// 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. <sldn@softlayer.com>


package main

import (
    "fmt"
    "net/http"
     "io/ioutil"
)

func main() {
    url := `https://username:apiKey@api.softlayer.com/rest/v3/SoftLayer_Account/getVirtualGuests?objectFilter={"virtualGuests":{"id":{"operation":27497599}}}&objectMask=mask[billingItem]`
    fmt.Println("URL:>", url)

    req, err := http.NewRequest("GET", url, nil)


    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    fmt.Println("response Status:", resp.Status)
    fmt.Println("response Headers:", resp.Header)
    body, _ := ioutil.ReadAll(resp.Body)
    fmt.Println("response Body:", string(body))
}

替换:用户名、apiKey 和 27497599 在请求中使用您自己的信息


SoftLayer_Product_Package::getItemPrices - 使用 objetFilter 请求

这里有一个带有 objectFilter 到SoftLayer_Product_Package::getItemPrices的脚本来检索性能存储空间的产品项目价格(标准)(在我的其他答案中使用 softlayer-go 提供的脚本),

如您所见,我设置了is+null因为空间引发了异常,但它工作正常

// Retrieve product item prices for performance storage space using objectFilter
//
// important manual pages:
// http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getItemPrices
// http://sldn.softlayer.com/article/object-filters
//
// @License: http://sldn.softlayer.com/article/License
// @Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>

package main

import (
    "fmt"
    "log"
    "net/http"
     "io/ioutil"
)

func main() {
    url := `https://username:apiKey@api.softlayer.com/rest/v3/SoftLayer_Product_Package/240/getItemPrices?objectFilter={"itemPrices":{"item":{"capacity":{"operation":40}},"attributes":{"value":{"operation":300}},"categories":{"categoryCode":{"operation":"performance_storage_space"}},"locationGroupId":{"operation":"is+null"}}}`
    fmt.Println("URL:>", url)

    req, err := http.NewRequest("GET", url, nil)

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        log.Fatal("Do: ", err)
        return
    }

    defer resp.Body.Close()

    fmt.Println("response Status:", resp.Status)
    fmt.Println("response Headers:", resp.Header)
    body, _ := ioutil.ReadAll(resp.Body)
    fmt.Println("response Body:", string(body))
}

替换:请求中的用户名和apiKey

我希望这个脚本可以帮助你,如果你有任何问题或疑问,请告诉我

于 2017-02-17T19:49:04.717 回答