Skip to content

Commit

Permalink
Refactor host group name (#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkad authored Apr 3, 2024
1 parent 75562d2 commit 9535a83
Showing 1 changed file with 43 additions and 43 deletions.
86 changes: 43 additions & 43 deletions clients/instance/ibm-pi-host-groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ import (
"github.com/IBM-Cloud/power-go-client/power/models"
)

// IBMPIHostgroupsClient
type IBMPIHostgroupsClient struct {
// IBMPIHostGroupsClient
type IBMPIHostGroupsClient struct {
IBMPIClient
}

// NewIBMPIHostgroupsClient
func NewIBMPHostgroupsClient(ctx context.Context, sess *ibmpisession.IBMPISession, cloudInstanceID string) *IBMPIHostgroupsClient {
return &IBMPIHostgroupsClient{
// NewIBMPIHostGroupsClient
func NewIBMPHostgroupsClient(ctx context.Context, sess *ibmpisession.IBMPISession, cloudInstanceID string) *IBMPIHostGroupsClient {
return &IBMPIHostGroupsClient{
*NewIBMPIClient(ctx, sess, cloudInstanceID),
}
}

// Get All available hosts
func (f *IBMPIHostgroupsClient) GetAvailableHosts() (models.AvailableHostList, error) {
func (f *IBMPIHostGroupsClient) GetAvailableHosts() (models.AvailableHostList, error) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
Expand All @@ -34,160 +34,160 @@ func (f *IBMPIHostgroupsClient) GetAvailableHosts() (models.AvailableHostList, e
}

if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to Get Available hosts")
return nil, fmt.Errorf("failed to get available hosts")
}
return resp.Payload, nil
}

// Get all HostGroups
func (f *IBMPIHostgroupsClient) GetHostGroups() (models.HostGroupList, error) {
// Get all host groups
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))
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to get Host groups for %s: %w", f.cloudInstanceID, err))
}

if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to Get Hostgroups")
return nil, fmt.Errorf("failed to get host groups")
}
return resp.Payload, nil
}

// Create a HostGroup
func (f *IBMPIHostgroupsClient) CreateHostGroup(body *models.HostGroupCreate) (*models.HostGroup, error) {
// Create a host group
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))
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to create host group for %s: %w", f.cloudInstanceID, err))
}

if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to Get Hostgroups")
return nil, fmt.Errorf("failed to create host groups")
}
return resp.Payload, nil
}

// Update a HostGroup
func (f *IBMPIHostgroupsClient) UpdateHostGroup(body *models.HostGroupShareOp, id string) (*models.HostGroup, error) {
// Update a host group
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))
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to update host group for %s: %w", f.cloudInstanceID, err))
}

if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to Update Hostgroups")
return nil, fmt.Errorf("failed to update host groups")
}
return resp.Payload, nil
}

// Get a Hostgroup
func (f *IBMPIHostgroupsClient) GetHostGroup(id string) (*models.HostGroup, error) {
// Get a host group
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))
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to get host group %s for %s: %w", id, f.cloudInstanceID, err))
}

if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to Get Hostgroup %s", id)
return nil, fmt.Errorf("failed to get host group %s", id)
}
return resp.Payload, nil
}

// Get All Hosts
func (f *IBMPIHostgroupsClient) GetHosts() (models.HostList, error) {
// Get all hosts
func (f *IBMPIHostGroupsClient) GetHosts() (models.HostList, error) {
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))
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to get hosts for %s: %w", f.cloudInstanceID, err))
}

if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to Get Hosts")
return nil, fmt.Errorf("failed to get hosts")
}
return resp.Payload, nil
}

// Create a Host
func (f *IBMPIHostgroupsClient) CreateHost(body *models.HostCreate) (models.HostList, error) {
// Create a host
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))
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to create a host for %s: %w", f.cloudInstanceID, err))
}

if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to Create Hosts")
return nil, fmt.Errorf("failed to create a host")
}
return resp.Payload, nil
}

// Get a Host
func (f *IBMPIHostgroupsClient) GetHost(id string) (*models.Host, error) {
// Get a host
func (f *IBMPIHostGroupsClient) GetHost(id string) (*models.Host, error) {
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))
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to get host %s for %s: %w", id, f.cloudInstanceID, err))
}

if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to Get Host %s", id)
return nil, fmt.Errorf("failed to get host %s", id)
}
return resp.Payload, nil
}

// Update a Host
func (f *IBMPIHostgroupsClient) UpdateHost(body *models.HostPut, id string) (*models.Host, error) {
// Update a host
func (f *IBMPIHostGroupsClient) UpdateHost(body *models.HostPut, id string) (*models.Host, error) {
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))
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to update host %s for %s: %w", id, f.cloudInstanceID, err))
}

if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to Update Host %s", id)
return nil, fmt.Errorf("failed to update host %s", id)
}
return resp.Payload, nil
}

// Delete a Host
func (f *IBMPIHostgroupsClient) DeleteHost(id string) error {
// Delete a host
func (f *IBMPIHostGroupsClient) DeleteHost(id string) error {
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))
return ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to delete host %s for %s: %w", id, f.cloudInstanceID, err))
}

if resp == nil || resp.Payload == nil {
return fmt.Errorf("failed to Delete Host %s", id)
return fmt.Errorf("failed to delete host %s", id)
}
return nil
}

0 comments on commit 9535a83

Please sign in to comment.