Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Port Update / Detach #35

Merged
merged 1 commit into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}