github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/compute/v2/extensions/migrate/requests.go (about)

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