diff options
author | Christopher Baines <mail@cbaines.net> | 2018-04-07 15:45:00 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2018-04-12 19:05:31 +0100 |
commit | cefa86029c9d4fc4cffaa05d33da9c978dbb1c16 (patch) | |
tree | 32287e4378e255c0937f89177ff5a133e057e029 /app/jobs | |
parent | 6670c74eae0cae82319365ee53c8ba01db16b758 (diff) | |
download | govuk-mini-environment-admin-cefa86029c9d4fc4cffaa05d33da9c978dbb1c16.tar govuk-mini-environment-admin-cefa86029c9d4fc4cffaa05d33da9c978dbb1c16.tar.gz |
Improve the support for Libvirt
Separate out the backend things, like the virtual network, from the
mini environment. This makes it easier to have resources shared
between mini environments.
Also handle the deployment of this new backend related Terraform
configuration.
Diffstat (limited to 'app/jobs')
-rw-r--r-- | app/jobs/backends/deploy_terraform_libvirt_job.rb | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/app/jobs/backends/deploy_terraform_libvirt_job.rb b/app/jobs/backends/deploy_terraform_libvirt_job.rb new file mode 100644 index 0000000..3b8b51a --- /dev/null +++ b/app/jobs/backends/deploy_terraform_libvirt_job.rb @@ -0,0 +1,59 @@ +# GOV.UK Mini Environment Admin +# Copyright © 2018 Christopher Baines <mail@cbaines.net> +# +# This file is part of the GOV.UK Mini Environment Admin. +# +# The GOV.UK Mini Environment Admin is free software: you can +# redistribute it and/or modify it under the terms of the GNU Affero +# General Public License as published by the Free Software Foundation, +# either version 3 of the License, or (at your option) any later +# version. +# +# The GOV.UK Mini Environment Admin is distributed in the hope that it +# will be useful, but WITHOUT ANY WARRANTY; without even the implied +# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with the GOV.UK Mini Environment Admin. If not, see +# <http://www.gnu.org/licenses/>. + +class Backends::DeployTerraformLibvirtJob < Que::Job + def run(terraform_libvirt_backend_id) + @terraform_libvirt_backend_id = terraform_libvirt_backend_id + + Backends::TerraformLibvirt + .find(terraform_libvirt_backend_id) + .deploy_backend + end + + def destroy + FinishedTerraformJob.create( + model_id: @terraform_libvirt_backend_id, + job_class: attrs[:job_class] + ) + super + end + + def self.jobs(terraform_libvirt_backend_id) + [ + QueJob + .where( + job_class: name + ).where( + "args->>0 = '#{terraform_libvirt_backend_id}'" + ).to_a, + FinishedTerraformJob + .where( + job_class: name, + model_id: terraform_libvirt_backend_id + ) + ].flatten.sort_by do |x| + if x.instance_of? QueJob + x.run_at + else # FinishedTerraformJob + x.created_at + end + end + end +end |