2011-05-11 22:47:30 -04:00
|
|
|
require 'fog/core/model'
|
|
|
|
|
|
|
|
module Fog
|
2011-06-16 19:28:54 -04:00
|
|
|
module Compute
|
|
|
|
class Ninefold
|
2011-05-11 22:47:30 -04:00
|
|
|
|
|
|
|
class Address < Fog::Model
|
|
|
|
|
|
|
|
identity :id
|
|
|
|
|
|
|
|
attribute :account
|
|
|
|
attribute :allocated
|
|
|
|
attribute :associatednetworkid
|
|
|
|
attribute :domain
|
|
|
|
attribute :domainid
|
|
|
|
attribute :forvirtualnetwork
|
|
|
|
attribute :ipaddress
|
|
|
|
attribute :issourcenat
|
|
|
|
attribute :isstaticnat
|
|
|
|
attribute :jobid
|
|
|
|
attribute :jobstatus
|
|
|
|
attribute :networkid
|
|
|
|
attribute :state
|
|
|
|
attribute :virtualmachinedisplayname
|
|
|
|
attribute :virtualmachineid
|
|
|
|
attribute :virtualmachinename
|
|
|
|
attribute :vlanid
|
|
|
|
attribute :vlanname
|
|
|
|
attribute :zoneid
|
|
|
|
attribute :zonename
|
|
|
|
|
|
|
|
def initialize(attributes={})
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
requires :identity
|
2012-12-22 18:24:54 -05:00
|
|
|
self.jobid = extract_job_id(service.disassociate_ip_address(:id => identity))
|
2011-05-11 22:47:30 -04:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def enable_static_nat(server)
|
|
|
|
server.kind_of?(Integer) ? serverid = server : serverid = server.identity
|
2012-12-22 18:24:54 -05:00
|
|
|
res = service.enable_static_nat(:virtualmachineid => serverid, :ipaddressid => identity)
|
2011-05-11 22:47:30 -04:00
|
|
|
reload
|
|
|
|
to_boolean(res['success'])
|
|
|
|
end
|
|
|
|
|
|
|
|
def disable_static_nat()
|
2012-12-22 18:24:54 -05:00
|
|
|
self.jobid = extract_job_id(service.disable_static_nat(:ipaddressid => identity))
|
2011-05-11 22:47:30 -04:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def reload
|
|
|
|
self.virtualmachinedisplayname = nil
|
|
|
|
self.virtualmachineid = nil
|
|
|
|
self.virtualmachinename = nil
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def ready?
|
2012-12-22 18:24:54 -05:00
|
|
|
if jobid && service.query_async_job_result(:jobid => jobid)['jobstatus'] == 0
|
2011-05-11 22:47:30 -04:00
|
|
|
false
|
|
|
|
else # No running job, we are ready. Refresh data.
|
|
|
|
reload
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
2011-06-04 05:51:08 -04:00
|
|
|
raise "Operation not supported" if self.identity
|
2011-05-11 22:47:30 -04:00
|
|
|
requires :zoneid
|
|
|
|
|
|
|
|
options = {
|
|
|
|
:zoneid => zoneid,
|
|
|
|
:networkid => networkid,
|
|
|
|
:account => account,
|
|
|
|
:domainid => domainid
|
|
|
|
}.delete_if {|k,v| v.nil? || v == "" }
|
2012-12-22 18:24:54 -05:00
|
|
|
data = service.associate_ip_address(options)
|
2011-05-11 22:47:30 -04:00
|
|
|
merge_attributes(data)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def extract_job_id(job)
|
|
|
|
if job.kind_of? Integer
|
|
|
|
job
|
|
|
|
else
|
|
|
|
job['jobid'] || job['id']
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# needed to hack around API inconsistencies
|
|
|
|
def to_boolean(val)
|
|
|
|
val && (val.to_s.match(/(true|t|yes|y|1)$/i) != nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|