Class: TortoiseLabs::VPS

Inherits:
Object
  • Object
show all
Defined in:
lib/tortoiselabs/vps.rb

Overview

VPS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vps) ⇒ VPS

Instance methods



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/tortoiselabs/vps.rb', line 50

def initialize(vps)
  @node, @name, @mac, @memory, @disk = vps["node"], vps["name"],  
    vps["mac"], vps["memory"], vps["disk"]
    
  @nickname, @id, @swap, @user = vps["nickname"], vps["id"], 
    vps["swap"], vps["user"]
    
  @ips = Hash.new
  vps["ips"].each do |iphash|
    obj = IP.new(iphash)
    @ips[obj.ip] = obj
  end
end

Instance Attribute Details

#diskObject (readonly)

Returns the value of attribute disk.



45
46
47
# File 'lib/tortoiselabs/vps.rb', line 45

def disk
  @disk
end

#idObject (readonly)

Returns the value of attribute id.



45
46
47
# File 'lib/tortoiselabs/vps.rb', line 45

def id
  @id
end

#ipsObject (readonly)

Returns the value of attribute ips.



46
47
48
# File 'lib/tortoiselabs/vps.rb', line 46

def ips
  @ips
end

#macObject (readonly)

Returns the value of attribute mac.



45
46
47
# File 'lib/tortoiselabs/vps.rb', line 45

def mac
  @mac
end

#memoryObject (readonly)

Returns the value of attribute memory.



45
46
47
# File 'lib/tortoiselabs/vps.rb', line 45

def memory
  @memory
end

#nameObject (readonly)

Returns the value of attribute name.



45
46
47
# File 'lib/tortoiselabs/vps.rb', line 45

def name
  @name
end

#nicknameObject

Returns the value of attribute nickname.



46
47
48
# File 'lib/tortoiselabs/vps.rb', line 46

def nickname
  @nickname
end

#nodeObject (readonly)

Returns the value of attribute node.



45
46
47
# File 'lib/tortoiselabs/vps.rb', line 45

def node
  @node
end

#swapObject (readonly)

Returns the value of attribute swap.



46
47
48
# File 'lib/tortoiselabs/vps.rb', line 46

def swap
  @swap
end

#userObject (readonly)

Returns the value of attribute user.



46
47
48
# File 'lib/tortoiselabs/vps.rb', line 46

def user
  @user
end

Class Method Details

.get(id) ⇒ Object



220
221
222
223
# File 'lib/tortoiselabs/vps.rb', line 220

def self.get(id)
  vpshash = JSON.parse(TortoiseLabs::Client.get("/vps/#{id}"))["service"]
  self.new(vpshash)
end

.listObject

Class methods



184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/tortoiselabs/vps.rb', line 184

def self.list
  json = JSON.parse(TortoiseLabs::Client.get("/vps/list"))
  return nil if json.empty?
  
  vpses = Hash.new
  json["vpslist"].each do |vps|
    obj = self.new(vps)
    vpses[obj.nickname] = obj
  end
  
  vpses
end

.plansObject



204
205
206
207
208
209
210
211
212
213
# File 'lib/tortoiselabs/vps.rb', line 204

def self.plans
  result = JSON.parse(TortoiseLabs::Client.get("/vps/signup"))
  plans = Array.new
  result["resource_plans"].each do |p|
    obj = Plan.new(p["id"], p["disk"], p["memory"], p["name"], 
      p["price_btc"], p["price_usd"], p["swap"])
    plans << obj
  end
  plans
end

.regionsObject



197
198
199
200
201
202
# File 'lib/tortoiselabs/vps.rb', line 197

def self.regions
  result = JSON.parse(TortoiseLabs::Client.get("/vps/signup"))["regions"]
  regions = Array.new
  result.each { |r| regions << Region.new(r["id"], r["name"]) }
  regions
end

.signup(regionid, planid) ⇒ Object



215
216
217
218
# File 'lib/tortoiselabs/vps.rb', line 215

def self.(regionid, planid)
  result = TortoiseLabs::Client.post("/vps/signup",
    {:region => regionid, :plan => planid})
end

Instance Method Details

#createObject



121
122
123
124
# File 'lib/tortoiselabs/vps.rb', line 121

def create
  result = TortoiseLabs::Client.get("/vps/#{@id}/create")
  result.parsed_response["job"]
end

#delete_iso(isoid) ⇒ Object



177
178
179
180
# File 'lib/tortoiselabs/vps.rb', line 177

def delete_iso(isoid)
  result = TortoiseLabs::Client.post("/vps/#{@id}/hvmiso/#{isoid}/delete")
  hvm
end

#deploy(image, rootpass, arch = "x86_64") ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/tortoiselabs/vps.rb', line 93

def deploy(image, rootpass, arch = "x86_64")
  # arch can be either x86_64 or i386
  # Image is one of the values returned by the templates method above
  
  unless image =~ /_login\.xml$/i
    image = image + "_login.xml"
  end
  
  result = TortoiseLabs::Client.post("/vps/#{@id}/deploy", 
    {:imagename => image, :rootpass => rootpass, :arch => arch})
  jobs
end

#destroyObject



111
112
113
114
# File 'lib/tortoiselabs/vps.rb', line 111

def destroy
  result = TortoiseLabs::Client.get("/vps/#{@id}/destroy")
  result.parsed_response["job"]
end

#hvmObject



147
148
149
150
# File 'lib/tortoiselabs/vps.rb', line 147

def hvm
  result = TortoiseLabs::Client.get("/vps/#{@id}/hvm").parsed_response
  JSON.parse(result)["isolist"]
end

#jobsObject



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/tortoiselabs/vps.rb', line 131

def jobs
  res = TortoiseLabs::Client.get("/vps/#{@id}/jobs.json").parsed_response
  
  jobs = Hash.new
  res.each do |jobhash|
    begin
      obj = Job.new(jobhash)
      jobs[obj.id] = obj
    rescue NoMethodError => err
      # occurs when there are no jobs
    end
  end
  
  jobs
end

#monitoring=(boolean) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/tortoiselabs/vps.rb', line 74

def monitoring=(boolean)
  if boolean
    result = TortoiseLabs::Client.get("/vps/#{@id}/monitoring/enable")
  else
    result = TortoiseLabs::Client.get("/vps/#{@id}/monitoring/disable")
  end
  boolean
end

#monitoring?Boolean

Returns:

  • (Boolean)


83
84
85
86
# File 'lib/tortoiselabs/vps.rb', line 83

def monitoring?
  vps = JSON.parse(TortoiseLabs::Client.get("/vps/#{id}"))
  vps["service"]["monitoring"]
end

#new_iso(isoname, isouri) ⇒ Object



171
172
173
174
175
# File 'lib/tortoiselabs/vps.rb', line 171

def new_iso(isoname, isouri)
  result = TortoiseLabs::Client.post("/vps/#{@id}/hvmiso/new", 
    {:isoname => isoname, :isouri => isouri})
  hvm
end

#powercycleObject



126
127
128
129
# File 'lib/tortoiselabs/vps.rb', line 126

def powercycle
  result = TortoiseLabs::Client.get("/vps/#{@id}/powercycle")
  result.parsed_response["job"]
end

#running?Boolean

Returns:

  • (Boolean)


106
107
108
109
# File 'lib/tortoiselabs/vps.rb', line 106

def running?
  result = TortoiseLabs::Client.get("/vps/#{@id}/status.json")
  result.parsed_response["running"]
end

#set_boot_order(bootorder) ⇒ Object



158
159
160
161
162
# File 'lib/tortoiselabs/vps.rb', line 158

def set_boot_order(bootorder)
  result = TortoiseLabs::Client.post("/vps/#{@id}/hvm/setbootorder",
    {:bootorder => bootorder})
  result.parsed_response["isolist"]
end

#set_iso(isoid) ⇒ Object



152
153
154
155
156
# File 'lib/tortoiselabs/vps.rb', line 152

def set_iso(isoid)
  result = TortoiseLabs::Client.post("/vps/#{@id}/hvm/setiso", 
    {:isoid => isoid})
  hvm
end

#set_nic_type(nictype) ⇒ Object



164
165
166
167
168
169
# File 'lib/tortoiselabs/vps.rb', line 164

def set_nic_type(nictype)
  # nictype can be e1000, virtio-net or rtl8139
  result = TortoiseLabs::Client.post("/vps/#{@id}/hvm/setnictype",
    {:nictype => nictype})
  hvm
end

#shutdownObject



116
117
118
119
# File 'lib/tortoiselabs/vps.rb', line 116

def shutdown
  result = TortoiseLabs::Client.get("/vps/#{@id}/shutdown")
  result.parsed_response["job"]
end

#templatesObject



88
89
90
91
# File 'lib/tortoiselabs/vps.rb', line 88

def templates
  result = TortoiseLabs::Client.get("/vps/#{@id}/deploy")
  JSON.parse(result)["templates"]
end

#to_sObject



64
65
66
# File 'lib/tortoiselabs/vps.rb', line 64

def to_s
  @nickname
end