Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.
Merged
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
28 changes: 19 additions & 9 deletions openstack/sdrs/v1/protectedinstances/results_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package protectedinstances

import (
"fmt"
"time"

"github.com/huaweicloud/golangsdk"
)
Expand All @@ -11,14 +12,18 @@ type JobResponse struct {
}

type JobStatus struct {
Status string `json:"status"`
Entities map[string]string `json:"entities"`
JobID string `json:"job_id"`
JobType string `json:"job_type"`
BeginTime string `json:"begin_time"`
EndTime string `json:"end_time"`
ErrorCode string `json:"error_code"`
FailReason string `json:"fail_reason"`
Status string `json:"status"`
Entities JobEntity `json:"entities"`
JobID string `json:"job_id"`
JobType string `json:"job_type"`
BeginTime string `json:"begin_time"`
EndTime string `json:"end_time"`
ErrorCode string `json:"error_code"`
FailReason string `json:"fail_reason"`
}

type JobEntity struct {
InstanceID string `json:"protected_instance_id"`
}

type JobResult struct {
Expand Down Expand Up @@ -47,6 +52,7 @@ func WaitForJobSuccess(client *golangsdk.ServiceClient, secs int, jobID string)
if err != nil {
return false, err
}
time.Sleep(5 * time.Second)

if job.Status == "SUCCESS" {
return true, nil
Expand All @@ -62,6 +68,10 @@ func WaitForJobSuccess(client *golangsdk.ServiceClient, secs int, jobID string)

func GetJobEntity(client *golangsdk.ServiceClient, jobId string, label string) (interface{}, error) {

if label != "protected_instance_id" {
return nil, fmt.Errorf("Unsupported label %s in GetJobEntity.", label)
}

jobClient := *client
jobClient.ResourceBase = jobClient.Endpoint
job := new(JobStatus)
Expand All @@ -71,7 +81,7 @@ func GetJobEntity(client *golangsdk.ServiceClient, jobId string, label string) (
}

if job.Status == "SUCCESS" {
if e := job.Entities[label]; e != "" {
if e := job.Entities.InstanceID; e != "" {
return e, nil
}
}
Expand Down