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

Fixing Json Parsing Issue #2550

Merged
merged 5 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
14 changes: 7 additions & 7 deletions drivers/pure/flasharray/fa.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func NewClient(mgmtIp string, apiToken string, userName string, password string,
requestKwargs := setDefaultRequestKwargs(kwargs, verifyHTTPS, sslCert)
c.Kwargs = requestKwargs

authToken, err := c.getAuthToken()
authToken, err := c.getAuthToken(restVersion)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -120,7 +120,7 @@ func (c *Client) login() error {
return nil
}

func (c *Client) Do(req *http.Request, v interface{}, reestablishSession bool) (*http.Response, error) {
func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error) {
log.Infof("\nRequest [%v]\n", req)
resp, err := c.client.Do(req)
if err != nil {
Expand All @@ -139,10 +139,10 @@ func (c *Client) Do(req *http.Request, v interface{}, reestablishSession bool) (
bodyBytes, _ := ioutil.ReadAll(resp.Body)
bodyString := string(bodyBytes)
err = json.Unmarshal([]byte(fmt.Sprintf("[%v]", bodyString)), v)

if err != nil {
return nil, err
}

return resp, nil

}
Expand All @@ -155,7 +155,6 @@ func (c *Client) NewRequest(method string, path string, params map[string]string
} else {
fpath = c.formatPath(path, false)
}

bodyReader := bytes.NewReader([]byte{})
baseURL, err := url.Parse(fpath)
if err != nil {
Expand Down Expand Up @@ -207,9 +206,9 @@ func (c *Client) NewGetRequests(path string, params map[string]string, data inte
return httpRequest, nil
}

func (c *Client) getAuthToken() (string, error) {
func (c *Client) getAuthToken(restVersion string) (string, error) {

authURL, err := url.Parse(c.formatPath("api/login", true))
authURL, err := url.Parse(c.formatPath(fmt.Sprintf("api/%v/login", restVersion), true))
if err != nil {
return "", err
}
Expand All @@ -220,12 +219,13 @@ func (c *Client) getAuthToken() (string, error) {
if err != nil {
return "", err
}

log.Infof("API Token [%v]", c.ApiToken)

request.Header.Add("Content-Type", "application/json")
request.Header.Add("api-token", c.ApiToken)

log.Infof(fmt.Sprintf("API Token [%v]", c.ApiToken))

tempClient := &http.Client{
// http.Client doesn't set the default Timeout,
// so it will be blocked forever without Timeout setting
Expand Down
114 changes: 63 additions & 51 deletions drivers/pure/flasharray/volumeTypes.go
Original file line number Diff line number Diff line change
@@ -1,70 +1,82 @@
package flasharray

type PriorityAdjustment struct {
PriorityAdjustmentOperator string `json:"priority_adjustment_operator"`
PriorityAdjustmentValue int `json:"priority_adjustment_value"`
type Space struct {
DataReduction float64 `json:"data_reduction"`
Shared *string `json:"shared"`
Snapshots int `json:"snapshots"`
System *string `json:"system"`
ThinProvisioning float64 `json:"thin_provisioning"`
TotalPhysical int64 `json:"total_physical"`
TotalProvisioned int64 `json:"total_provisioned"`
TotalReduction float64 `json:"total_reduction"`
Unique int64 `json:"unique"`
Virtual int64 `json:"virtual"`
}

type Space struct {
DataReduction int `json:"data_reduction"`
Shared int64 `json:"shared"`
Snapshots int `json:"snapshots"`
System int `json:"system"`
ThinProvisioning int `json:"thin_provisioning"`
TotalPhysical int `json:"total_physical"`
TotalProvisioned int64 `json:"total_provisioned"`
TotalReduction int `json:"total_reduction"`
Unique int `json:"unique"`
Virtual int `json:"virtual"`
UsedProvisioned int64 `json:"used_provisioned"`
TotalUsed int `json:"total_used"`
SnapshotsEffective int `json:"snapshots_effective"`
UniqueEffective int `json:"unique_effective"`
TotalEffective int `json:"total_effective"`
type Source struct {
Name *string `json:"name"`
ID *string `json:"id"`
}

type Pod struct {
Id string `json:"id"`
Name string `json:"name"`
Name *string `json:"name"`
ID *string `json:"id"`
}

type Source struct {
Id string `json:"id"`
Name string `json:"name"`
type QoS struct {
BandwidthLimit *string `json:"bandwidth_limit"`
IopsLimit *string `json:"iops_limit"`
}

type VolumeGroup struct {
Id string `json:"id"`
Name string `json:"name"`
Name *string `json:"name"`
ID *string `json:"id"`
}

type Qos struct {
BandwidthLimit int `json:"bandwidth_limit"`
IopsLimit int `json:"iops_limit"`
type Item struct {
Space Space `json:"space"`
ConnectionCount int `json:"connection_count"`
Provisioned int64 `json:"provisioned"`
Created int64 `json:"created"`
Source Source `json:"source"`
Name string `json:"name"`
ID string `json:"id"`
Serial string `json:"serial"`
Destroyed bool `json:"destroyed"`
TimeRemaining *string `json:"time_remaining"`
HostEncryptionKeyStatus string `json:"host_encryption_key_status"`
RequestedPromotionState string `json:"requested_promotion_state"`
PromotionStatus string `json:"promotion_status"`
Pod Pod `json:"pod"`
QoS QoS `json:"qos"`
Subtype string `json:"subtype"`
VolumeGroup VolumeGroup `json:"volume_group"`
}

type VolItems struct {
Id string `json:"id"`
Name string `json:"name"`
ConnectionCount int `json:"connection_count"`
Created int `json:"created"`
Destroyed bool `json:"destroyed"`
HostEncryptionKeyStatus string `json:"host_encryption_key_status"`
Provisioned int `json:"provisioned"`
Qos *Qos `json:"qos"`
PriorityAdjustment *PriorityAdjustment `json:"priority_adjustment"`
Serial string `json:"serial"`
Space *Space `json:"space"`
TimeRemaining int `json:"time_remaining"`
Pod *Pod `json:"pod"`
Source *Source `json:"source"`
Subtype string `json:"subtype"`
VolumeGroup *VolumeGroup `json:"volume_group"`
RequestedPromotionState string `json:"requested_promotion_state"`
PromotionStatus string `json:"promotion_status"`
Priority int `json:"priority"`
type Total struct {
Space Space `json:"space"`
ConnectionCount *int `json:"connection_count"`
Provisioned int64 `json:"provisioned"`
Created *int64 `json:"created"`
Source Source `json:"source"`
Name *string `json:"name"`
ID *string `json:"id"`
Serial *string `json:"serial"`
Destroyed *bool `json:"destroyed"`
TimeRemaining *string `json:"time_remaining"`
HostEncryptionKeyStatus *string `json:"host_encryption_key_status"`
RequestedPromotionState *string `json:"requested_promotion_state"`
PromotionStatus *string `json:"promotion_status"`
Pod Pod `json:"pod"`
QoS QoS `json:"qos"`
Subtype *string `json:"subtype"`
VolumeGroup VolumeGroup `json:"volume_group"`
}

type Volumes struct {
Volumes []Volumes `json:"total"`
type VolResponse struct {
ContinuationToken *string `json:"continuation_token"`
Items []Item `json:"items"`
MoreItemsRemaining bool `json:"more_items_remaining"`
Total []Total `json:"total"`
TotalItemCount *int `json:"total_item_count"`
}
23 changes: 4 additions & 19 deletions drivers/pure/flasharray/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,13 @@ type VolumeServices struct {
client *Client
}

func (fs *VolumeServices) ListAllAvailableVolumes(params map[string]string, data interface{}) ([]Volumes, error) {
params["destroyed"] = "false"
req, err := fs.client.NewRequest("GET", "volumes", params, data)
func (vols *VolumeServices) ListAllAvailableVolumes(params map[string]string, data interface{}) ([]VolResponse, error) {
req, err := vols.client.NewRequest("GET", "volumes", params, data)
vprabhakar-px marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, err
}
m := []Volumes{}
_, err = fs.client.Do(req, &m, true)
if err != nil {
return nil, err
}
return m, nil
}

func (fs *VolumeServices) ListAllDestroyedVolumes(params map[string]string, data interface{}) ([]Volumes, error) {
params["destroyed"] = "true"
req, err := fs.client.NewRequest("GET", "volumes", params, data)
if err != nil {
return nil, err
}
m := []Volumes{}
_, err = fs.client.Do(req, &m, true)
m := []VolResponse{}
_, err = vols.client.Do(req, &m)
if err != nil {
return nil, err
}
Expand Down
17 changes: 10 additions & 7 deletions pkg/pureutils/purefa_rest2x.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package pureutils

import (
"github.com/devans10/pugo/flasharray"
fa "github.com/portworx/torpedo/drivers/pure/flasharray"
"github.com/portworx/torpedo/drivers/pure/flasharray"
)

const (
Expand All @@ -11,7 +10,7 @@ const (

// PureCreateClientAndConnect Create FA Client and Connect
func PureCreateClientAndConnectRest226(faMgmtEndpoint string, apiToken string) (*flasharray.Client, error) {
faClient, err := flasharray.NewClient(faMgmtEndpoint, "", "", apiToken,
faClient, err := flasharray.NewClient(faMgmtEndpoint, apiToken, "", "",
RestAPI, false, false, "", nil)
if err != nil {
return nil, err
Expand All @@ -20,17 +19,21 @@ func PureCreateClientAndConnectRest226(faMgmtEndpoint string, apiToken string) (
}

// ListAllVolumesFromFA returns list of all Available Volumes present in FA (Function should be used with RestAPI 2.x)
func ListAllVolumesFromFA(faClient *fa.Client) ([]fa.Volumes, error) {
volumes, err := faClient.Volumes.ListAllAvailableVolumes(nil, nil)
func ListAllVolumesFromFA(faClient *flasharray.Client) ([]flasharray.VolResponse, error) {
params := make(map[string]string)
params["destroyed"] = "false"
volumes, err := faClient.Volumes.ListAllAvailableVolumes(params, nil)
if err != nil {
return nil, err
}
return volumes, nil
}

// ListAllDestroyedVolumesFromFA Returns list of all Destroyed FA Volumes (Function should be used with RestAPI 2.x)
func ListAllDestroyedVolumesFromFA(faClient *fa.Client) ([]fa.Volumes, error) {
volumes, err := faClient.Volumes.ListAllDestroyedVolumes(nil, nil)
func ListAllDestroyedVolumesFromFA(faClient *flasharray.Client) ([]flasharray.VolResponse, error) {
params := make(map[string]string)
params["destroyed"] = "true"
vprabhakar-px marked this conversation as resolved.
Show resolved Hide resolved
volumes, err := faClient.Volumes.ListAllAvailableVolumes(nil, nil)
if err != nil {
return nil, err
}
Expand Down