Class: Fog::Compute::Glesys::Server
- Inherits:
-
Server
- Object
- Server
- Fog::Compute::Glesys::Server
- Extended by:
- Deprecation
- Defined in:
- lib/fog/glesys/models/compute/server.rb
Instance Method Summary collapse
- #destroy(options = {}) ⇒ Object
- #ip(ip) ⇒ Object
- #ips ⇒ Object
- #public_ip_address(options = {}) ⇒ Object
- #ready? ⇒ Boolean
- #reboot ⇒ Object
- #save ⇒ Object
- #setup(credentials = {}) ⇒ Object
- #ssh(command, options = {}, &block) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Instance Method Details
#destroy(options = {}) ⇒ Object
50 51 52 53 |
# File 'lib/fog/glesys/models/compute/server.rb', line 50 def destroy( = {}) requires :identity service.destroy(.merge!({:serverid => identity})) end |
#ip(ip) ⇒ Object
129 130 131 |
# File 'lib/fog/glesys/models/compute/server.rb', line 129 def ip(ip) Fog::Compute::Glesys::Ips.new(:serverid => identity, :server => self, :service => service).get(ip) end |
#ips ⇒ Object
125 126 127 |
# File 'lib/fog/glesys/models/compute/server.rb', line 125 def ips Fog::Compute::Glesys::Ips.new(:serverid => identity, :server => self, :service => service).all end |
#public_ip_address(options = {}) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/fog/glesys/models/compute/server.rb', line 133 def public_ip_address( = {}) return nil if iplist.nil? type = [: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
31 32 33 |
# File 'lib/fog/glesys/models/compute/server.rb', line 31 def ready? state == 'running' end |
#reboot ⇒ Object
45 46 47 48 |
# File 'lib/fog/glesys/models/compute/server.rb', line 45 def reboot requires :identity service.reboot(:serverid => identity) end |
#save ⇒ Object
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 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/fog/glesys/models/compute/server.rb', line 55 def save if self.identity = { :serverid => self.identity, :disksize => disksize, :memorysize => memorysize, :cpucores => cpucores, :hostname => hostname, :bandwidth => bandwidth } data = service.edit() else requires :hostname, :rootpassword = { :datacenter => datacenter || "Falkenberg", :platform => platform || "OpenVz", :hostname => hostname, :templatename => templatename || "Debian 7.0 64-bit", :disksize => disksize || "10", :memorysize => memorysize || "512", :cpucores => cpucores || "1", :rootpassword => rootpassword, :transfer => transfer || "500", :bandwidth => bandwidth || "10", } # optional options when creating a server: [:ip, :ipv6, :description].each do |k| [k] = attributes[k] if attributes[k] end data = service.create() end merge_attributes(data.body['response']['server']) data.status == 200 ? true : false end |
#setup(credentials = {}) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/fog/glesys/models/compute/server.rb', line 93 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
118 119 120 121 122 123 |
# File 'lib/fog/glesys/models/compute/server.rb', line 118 def ssh(command, ={}, &block) if [:password].nil? && !rootpassword.nil? [:password] = rootpassword end super(command, , &block) end |
#start ⇒ Object
35 36 37 38 |
# File 'lib/fog/glesys/models/compute/server.rb', line 35 def start requires :identity service.start(:serverid => identity) end |
#stop ⇒ Object
40 41 42 43 |
# File 'lib/fog/glesys/models/compute/server.rb', line 40 def stop requires :identity service.stop(:serverid => identity) end |