lib/vagabond/vagabond.rb in vagabond-0.1.0 vs lib/vagabond/vagabond.rb in vagabond-0.1.2

- old
+ new

@@ -6,16 +6,19 @@ require action_module end require 'vagabond/vagabondfile' require 'vagabond/internal_configuration' +require 'vagabond/helpers' require 'chef/knife/core/ui' require File.join(File.dirname(__FILE__), 'cookbooks/lxc/libraries/lxc.rb') module Vagabond class Vagabond + include Helpers + class << self attr_accessor :ui end # Load available actions @@ -53,33 +56,44 @@ @config = @vagabondfile[:boxes][name] @lxc = Lxc.new(@internal_config[:mappings][name] || '____nonreal____') unless(Config[:disable_local_server]) if(@vagabondfile[:local_chef_server] && @vagabondfile[:local_chef_server][:enabled]) srv = Lxc.new(@internal_config[:mappings][:server]) - Config[:knife_opts] = " -s https://#{srv.container_ip(10, true)}" + if(srv.running?) + Config[:knife_opts] = " --server-url https://#{srv.container_ip(10, true)}" + else + ui.warn 'Local chef server is not currently running!' unless @action.to_sym == :status + Config[:knife_opts] = ' --server-url https://no-local-server' + end end end end + protected + def setup_ui - Chef::Config[:color] = true + Chef::Config[:color] = Config[:color] @ui = Chef::Knife::UI.new(STDOUT, STDERR, STDIN, {}) self.class.ui = @ui end def validate! if(name.to_s == 'server') - raise 'Box name `server` is reserved and not allowed!' + ui.fatal "Invalid name supplied: #{ui.color(name, :red)}" + ui.info ui.color(" -> Try: vagabond server #{@action}", :cyan) + exit -1 end end def execute - send(@action) + if(public_methods.include?(@action.to_sym)) + send(@action) + else + ui.error "Invalid action received: #{@action}" + end end - private - def generate_hash Digest::MD5.hexdigest(@vagabondfile.path) end def check_existing! @@ -87,18 +101,9 @@ ui.error "LXC: #{name} already exists!" true end end - def sudo - case @vagabondfile[:sudo] - when TrueClass - 'sudo ' - when String - "#{@vagabondfile[:sudo]} " - end - end - def base_dir File.dirname(vagabondfile.path) end def vagabond_dir