Skip to content

Commit 9f4062e

Browse files
committed
change from list to get resource instance
Signed-off-by: Yussuf Shaikh <[email protected]>
1 parent faa043c commit 9f4062e

File tree

1 file changed

+10
-28
lines changed

1 file changed

+10
-28
lines changed

pkg/cloud/powervs.go

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,6 @@ import (
3838

3939
var _ Cloud = &powerVSCloud{}
4040

41-
var (
42-
// TODO: Never seen these catalog values changing, lets add code to get these values in future for the sake of better design.
43-
44-
// This can be found in the IBM Cloud catalog, command used to get this information is
45-
// $ ibmcloud catalog service-marketplace| grep power-iaas
46-
// abd259f0-9990-11e8-acc8-b9f54a8f1661 power-iaas
47-
powerVSServiceID = "abd259f0-9990-11e8-acc8-b9f54a8f1661"
48-
49-
// PlanID can be fetched via command:
50-
// $ ibmcloud catalog service abd259f0-9990-11e8-acc8-b9f54a8f1661 | grep plan
51-
// power-virtual-server-group plan f165dd34-3a40-423b-9d95-e90a23f724dd
52-
powerVSPlanID = "f165dd34-3a40-423b-9d95-e90a23f724dd"
53-
)
54-
5541
const (
5642
PollTimeout = 120 * time.Second
5743
PollInterval = 5 * time.Second
@@ -92,28 +78,24 @@ func NewPowerVSCloud(cloudInstanceID, zone string, debug bool) (Cloud, error) {
9278
func newPowerVSCloud(cloudInstanceID, zone string, debug bool) (Cloud, error) {
9379
apikey := os.Getenv("IBMCLOUD_API_KEY")
9480

81+
authenticator := &core.IamAuthenticator{ApiKey: apikey}
82+
9583
serviceClientOptions := &resourcecontrollerv2.ResourceControllerV2Options{
96-
Authenticator: &core.IamAuthenticator{ApiKey: apikey},
84+
Authenticator: authenticator,
9785
}
98-
serviceClient, err := resourcecontrollerv2.NewResourceControllerV2UsingExternalConfig(serviceClientOptions)
86+
serviceClient, err := resourcecontrollerv2.NewResourceControllerV2(serviceClientOptions)
9987
if err != nil {
100-
return nil, fmt.Errorf("errored while creating NewResourceControllerV2UsingExternalConfig: %v", err)
88+
return nil, fmt.Errorf("errored while creating NewResourceControllerV2: %v", err)
10189
}
102-
resourceInstanceList, _, err := serviceClient.ListResourceInstances(&resourcecontrollerv2.ListResourceInstancesOptions{
103-
GUID: &cloudInstanceID,
104-
ResourceID: &powerVSServiceID,
105-
ResourcePlanID: &powerVSPlanID,
90+
resourceInstance, _, err := serviceClient.GetResourceInstance(&resourcecontrollerv2.GetResourceInstanceOptions{
91+
ID: &cloudInstanceID,
10692
})
107-
if err != nil {
108-
return nil, fmt.Errorf("errored while listing the Power VS service instance with ID: %s, err: %v", cloudInstanceID, err)
109-
}
11093

111-
if len(resourceInstanceList.Resources) == 0 {
112-
return nil, fmt.Errorf("no Power VS service instance found with ID: %s", cloudInstanceID)
94+
if err != nil {
95+
return nil, fmt.Errorf("errored while getting the Power VS service instance with ID: %s, err: %v", cloudInstanceID, err)
11396
}
11497

115-
authenticator := &core.IamAuthenticator{ApiKey: apikey}
116-
piOptions := ibmpisession.IBMPIOptions{Authenticator: authenticator, Debug: debug, UserAccount: *resourceInstanceList.Resources[0].AccountID, Zone: zone}
98+
piOptions := ibmpisession.IBMPIOptions{Authenticator: authenticator, Debug: debug, UserAccount: *resourceInstance.AccountID, Zone: zone}
11799
piSession, err := ibmpisession.NewIBMPISession(&piOptions)
118100
if err != nil {
119101
return nil, err

0 commit comments

Comments
 (0)