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

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

Instance Attribute Summary

Attributes inherited from Model

#collection, #connection

Instance Method Summary collapse

Methods included from Deprecation

deprecate, self_deprecate

Methods inherited from Model

#inspect, #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, #identity, #identity=, #merge_attributes, #new_record?, #requires

Constructor Details

#initialize(attributes = {}) ⇒ Server

Returns a new instance of Server.



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

def initialize(attributes={})
  super
end

Instance Method Details

#destroyObject



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

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

#imageObject



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

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

#private_ip_addressObject



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

def private_ip_address
  nil
end

#ready?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/fog/compute/models/go_grid/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/compute/models/go_grid/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:



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

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

#scp(local_path, remote_path) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/fog/compute/models/go_grid/server.rb', line 80

def scp(local_path, remote_path)
  requires :ip, :username

  options = {}
  options[:key_data] = [private_key] if private_key
  Fog::SCP.new(ip['ip'], username, options).upload(local_path, remote_path)
end

#setup(credentials = {}) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/fog/compute/models/go_grid/server.rb', line 88

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

#ssh(commands) ⇒ Object



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

def ssh(commands)
  requires :ip, :identity, :username

  options = {}
  options[:key_data] = [private_key] if private_key
  Fog::SSH.new(ip['ip'], username, options).run(commands)
end

#usernameObject



102
103
104
# File 'lib/fog/compute/models/go_grid/server.rb', line 102

def username
  @username ||= 'root'
end