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 IpForwardingRule < Fog::Model
|
|
|
|
|
|
|
|
identity :id
|
|
|
|
|
|
|
|
attribute :protocol
|
|
|
|
attribute :virtualmachineid
|
|
|
|
attribute :virtualmachinename
|
|
|
|
attribute :ipaddressid
|
|
|
|
attribute :ipaddress
|
|
|
|
attribute :startport
|
|
|
|
attribute :endport
|
|
|
|
attribute :state
|
|
|
|
|
|
|
|
attribute :jobid
|
|
|
|
|
|
|
|
def initialize(attributes={})
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
requires :identity
|
2012-12-22 18:24:54 -05:00
|
|
|
self.jobid = extract_job_id(service.delete_ip_forwarding_rule(:id => identity))
|
2011-05-11 22:47:30 -04:00
|
|
|
true
|
|
|
|
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 address
|
|
|
|
Ninefold.address.get(ipaddressid)
|
|
|
|
end
|
|
|
|
|
|
|
|
def address=(addr)
|
|
|
|
self.ipaddressid = addr.identity
|
|
|
|
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 :ipaddressid
|
|
|
|
requires :protocol
|
|
|
|
requires :startport
|
|
|
|
|
|
|
|
options = {
|
|
|
|
:ipaddressid => ipaddressid,
|
|
|
|
:protocol => protocol,
|
|
|
|
:startport => startport,
|
|
|
|
:endport => endport
|
|
|
|
}.delete_if {|k,v| v.nil? || v == "" }
|
2012-12-22 18:24:54 -05:00
|
|
|
data = service.create_ip_forwarding_rule(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
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|