Class: Fog::Compute::VirtualBox::Server

Inherits:
Server show all
Defined in:
lib/fog/virtual_box/models/compute/server.rb

Instance Attribute Summary

Attributes inherited from Server

#private_key, #private_key_path, #public_key, #public_key_path, #username

Attributes inherited from Model

#collection, #connection

Instance Method Summary collapse

Methods inherited from Server

#scp, #scp_download, #ssh, #ssh_port, #sshable?

Methods inherited from Model

#inspect, #reload, #symbolize_keys, #to_json, #wait_for

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #requires, #requires_one

Constructor Details

#initialize(attributes = {}) ⇒ Server

property :accelerate_2d_video_enabled, T_BOOL property :accelerate_3d_enabled, T_BOOL property :access_error, :VirtualBoxErrorInfo, :readonly => true property :accessible, T_BOOL, :readonly => true property :audio_adapter, :AudioAdapter, :readonly => true property :bandwidth_control, :BandwidthControl, :readonly => true property :bios_settings, :BIOSSettings, :readonly => true property :chipset_type, :ChipsetType property :clipboard_mode, :ClipboardMode property :cpu_count, T_UINT32 property :cpu_execution_cap, T_UINT64 property :cpu_hot_plug_enabled, T_BOOL property :current_snapshot, :Snapshot, :readonly => true property :current_state_modified, T_BOOL, :readonly => true property :fault_tolerance_address, WSTRING property :fault_tolerance_password, WSTRING property :fault_tolerance_port, T_UINT64 property :fault_tolerance_state, :FaultToleranceState property :fault_tolerance_sync_interval, T_UINT64 property :firmware_type, :FirmwareType property :guest_property_notification_patterns, WSTRING property :hardware_uuid, WSTRING property :hardware_version, WSTRING property :hpet_enabled, T_BOOL property :io_cache_enabled, T_BOOL property :io_cache_size, T_UINT32 property :keyboard_hid_type, T_UINT32 property :last_state_change, T_INT64, :readonly => true property :log_folder, WSTRING, :readonly => true property :medium_attachments, [:MediumAttachment], :readonly => true property :memory_balloon_size, T_UINT64 property :monitor_count, T_UINT64 property :page_fusion_enabled, T_BOOL property :parent, :VirtualBox, :readonly => true property :pci_device_assignments, [:PciDeviceAttachment], :readonly => true property :pointing_hid_type, T_UINT32 property :session_pid, T_UINT64, :readonly => true property :session_type, WSTRING, :readonly => true property :settings_file_path, WSTRING, :readonly => true property :settings_modified, T_BOOL, :readonly => true property :shared_folders, [:SharedFolder], :readonly => true property :snapshot_count, T_UINT32, :readonly => true property :snapshot_folder, WSTRING property :state_file_path, WSTRING, :readonly => true property :storage_controllers, [:StorageController], :readonly => true property :teleporter_address, WSTRING property :teleporter_enabled, T_BOOL property :teleporter_password, WSTRING property :teleporter_port, T_UINT32 property :usb_controller, :USBController, :readonly => true property :vrde_server, :VRDEServer, :readonly => true



72
73
74
75
76
77
# File 'lib/fog/virtual_box/models/compute/server.rb', line 72

def initialize(attributes={})
  self.memory_size = 256
  self.rtc_use_utc = true
  self.vram_size   = 8
  super
end

Instance Method Details

#destroyObject



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/fog/virtual_box/models/compute/server.rb', line 79

def destroy
  requires :name, :raw
  unless raw.state == :powered_off
    stop
    wait_for { raw.session_state == :closed }
  end
  raw.unregister(:full)
  config_file = connection.compose_machine_filename(name)
  config_directory = config_file.split(File::SEPARATOR)[0...-1].join(File::SEPARATOR)
  FileUtils.rm_rf(config_directory)
  true
end

#network_adaptersObject



92
93
94
95
96
97
# File 'lib/fog/virtual_box/models/compute/server.rb', line 92

def network_adapters
  Fog::Compute::VirtualBox::NetworkAdapters.new(
    :connection => connection,
    :machine => self
  )
end

#private_ip_addressObject



99
100
101
# File 'lib/fog/virtual_box/models/compute/server.rb', line 99

def private_ip_address
  nil
end

#public_ip_addressObject



103
104
105
# File 'lib/fog/virtual_box/models/compute/server.rb', line 103

def public_ip_address
  nil
end

#ready?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/fog/virtual_box/models/compute/server.rb', line 107

def ready?
  status == :running
end

#rebootObject



111
112
113
114
115
# File 'lib/fog/virtual_box/models/compute/server.rb', line 111

def reboot
  requires :raw
  session.console.reset
  true
end

#saveObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/fog/virtual_box/models/compute/server.rb', line 117

def save
  unless identity
    requires :name, :os
    self.raw = connection.create_machine(nil, name, os)
    connection.register_machine(raw)
    with_session do |session|
      for attribute in [:description, :memory_size, :rtc_use_utc, :vram_size]
        session.machine.send(:"#{attribute}=", attributes[attribute])
      end
      session.machine.save_settings
    end
    true
  else
    raise Fog::Errors::Error.new('Updating an existing server is not yet implemented. Contributions welcome!')
  end
end

#setup(credentials = {}) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/fog/virtual_box/models/compute/server.rb', line 134

def setup(credentials = {})
  raise 'Not Implemented'
#   requires :addresses, :identity, :public_key, :username
#   Fog::SSH.new(addresses['public'].first, username, credentials).run([
#     %{mkdir .ssh},
#     %{echo "#{public_key}" >> ~/.ssh/authorized_keys},
#     %{passwd -l #{username}},
#     %{echo "#{Fog::JSON.encode(attributes)}" >> ~/attributes.json},
#     %{echo "#{Fog::JSON.encode(metadata)}" >> ~/metadata.json}
#   ])
# rescue Errno::ECONNREFUSED
#   sleep(1)
#   retry
end

#start(type = 'headless') ⇒ Object



149
150
151
152
153
154
# File 'lib/fog/virtual_box/models/compute/server.rb', line 149

def start(type = 'headless')
  requires :raw
  # session, type in ['gui', 'headless'], key[=value]\n env variables
  raw.launch_vm_process(session, type, '').wait
  true
end

#stopObject



156
157
158
159
160
# File 'lib/fog/virtual_box/models/compute/server.rb', line 156

def stop
  requires :raw
  session.console.power_down.wait
  true
end

#storage_controllersObject



162
163
164
165
166
167
# File 'lib/fog/virtual_box/models/compute/server.rb', line 162

def storage_controllers
  Fog::Compute::VirtualBox::StorageControllers.new(
    :connection => connection,
    :machine    => self
  )
end