From ccaea30db6b873e31db45003e2e5826773fb9640 Mon Sep 17 00:00:00 2001 From: vprabhakar-px Date: Tue, 28 May 2024 23:31:54 +0530 Subject: [PATCH 1/5] Fixing Json Parsing Issue --- drivers/pure/flasharray/fa.go | 16 ++-- drivers/pure/flasharray/volumeTypes.go | 114 ++++++++++++++----------- drivers/pure/flasharray/volumes.go | 23 +---- pkg/pureutils/purefa_rest2x.go | 17 ++-- 4 files changed, 86 insertions(+), 84 deletions(-) diff --git a/drivers/pure/flasharray/fa.go b/drivers/pure/flasharray/fa.go index 938598587ba..e4be25868e9 100644 --- a/drivers/pure/flasharray/fa.go +++ b/drivers/pure/flasharray/fa.go @@ -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 } @@ -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 { @@ -139,10 +139,11 @@ 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 } - + fmt.Printf("%v", resp) return resp, nil } @@ -155,7 +156,7 @@ func (c *Client) NewRequest(method string, path string, params map[string]string } else { fpath = c.formatPath(path, false) } - + fmt.Printf("%v", fpath) bodyReader := bytes.NewReader([]byte{}) baseURL, err := url.Parse(fpath) if err != nil { @@ -207,9 +208,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 } @@ -220,12 +221,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) + fmt.Println(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 diff --git a/drivers/pure/flasharray/volumeTypes.go b/drivers/pure/flasharray/volumeTypes.go index 3488f234de2..ebf7777f8e7 100644 --- a/drivers/pure/flasharray/volumeTypes.go +++ b/drivers/pure/flasharray/volumeTypes.go @@ -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"` } diff --git a/drivers/pure/flasharray/volumes.go b/drivers/pure/flasharray/volumes.go index 084d0c5f3c2..3b9a2ccc7f9 100644 --- a/drivers/pure/flasharray/volumes.go +++ b/drivers/pure/flasharray/volumes.go @@ -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) 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 } diff --git a/pkg/pureutils/purefa_rest2x.go b/pkg/pureutils/purefa_rest2x.go index 90a8cf107cc..b11d72a9ff2 100644 --- a/pkg/pureutils/purefa_rest2x.go +++ b/pkg/pureutils/purefa_rest2x.go @@ -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 ( @@ -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 @@ -20,8 +19,10 @@ 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 } @@ -29,8 +30,10 @@ func ListAllVolumesFromFA(faClient *fa.Client) ([]fa.Volumes, error) { } // 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" + volumes, err := faClient.Volumes.ListAllAvailableVolumes(nil, nil) if err != nil { return nil, err } From 76beb5c7b63c10e5228298eea4d4c655df044acd Mon Sep 17 00:00:00 2001 From: vprabhakar-px Date: Tue, 28 May 2024 23:36:41 +0530 Subject: [PATCH 2/5] Fixing Json Parsing Issue --- drivers/pure/flasharray/fa.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/pure/flasharray/fa.go b/drivers/pure/flasharray/fa.go index e4be25868e9..5bb3ade5383 100644 --- a/drivers/pure/flasharray/fa.go +++ b/drivers/pure/flasharray/fa.go @@ -143,7 +143,6 @@ func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error) { if err != nil { return nil, err } - fmt.Printf("%v", resp) return resp, nil } @@ -156,7 +155,6 @@ func (c *Client) NewRequest(method string, path string, params map[string]string } else { fpath = c.formatPath(path, false) } - fmt.Printf("%v", fpath) bodyReader := bytes.NewReader([]byte{}) baseURL, err := url.Parse(fpath) if err != nil { From 98e2291bcb4ec1be37a1130298bf91277f241fa8 Mon Sep 17 00:00:00 2001 From: vprabhakar-px Date: Tue, 28 May 2024 23:37:11 +0530 Subject: [PATCH 3/5] Fixing Json Parsing Issue --- drivers/pure/flasharray/fa.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pure/flasharray/fa.go b/drivers/pure/flasharray/fa.go index 5bb3ade5383..acc256c3b21 100644 --- a/drivers/pure/flasharray/fa.go +++ b/drivers/pure/flasharray/fa.go @@ -224,7 +224,7 @@ func (c *Client) getAuthToken(restVersion string) (string, error) { request.Header.Add("Content-Type", "application/json") request.Header.Add("api-token", c.ApiToken) - fmt.Println(fmt.Sprintf("API Token [%v]", c.ApiToken)) + log.Infof(fmt.Sprintf("API Token [%v]", c.ApiToken)) tempClient := &http.Client{ // http.Client doesn't set the default Timeout, From b5908cab6978b67c03ac8b4fe898bffbdcd27c12 Mon Sep 17 00:00:00 2001 From: vprabhakar-px Date: Tue, 28 May 2024 23:45:17 +0530 Subject: [PATCH 4/5] Fixing Json Parsing Issue --- pkg/pureutils/purefa_rest2x.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/pureutils/purefa_rest2x.go b/pkg/pureutils/purefa_rest2x.go index b11d72a9ff2..a19094a08fe 100644 --- a/pkg/pureutils/purefa_rest2x.go +++ b/pkg/pureutils/purefa_rest2x.go @@ -33,7 +33,7 @@ func ListAllVolumesFromFA(faClient *flasharray.Client) ([]flasharray.VolResponse func ListAllDestroyedVolumesFromFA(faClient *flasharray.Client) ([]flasharray.VolResponse, error) { params := make(map[string]string) params["destroyed"] = "true" - volumes, err := faClient.Volumes.ListAllAvailableVolumes(nil, nil) + volumes, err := faClient.Volumes.ListAllAvailableVolumes(params, nil) if err != nil { return nil, err } From d2a1ff18e48e572242cce61921f4f298bc8e898b Mon Sep 17 00:00:00 2001 From: vprabhakar-px Date: Wed, 29 May 2024 11:28:35 +0530 Subject: [PATCH 5/5] Fixing Json Parsing Issue --- drivers/pure/flasharray/fa.go | 2 +- drivers/pure/flasharray/volumeTypes.go | 4 ++-- pkg/pureutils/purefa_rest2x.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/pure/flasharray/fa.go b/drivers/pure/flasharray/fa.go index acc256c3b21..6df38918790 100644 --- a/drivers/pure/flasharray/fa.go +++ b/drivers/pure/flasharray/fa.go @@ -16,7 +16,7 @@ import ( ) // supportedRestVersions is used to negotiate the API version to use -var supportedRestVersions = [...]string{"2.26"} +var supportedRestVersions = [...]string{"2.2", "2.3", "2.4", "2.5", "2.6", "2.7", "2.8"} type Client struct { MgmtIp string diff --git a/drivers/pure/flasharray/volumeTypes.go b/drivers/pure/flasharray/volumeTypes.go index ebf7777f8e7..f892a96f78b 100644 --- a/drivers/pure/flasharray/volumeTypes.go +++ b/drivers/pure/flasharray/volumeTypes.go @@ -24,8 +24,8 @@ type Pod struct { } type QoS struct { - BandwidthLimit *string `json:"bandwidth_limit"` - IopsLimit *string `json:"iops_limit"` + BandwidthLimit uint64 `json:"bandwidth_limit"` + IopsLimit uint64 `json:"iops_limit"` } type VolumeGroup struct { diff --git a/pkg/pureutils/purefa_rest2x.go b/pkg/pureutils/purefa_rest2x.go index a19094a08fe..06a1eefa484 100644 --- a/pkg/pureutils/purefa_rest2x.go +++ b/pkg/pureutils/purefa_rest2x.go @@ -5,7 +5,7 @@ import ( ) const ( - RestAPI = "2.26" + RestAPI = "2.4" ) // PureCreateClientAndConnect Create FA Client and Connect