Skip to content

Commit

Permalink
Merge pull request #35 from surajsub/master
Browse files Browse the repository at this point in the history
Port Update / Detach
  • Loading branch information
surajsub authored Jun 1, 2020
2 parents 3f12adc + 7bffbe1 commit e80e70f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
18 changes: 17 additions & 1 deletion clients/instance/ibm-pi-instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,29 @@ func (f *IBMPIInstanceClient) RestoreSnapShotVM(powerinstanceid, pvminstanceid,
params := p_cloud_p_vm_instances.NewPcloudPvminstancesSnapshotsRestorePostParamsWithTimeout(postTimeOut).WithCloudInstanceID(powerinstanceid).WithPvmInstanceID(pvminstanceid).WithSnapshotID(snapshotid).WithRestoreFailAction(&restoreAction).WithBody(restoreparams.Body)
resp, err := f.session.Power.PCloudPVMInstances.PcloudPvminstancesSnapshotsRestorePost(params, ibmpisession.NewAuth(f.session, powerinstanceid))

if err != nil || resp.Payload.SnapshotID != nil {
if err != nil {
log.Printf("Failed to perform the snapshot restore operation")
return nil, errors.ToError(err)
}
return resp.Payload, nil
}

// Add a network to the instance

func (f *IBMPIInstanceClient) AddNetwork(powerinstanceid, pvminstanceid string, networkdef *p_cloud_p_vm_instances.PcloudPvminstancesNetworksPostParams) (*models.PVMInstanceNetwork, error) {
log.Printf("Adding a network to the existing pvm instance with instanceid [%s] ", pvminstanceid)
params := p_cloud_p_vm_instances.NewPcloudPvminstancesNetworksPostParamsWithTimeout(postTimeOut).WithCloudInstanceID(powerinstanceid).WithPvmInstanceID(pvminstanceid).WithBody(networkdef.Body)
resp, err := f.session.Power.PCloudPVMInstances.PcloudPvminstancesNetworksPost(params, ibmpisession.NewAuth(f.session, powerinstanceid))

if err != nil || resp.Payload.NetworkID == "" {
return nil, fmt.Errorf("Failed to attach the network to the pvminstanceid ")

}
return resp.Payload, nil
}

// Delete a network from an instance

// Create SAP Systems

func (f *IBMPIInstanceClient) CreateSAP(powerdef *p_cloud_s_a_p.PcloudSapPostParams, powerinstanceid string) (*models.PVMInstanceList, error) {
Expand Down
33 changes: 33 additions & 0 deletions clients/instance/ibm-pi-network.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,36 @@ func (f *IBMPINetworkClient) DeletePort(networkid string, powerinstanceid string
}
return &resp.Payload, nil
}

//Attach Port to the PVM Instance

func (f *IBMPINetworkClient) AttachPort(powerinstanceid, network_id, port_id string, networkparams *p_cloud_networks.PcloudNetworksPortsPutParams) (*models.NetworkPort, error) {

params := p_cloud_networks.NewPcloudNetworksPortsPutParamsWithTimeout(f.session.Timeout).WithCloudInstanceID(powerinstanceid).WithNetworkID(network_id).WithPortID(port_id).WithBody(networkparams.Body)
resp, err := f.session.Power.PCloudNetworks.PcloudNetworksPortsPut(params, ibmpisession.NewAuth(f.session, powerinstanceid))

if err != nil {
log.Printf("Failed to attach the port to the pvminstance")
return nil, fmt.Errorf("Failed to attach the port [%s] to the pvminstance [%s]", port_id, networkparams.Body.PvmInstanceID)
}

return resp.Payload, nil
}

// Detach Port from the PVM Instance

func (f *IBMPINetworkClient) DetachPort(powerinstanceid, network_id, port_id string) (*models.NetworkPort, error) {
log.Printf("Calling the detach port ")
var body = models.NetworkPortUpdate{}
body.PvmInstanceID = nil

params := p_cloud_networks.NewPcloudNetworksPortsPutParamsWithTimeout(f.session.Timeout).WithCloudInstanceID(powerinstanceid).WithNetworkID(network_id).WithPortID(port_id).WithBody(&body)
resp, err := f.session.Power.PCloudNetworks.PcloudNetworksPortsPut(params, ibmpisession.NewAuth(f.session, powerinstanceid))

if err != nil {
log.Printf("Failed to detach the port to the pvminstance")
return nil, fmt.Errorf("Failed to detach the port [%s]", port_id)
}

return resp.Payload, nil
}

0 comments on commit e80e70f

Please sign in to comment.