Module: CapGCE::Utils
- Included in:
- GCEHandler, StatusTable
- Defined in:
- lib/cap-gce/utils.rb
Defined Under Namespace
Modules: Server
Class Method Summary collapse
- .all_network_interfaces(instance) ⇒ Object
- .contact_point(instance) ⇒ Object
- .contact_point_mapping ⇒ Object
- .nat_ip(instance) ⇒ Object
Instance Method Summary collapse
Class Method Details
.all_network_interfaces(instance) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/cap-gce/utils.rb', line 45 def self.all_network_interfaces(instance) { network_ip: instance.network_interfaces.map(&:network_ip), nat_ip: nat_ip(instance) } end |
.contact_point(instance) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/cap-gce/utils.rb', line 36 def self.contact_point(instance) gce_interface = contact_point_mapping[fetch(:gce_contact_point)] network_interfaces = all_network_interfaces(instance) return network_interfaces[gce_interface] if gce_interface !network_interfaces[:nat_ip].empty? && network_interfaces[:nat_ip] || !network_interfaces[:network_ip].empty? && network_interfaces[:network_ip] end |
.contact_point_mapping ⇒ Object
29 30 31 32 33 34 |
# File 'lib/cap-gce/utils.rb', line 29 def self.contact_point_mapping { public_ip: :nat_ip, private_ip: :network_ip } end |
.nat_ip(instance) ⇒ Object
52 53 54 55 |
# File 'lib/cap-gce/utils.rb', line 52 def self.nat_ip(instance) return [] if (instance.network_interfaces.map(&:access_configs).flatten - [nil]).empty? instance.network_interfaces.map(&:access_configs).flatten.map(&:nat_ip) - [nil] end |
Instance Method Details
#project_tag ⇒ Object
10 11 12 |
# File 'lib/cap-gce/utils.rb', line 10 def project_tag fetch(:gce_project_tag) end |
#roles_tag ⇒ Object
14 15 16 |
# File 'lib/cap-gce/utils.rb', line 14 def roles_tag fetch(:gce_roles_tag) end |
#stages_tag ⇒ Object
18 19 20 |
# File 'lib/cap-gce/utils.rb', line 18 def stages_tag fetch(:gce_stages_tag) end |
#tag_value(instance, key) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/cap-gce/utils.rb', line 22 def tag_value(instance, key) return nil unless instance..items find = instance..items.detect { |t| t.key == key.to_s } return nil unless find find.value end |