Class: Veewee::Provider::Core::Box

Inherits:
Object
  • Object
show all
Includes:
BoxCommand, Helper::Comm, Helper::Iso, Helper::Shell, Helper::Ssh, Helper::Tcp, Helper::Web
Defined in:
lib/veewee/provider/core/box.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BoxCommand

#build, #build_info, #copy_to_box, #create_floppy, #create_wget_vbs_command, #escape_and_echo, #exec, #fill_sequence, #filter_postinstall_files, #halt, #handle_kickstart, #handle_postinstall, #issh, #poweroff, #scp, #send_vnc_keycode, #ssh, #ssh_command_string, #string_to_vnccode, #sudo, #transfer_buildinfo, #validate_postinstall_regex, #validate_tags, #vnc_type, #wget_vbs, #wget_vbs_file, #wincp, #winrm, #winrm_command_string

Methods included from Helper::Iso

#download_iso, #download_progress, #hashsum, #verify_iso, #verify_sum

Methods included from Helper::Comm

#comm_execute, #comm_method, #comm_transfer_file, #when_comm_login_works

Methods included from Helper::Ssh

#ssh_execute, #ssh_transfer_file, #when_ssh_login_works

Methods included from Helper::Shell

#shell_exec

Methods included from Helper::Web

#allow_for_http_request, #server_for_http_request, #wait_for_http_request

Methods included from Helper::Tcp

#execute_when_tcp_available, #get_local_ip, #guess_free_port, #host_ip_as_seen_by_guest, #is_tcp_port_open?

Constructor Details

#initialize(name, env) ⇒ Box

Returns a new instance of Box.



47
48
49
50
51
# File 'lib/veewee/provider/core/box.rb', line 47

def initialize(name,env)
  @env=env
  @name=name
  self.set_definition(name)
end

Instance Attribute Details

#definitionObject

Returns the value of attribute definition.



26
27
28
# File 'lib/veewee/provider/core/box.rb', line 26

def definition
  @definition
end

#envObject

Returns the value of attribute env.



27
28
29
# File 'lib/veewee/provider/core/box.rb', line 27

def env
  @env
end

#nameObject

Returns the value of attribute name.



28
29
30
# File 'lib/veewee/provider/core/box.rb', line 28

def name
  @name
end

#providerObject

Returns the value of attribute provider.



29
30
31
# File 'lib/veewee/provider/core/box.rb', line 29

def provider
  @provider
end

Instance Method Details

#gem_available?(gemname) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/veewee/provider/core/box.rb', line 53

def gem_available?(gemname)
  env.logger.info "Checking for gem #{gemname}"
  available=false
  begin
    available=true unless Gem::Specification::find_by_name("#{gemname}").nil?
  rescue Gem::LoadError
    env.logger.info "Error loading gem #{gemname}"
    available=false
  rescue
    env.logger.info "Falling back to old syntax for #{gemname}"
    available=Gem.available?("#{gemname}")
    env.logger.info "Old syntax #{gemname}.available? #{available}"
  end
  return available
end

#reloadObject



96
97
98
# File 'lib/veewee/provider/core/box.rb', line 96

def reload
  @raw=nil
end

#set_definition(definition_name) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/veewee/provider/core/box.rb', line 69

def set_definition(definition_name)
  @definition=env.definitions[definition_name]

  unless @definition.nil?
    # We check for windows as em-winrm is not available on ruby1.9
    is_windows =  @definition.os_type_id.start_with?('Windows')

    # On windows systems
    if is_windows
      # Check if winrm is available
      if gem_available?('em-winrm')
        require 'veewee/provider/core/box/winrm'
        require 'veewee/provider/core/helper/winrm'
        require 'veewee/provider/core/box/wincp'

        self.class.send(:include, ::Veewee::Provider::Core::Helper::Winrm)
      else
        raise Veewee::Error, "\nTo build a windows basebox you need to install the gem 'em-winrm' first"
      end
    end
  else
    raise Veewee::Error, "definition '#{definition_name}' does not exist. Are you sure you are in the top directory?"
  end

  return self
end

#uiObject



40
41
42
43
44
45
# File 'lib/veewee/provider/core/box.rb', line 40

def ui
  return @_ui if defined?(@_ui)
  @_ui = @env.ui.dup
  @_ui.resource = @name
  @_ui
end