Class: ForemanGoogle::GoogleCompute
- Inherits:
-
Object
- Object
- ForemanGoogle::GoogleCompute
- Defined in:
- app/models/foreman_google/google_compute.rb
Instance Attribute Summary collapse
-
#associate_external_ip ⇒ Object
readonly
Returns the value of attribute associate_external_ip.
-
#creation_timestamp ⇒ Object
readonly
Returns the value of attribute creation_timestamp.
-
#disks ⇒ Object
readonly
Returns the value of attribute disks.
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#identity ⇒ Object
readonly
Returns the value of attribute identity.
-
#image_id ⇒ Object
readonly
Returns the value of attribute image_id.
-
#machine_type ⇒ Object
readonly
Returns the value of attribute machine_type.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#network ⇒ Object
readonly
Returns the value of attribute network.
-
#network_interfaces ⇒ Object
readonly
Returns the value of attribute network_interfaces.
-
#volumes ⇒ Object
readonly
Returns the value of attribute volumes.
-
#zone ⇒ Object
readonly
Returns the value of attribute zone.
-
#zone_name ⇒ Object
readonly
Returns the value of attribute zone_name.
Instance Method Summary collapse
- #create_instance ⇒ Object
- #create_volumes ⇒ Object
- #destroy_volumes ⇒ Object
-
#initialize(client:, zone:, identity: nil, instance: nil, args: {}) ⇒ GoogleCompute
constructor
A new instance of GoogleCompute.
- #interfaces ⇒ Object
- #ip_addresses ⇒ Object
- #persisted? ⇒ Boolean
- #pretty_image_name ⇒ Object
- #pretty_machine_type ⇒ Object
- #private_ip_address ⇒ Object
- #ready? ⇒ Boolean
- #reload ⇒ Object
- #serial_port_output ⇒ Object
- #set_disk_auto_delete ⇒ Object
- #start ⇒ Object
-
#status ⇒ Object
(also: #state)
if nil, instance is not persisted as VM on GCE.
- #stop ⇒ Object
- #to_s ⇒ Object
- #vm_description ⇒ Object
- #vm_ip_address ⇒ Object (also: #public_ip_address)
- #volumes_attributes=(_attrs) ⇒ Object
- #wait_for(&block) ⇒ Object
Constructor Details
#initialize(client:, zone:, identity: nil, instance: nil, args: {}) ⇒ GoogleCompute
Returns a new instance of GoogleCompute.
6 7 8 9 10 11 12 13 14 |
# File 'app/models/foreman_google/google_compute.rb', line 6 def initialize(client:, zone:, identity: nil, instance: nil, args: {}) @client = client @zone = zone @identity = identity @instance = instance load if identity && instance.nil? load_attributes(args) end |
Instance Attribute Details
#associate_external_ip ⇒ Object (readonly)
Returns the value of attribute associate_external_ip.
3 4 5 |
# File 'app/models/foreman_google/google_compute.rb', line 3 def associate_external_ip @associate_external_ip end |
#creation_timestamp ⇒ Object (readonly)
Returns the value of attribute creation_timestamp.
3 4 5 |
# File 'app/models/foreman_google/google_compute.rb', line 3 def @creation_timestamp end |
#disks ⇒ Object (readonly)
Returns the value of attribute disks.
3 4 5 |
# File 'app/models/foreman_google/google_compute.rb', line 3 def disks @disks end |
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
3 4 5 |
# File 'app/models/foreman_google/google_compute.rb', line 3 def hostname @hostname end |
#identity ⇒ Object (readonly)
Returns the value of attribute identity.
3 4 5 |
# File 'app/models/foreman_google/google_compute.rb', line 3 def identity @identity end |
#image_id ⇒ Object (readonly)
Returns the value of attribute image_id.
3 4 5 |
# File 'app/models/foreman_google/google_compute.rb', line 3 def image_id @image_id end |
#machine_type ⇒ Object (readonly)
Returns the value of attribute machine_type.
3 4 5 |
# File 'app/models/foreman_google/google_compute.rb', line 3 def machine_type @machine_type end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
3 4 5 |
# File 'app/models/foreman_google/google_compute.rb', line 3 def @metadata end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'app/models/foreman_google/google_compute.rb', line 3 def name @name end |
#network ⇒ Object (readonly)
Returns the value of attribute network.
3 4 5 |
# File 'app/models/foreman_google/google_compute.rb', line 3 def network @network end |
#network_interfaces ⇒ Object (readonly)
Returns the value of attribute network_interfaces.
3 4 5 |
# File 'app/models/foreman_google/google_compute.rb', line 3 def network_interfaces @network_interfaces end |
#volumes ⇒ Object (readonly)
Returns the value of attribute volumes.
3 4 5 |
# File 'app/models/foreman_google/google_compute.rb', line 3 def volumes @volumes end |
#zone ⇒ Object (readonly)
Returns the value of attribute zone.
3 4 5 |
# File 'app/models/foreman_google/google_compute.rb', line 3 def zone @zone end |
#zone_name ⇒ Object (readonly)
Returns the value of attribute zone_name.
3 4 5 |
# File 'app/models/foreman_google/google_compute.rb', line 3 def zone_name @zone_name end |
Instance Method Details
#create_instance ⇒ Object
68 69 70 71 |
# File 'app/models/foreman_google/google_compute.rb', line 68 def create_instance args = GoogleCloudCompute::ComputeAttributes.new(@client).for_create(self) @client.insert_instance(@zone, args) end |
#create_volumes ⇒ Object
55 56 57 58 59 60 |
# File 'app/models/foreman_google/google_compute.rb', line 55 def create_volumes @volumes.each do |vol| @client.insert_disk(@zone, vol.insert_attrs) wait_for { @client.disk(@zone, vol.device_name).status == 'READY' } end end |
#destroy_volumes ⇒ Object
62 63 64 65 66 |
# File 'app/models/foreman_google/google_compute.rb', line 62 def destroy_volumes @volumes.each do |volume| @client.delete_disk(@zone, volume.device_name) end end |
#interfaces ⇒ Object
51 52 53 |
# File 'app/models/foreman_google/google_compute.rb', line 51 def interfaces @network_interfaces end |
#ip_addresses ⇒ Object
115 116 117 |
# File 'app/models/foreman_google/google_compute.rb', line 115 def ip_addresses [vm_ip_address, private_ip_address] end |
#persisted? ⇒ Boolean
16 17 18 |
# File 'app/models/foreman_google/google_compute.rb', line 16 def persisted? !!identity end |
#pretty_image_name ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'app/models/foreman_google/google_compute.rb', line 99 def pretty_image_name return unless @instance.disks.any? disk_name = @instance.disks.first.source.split('/').last image_name = @client.disk(@zone_name, disk_name).source_image image_name.split('/').last end |
#pretty_machine_type ⇒ Object
77 78 79 80 |
# File 'app/models/foreman_google/google_compute.rb', line 77 def pretty_machine_type return @machine_type unless @instance @instance.machine_type.split('/').last end |
#private_ip_address ⇒ Object
93 94 95 96 97 |
# File 'app/models/foreman_google/google_compute.rb', line 93 def private_ip_address return unless @instance.network_interfaces.any? @instance.network_interfaces.first.network_i_p end |
#ready? ⇒ Boolean
20 21 22 |
# File 'app/models/foreman_google/google_compute.rb', line 20 def ready? status == 'RUNNING' end |
#reload ⇒ Object
24 25 26 27 28 |
# File 'app/models/foreman_google/google_compute.rb', line 24 def reload return unless identity load self end |
#serial_port_output ⇒ Object
111 112 113 |
# File 'app/models/foreman_google/google_compute.rb', line 111 def serial_port_output @client.serial_port_output(@zone, @identity)&.contents end |
#set_disk_auto_delete ⇒ Object
73 74 75 |
# File 'app/models/foreman_google/google_compute.rb', line 73 def set_disk_auto_delete @client.set_disk_auto_delete(@zone, @name) end |
#start ⇒ Object
37 38 39 40 |
# File 'app/models/foreman_google/google_compute.rb', line 37 def start raise Foreman::Exception('unable to start machine that is not persisted') unless persisted? @client.start(@zone, identity) end |
#status ⇒ Object Also known as: state
if nil, instance is not persisted as VM on GCE
32 33 34 |
# File 'app/models/foreman_google/google_compute.rb', line 32 def status persisted? && @instance.status end |
#stop ⇒ Object
42 43 44 45 |
# File 'app/models/foreman_google/google_compute.rb', line 42 def stop raise Foreman::Exception('unable to stop machine that is not persisted') unless persisted? @client.stop(@zone, identity) end |
#to_s ⇒ Object
47 48 49 |
# File 'app/models/foreman_google/google_compute.rb', line 47 def to_s @name end |
#vm_description ⇒ Object
82 83 84 |
# File 'app/models/foreman_google/google_compute.rb', line 82 def vm_description pretty_machine_type end |
#vm_ip_address ⇒ Object Also known as: public_ip_address
86 87 88 89 90 |
# File 'app/models/foreman_google/google_compute.rb', line 86 def vm_ip_address return if @instance.network_interfaces.empty? @instance.network_interfaces.first.access_configs.first&.nat_i_p end |
#volumes_attributes=(_attrs) ⇒ Object
108 109 |
# File 'app/models/foreman_google/google_compute.rb', line 108 def volumes_attributes=(_attrs) end |
#wait_for(&block) ⇒ Object
119 120 121 |
# File 'app/models/foreman_google/google_compute.rb', line 119 def wait_for(&block) @client.wait_for(&block) end |