Sha256: 0dc866df9d1852c47e26099ce7ec45afa0e46b5f788cbd2cc9caec8b22d06bef

Contents?: true

Size: 841 Bytes

Versions: 3

Compression:

Stored size: 841 Bytes

Contents

module VagrantPlugins
  module ProviderLibvirt
    module Action

      # Setup name for domain and domain volumes.
      class SetNameOfDomain
        def initialize(app, env)
          @app = app
        end

        def call(env)
          require 'securerandom'
          env[:domain_name] = env[:root_path].basename.to_s.dup
          env[:domain_name].gsub!(/[^-a-z0-9_]/i, "")
          env[:domain_name] << "_#{SecureRandom.hex}"

          # Check if the domain name is not already taken
          domain = ProviderLibvirt::Util::Collection.find_matching(
            env[:libvirt_compute].servers.all, env[:domain_name])
          if domain != nil
            raise Vagrant::Errors::DomainNameExists,
              :domain_name => env[:domain_name]
          end

          @app.call(env)
        end
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vagrant-libvirt-0.0.10 lib/vagrant-libvirt/action/set_name_of_domain.rb
vagrant-libvirt-0.0.9 lib/vagrant-libvirt/action/set_name_of_domain.rb
vagrant-libvirt-0.0.8 lib/vagrant-libvirt/action/set_name_of_domain.rb