-
Notifications
You must be signed in to change notification settings - Fork 115
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
Client SDK changes for foundation based bare metal provisioning #352
Merged
siddharth-nutanix
merged 8 commits into
nutanix:feat/m-foundation
from
bhatipradeep:task/m-add-foundation-client
Feb 22, 2022
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
626a5f4
[Add] Provider level foundation changes
bhatipradeep 24b7862
1. [Add] Foundation client 2. [Update] Existing client level changes …
bhatipradeep 2ff4416
1. [Add] Base client to create a basic http/https client as per flag …
bhatipradeep ff3656b
[Fix] Minor Typos
bhatipradeep 4d2b0f9
Remove foundation url from credentials and create same from foundatio…
bhatipradeep ff68ab4
Removing unnecesary comments
bhatipradeep c5ac745
Change foundation struct types for as per usecases
bhatipradeep 16adaeb
change struct types from int to int64
bhatipradeep File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package foundation | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/terraform-providers/terraform-provider-nutanix/client" | ||
) | ||
|
||
const ( | ||
absolutePath = "foundation" | ||
userAgent = "foundation" | ||
) | ||
|
||
//Foundation client with its services | ||
type Client struct { | ||
|
||
//base client | ||
client *client.Client | ||
|
||
//Service for Imaging Nodes and Cluster Creation | ||
NodeImaging NodeImagingService | ||
|
||
//Service for File Management in foundation VM | ||
FileManagement FileManagementService | ||
} | ||
|
||
//This routine returns new Foundation API Client | ||
func NewFoundationAPIClient(credentials client.Credentials) (*Client, error) { | ||
|
||
//for foundation client, url should be based on foundation's endpoint and port | ||
credentials.URL = fmt.Sprintf("%s:%s", credentials.FoundationEndpoint, credentials.FoundationPort) | ||
client, err := client.NewBaseClient(&credentials, absolutePath, true) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
//Fill user agent details | ||
client.UserAgent = userAgent | ||
|
||
foundationClient := &Client{ | ||
client: client, | ||
NodeImaging: NodeImagingOperations{ | ||
client: client, | ||
}, | ||
FileManagement: FileManagementOperations{ | ||
client: client, | ||
}, | ||
} | ||
return foundationClient, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package foundation | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/terraform-providers/terraform-provider-nutanix/client" | ||
) | ||
|
||
type FileManagementService interface { | ||
ListNOSPackages(context.Context) (*ListNOSPackagesResponse, error) | ||
ListHypervisorISOs(context.Context) (*ListHypervisorISOsResponse, error) | ||
} | ||
|
||
type FileManagementOperations struct { | ||
client *client.Client | ||
} | ||
|
||
//Lists the available AOS packages in Foundation | ||
func (fmo FileManagementOperations) ListNOSPackages(ctx context.Context) (*ListNOSPackagesResponse, error) { | ||
path := "/enumerate_nos_packages" | ||
req, err := fmo.client.NewUnAuthRequest(ctx, http.MethodGet, path, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
listNOSPackagesResponse := new(ListNOSPackagesResponse) | ||
return listNOSPackagesResponse, fmo.client.Do(ctx, req, listNOSPackagesResponse) | ||
} | ||
|
||
//Lists the hypervisor ISOs available in Foundation | ||
func (fmo FileManagementOperations) ListHypervisorISOs(ctx context.Context) (*ListHypervisorISOsResponse, error) { | ||
path := "/enumerate_hypervisor_isos" | ||
req, err := fmo.client.NewUnAuthRequest(ctx, http.MethodGet, path, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
listHypervisorISOsResponse := new(ListHypervisorISOsResponse) | ||
return listHypervisorISOsResponse, fmo.client.Do(ctx, req, listHypervisorISOsResponse) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package foundation | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/terraform-providers/terraform-provider-nutanix/client" | ||
) | ||
|
||
type NodeImagingService interface { | ||
ImageNodes(context.Context, *ImageNodesInput) (*ImageNodesAPIResponse, error) | ||
ImageNodesProgress(context.Context, string) (*ImageNodesProgressResponse, error) | ||
} | ||
|
||
type NodeImagingOperations struct { | ||
client *client.Client | ||
} | ||
|
||
func (op NodeImagingOperations) ImageNodes(ctx context.Context, imageNodeInput *ImageNodesInput) (*ImageNodesAPIResponse, error) { | ||
path := "/image_nodes" | ||
req, err := op.client.NewUnAuthRequest(ctx, http.MethodPost, path, imageNodeInput) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
imageNodesAPIResponse := new(ImageNodesAPIResponse) | ||
return imageNodesAPIResponse, op.client.Do(ctx, req, imageNodesAPIResponse) | ||
} | ||
|
||
//Gets progress of imaging session. | ||
func (op NodeImagingOperations) ImageNodesProgress(ctx context.Context, session_id string) (*ImageNodesProgressResponse, error) { | ||
path := "/progress?session_id=" + session_id | ||
req, err := op.client.NewUnAuthRequest(ctx, http.MethodGet, path, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
imageNodesProgressResponse := new(ImageNodesProgressResponse) | ||
return imageNodesProgressResponse, op.client.Do(ctx, req, imageNodesProgressResponse) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets move http / https in constants.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also create a method to figure out and construct a baseURL