MCPcopy
hub / github.com/lxc/incus / proxyMigration

Method proxyMigration

client/incus_instances.go:3111–3194  ·  view source on GitHub ↗
(targetOp *operation, targetSecrets map[string]string, source InstanceServer, sourceOp *operation, sourceSecrets map[string]string)

Source from the content-addressed store, hash-verified

3109}
3110
3111func (r *ProtocolIncus) proxyMigration(targetOp *operation, targetSecrets map[string]string, source InstanceServer, sourceOp *operation, sourceSecrets map[string]string) error {
3112 // Quick checks.
3113 for n := range targetSecrets {
3114 _, ok := sourceSecrets[n]
3115 if !ok {
3116 return fmt.Errorf("Migration target expects the \"%s\" socket but source isn't providing it", n)
3117 }
3118 }
3119
3120 if targetSecrets[api.SecretNameControl] == "" {
3121 return errors.New("Migration target didn't setup the required \"control\" socket")
3122 }
3123
3124 // Struct used to hold everything together
3125 type proxy struct {
3126 done chan struct{}
3127 sourceConn *websocket.Conn
3128 targetConn *websocket.Conn
3129 }
3130
3131 proxies := map[string]*proxy{}
3132
3133 // Connect the control socket
3134 sourceConn, err := source.GetOperationWebsocket(sourceOp.ID, sourceSecrets[api.SecretNameControl])
3135 if err != nil {
3136 return err
3137 }
3138
3139 targetConn, err := r.GetOperationWebsocket(targetOp.ID, targetSecrets[api.SecretNameControl])
3140 if err != nil {
3141 return err
3142 }
3143
3144 proxies[api.SecretNameControl] = &proxy{
3145 done: ws.Proxy(sourceConn, targetConn),
3146 sourceConn: sourceConn,
3147 targetConn: targetConn,
3148 }
3149
3150 // Connect the data sockets
3151 for name := range sourceSecrets {
3152 if name == api.SecretNameControl {
3153 continue
3154 }
3155
3156 // Handle resets (used for multiple objects)
3157 sourceConn, err := source.GetOperationWebsocket(sourceOp.ID, sourceSecrets[name])
3158 if err != nil {
3159 break
3160 }
3161
3162 targetConn, err := r.GetOperationWebsocket(targetOp.ID, targetSecrets[name])
3163 if err != nil {
3164 break
3165 }
3166
3167 proxies[name] = &proxy{
3168 sourceConn: sourceConn,

Callers 3

CopyStoragePoolVolumeMethod · 0.95
CopyInstanceMethod · 0.95
CopyInstanceSnapshotMethod · 0.95

Calls 5

GetOperationWebsocketMethod · 0.95
ProxyFunction · 0.92
ErrorfMethod · 0.80
GetOperationWebsocketMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected