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



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



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}/pvm-instances/#{pvm_instance_id}/volumes/#{volume_id}", {})
end

#create_key_pair(name, sshkey) ⇒ Hash

Add a new SSH key to the tenant



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



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



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.



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



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



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



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



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



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



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



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}/pvm-instances/#{pvm_instance_id}/volumes/#{volume_id}")
end

#endpointString

Get the API service 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



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



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



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



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



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



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



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



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



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



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



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.



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



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



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.



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



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



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'



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



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



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



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



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