Skip to content

Commit

Permalink
lxd/*: Make fields of migrationSinkArgs structure private
Browse files Browse the repository at this point in the history
Signed-off-by: Din Music <[email protected]>
  • Loading branch information
MusicDin committed Jul 18, 2024
1 parent b370924 commit 0291b46
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 55 deletions.
18 changes: 9 additions & 9 deletions lxd/instances_post.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,15 @@ func createFromMigration(s *state.State, r *http.Request, projectName string, pr
}

migrationArgs := migrationSinkArgs{
URL: req.Source.Operation,
Dialer: dialer,
Instance: inst,
Secrets: req.Source.Websockets,
Push: push,
Live: req.Source.Live,
InstanceOnly: instanceOnly,
ClusterMoveSourceName: clusterMoveSourceName,
Refresh: req.Source.Refresh,
url: req.Source.Operation,
dialer: dialer,
instance: inst,
secrets: req.Source.Websockets,
push: push,
live: req.Source.Live,
instanceOnly: instanceOnly,
clusterMoveSourceName: clusterMoveSourceName,
refresh: req.Source.Refresh,
}

sink, err := newMigrationSink(&migrationArgs)
Expand Down
28 changes: 14 additions & 14 deletions lxd/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,24 +193,24 @@ type migrationSink struct {
// migrationSinkArgs arguments to configure migration sink.
type migrationSinkArgs struct {
// General migration fields
Dialer *websocket.Dialer
Push bool
Secrets map[string]string
URL string

// Instance specific fields
Instance instance.Instance
InstanceOnly bool
Live bool
Refresh bool
ClusterMoveSourceName string
Snapshots []*migration.Snapshot
dialer *websocket.Dialer
push bool
secrets map[string]string
url string

// instance specific fields
instance instance.Instance
instanceOnly bool
live bool
refresh bool
clusterMoveSourceName string
snapshots []*migration.Snapshot

// Storage specific fields
VolumeOnly bool
volumeOnly bool

// Transport specific fields
RsyncFeatures []string
rsyncFeatures []string
}

// Metadata returns metadata for the migration sink.
Expand Down
20 changes: 10 additions & 10 deletions lxd/migrate_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@ func (s *migrationSourceWs) Do(state *state.State, migrateOp *operations.Operati
func newMigrationSink(args *migrationSinkArgs) (*migrationSink, error) {
sink := migrationSink{
migrationFields: migrationFields{
instance: args.Instance,
instanceOnly: args.InstanceOnly,
live: args.Live,
instance: args.instance,
instanceOnly: args.instanceOnly,
live: args.live,
},
url: args.URL,
clusterMoveSourceName: args.ClusterMoveSourceName,
push: args.Push,
refresh: args.Refresh,
url: args.url,
clusterMoveSourceName: args.clusterMoveSourceName,
push: args.push,
refresh: args.refresh,
}

secretNames := []string{api.SecretNameControl, api.SecretNameFilesystem}
Expand All @@ -186,16 +186,16 @@ func newMigrationSink(args *migrationSinkArgs) (*migrationSink, error) {
sink.conns = make(map[string]*migrationConn, len(secretNames))
for _, connName := range secretNames {
if !sink.push {
if args.Secrets[connName] == "" {
if args.secrets[connName] == "" {
return nil, fmt.Errorf("Expected %q connection secret missing from migration sink target request", connName)
}

u, err := url.Parse(fmt.Sprintf("wss://%s/websocket", strings.TrimPrefix(args.URL, "https://")))
u, err := url.Parse(fmt.Sprintf("wss://%s/websocket", strings.TrimPrefix(args.url, "https://")))
if err != nil {
return nil, fmt.Errorf("Failed parsing websocket URL for migration sink %q connection: %w", connName, err)
}

sink.conns[connName] = newMigrationConn(args.Secrets[connName], args.Dialer, u)
sink.conns[connName] = newMigrationConn(args.secrets[connName], args.dialer, u)
} else {
secret, err := shared.RandomCryptoString()
if err != nil {
Expand Down
32 changes: 16 additions & 16 deletions lxd/migrate_storage_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,27 +207,27 @@ func (s *migrationSourceWs) DoStorage(state *state.State, projectName string, po
func newStorageMigrationSink(args *migrationSinkArgs) (*migrationSink, error) {
sink := migrationSink{
migrationFields: migrationFields{
volumeOnly: args.VolumeOnly,
volumeOnly: args.volumeOnly,
},
url: args.URL,
push: args.Push,
refresh: args.Refresh,
url: args.url,
push: args.push,
refresh: args.refresh,
}

secretNames := []string{api.SecretNameControl, api.SecretNameFilesystem}
sink.conns = make(map[string]*migrationConn, len(secretNames))
for _, connName := range secretNames {
if !sink.push {
if args.Secrets[connName] == "" {
if args.secrets[connName] == "" {
return nil, fmt.Errorf("Expected %q connection secret missing from migration sink target request", connName)
}

u, err := url.Parse(fmt.Sprintf("wss://%s/websocket", strings.TrimPrefix(args.URL, "https://")))
u, err := url.Parse(fmt.Sprintf("wss://%s/websocket", strings.TrimPrefix(args.url, "https://")))
if err != nil {
return nil, fmt.Errorf("Failed parsing websocket URL for migration sink %q connection: %w", connName, err)
}

sink.conns[connName] = newMigrationConn(args.Secrets[connName], args.Dialer, u)
sink.conns[connName] = newMigrationConn(args.secrets[connName], args.dialer, u)
} else {
secret, err := shared.RandomCryptoString()
if err != nil {
Expand Down Expand Up @@ -331,15 +331,15 @@ func (c *migrationSink) DoStorage(state *state.State, projectName string, poolNa
MigrationType: respTypes[0],
TrackProgress: true,
ContentType: req.ContentType,
Refresh: args.Refresh,
VolumeOnly: args.VolumeOnly,
Refresh: args.refresh,
VolumeOnly: args.volumeOnly,
}

// A zero length Snapshots slice indicates volume only migration in
// VolumeTargetArgs. So if VoluneOnly was requested, do not populate them.
if !args.VolumeOnly {
volTargetArgs.Snapshots = make([]string, 0, len(args.Snapshots))
for _, snap := range args.Snapshots {
if !args.volumeOnly {
volTargetArgs.Snapshots = make([]string, 0, len(args.snapshots))
for _, snap := range args.snapshots {
volTargetArgs.Snapshots = append(volTargetArgs.Snapshots, *snap.Name)
}
}
Expand Down Expand Up @@ -428,10 +428,10 @@ func (c *migrationSink) DoStorage(state *state.State, projectName string, poolNa
// as part of MigrationSinkArgs below.
rsyncFeatures := respHeader.GetRsyncFeaturesSlice()
args := migrationSinkArgs{
RsyncFeatures: rsyncFeatures,
Snapshots: respHeader.Snapshots,
VolumeOnly: c.volumeOnly,
Refresh: c.refresh,
rsyncFeatures: rsyncFeatures,
snapshots: respHeader.Snapshots,
volumeOnly: c.volumeOnly,
refresh: c.refresh,
}

fsConn, err := c.conns[api.SecretNameFilesystem].WebsocketIO(context.TODO())
Expand Down
12 changes: 6 additions & 6 deletions lxd/storage_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -1221,16 +1221,16 @@ func doVolumeMigration(s *state.State, r *http.Request, requestProjectName strin
// Initialise migrationArgs, don't set the Storage property yet, this is done in DoStorage,
// to avoid this function relying on the legacy storage layer.
migrationArgs := migrationSinkArgs{
URL: req.Source.Operation,
Dialer: &websocket.Dialer{
url: req.Source.Operation,
dialer: &websocket.Dialer{
TLSClientConfig: config,
NetDialContext: shared.RFC3493Dialer,
HandshakeTimeout: time.Second * 5,
},
Secrets: req.Source.Websockets,
Push: push,
VolumeOnly: req.Source.VolumeOnly,
Refresh: req.Source.Refresh,
secrets: req.Source.Websockets,
push: push,
volumeOnly: req.Source.VolumeOnly,
refresh: req.Source.Refresh,
}

sink, err := newStorageMigrationSink(&migrationArgs)
Expand Down

0 comments on commit 0291b46

Please sign in to comment.