Class: IBM::Cloud::SDK::PowerIaas

Inherits:
BaseService show all
Includes:
Logging
Defined in:
lib/ibm/cloud/sdk/power_iaas.rb

Instance Method Summary collapse

Methods included from Logging

#logger

Methods inherited from BaseService

#delete, endpoint, #get, #post

Constructor Details

#initialize(region, guid, token, crn, tenant) ⇒ PowerIaas

Create an API Client object for the Power IaaS service

Parameters:

  • region (String)

    the IBM Power Cloud instance region

  • guid (String)

    the IBM Power Cloud instance GUID

  • token (IAMtoken)

    the IBM Cloud IAM Token object

  • crn (String)

    the IBM Power Cloud instance CRN

  • tenant (String)

    the IBM Power Cloud account ID



16
17
18
19
20
21
22
23
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 16

def initialize(region, guid, token, crn, tenant)
  @crn    = crn
  @guid   = guid
  @region = region
  @token  = token
  @tenant = tenant
  RestClient.log = logger
end

Instance Method Details

#attach_volume(pvm_instance_id, volume_id) ⇒ Object

Attach a volume

Parameters:

  • pvm_instance_id (String)

    PVM Instance ID

  • volume_id (String)

    Volume ID



212
213
214
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 212

def attach_volume(pvm_instance_id, volume_id)
  post("cloud-instances/#{guid}/volumes/#{volumd_id}")
end

#create_key_pair(name, sshkey) ⇒ Hash

Add a new SSH key to the tenant

Parameters:

  • name (String)

    User defined name for the SSH key

  • sshkey (String)

    SSH RSA key

Returns:

  • (Hash)

    SSHKey



293
294
295
296
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 293

def create_key_pair(name, sshkey)
  payload = {"name" => name, "sshkey" => sshkey}
  post("tenants/#{tenant}/sshkeys", payload.to_json)
end

#create_network(network_hash) ⇒ Hash

Create a new network

Parameters:

  • network_hash (Hash)

    New network attributes

Returns:

  • (Hash)

    Network



262
263
264
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 262

def create_network(network_hash)
  post("cloud-instances/#{guid}/networks", network_hash.to_json)
end

#create_pvm_instance(instance_hash) ⇒ Hash

Create a new PVM instance

Parameters:

  • instance_hash (Hash)

    New instance attributes

Returns:

  • (Hash)

    PVMInstance



135
136
137
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 135

def create_pvm_instance(instance_hash)
  post("cloud-instances/#{guid}/pvm-instances", instance_hash.to_json)
end

#create_sap_pvm_instance(instance_hash) ⇒ Hash

Create a new SAP PVM Instance

Create a new PVM instance using an SAP profile. The resultant PVM instance is the standard ‘PVMInstance’ type and can be accessed via the existing *_pvm_instance methods.

Parameters:

  • sap_profile_id (String)

    SAP Profile ID

Returns:

  • (Hash)

    SAP profile



332
333
334
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 332

def create_sap_pvm_instance(instance_hash)
  post("cloud-instances/#{guid}/sap", instance_hash.to_json)
end

#create_volume(volume_hash) ⇒ Hash

Create a volume

Parameters:

  • volume_hash (Hash)

    New volume attributes

Returns:

  • (Hash)

    Volume



204
205
206
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 204

def create_volume(volume_hash)
  post("cloud-instances/#{guid}/volumes", volume_hash.to_json)
end

#delete_image(image_id) ⇒ Object

Delete an image from a cloud instance

Parameters:

  • image_id (String)

    Image ID



170
171
172
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 170

def delete_image(image_id)
  delete("cloud-instances/#{guid}/images/#{image_id}")
end

#delete_key_pair(name) ⇒ Object

Delete SSH key from the tenant

Parameters:

  • sshkey_name (String)

    SSH Key name



301
302
303
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 301

def delete_key_pair(name)
  delete("tenants/#{tenant}/sshkeys/#{name}")
end

#delete_network(network_id) ⇒ Object

Delete a network

Parameters:

  • network_id (String)

    Network ID



269
270
271
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 269

def delete_network(network_id)
  delete("cloud-instances/#{guid}/networks/#{network_id}")
end

#delete_pvm_instance(instance_id) ⇒ Object

Delete a PVM instance

Parameters:

  • pvm_instance_id (String)

    PVM instance ID



142
143
144
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 142

def delete_pvm_instance(instance_id)
  delete("cloud-instances/#{guid}/pvm-instances/#{instance_id}")
end

#delete_volume(volume_id) ⇒ Object

Delete a volume

Parameters:

  • volume_id (String)

    Volume ID



196
197
198
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 196

def delete_volume(volume_id)
  delete("cloud-instances/#{guid}/volumes/#{volume_id}")
end

#detach_volume(pvm_instance_id, volume_id) ⇒ Object

Detach a volume

Parameters:

  • pvm_instance_id (String)

    PVM Instance ID

  • volume_id (String)

    Volume ID



220
221
222
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 220

def detach_volume(pvm_instance_id, volume_id)
  delete("cloud-instances/#{guid}/volumes/#{volumd_id}")
end

#endpointString

Get the API service Endpoint URL

Returns:

  • (String)

    Endpoint URL



28
29
30
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 28

def endpoint
  "https://#{region.sub(/-\d$/, '')}.power-iaas.cloud.ibm.com/pcloud/v1"
end

#get_image(image_id) ⇒ Hash

Get an IBM Power Cloud image

Parameters:

  • image_id (String)

    Image ID

Returns:

  • (Hash)

    Image



161
162
163
164
165
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 161

def get_image(image_id)
  get("cloud-instances/#{guid}/images/#{image_id}")
rescue
  nil
end

#get_imagesArray<Hash>

Get all images in an IBM Power Cloud instance

Returns:

  • (Array<Hash>)

    all Images for this instance



149
150
151
152
153
154
155
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 149

def get_images
  images = get("cloud-instances/#{guid}/images")["images"] || []

  images.map do |image|
    get_image(image["imageID"])
  end.compact
end

#get_network(network_id) ⇒ Hash

Get an IBM Power Cloud network

Parameters:

  • network_id (String)

    Network ID

Returns:

  • (Hash)

    Network



238
239
240
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 238

def get_network(network_id)
  get("cloud-instances/#{guid}/networks/#{network_id}")
end

#get_network_ports(network_id) ⇒ Array<Hash>

Get all ports for a network

Parameters:

  • network_id (String)

    Network ID

Returns:

  • (Array<Hash>)

    NetworkPort



277
278
279
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 277

def get_network_ports(network_id)
  get("cloud-instances/#{guid}/networks/#{network_id}/ports")["ports"]
end

#get_networksArray<Hash>

Get all networks in an IBM Power Cloud instance

Returns:

  • (Array<Hash>)

    all networks for this IBM Power Cloud instance



227
228
229
230
231
232
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 227

def get_networks
  networks = get("cloud-instances/#{guid}/networks")["networks"] || []
  networks.map do |network|
    get_network(network["networkID"])
  end
end

#get_pcloud_instanceHash

Get Power Cloud Instance information

Returns:

  • (Hash)

    CloudInstance



35
36
37
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 35

def get_pcloud_instance
  get("cloud-instances/#{guid}")
end

#get_pvm_instance(instance_id) ⇒ Hash

Get an IBM Power Cloud PVM instance

Parameters:

  • pvm_instance_id (String)

    PVM instance ID

Returns:

  • (Hash)

    PVM Instances



54
55
56
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 54

def get_pvm_instance(instance_id)
  get("cloud-instances/#{guid}/pvm-instances/#{instance_id}")
end

#get_pvm_instancesArray<Hash>

Get all PVM instances in an IBM Power Cloud instance

Returns:

  • (Array<Hash>)

    all PVM Instances for this instance



42
43
44
45
46
47
48
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 42

def get_pvm_instances
  pvm_instances = get("cloud-instances/#{guid}/pvm-instances")["pvmInstances"] || []

  pvm_instances.map do |pvm_instance|
    get_pvm_instance(pvm_instance["pvmInstanceID"])
  end
end

#get_sap_profile(sap_profile_id) ⇒ Hash

Get an SAP profile

Parameters:

  • sap_profile_id (String)

    SAP Profile ID

Returns:

  • (Hash)

    SAP profile



309
310
311
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 309

def get_sap_profile(sap_profile_id)
  get("cloud-instances/#{guid}/sap/#{sap_profile_id}")
end

#get_sap_profilesArray<Hash>

Get list of all SAP profiles

Returns:

  • (Array<Hash>)

    all SAP profiles available to this instance



316
317
318
319
320
321
322
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 316

def get_sap_profiles
  sap_profiles = get("cloud-instances/#{guid}/sap")["profiles"] || []

  sap_profiles.map do |sap_profile|
    get_sap_profile(sap_profile["profileID"])
  end
end

#get_ssh_keysArray<Hash>

List the tenant’s SSH Keys

Returns:

  • (Array<Hash>)

    SSHKey



284
285
286
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 284

def get_ssh_keys
  get("tenants/#{tenant}")["sshKeys"]
end

#get_storage_typesArray<Hash>

Get a storage types list in IBM Power Cloud. note: this method to be refactored under the common IBM::Cloud::SDK::PowerIaas.endpoint when the rest api become available.

Returns:

  • (Array<Hash>)

    StorageType



254
255
256
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 254

def get_storage_types
  JSON.parse(RestClient.get("https://#{region.sub(/-\d$/, '')}.power-iaas.cloud.ibm.com/broker/v1/storage-types", headers))[region]
end

#get_system_poolHash

Get a available system pools list for IBM Power Cloud DC

Returns:

  • (Hash)

    SystemPool



245
246
247
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 245

def get_system_pool
  get("cloud-instances/#{guid}/system-pools")
end

#get_volume(volume_id) ⇒ Hash

Get a specific volume

Parameters:

  • volume_id (String)

    Image ID

Returns:

  • (Hash)

    Volume



189
190
191
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 189

def get_volume(volume_id)
  get("cloud-instances/#{guid}/volumes/#{volume_id}")
end

#get_volumesArray<Hash>

List all the volumes.

Returns:

  • (Array<Hash>)

    all volumes for this instance



177
178
179
180
181
182
183
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 177

def get_volumes
  volumes = get("cloud-instances/#{guid}/volumes")["volumes"] || []

  volumes.map do |volume|
    get_volume(volume["volumeID"])
  end
end

#hard_reboot_pvm_instance(instance_id) ⇒ Object

Perform ‘hard-reboot’ action on a PVMInstance

Parameters:

  • pvm_instance_id (String)

    PVM instance ID



114
115
116
117
118
119
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 114

def hard_reboot_pvm_instance(instance_id)
  post(
    "cloud-instances/#{guid}/pvm-instances/#{instance_id}/action",
    {"action" => "hard-reboot"}.to_json
  )
end

#immediate_shutdown_pvm_instance(instance_id) ⇒ Object

Perform ‘immediate-shutdown’ action on a PVMInstance

Parameters:

  • pvm_instance_id (String)

    PVM instance ID



81
82
83
84
85
86
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 81

def immediate_shutdown_pvm_instance(instance_id)
  post(
    "cloud-instances/#{guid}/pvm-instances/#{instance_id}/action",
    {"action" => "immediate-shutdown"}.to_json
  )
end

#reboot_pvm_instance(instance_id) ⇒ Object

Perform ‘reboot’ action on a PVMInstance

This action has been deprecated and replaced by ‘soft-reboot’ and ‘hard-reboot’

Parameters:

  • pvm_instance_id (String)

    PVM instance ID



94
95
96
97
98
99
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 94

def reboot_pvm_instance(instance_id)
  post(
    "cloud-instances/#{guid}/pvm-instances/#{instance_id}/action",
    {"action" => "reboot"}.to_json
  )
end

#reset_state_pvm_instance(instance_id) ⇒ Object

Perform ‘reset-state’ action on a PVMInstance

Parameters:

  • pvm_instance_id (String)

    PVM instance ID



124
125
126
127
128
129
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 124

def reset_state_pvm_instance(instance_id)
  post(
    "cloud-instances/#{guid}/pvm-instances/#{instance_id}/action",
    {"action" => "reset-state"}.to_json
  )
end

#soft_reboot_pvm_instance(instance_id) ⇒ Object

Perform ‘soft-reboot’ action on a PVMInstance

Parameters:

  • pvm_instance_id (String)

    PVM instance ID



104
105
106
107
108
109
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 104

def soft_reboot_pvm_instance(instance_id)
  post(
    "cloud-instances/#{guid}/pvm-instances/#{instance_id}/action",
    {"action" => "soft-reboot"}.to_json
  )
end

#start_pvm_instance(instance_id) ⇒ Object

Perform ‘start’ action on a PVMInstance

Parameters:

  • pvm_instance_id (String)

    PVM instance ID



61
62
63
64
65
66
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 61

def start_pvm_instance(instance_id)
  post(
    "cloud-instances/#{guid}/pvm-instances/#{instance_id}/action",
    {"action" => "start"}.to_json
  )
end

#stop_pvm_instance(instance_id) ⇒ Object

Perform ‘stop’ action on a PVMInstance

Parameters:

  • pvm_instance_id (String)

    PVM instance ID



71
72
73
74
75
76
# File 'lib/ibm/cloud/sdk/power_iaas.rb', line 71

def stop_pvm_instance(instance_id)
  post(
    "cloud-instances/#{guid}/pvm-instances/#{instance_id}/action",
    {"action" => "stop"}.to_json
  )
end