November 23, 2017


Create an flex image from a Virtual Server

The script makes a single call to the  SoftLayer_Virtual_Guest::captureImage method to create a
flex image. Please see below for more information.

Important manual pages:

Author: SoftLayer Technologies, Inc. <>
package main

import (

func main() {
	// SoftLayer API username and key.
	username  := "set me"
  	apikey    := "set me"

  	// The virtual guest id you wish to create a flex image disk.
	virtualGuestId := 29857155

	// Build the template object that will be used to capture a flex image.
	captureTemplate := datatypes.Container_Disk_Image_Capture_Template {
		Description : sl.String("Description example"),
		Name        : sl.String("Image Name"),
		Summary     : sl.String("Summary example"),

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

	// Get SoftLayer_Virtual_Guest service.
  	service := services.GetVirtualGuestService(sess)

	// Capture flex image.
  	flexImage, err := service.Id(virtualGuestId).CaptureImage(&captureTemplate)
	if err != nil {
		fmt.Printf("\n Unable to create Flex Image:\n - %s\n", err)

	// Following creates a JSON object which is based on data of the captured image.
  	jsonFormat, JsonErr := json.MarshalIndent(flexImage,"","     ")
	if JsonErr != nil {

	// Print result in JSON format


If this article contains any error, or leaves any of your questions unanswered, please help us out by opening up a github issue.
Open an issue