aboutsummaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2018-06-23 11:16:26 +0100
committerChristopher Baines <mail@cbaines.net>2018-06-23 12:58:05 +0100
commit05df9f91e9bdf39b190710ef5d80162d03dd52c5 (patch)
tree4a092a555a120131f8b3f096d274d2e3afc5bbae /app/models
parent837e1ecec9798381f78b838947f8028403cb0bef (diff)
downloadgovuk-mini-environment-admin-05df9f91e9bdf39b190710ef5d80162d03dd52c5.tar
govuk-mini-environment-admin-05df9f91e9bdf39b190710ef5d80162d03dd52c5.tar.gz
Support managing the libvirt backend from the show page
Diffstat (limited to 'app/models')
-rw-r--r--app/models/backends/terraform_libvirt/backend_methods.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/app/models/backends/terraform_libvirt/backend_methods.rb b/app/models/backends/terraform_libvirt/backend_methods.rb
index 7c3c47d..7595611 100644
--- a/app/models/backends/terraform_libvirt/backend_methods.rb
+++ b/app/models/backends/terraform_libvirt/backend_methods.rb
@@ -33,4 +33,39 @@ module Backends::TerraformLibvirt::BackendMethods
)
end
end
+
+ def destroy_backend
+ TerraformWorkingDirectory.new(
+ terraform_state_id,
+ 'terraform/libvirt/backend'
+ ).within_working_directory do
+ RubyTerraform.destroy(
+ vars: {
+ uri: uri,
+ domain: domain
+ },
+ force: true
+ )
+ end
+ end
+
+ def backend_terraform_states
+ TerraformState.where(
+ state_id: terraform_state_id
+ )
+ end
+
+ def status
+ latest_terraform_state = backend_terraform_states.order(:id).last
+
+ running = (
+ latest_terraform_state &&
+ (latest_terraform_state.output_value('backend_up') == 'true')
+ )
+
+ {
+ running: running,
+ updated_at: latest_terraform_state.try(:created_at)
+ }
+ end
end