Class: Fog::Compute::Glesys::Server

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

Instance Attribute Summary

Attributes inherited from Server

#private_key, #private_key_path, #public_key, #public_key_path, #ssh_options, #ssh_port, #username

Attributes inherited from Model

#collection, #service

Instance Method Summary collapse

Methods included from Deprecation

deprecate, self_deprecate

Methods inherited from Server

#scp, #scp_download, #ssh_ip_address, #ssh_ip_address=, #sshable?

Methods inherited from Model

#initialize, #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 Fog::Core::DeprecatedConnectionAccessors

#connection, #connection=, #prepare_service_value

Methods included from Attributes::InstanceMethods

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

Constructor Details

This class inherits a constructor from Fog::Model

Instance Method Details

#destroy(options = {}) ⇒ Object



50
51
52
53
# File 'lib/fog/glesys/models/compute/server.rb', line 50

def destroy(options = {})
  requires :identity
  service.destroy(options.merge!({:serverid => identity}))
end

#ip(ip) ⇒ Object



117
118
119
# File 'lib/fog/glesys/models/compute/server.rb', line 117

def ip(ip)
  Fog::Compute::Glesys::Ips.new(:serverid => identity, :server => self, :service => service).get(ip)
end

#ipsObject



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

def ips
  Fog::Compute::Glesys::Ips.new(:serverid => identity, :server => self, :service => service).all
end

#public_ip_address(options = {}) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/fog/glesys/models/compute/server.rb', line 121

def public_ip_address(options = {})

  return nil if iplist.nil?

  type = options[:type] || nil

  ips = case type
    when :ipv4 then iplist.select { |ip| ip["version"] == 4 }
    when :ipv6 then iplist.select { |ip| ip["version"] == 6 }
    else iplist.sort_by { |ip| ip["version"] }
  end

  if ips.empty?
    nil
  else
    ips.first["ipaddress"]
  end
end

#ready?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/fog/glesys/models/compute/server.rb', line 31

def ready?
  state == 'running'
end

#rebootObject



45
46
47
48
# File 'lib/fog/glesys/models/compute/server.rb', line 45

def reboot
  requires :identity
  service.reboot(:serverid => identity)
end

#saveObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/fog/glesys/models/compute/server.rb', line 55

def save
  raise "Operation not supported" if self.identity
  requires :hostname, :rootpassword

  options = {
    :datacenter     => datacenter   || "Falkenberg",
    :platform       => platform     || "Xen",
    :hostname       => hostname,
    :templatename   => templatename || "Debian-6 x64",
    :disksize       => disksize     || "10",
    :memorysize     => memorysize   || "512",
    :cpucores       => cpucores     || "1",
    :rootpassword   => rootpassword,
    :transfer       => transfer     || "500",
  }

  # optional options when creating a server:
  [:ip, :ipv6, :description].each do |k|
    options[k] = attributes[k] if attributes[k]
  end

  data = service.create(options)
  merge_attributes(data.body['response']['server'])
  data.status == 200 ? true : false
end

#setup(credentials = {}) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/fog/glesys/models/compute/server.rb', line 81

def setup(credentials = {})
  requires :ssh_ip_address, :username
  require 'net/ssh'

  attrs = attributes.dup
  attrs.delete(:rootpassword)

  commands = [
    %{mkdir -p .ssh},
    %{echo "#{Fog::JSON.encode(Fog::JSON.sanitize(attrs))}" >> ~/attributes.json}
  ]
  if public_key
    commands << %{echo "#{public_key}" >> ~/.ssh/authorized_keys}
  end

  if credentials[:password].nil? && !rootpassword.nil?
    credentials[:password] = rootpassword
  end

  # wait for glesys to be ready
  wait_for { sshable?(credentials) }

  Fog::SSH.new(ssh_ip_address, username, credentials).run(commands)
end

#ssh(command, options = {}, &block) ⇒ Object



106
107
108
109
110
111
# File 'lib/fog/glesys/models/compute/server.rb', line 106

def ssh(command, options={}, &block)
  if options[:password].nil? && !rootpassword.nil?
    options[:password] = rootpassword
  end
  super(command, options, &block)
end

#startObject



35
36
37
38
# File 'lib/fog/glesys/models/compute/server.rb', line 35

def start
  requires :identity
  service.start(:serverid => identity)
end

#stopObject



40
41
42
43
# File 'lib/fog/glesys/models/compute/server.rb', line 40

def stop
  requires :identity
  service.stop(:serverid => identity)
end