Skip to content

Commit

Permalink
Virtual Serial Number Drop2 (#495)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkad authored Oct 16, 2024
1 parent 332b353 commit 9409863
Showing 1 changed file with 70 additions and 4 deletions.
74 changes: 70 additions & 4 deletions clients/instance/ibm-pi-virtual-serial-number.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ func (f *IBMPIVSNClient) Get(id string) (*models.VirtualSerialNumber, error) {
WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).WithVirtualSerialNumber(id)
resp, err := f.session.Power.PCloudVirtualSerialNumber.PcloudVirtualserialnumberGet(params, f.session.AuthInfo(f.cloudInstanceID))
if err != nil {
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to Get virtual serial number %s :%w", id, err))
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to get virtual serial number %s :%w", id, err))
}
if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to Get virtual serial number %s", id)
return nil, fmt.Errorf("failed to get virtual serial number %s", id)
}
return resp.Payload, nil
}
Expand All @@ -46,10 +46,76 @@ func (f *IBMPIVSNClient) GetAll(pvmInstanceID *string) (models.VirtualSerialNumb
}
resp, err := f.session.Power.PCloudVirtualSerialNumber.PcloudVirtualserialnumberGetall(params, f.session.AuthInfo(f.cloudInstanceID))
if err != nil {
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to Get all virtual serial numbers in %s :%w", f.cloudInstanceID, err))
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to get all virtual serial numbers in %s :%w", f.cloudInstanceID, err))
}
if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to Get all virtual serial numbers in %s", f.cloudInstanceID)
return nil, fmt.Errorf("failed to get all virtual serial numbers in %s", f.cloudInstanceID)
}
return resp.Payload, nil
}

// Update Virtual Serial Nunber
func (f *IBMPIVSNClient) Update(id string, body *models.UpdateVirtualSerialNumber) (*models.GetServerVirtualSerialNumber, error) {
params := p_cloud_virtual_serial_number.NewPcloudVirtualserialnumberPutParams().
WithContext(f.ctx).WithTimeout(helpers.PIUpdateTimeOut).WithVirtualSerialNumber(id).
WithBody(body)
resp, err := f.session.Power.PCloudVirtualSerialNumber.PcloudVirtualserialnumberPut(params, f.session.AuthInfo(f.cloudInstanceID))
if err != nil {
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to update virtual serial number %s :%w", id, err))
}
if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to Update virtual serial number %s", id)
}
return resp.Payload, nil
}

// Delete Virtual Serial Number
func (f *IBMPIVSNClient) Delete(id string) error {
params := p_cloud_virtual_serial_number.NewPcloudVirtualserialnumberDeleteParams().
WithContext(f.ctx).WithTimeout(helpers.PIDeleteTimeOut).
WithVirtualSerialNumber(id)
_, err := f.session.Power.PCloudVirtualSerialNumber.PcloudVirtualserialnumberDelete(params, f.session.AuthInfo(f.cloudInstanceID))
if err != nil {
return ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to delete virtual serial number %s :%w", id, err))
}
return nil
}

// PVM Instance Delete VSN
func (f *IBMPIVSNClient) PVMInstanceDeleteVSN(pvmInstanceID string, body *models.DeleteServerVirtualSerialNumber) error {
params := p_cloud_virtual_serial_number.NewPcloudPvminstancesVirtualserialnumberDeleteParams().
WithContext(f.ctx).WithTimeout(helpers.PIDeleteTimeOut).WithCloudInstanceID(f.cloudInstanceID).WithPvmInstanceID(pvmInstanceID).
WithBody(body)
_, err := f.session.Power.PCloudVirtualSerialNumber.PcloudPvminstancesVirtualserialnumberDelete(params, f.session.AuthInfo(f.cloudInstanceID))
if err != nil {
return ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to delete virtual serial number for pvm instance %s :%w", pvmInstanceID, err))
}
return nil
}

// PVM Instance Update VSN
func (f *IBMPIVSNClient) PVMInstanceUpdateVSN(pvmInstanceID string, body *models.UpdateServerVirtualSerialNumber) (*models.VirtualSerialNumber, error) {
params := p_cloud_virtual_serial_number.NewPcloudPvminstancesVirtualserialnumberPutParams().
WithContext(f.ctx).WithTimeout(helpers.PICreateTimeOut).WithCloudInstanceID(f.cloudInstanceID).
WithPvmInstanceID(pvmInstanceID).WithBody(body)
resp, err := f.session.Power.PCloudVirtualSerialNumber.PcloudPvminstancesVirtualserialnumberPut(params, f.session.AuthInfo(f.cloudInstanceID))
if err != nil {
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to update virtual serial number for pvm instance %s :%w", pvmInstanceID, err))
}
if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to update virtual serial number for pvm instance %s", pvmInstanceID)
}
return resp.Payload, nil
}

// PVM Attach VSN
func (f *IBMPIVSNClient) PVMInstanceAttachVSN(pvmInstanceID string, body *models.AddServerVirtualSerialNumber) error {
params := p_cloud_virtual_serial_number.NewPcloudPvminstancesVirtualserialnumberPostParams().
WithContext(f.ctx).WithTimeout(helpers.PICreateTimeOut).WithCloudInstanceID(f.cloudInstanceID).
WithPvmInstanceID(pvmInstanceID).WithBody(body)
_, err := f.session.Power.PCloudVirtualSerialNumber.PcloudPvminstancesVirtualserialnumberPost(params, f.session.AuthInfo(f.cloudInstanceID))
if err != nil {
return ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to attach virtual serial number for pvm instance %s :%w", pvmInstanceID, err))
}
return nil
}

0 comments on commit 9409863

Please sign in to comment.