Skip to content

Commit

Permalink
Merge pull request #18 from dell/feature/replication
Browse files Browse the repository at this point in the history
CSM Replication Support For PowerScale
  • Loading branch information
bpjain2004 authored Jan 31, 2022
2 parents d2ec147 + 67f809d commit bf7e8c0
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
63 changes: 63 additions & 0 deletions api/v11/api_v11_replication.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package v11

import (
"context"
"fmt"
"github.com/dell/goisilon/api"
)

const (
policiesPath = "/platform/11/sync/policies/"
)

// Policy contains the CloudIQ policy info.
type Policy struct {
Action string `json:"action,omitempty"`
Id string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Enabled bool `json:"enabled,omitempty"`
TargetPath string `json:"target_path,omitempty"`
SourcePath string `json:"source_root_path,omitempty"`
TargetHost string `json:"target_host,omitempty"`
JobDelay int `json:"job_delay,omitempty"`
Schedule string `json:"schedule,omitempty"`
}

type Policies struct {
Policy []Policy `json:"policies,omitempty"`
}

// GetPolicyByName returns policy by name
func GetPolicyByName(
ctx context.Context,
client api.Client, name string) (policy *Policy, err error) {
p := &Policies{}
err = client.Get(ctx, policiesPath, name, nil, nil, &p)
if err != nil {
return nil, err
} else if len(p.Policy) == 0 {
return nil, fmt.Errorf("successful code returned, but policy %s not found", name)
}
return &p.Policy[0], nil
}

func CreatePolicy(ctx context.Context, client api.Client, name string, sourcePath string, targetPath string, targetHost string, rpo int) error {
resp := ""
body := &Policy{
Action: "sync",
Id: "",
Name: name,
Enabled: true,
TargetPath: targetPath,
SourcePath: sourcePath,
TargetHost: targetHost,
JobDelay: rpo,
Schedule: "when-source-modified",
}
return client.Post(ctx, policiesPath, "", nil, nil, body, resp)
}

func DeletePolicy(ctx context.Context, client api.Client, name string) error {
resp := ""
return client.Delete(ctx, policiesPath, name, nil, nil, &resp)
}
22 changes: 22 additions & 0 deletions replication.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package goisilon

import (
"context"
apiv11 "github.com/dell/goisilon/api/v11"
)

// Policy is an Isilon Policy
type Policy *apiv11.Policy

// GetPolicyByName returns a policy with the provided ID.
func (c *Client) GetPolicyByName(ctx context.Context, id string) (Policy, error) {
return apiv11.GetPolicyByName(ctx,c.API,id)
}

func (c *Client) CreatePolicy(ctx context.Context, name string, rpo int, sourcePath string, targetPath string, targetHost string) error{
return apiv11.CreatePolicy(ctx,c.API,name,sourcePath,targetPath,targetHost,rpo)
}

func (c *Client) DeletePolicy(ctx context.Context, name string) error{
return apiv11.DeletePolicy(ctx,c.API,name)
}

0 comments on commit bf7e8c0

Please sign in to comment.