github.com/gophercloud/gophercloud@v1.11.0/openstack/compute/v2/extensions/migrate/requests.go (about)

     1  package migrate
     2  
     3  import (
     4  	"github.com/gophercloud/gophercloud"
     5  	"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions"
     6  )
     7  
     8  // Migrate will initiate a migration of the instance to another host.
     9  func Migrate(client *gophercloud.ServiceClient, id string) (r MigrateResult) {
    10  	resp, err := client.Post(extensions.ActionURL(client, id), map[string]interface{}{"migrate": nil}, nil, nil)
    11  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
    12  	return
    13  }
    14  
    15  // LiveMigrateOptsBuilder allows extensions to add additional parameters to the
    16  // LiveMigrate request.
    17  type LiveMigrateOptsBuilder interface {
    18  	ToLiveMigrateMap() (map[string]interface{}, error)
    19  }
    20  
    21  // LiveMigrateOpts specifies parameters of live migrate action.
    22  type LiveMigrateOpts struct {
    23  	// The host to which to migrate the server.
    24  	// If this parameter is None, the scheduler chooses a host.
    25  	Host *string `json:"host"`
    26  
    27  	// Set to True to migrate local disks by using block migration.
    28  	// If the source or destination host uses shared storage and you set
    29  	// this value to True, the live migration fails.
    30  	BlockMigration *bool `json:"block_migration,omitempty"`
    31  
    32  	// Set to True to enable over commit when the destination host is checked
    33  	// for available disk space. Set to False to disable over commit. This setting
    34  	// affects only the libvirt virt driver.
    35  	DiskOverCommit *bool `json:"disk_over_commit,omitempty"`
    36  }
    37  
    38  // ToLiveMigrateMap constructs a request body from LiveMigrateOpts.
    39  func (opts LiveMigrateOpts) ToLiveMigrateMap() (map[string]interface{}, error) {
    40  	return gophercloud.BuildRequestBody(opts, "os-migrateLive")
    41  }
    42  
    43  // LiveMigrate will initiate a live-migration (without rebooting) of the instance to another host.
    44  func LiveMigrate(client *gophercloud.ServiceClient, id string, opts LiveMigrateOptsBuilder) (r MigrateResult) {
    45  	b, err := opts.ToLiveMigrateMap()
    46  	if err != nil {
    47  		r.Err = err
    48  		return
    49  	}
    50  	resp, err := client.Post(extensions.ActionURL(client, id), b, nil, nil)
    51  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
    52  	return
    53  }