September 19, 2016


Execute Remote Script
Example of running a remotely hosted script on a VM. Demonstrates usage of Id() to specify the object to act on, as well as how to pass parameters (script URL) to a service method

package main

import (
    "fmt"
    "log"

    "github.com/softlayer/softlayer-go/services"
    "github.com/softlayer/softlayer-go/session"
)

var remoteScriptURL = "http://example.com/scripts/preparevm"

func main() {
    // Create a session
    sess := session.New()

    // Get the VirtualGuest service
    service := services.GetVirtualGuestService(sess)

    // Execute the script on VM with ID 12345678
    err := service.Id(12345678).ExecuteRemoteScript(&remoteScriptURL)

    if err != nil {
        log.Fatal(err)
    } else {
        fmt.Println("Remote script sent for execution")
    }
}

Feedback?

We would love to hear it
Open an issue

/go/execute_remote_script/