Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement vfs with openstack swift #3708

Merged
merged 1 commit into from
Nov 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions util/pkg/vfs/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"time"

"github.com/golang/glog"
"github.com/gophercloud/gophercloud"
"golang.org/x/net/context"
"golang.org/x/oauth2/google"
storage "google.golang.org/api/storage/v1"
Expand All @@ -43,6 +44,8 @@ type VFSContext struct {
mutex sync.Mutex
// The google cloud storage client, if initialized
gcsClient *storage.Service
// swiftClient is the openstack swift client
swiftClient *gophercloud.ServiceClient
}

var Context = VFSContext{
Expand Down Expand Up @@ -113,6 +116,10 @@ func (c *VFSContext) BuildVfsPath(p string) (Path, error) {
return c.buildKubernetesPath(p)
}

if strings.HasPrefix(p, "swift://") {
return c.buildOpenstackSwiftPath(p)
}

return nil, fmt.Errorf("unknown / unhandled path type: %q", p)
}

Expand Down Expand Up @@ -310,3 +317,29 @@ func (c *VFSContext) getGCSClient() (*storage.Service, error) {
c.gcsClient = gcsClient
return gcsClient, nil
}

func (c *VFSContext) buildOpenstackSwiftPath(p string) (*SwiftPath, error) {
u, err := url.Parse(p)
if err != nil {
return nil, fmt.Errorf("invalid openstack cloud storage path: %q", p)
}

if u.Scheme != "swift" {
return nil, fmt.Errorf("invalid openstack cloud storage path: %q", p)
}

bucket := strings.TrimSuffix(u.Host, "/")
if bucket == "" {
return nil, fmt.Errorf("invalid swift path: %q", p)
}

if c.swiftClient == nil {
swiftClient, err := NewSwiftClient()
if err != nil {
return nil, err
}
c.swiftClient = swiftClient
}

return NewSwiftPath(c.swiftClient, bucket, u.Path)
}
Loading