Class: OracleCloud::Orchestration

Inherits:
Asset
  • Object
show all
Defined in:
lib/oraclecloud/orchestration.rb

Instance Attribute Summary

Attributes inherited from Asset

#asset_data, #asset_type, #client, #container, #path

Instance Method Summary collapse

Methods inherited from Asset

#fetch, #full_name, #id, #initialize, #name_with_container, #strip_identity_domain, #validate!

Constructor Details

This class inherits a constructor from OracleCloud::Asset

Instance Method Details

#deleteObject



46
47
48
# File 'lib/oraclecloud/orchestration.rb', line 46

def delete
  client.asset_delete(asset_type, name_with_container)
end

#descriptionObject



28
29
30
# File 'lib/oraclecloud/orchestration.rb', line 28

def description
  asset_data['description']
end

#error?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/oraclecloud/orchestration.rb', line 75

def error?
  status == 'error'
end

#errorsObject



79
80
81
82
83
# File 'lib/oraclecloud/orchestration.rb', line 79

def errors
  return [] unless launch_plan.key?('info') && launch_plan['info'].key?('errors')

  launch_plan['info']['errors'].values
end

#instance_countObject



71
72
73
# File 'lib/oraclecloud/orchestration.rb', line 71

def instance_count
  instance_records.count
end

#instance_recordsObject



56
57
58
59
60
61
62
63
# File 'lib/oraclecloud/orchestration.rb', line 56

def instance_records
  return [] if launch_plan.nil? || launch_plan['objects'].nil?

  instance_object = launch_plan['objects'].find { |x| x.respond_to?(:key?) && x.key?('instances') }
  return [] if instance_object.nil?

  instance_object['instances'].select { |x| x.key?('state') }
end

#instancesObject



65
66
67
68
69
# File 'lib/oraclecloud/orchestration.rb', line 65

def instances
  return [] if instance_records.nil?

  instance_records.map { |x| client.instances.by_name(x['name']) }
end

#launch_planObject



50
51
52
53
54
# File 'lib/oraclecloud/orchestration.rb', line 50

def launch_plan
  return if asset_data['oplans'].nil?

  asset_data['oplans'].find { |x| x['obj_type'] == 'launchplan' }
end

#local_initObject



20
21
22
# File 'lib/oraclecloud/orchestration.rb', line 20

def local_init
  @asset_type = 'orchestration'
end

#startObject



32
33
34
35
36
37
# File 'lib/oraclecloud/orchestration.rb', line 32

def start
  return if %w(starting ready).include?(status)

  client.asset_put(asset_type, "#{name_with_container}?action=START")
  refresh
end

#statusObject



24
25
26
# File 'lib/oraclecloud/orchestration.rb', line 24

def status
  asset_data['status']
end

#stopObject



39
40
41
42
43
44
# File 'lib/oraclecloud/orchestration.rb', line 39

def stop
  return if status == 'stopped'

  client.asset_put(asset_type, "#{name_with_container}?action=STOP")
  refresh
end