Skip to content

Commit

Permalink
implement vfs with openstack swift
Browse files Browse the repository at this point in the history
  • Loading branch information
zengchen1024 committed Oct 31, 2017
1 parent c1c1d6b commit ce6ef6a
Show file tree
Hide file tree
Showing 2 changed files with 484 additions and 0 deletions.
28 changes: 28 additions & 0 deletions util/pkg/vfs/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package vfs
import (
"fmt"
"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 @@ -42,6 +43,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 @@ -112,6 +115,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 @@ -309,3 +316,24 @@ 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)
}

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

return NewSwiftPath(c.swiftClient, strings.TrimSuffix(u.Host, "/"), u.Path)
}
Loading

0 comments on commit ce6ef6a

Please sign in to comment.