This repository was archived by the owner on Jun 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from imikushin/attach
Attach managed volumes to the host before starting container
- Loading branch information
Showing
6 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// +build linux freebsd solaris openbsd darwin | ||
|
||
package storage | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"github.com/Sirupsen/logrus" | ||
"github.com/docker/go-connections/sockets" | ||
"github.com/pkg/errors" | ||
"github.com/rancher/agent/model" | ||
"net/http" | ||
) | ||
|
||
func callRancherStorageVolumeAttach(volume model.Volume) error { | ||
transport := new(http.Transport) | ||
sockets.ConfigureTransport(transport, "unix", rancherStorageSockPath(volume)) | ||
client := &http.Client{ | ||
Transport: transport, | ||
} | ||
url := "http://volume-plugin/VolumeDriver.Attach" | ||
|
||
bs, err := json.Marshal(struct{ Name string }{Name: volume.Name}) | ||
if err != nil { | ||
return errors.Wrap(err, "Failed to marshal JSON") | ||
} | ||
|
||
driver := volume.Data.Fields.Driver | ||
resp, err := client.Post(url, "application/json", bytes.NewReader(bs)) | ||
if err != nil { | ||
logrus.Errorf("Failed to call /VolumeDriver.Attach '%s' (driver '%s'): %s", volume.Name, driver, err) | ||
return err | ||
} | ||
defer resp.Body.Close() | ||
|
||
switch { | ||
case resp.StatusCode >= 200 && resp.StatusCode < 300: | ||
logrus.Infof("Success: /VolumeDriver.Attach '%s' (driver '%s')", volume.Name, driver) | ||
case resp.StatusCode >= 400 && resp.StatusCode < 500: | ||
logrus.Infof("/VolumeDriver.Attach '%s' is not supported by driver '%s'", volume.Name, driver) | ||
default: | ||
return errors.Errorf("/VolumeDriver.Attach '%s' (driver '%s') returned status %v: %s", volume.Name, driver, resp.StatusCode, resp.Status) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package storage | ||
|
||
// callRancherStorageVolumeAttach is not supported on windows | ||
func callRancherStorageVolumeAttach(volume model.Volume) error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters