Skip to content
Open
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
31 changes: 25 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ variables to configure the GoIsilon client:
#### Environment Variables
Name | Description
---- | -----------
`GOISILON_ENDPOINT` | the API endpoint, ex. `https://172.17.177.230:8080`
`GOISILON_USERNAME` | the username
`GOISILON_GROUP` | the user's group
`GOISILON_PASSWORD` | the password
`GOISILON_INSECURE` | whether to skip SSL validation
`GOISILON_VOLUMEPATH` | which base path to use when looking for volume directories
`GOISILON_ENDPOINT` | the API endpoint, ex. `https://172.17.177.230:8080`
`GOISILON_USERNAME` | the username
`GOISILON_GROUP` | the user's group
`GOISILON_PASSWORD` | the password
`GOISILON_INSECURE` | whether to skip SSL validation
`GOISILON_VOLUMEPATH` | which filesystem base path to use when looking for volume directories
`GOISILON_ACCESSPATH` | (optional) URL base path to volume directories including access point. Defaults to `GOISILON_VOLUMEPATH` if not specified.

### Initialize a new client with options
The following example demonstrates how to explicitly specify options when
Expand All @@ -51,12 +52,30 @@ client, err := NewClientWithArgs(
"userName",
"password",
true,
"",
"/ifs/volumes")
if err != nil {
panic(err)
}
```

Another example with Access Point, for users with limited permissions:

```go
client, err := NewClientWithArgs(
context.Background(),
"https://172.17.177.230:8080",
"groupName",
"userName",
"password",
true,
"/user1_access_point",
"/ifs/data/user1_volumes")
if err != nil {
panic(err)
}
```

### Create a Volume
This snippet creates a new volume named "testing" at "/ifs/volumes/loremipsum".
The volume path is generated by concatenating the client's volume path and the
Expand Down
27 changes: 27 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,15 @@ type Client interface {
// Group returns the group name used to access the OneFS API.
Group() string

// VolumesAccessPath returns the client's configured volumes URL path.
VolumesAccessPath() string

// VolumesPath returns the client's configured volumes path.
VolumesPath() string

// VolumeAccessPath returns the URL path to a volume with the provided name
VolumeAccessPath(name string) string

// VolumePath returns the path to a volume with the provided name.
VolumePath(name string) string
}
Expand All @@ -100,6 +106,7 @@ type client struct {
auth string
user string
grup string
vola string
volp string
apiv uint8
}
Expand All @@ -126,6 +133,10 @@ type ClientOptions struct {
// Insecure is a flag that indicates whether or not to supress SSL errors.
Insecure bool

// VolumesAccessPath is the URL location on the Isilon server where volumes
// are stored.
VolumesAccessPath string

// VolumesPath is the location on the Isilon server where volumes are
// stored.
VolumesPath string
Expand All @@ -149,6 +160,7 @@ func New(
user: user,
grup: group,
auth: fmtAuthHeaderVal(user, pass),
vola: defaultVolumesPath,
volp: defaultVolumesPath,
}

Expand All @@ -158,6 +170,13 @@ func New(
if opts.VolumesPath != "" {
c.volp = opts.VolumesPath
}
// If VolumesAccessPath is not set, fall back to VolumesPath for
// backward compatibility (make sure VolumesAccessPath is optional).
if opts.VolumesAccessPath != "" {
c.vola = opts.VolumesAccessPath
} else {
c.vola = c.volp
}

if opts.Timeout != 0 {
c.http.Timeout = opts.Timeout
Expand Down Expand Up @@ -467,6 +486,14 @@ func (c *client) Group() string {
return c.grup
}

func (c *client) VolumesAccessPath() string {
return c.vola
}

func (c *client) VolumeAccessPath(volumeName string) string {
return path.Join(c.vola, volumeName)
}

func (c *client) VolumesPath() string {
return c.volp
}
Expand Down
10 changes: 4 additions & 6 deletions api/v1/api_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"os"
"path"
"strconv"
"strings"

"github.com/thecodeteam/goisilon/api"
)
Expand All @@ -14,22 +13,21 @@ const (
exportsPath = "platform/1/protocols/nfs/exports"
quotaPath = "platform/1/quota/quotas"
snapshotsPath = "platform/1/snapshot/snapshots"
volumesnapshotsPath = "/ifs/.snapshot"
volumesnapshotsPath = ".snapshot"
)

var (
debug, _ = strconv.ParseBool(os.Getenv("GOISILON_DEBUG"))
)

func realNamespacePath(client api.Client) string {
return path.Join(namespacePath, client.VolumesPath())
return path.Join(namespacePath, client.VolumesAccessPath())
}

func realexportsPath(client api.Client) string {
return path.Join(exportsPath, client.VolumesPath())
return path.Join(exportsPath, client.VolumesAccessPath())
}

func realVolumeSnapshotPath(client api.Client, name string) string {
parts := strings.SplitN(realNamespacePath(client), "/ifs/", 2)
return path.Join(parts[0], volumesnapshotsPath, name, parts[1])
return path.Join(realNamespacePath(client), volumesnapshotsPath, name)
}
10 changes: 4 additions & 6 deletions api/v2/api_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"os"
"path"
"strconv"
"strings"

"github.com/thecodeteam/goisilon/api"
)
Expand All @@ -14,7 +13,7 @@ const (
exportsPath = "platform/2/protocols/nfs/exports"
quotaPath = "platform/2/quota/quotas"
snapshotsPath = "platform/2/snapshot/snapshots"
volumeSnapshotsPath = "/ifs/.snapshot"
volumeSnapshotsPath = ".snapshot"
)

var (
Expand All @@ -23,14 +22,13 @@ var (
)

func realNamespacePath(c api.Client) string {
return path.Join(namespacePath, c.VolumesPath())
return path.Join(namespacePath, c.VolumesAccessPath())
}

func realExportsPath(c api.Client) string {
return path.Join(exportsPath, c.VolumesPath())
return path.Join(exportsPath, c.VolumesAccessPath())
}

func realVolumeSnapshotPath(c api.Client, name string) string {
parts := strings.SplitN(realNamespacePath(c), "/ifs/", 2)
return path.Join(parts[0], volumeSnapshotsPath, name, parts[1])
return path.Join(realNamespacePath(c), volumeSnapshotsPath, name)
}
2 changes: 1 addition & 1 deletion api/v2/api_v2_acls.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"strconv"
"strings"

"github.com/thecodeteam/goisilon/api"
"context"
"github.com/thecodeteam/goisilon/api"
)

// AuthoritativeType is a possible value used with an ACL's Authoritative field.
Expand Down
2 changes: 1 addition & 1 deletion api/v2/api_v2_fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"strings"
"sync"

"github.com/thecodeteam/goisilon/api"
"context"
"github.com/thecodeteam/goisilon/api"
)

// ContainerChild is a child object of a container.
Expand Down
11 changes: 7 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,26 @@ func NewClient(ctx context.Context) (*Client, error) {
os.Getenv("GOISILON_USERNAME"),
os.Getenv("GOISILON_GROUP"),
os.Getenv("GOISILON_PASSWORD"),
os.Getenv("GOISILON_ACCESSPATH"),
os.Getenv("GOISILON_VOLUMEPATH"))
}

func NewClientWithArgs(
ctx context.Context,
endpoint string,
insecure bool,
user, group, pass, volumesPath string) (*Client, error) {
user, group, pass,
volumesAccessPath string, volumesPath string) (*Client, error) {

timeout, _ := time.ParseDuration(os.Getenv("GOISILON_TIMEOUT"))

client, err := api.New(
ctx, endpoint, user, pass, group,
&api.ClientOptions{
Insecure: insecure,
VolumesPath: volumesPath,
Timeout: timeout,
Insecure: insecure,
VolumesAccessPath: volumesAccessPath,
VolumesPath: volumesPath,
Timeout: timeout,
})
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions goisilon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"os"
"testing"

"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
log "github.com/akutz/gournal"
glogrus "github.com/akutz/gournal/logrus"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (c *Client) ForceDeleteVolume(ctx context.Context, name string) error {

var (
user = c.API.User()
vpl = len(c.API.VolumesPath()) + 1
vpl = len(c.API.VolumesAccessPath()) + 1
errs = make(chan error)
queryDone = make(chan int)
childPaths = make(chan string)
Expand Down