Skip to content

Commit

Permalink
Update Hostgroup client and add stratos validation (#361)
Browse files Browse the repository at this point in the history
* Update Hostgroup client and add stratos validation

* Update name to hostGroup pattern

* Rename file
  • Loading branch information
michaelkad authored Mar 28, 2024
1 parent 7634d3b commit 4d896a2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/IBM-Cloud/power-go-client/helpers"
"github.com/IBM-Cloud/power-go-client/ibmpisession"
"github.com/IBM-Cloud/power-go-client/power/client/hostgroups"
"github.com/IBM-Cloud/power-go-client/power/client/host_groups"
"github.com/IBM-Cloud/power-go-client/power/models"
)

Expand All @@ -24,8 +24,11 @@ func NewIBMPHostgroupsClient(ctx context.Context, sess *ibmpisession.IBMPISessio

// Get All available hosts
func (f *IBMPIHostgroupsClient) GetAvailableHosts() (models.AvailableHostList, error) {
params := hostgroups.NewV1AvailableHostsParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut)
resp, err := f.session.Power.Hostgroups.V1AvailableHosts(params, f.session.AuthInfo(f.cloudInstanceID))
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := host_groups.NewV1AvailableHostsParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut)
resp, err := f.session.Power.HostGroups.V1AvailableHosts(params, f.session.AuthInfo(f.cloudInstanceID))
if err != nil {
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to Get available hosts for %s: %w", f.cloudInstanceID, err))
}
Expand All @@ -36,10 +39,13 @@ func (f *IBMPIHostgroupsClient) GetAvailableHosts() (models.AvailableHostList, e
return resp.Payload, nil
}

// Get all Hostgroups
func (f *IBMPIHostgroupsClient) GetHostgroups() (models.HostgroupList, error) {
params := hostgroups.NewV1HostgroupsGetParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut)
resp, err := f.session.Power.Hostgroups.V1HostgroupsGet(params, f.session.AuthInfo(f.cloudInstanceID))
// Get all HostGroups
func (f *IBMPIHostgroupsClient) GetHostGroups() (models.HostGroupList, error) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := host_groups.NewV1HostGroupsGetParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut)
resp, err := f.session.Power.HostGroups.V1HostGroupsGet(params, f.session.AuthInfo(f.cloudInstanceID))
if err != nil {
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to Get Hostgroups for %s: %w", f.cloudInstanceID, err))
}
Expand All @@ -50,10 +56,13 @@ func (f *IBMPIHostgroupsClient) GetHostgroups() (models.HostgroupList, error) {
return resp.Payload, nil
}

// Create a Hostgroup
func (f *IBMPIHostgroupsClient) CreateHostgroup(body *models.HostgroupCreate) (*models.Hostgroup, error) {
params := hostgroups.NewV1HostgroupsPostParams().WithContext(f.ctx).WithTimeout(helpers.PICreateTimeOut).WithBody(body)
resp, err := f.session.Power.Hostgroups.V1HostgroupsPost(params, f.session.AuthInfo(f.cloudInstanceID))
// Create a HostGroup
func (f *IBMPIHostgroupsClient) CreateHostGroup(body *models.HostGroupCreate) (*models.HostGroup, error) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := host_groups.NewV1HostGroupsPostParams().WithContext(f.ctx).WithTimeout(helpers.PICreateTimeOut).WithBody(body)
resp, err := f.session.Power.HostGroups.V1HostGroupsPost(params, f.session.AuthInfo(f.cloudInstanceID))
if err != nil {
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to Create Hostgroup for %s: %w", f.cloudInstanceID, err))
}
Expand All @@ -64,10 +73,13 @@ func (f *IBMPIHostgroupsClient) CreateHostgroup(body *models.HostgroupCreate) (*
return resp.Payload, nil
}

// Update a Hostgroup
func (f *IBMPIHostgroupsClient) UpdateHostgroup(body *models.HostgroupShareOp, id string) (*models.Hostgroup, error) {
params := hostgroups.NewV1HostgroupsIDPutParams().WithContext(f.ctx).WithTimeout(helpers.PICreateTimeOut).WithBody(body).WithHostgroupID(id)
resp, err := f.session.Power.Hostgroups.V1HostgroupsIDPut(params, f.session.AuthInfo(f.cloudInstanceID))
// Update a HostGroup
func (f *IBMPIHostgroupsClient) UpdateHostGroup(body *models.HostGroupShareOp, id string) (*models.HostGroup, error) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := host_groups.NewV1HostGroupsIDPutParams().WithContext(f.ctx).WithTimeout(helpers.PICreateTimeOut).WithBody(body).WithHostGroupID(id)
resp, err := f.session.Power.HostGroups.V1HostGroupsIDPut(params, f.session.AuthInfo(f.cloudInstanceID))
if err != nil {
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to Update Hostgroup for %s: %w", f.cloudInstanceID, err))
}
Expand All @@ -79,9 +91,12 @@ func (f *IBMPIHostgroupsClient) UpdateHostgroup(body *models.HostgroupShareOp, i
}

// Get a Hostgroup
func (f *IBMPIHostgroupsClient) GetHostgroup(id string) (*models.Hostgroup, error) {
params := hostgroups.NewV1HostgroupsIDGetParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).WithHostgroupID(id)
resp, err := f.session.Power.Hostgroups.V1HostgroupsIDGet(params, f.session.AuthInfo(f.cloudInstanceID))
func (f *IBMPIHostgroupsClient) GetHostGroup(id string) (*models.HostGroup, error) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := host_groups.NewV1HostGroupsIDGetParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).WithHostGroupID(id)
resp, err := f.session.Power.HostGroups.V1HostGroupsIDGet(params, f.session.AuthInfo(f.cloudInstanceID))
if err != nil {
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to Get Hostgroup %s for %s: %w", id, f.cloudInstanceID, err))
}
Expand All @@ -94,8 +109,11 @@ func (f *IBMPIHostgroupsClient) GetHostgroup(id string) (*models.Hostgroup, erro

// Get All Hosts
func (f *IBMPIHostgroupsClient) GetHosts() (models.HostList, error) {
params := hostgroups.NewV1HostsGetParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut)
resp, err := f.session.Power.Hostgroups.V1HostsGet(params, f.session.AuthInfo(f.cloudInstanceID))
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := host_groups.NewV1HostsGetParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut)
resp, err := f.session.Power.HostGroups.V1HostsGet(params, f.session.AuthInfo(f.cloudInstanceID))
if err != nil {
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to Get Hosts for %s: %w", f.cloudInstanceID, err))
}
Expand All @@ -107,9 +125,12 @@ func (f *IBMPIHostgroupsClient) GetHosts() (models.HostList, error) {
}

// Create a Host
func (f *IBMPIHostgroupsClient) CreateHost(body *models.HostCreate) (*models.Host, error) {
params := hostgroups.NewV1HostsPostParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).WithBody(body)
resp, err := f.session.Power.Hostgroups.V1HostsPost(params, f.session.AuthInfo(f.cloudInstanceID))
func (f *IBMPIHostgroupsClient) CreateHost(body *models.HostCreate) (models.HostList, error) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := host_groups.NewV1HostsPostParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).WithBody(body)
resp, err := f.session.Power.HostGroups.V1HostsPost(params, f.session.AuthInfo(f.cloudInstanceID))
if err != nil {
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to Create Hosts for %s: %w", f.cloudInstanceID, err))
}
Expand All @@ -122,8 +143,11 @@ func (f *IBMPIHostgroupsClient) CreateHost(body *models.HostCreate) (*models.Hos

// Get a Host
func (f *IBMPIHostgroupsClient) GetHost(id string) (*models.Host, error) {
params := hostgroups.NewV1HostsIDGetParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).WithHostID(id)
resp, err := f.session.Power.Hostgroups.V1HostsIDGet(params, f.session.AuthInfo(f.cloudInstanceID))
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := host_groups.NewV1HostsIDGetParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).WithHostID(id)
resp, err := f.session.Power.HostGroups.V1HostsIDGet(params, f.session.AuthInfo(f.cloudInstanceID))
if err != nil {
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to Get Host %s for %s: %w", id, f.cloudInstanceID, err))
}
Expand All @@ -136,8 +160,11 @@ func (f *IBMPIHostgroupsClient) GetHost(id string) (*models.Host, error) {

// Update a Host
func (f *IBMPIHostgroupsClient) UpdateHost(body *models.HostPut, id string) (*models.Host, error) {
params := hostgroups.NewV1HostsIDPutParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).WithHostID(id).WithBody(body)
resp, err := f.session.Power.Hostgroups.V1HostsIDPut(params, f.session.AuthInfo(f.cloudInstanceID))
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := host_groups.NewV1HostsIDPutParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).WithHostID(id).WithBody(body)
resp, err := f.session.Power.HostGroups.V1HostsIDPut(params, f.session.AuthInfo(f.cloudInstanceID))
if err != nil {
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to Update Host %s for %s: %w", id, f.cloudInstanceID, err))
}
Expand All @@ -150,8 +177,11 @@ func (f *IBMPIHostgroupsClient) UpdateHost(body *models.HostPut, id string) (*mo

// Delete a Host
func (f *IBMPIHostgroupsClient) DeleteHost(id string) error {
params := hostgroups.NewV1HostsIDDeleteParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).WithHostID(id)
resp, err := f.session.Power.Hostgroups.V1HostsIDDelete(params, f.session.AuthInfo(f.cloudInstanceID))
if f.session.IsOnPrem() {
return fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := host_groups.NewV1HostsIDDeleteParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).WithHostID(id)
resp, err := f.session.Power.HostGroups.V1HostsIDDelete(params, f.session.AuthInfo(f.cloudInstanceID))
if err != nil {
return ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to Delete Host %s for %s: %w", id, f.cloudInstanceID, err))
}
Expand Down
2 changes: 1 addition & 1 deletion examples/hostgroups/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func main() {
}
log.Printf("***************[0]****************** %+v \n", getAllAvailableHost)

getHostgroups, err := powerClient.GetHostgroups()
getHostgroups, err := powerClient.GetHostGroups()
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit 4d896a2

Please sign in to comment.