Class: Mist::LxcHandler
- Inherits:
-
Object
- Object
- Mist::LxcHandler
- Defined in:
- lib/mist/handlers/lxc.rb
Instance Method Summary collapse
- #create(args) ⇒ Object
- #destroy(args) ⇒ Object
-
#initialize(config) ⇒ LxcHandler
constructor
A new instance of LxcHandler.
Constructor Details
#initialize(config) ⇒ LxcHandler
Returns a new instance of LxcHandler.
20 21 22 |
# File 'lib/mist/handlers/lxc.rb', line 20 def initialize(config) @config = config end |
Instance Method Details
#create(args) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mist/handlers/lxc.rb', line 24 def create(args) Mist.logger.debug "create: args=#{args}" hostname = Socket.gethostname distro = args['distro'] || @config.default_distro release = args['release'] || @config.default_release name = args['name'] || create_name begin Mist.logger.info "creating container #{name} with #{distro}-#{release}" container = Mist::LXCContainer.new(name, distro, release) raise "container with the name #{name} already exists!" if container.exists? startup_script = File.join(@config.startup_script_path, 'lxc', distro) container.create(@config, startup_script) ip = container.ips.first rescue StandardError => ex Mist.logger.error "Create request failed: #{ex}" return { status: false, server: hostname, message: "create request failed: #{ex}" } end return { status: true, server: hostname, message: 'created new container', name: name, ip: ip, username: @config.username } end |
#destroy(args) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/mist/handlers/lxc.rb', line 56 def destroy(args) Mist.logger.debug "destroy: args=#{args}" begin name = args['name'] container = Mist::LXCContainer.new(name) Mist.logger.info "destroying #{name}" container.destroy rescue StandardError => ex Mist.logger.error "Destroy request failed: #{ex}" return { status: false, message: "destroy request failed: #{ex}" } end return { status: true, message: 'destroyed container', name: name } end |