|
4 | 4 | "context" |
5 | 5 | "errors" |
6 | 6 | "fmt" |
7 | | - "time" |
8 | 7 |
|
9 | 8 | "github.com/mitchellh/mapstructure" |
10 | 9 | ) |
@@ -66,91 +65,24 @@ func (c *Sys) Unmount(path string) error { |
66 | 65 | return err |
67 | 66 | } |
68 | 67 |
|
69 | | -// Remount kicks off a remount operation, polls the status endpoint using |
70 | | -// the migration ID till either success or failure state is observed |
71 | 68 | func (c *Sys) Remount(from, to string) error { |
72 | | - remountResp, err := c.StartRemount(from, to) |
73 | | - if err != nil { |
74 | | - return err |
75 | | - } |
76 | | - |
77 | | - for { |
78 | | - remountStatusResp, err := c.RemountStatus(remountResp.MigrationID) |
79 | | - if err != nil { |
80 | | - return err |
81 | | - } |
82 | | - if remountStatusResp.MigrationInfo.MigrationStatus == "success" { |
83 | | - return nil |
84 | | - } |
85 | | - if remountStatusResp.MigrationInfo.MigrationStatus == "failure" { |
86 | | - return fmt.Errorf("Failure! Error encountered moving mount %s to %s, with migration ID %s", from, to, remountResp.MigrationID) |
87 | | - } |
88 | | - time.Sleep(1 * time.Second) |
89 | | - } |
90 | | -} |
91 | | - |
92 | | -// StartRemount kicks off a mount migration and returns a response with the migration ID |
93 | | -func (c *Sys) StartRemount(from, to string) (*MountMigrationOutput, error) { |
94 | 69 | body := map[string]interface{}{ |
95 | 70 | "from": from, |
96 | 71 | "to": to, |
97 | 72 | } |
98 | 73 |
|
99 | 74 | r := c.c.NewRequest("POST", "/v1/sys/remount") |
100 | 75 | if err := r.SetJSONBody(body); err != nil { |
101 | | - return nil, err |
| 76 | + return err |
102 | 77 | } |
103 | 78 |
|
104 | 79 | ctx, cancelFunc := context.WithCancel(context.Background()) |
105 | 80 | defer cancelFunc() |
106 | 81 | resp, err := c.c.RawRequestWithContext(ctx, r) |
107 | | - if err != nil { |
108 | | - return nil, err |
109 | | - } |
110 | | - defer resp.Body.Close() |
111 | | - secret, err := ParseSecret(resp.Body) |
112 | | - if err != nil { |
113 | | - return nil, err |
114 | | - } |
115 | | - if secret == nil || secret.Data == nil { |
116 | | - return nil, errors.New("data from server response is empty") |
117 | | - } |
118 | | - |
119 | | - var result MountMigrationOutput |
120 | | - err = mapstructure.Decode(secret.Data, &result) |
121 | | - if err != nil { |
122 | | - return nil, err |
123 | | - } |
124 | | - |
125 | | - return &result, err |
126 | | -} |
127 | | - |
128 | | -// RemountStatus checks the status of a mount migration operation with the provided ID |
129 | | -func (c *Sys) RemountStatus(migrationID string) (*MountMigrationStatusOutput, error) { |
130 | | - r := c.c.NewRequest("GET", fmt.Sprintf("/v1/sys/remount/status/%s", migrationID)) |
131 | | - |
132 | | - ctx, cancelFunc := context.WithCancel(context.Background()) |
133 | | - defer cancelFunc() |
134 | | - resp, err := c.c.RawRequestWithContext(ctx, r) |
135 | | - if err != nil { |
136 | | - return nil, err |
137 | | - } |
138 | | - defer resp.Body.Close() |
139 | | - secret, err := ParseSecret(resp.Body) |
140 | | - if err != nil { |
141 | | - return nil, err |
142 | | - } |
143 | | - if secret == nil || secret.Data == nil { |
144 | | - return nil, errors.New("data from server response is empty") |
145 | | - } |
146 | | - |
147 | | - var result MountMigrationStatusOutput |
148 | | - err = mapstructure.Decode(secret.Data, &result) |
149 | | - if err != nil { |
150 | | - return nil, err |
| 82 | + if err == nil { |
| 83 | + defer resp.Body.Close() |
151 | 84 | } |
152 | | - |
153 | | - return &result, err |
| 85 | + return err |
154 | 86 | } |
155 | 87 |
|
156 | 88 | func (c *Sys) TuneMount(path string, config MountConfigInput) error { |
@@ -255,18 +187,3 @@ type MountConfigOutput struct { |
255 | 187 | // Deprecated: This field will always be blank for newer server responses. |
256 | 188 | PluginName string `json:"plugin_name,omitempty" mapstructure:"plugin_name"` |
257 | 189 | } |
258 | | - |
259 | | -type MountMigrationOutput struct { |
260 | | - MigrationID string `mapstructure:"migration_id"` |
261 | | -} |
262 | | - |
263 | | -type MountMigrationStatusOutput struct { |
264 | | - MigrationID string `mapstructure:"migration_id"` |
265 | | - MigrationInfo *MountMigrationStatusInfo `mapstructure:"migration_info"` |
266 | | -} |
267 | | - |
268 | | -type MountMigrationStatusInfo struct { |
269 | | - SourceMount string `mapstructure:"source_mount"` |
270 | | - TargetMount string `mapstructure:"target_mount"` |
271 | | - MigrationStatus string `mapstructure:"status"` |
272 | | -} |
0 commit comments