如何为网关及其成员配置ssh订购软层网络网关

时间:2018-03-27 02:26:41

标签: go ibm-cloud-infrastructure gateway

如何为网关及其成员配置ssh订购软层网络网关

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() {
    // SoftLayer API username and key
    username := "set me"
    apikey   := "set me"



    // Build a Container_Product_Order_Virtual_Disk_Image object containing the order
    // you wish to place
    order := datatypes.Container_Product_Order{
        ContainerIdentifier: sl.String(d.Get("hostname").(string)),
        Quantity:            sl.Int(1),
        Hardware: []datatypes.Hardware{
            {
                Hostname: sl.String(d.Get("hostname").(string)),
                Domain:   sl.String(d.Get("domain").(string)),
            },
        },
        Location:  sl.String(strconv.Itoa(*dc.Id)),
        PackageId: pkg.Id,
        Prices: []datatypes.Product_Item_Price{
            server,
            os,
            ram,
            portSpeed,
            priIpAddress,
            remoteManagement,
            vpnManagement,
            monitoring,
            notification,
            response,
            vulnerabilityScanner,
        },
    }

    // Set SSH Key on main order
    ssh_key_ids := members[0].Get("ssh_key_ids").([]interface{})
    sshKeyP := make([]int, len(ssh_key_ids))
    for i, ssh_key_id := range ssh_key_ids {
        sshKeyP[i] = ssh_key_id.(int)
    }
    order.SshKeys = make([]datatypes.Container_Product_Order_SshKeys, len(members))
    order.SshKeys[0] = datatypes.Container_Product_Order_SshKeys{
        SshKeyIds: sshKeyP,
    }

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

    // Get SoftLayer_Product_Order service
    service := services.GetProductOrderService(sess)

    // Use verifyOrder() method to check for errors. Replace this with placeOrder() when
    // you are ready to order.
    receipt, err := service.VerifyOrder(&templateObject)
    if err != nil {
        fmt.Printf("\n Unable to place order:\n - %s\n", err)
        return
    }

    // Following helps to print the result in json format.
    jsonFormat, jsonErr := json.MarshalIndent(receipt, "","     ")
    if jsonErr != nil {
            fmt.Println(jsonErr)
            return
    }
    fmt.Println(string(jsonFormat))
}

这是我用来订购的脚本,但它仅为网关成员而不是网关配置ssh密钥。你能帮我解决一下如何配置网关及其成员的ssh密钥。如果您可以更新相同的脚本并分享它,那就太好了。

1 个答案:

答案 0 :(得分:0)

SoftLayer网关是一个由一个成员(独立)或两个成员(高可用性)组成的对象。当您通过ssh访问网关时,它实际上与网关成员之一建立了ssh会话。因此,您只能为网关成员配置ssh密钥,而不能为网关本身配置。