Class: Fog::Compute::GoGrid::Server

Inherits:
Server
  • Object
show all
Extended by:
Deprecation
Defined in:
lib/fog/go_grid/models/compute/server.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Server

Returns a new instance of Server.



22
23
24
25
# File 'lib/fog/go_grid/models/compute/server.rb', line 22

def initialize(attributes={})
  image_id ||= 'ubuntu_10_04_LTS_64_base' # Ubuntu 10.04 LTS 64bit
  super
end

Instance Method Details

#destroyObject



27
28
29
30
31
# File 'lib/fog/go_grid/models/compute/server.rb', line 27

def destroy
  requires :id
  service.grid_server_delete(id)
  true
end

#imageObject



33
34
35
36
# File 'lib/fog/go_grid/models/compute/server.rb', line 33

def image
  requires :image_id
  service.grid_image_get(:image => image_id)
end

#private_ip_addressObject



38
39
40
# File 'lib/fog/go_grid/models/compute/server.rb', line 38

def private_ip_address
  nil
end

#ready?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/fog/go_grid/models/compute/server.rb', line 42

def ready?
  @state && @state["name"] == 'On'
end

#reloadObject



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/fog/go_grid/models/compute/server.rb', line 46

def reload
  requires :name
  begin
    if data = collection.get(name)
      new_attributes = data.attributes
      merge_attributes(new_attributes)
      self
    end
  rescue Excon::Errors::BadRequest
    false
  end
end

#saveObject

Raises:

  • (Fog::Errors::Error)


59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/fog/go_grid/models/compute/server.rb', line 59

def save
  raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
  requires :name, :image_id, :memory, :public_ip_address
  options = {
    'isSandbox'   => sandbox,
    'image'       => image_id
  }
  options = options.reject {|key, value| value.nil?}
  data = service.grid_server_add(image, public_ip_address, name, memory, options)
  merge_attributes(data.body)
  true
end

#setup(credentials = {}) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/fog/go_grid/models/compute/server.rb', line 72

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