Class: ForemanOpentofu::Tofu

Inherits:
ComputeResource
  • Object
show all
Includes:
ComputeResourceCaching, OpentofuVMCommands, KeyPairComputeResource
Defined in:
app/models/foreman_opentofu/tofu.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from OpentofuVMCommands

#create_vm, #destroy_vm, #fetch_resource, #find_vm_by_uuid, #new_vm, #save_vm, #start_vm, #stop_vm, #test_connection

Class Method Details

.model_nameObject



87
88
89
# File 'app/models/foreman_opentofu/tofu.rb', line 87

def self.model_name
  ComputeResource.model_name
end

.provider_friendly_nameObject



83
84
85
# File 'app/models/foreman_opentofu/tofu.rb', line 83

def self.provider_friendly_name
  'OpenTofu'
end

Instance Method Details

#available_imagesObject



39
40
41
42
# File 'app/models/foreman_opentofu/tofu.rb', line 39

def available_images
  # make sure available_images can use this CR, e.g. for requesting data_source
  tofu_provider.available_images(self)
end

#available_resource(resource_name, options = {}) ⇒ Object



129
130
131
132
133
134
# File 'app/models/foreman_opentofu/tofu.rb', line 129

def available_resource(resource_name, options = {})
  cache.cache("#{name}_#{resource_name}") do
    resource = fetch_resource(resource_name, options)
    resource.map { |h| OpenStruct.new(h) }
  end
end

#available_resource_ui_select(resource_name, options = {}) ⇒ Object



140
141
142
# File 'app/models/foreman_opentofu/tofu.rb', line 140

def available_resource_ui_select(resource_name, options = {})
  available_resource(resource_name, options)&.map { |obj| [obj['name'], obj['id']] }
end

#available_ssh_keysObject



44
45
46
47
# File 'app/models/foreman_opentofu/tofu.rb', line 44

def available_ssh_keys
  # make sure available_ssh_keys can use this CR, e.g. for requesting data_source
  tofu_provider.available_ssh_keys(self)
end

#cache_delete(resource_name) ⇒ Object



136
137
138
# File 'app/models/foreman_opentofu/tofu.rb', line 136

def cache_delete(resource_name)
  cache.delete("#{name}_#{resource_name}") if resource_name.present?
end

#capabilitiesObject



33
34
35
36
37
# File 'app/models/foreman_opentofu/tofu.rb', line 33

def capabilities
  # do not delegate to avoid problems with (Foreman::)KeyPairCapabilities concern
  # Attention: KeyPairCapabilities concern adds 'key_pair'-capabilities to all OpenTofu compute resources!
  tofu_provider.capabilities || []
end

#default_attributesObject



91
92
93
# File 'app/models/foreman_opentofu/tofu.rb', line 91

def default_attributes
  tofu_provider&.default_attributes || {}
end

#default_interfacesObject



121
122
123
# File 'app/models/foreman_opentofu/tofu.rb', line 121

def default_interfaces
  tofu_provider&.default_interfaces || {}
end

#default_volumesObject



117
118
119
# File 'app/models/foreman_opentofu/tofu.rb', line 117

def default_volumes
  tofu_provider&.default_volumes || {}
end

#editable_network_interfaces?Boolean

Returns:

  • (Boolean)


125
126
127
# File 'app/models/foreman_opentofu/tofu.rb', line 125

def editable_network_interfaces?
  true
end

#new_interface(attr = {}) ⇒ Object



109
110
111
# File 'app/models/foreman_opentofu/tofu.rb', line 109

def new_interface(attr = {})
  OpenStruct.new(attr)
end

#new_volume(attr = {}) ⇒ Object



113
114
115
# File 'app/models/foreman_opentofu/tofu.rb', line 113

def new_volume(attr = {})
  OpenStruct.new(attr.merge({}))
end

#opentofu_providerObject



61
62
63
# File 'app/models/foreman_opentofu/tofu.rb', line 61

def opentofu_provider
  attrs[:opentofu_provider]
end

#opentofu_provider=(value) ⇒ Object



65
66
67
# File 'app/models/foreman_opentofu/tofu.rb', line 65

def opentofu_provider=(value)
  attrs[:opentofu_provider] = value
end

#opentofu_templateObject



69
70
71
72
73
# File 'app/models/foreman_opentofu/tofu.rb', line 69

def opentofu_template
  return ProvisioningTemplate.find(attrs[:opentofu_template_id]) if attrs.key? :opentofu_template_id
  # or default-template for this opentofu_provider
  nil
end

#opentofu_template_idObject



75
76
77
# File 'app/models/foreman_opentofu/tofu.rb', line 75

def opentofu_template_id
  attrs[:opentofu_template_id]
end

#opentofu_template_id=(value) ⇒ Object



79
80
81
# File 'app/models/foreman_opentofu/tofu.rb', line 79

def opentofu_template_id=(value)
  attrs[:opentofu_template_id] = value
end

#provided_attributesObject



53
54
55
# File 'app/models/foreman_opentofu/tofu.rb', line 53

def provided_attributes
  super.merge(tofu_provider.provided_attributes || {})
end

#reset_cached_ssh_keysObject



49
50
51
# File 'app/models/foreman_opentofu/tofu.rb', line 49

def reset_cached_ssh_keys
  tofu_provider.reset_cached_ssh_keys(self)
end

#supports_update?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'app/models/foreman_opentofu/tofu.rb', line 95

def supports_update?
  true
end

#tofu_providerObject



105
106
107
# File 'app/models/foreman_opentofu/tofu.rb', line 105

def tofu_provider
  ProviderTypeManager.find(opentofu_provider)
end

#user_data_supported?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'app/models/foreman_opentofu/tofu.rb', line 57

def user_data_supported?
  true
end

#vm_compute_attributes(vm) ⇒ Object



144
145
146
147
# File 'app/models/foreman_opentofu/tofu.rb', line 144

def vm_compute_attributes(vm)
  vm_attrs = super
  tofu_provider.normalize_interfaces(vm_attrs)
end

#vm_ready(vm) ⇒ Object



99
100
101
102
103
# File 'app/models/foreman_opentofu/tofu.rb', line 99

def vm_ready(vm)
  return tofu_provider.vm_ready(vm) if tofu_provider.respond_to? :vm_ready

  vm.wait_for { ready? }
end