Class: Fog::Compute::Ninefold::Server

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/compute/models/ninefold/server.rb

Instance Attribute Summary

Attributes inherited from Model

#collection, #connection

Instance Method Summary collapse

Methods inherited from Model

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

Constructor Details

#initialize(attributes = {}) ⇒ Server

Returns a new instance of Server.



67
68
69
# File 'lib/fog/compute/models/ninefold/server.rb', line 67

def initialize(attributes={})
  super
end

Instance Method Details

#destroyObject



95
96
97
98
99
# File 'lib/fog/compute/models/ninefold/server.rb', line 95

def destroy
  requires :identity
  self.jobid = extract_job_id(connection.destroy_virtual_machine(:id => identity))
  true
end

#flavorObject



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

def flavor
  requires :serviceofferingid
  connection.flavors.get(serviceofferingid)
end

#imageObject



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

def image
  requires :templateid
  connection.images.get(templateid)
end

#ipaddressObject

This is temporary - we need to model nics.



72
73
74
# File 'lib/fog/compute/models/ninefold/server.rb', line 72

def ipaddress
  nic[0] ? nic[0]['ipaddress'] : nil
end

#ready?Boolean

Returns:

  • (Boolean)


111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/fog/compute/models/ninefold/server.rb', line 111

def ready?
  if jobid
    # we do this by polling the last job id status.
    res = connection.query_async_job_result(:jobid => jobid)
    if res['jobstatus'] == 0
      false
    else
      # update with new values.
      merge_attributes(res['jobresult']['virtualmachine'])
      true
    end
  else # No running job, we are ready. Refresh data.
    reload
    true
  end
end

#rebootObject



76
77
78
79
80
81
# File 'lib/fog/compute/models/ninefold/server.rb', line 76

def reboot
  requires :identity
  self.jobid = extract_job_id(connection.reboot_virtual_machine(:id => identity))
  puts "jobid: " + jobid.to_s
  true
end

#saveObject



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/fog/compute/models/ninefold/server.rb', line 128

def save
  raise "Operation not supported" if self.identity
  requires :serviceofferingid
  requires :templateid
  requires :zoneid

  unless networkids
    # No network specified, use first in this zone.
    networks = connection.list_networks(:zoneid => zoneid)
    if networks.empty?
      raise "No networks. Please create one, or specify a network ID"
    else
      # use the network with the lowest ID - the safe default
      self.networkids = networks.sort {|x,y| x['id'] <=> y['id']}[0]['id']
    end
  end

  options = {
    :serviceofferingid => serviceofferingid,
    :templateid => templateid,
    :name => name,
    :zoneid => zoneid,
    :networkids => networkids,
    :account => ,
    :diskofferingid => diskofferingid,
    :displayname => displayname,
    :domainid => domainid,
    :group => group,
    :hypervisor => hypervisor,
    :keypair => keypair,
    :securitygroupids => securitygroupids,
    :size => size,
    :userdata => userdata
  }.delete_if {|k,v| v.nil? || v == "" }
  data = connection.deploy_virtual_machine(options)
  merge_attributes(data)
  true
end

#startObject



83
84
85
86
87
# File 'lib/fog/compute/models/ninefold/server.rb', line 83

def start
  requires :identity
  self.jobid = extract_job_id(connection.start_virtual_machine(:id => identity))
  true
end

#stopObject



89
90
91
92
93
# File 'lib/fog/compute/models/ninefold/server.rb', line 89

def stop
  requires :identity
  self.jobid = extract_job_id(connection.stop_virtual_machine(:id => identity))
  true
end