1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[cloudstack] Updates reference to service

This commit is contained in:
Paul Thornthwaite 2012-12-22 23:28:53 +00:00
parent 4c129b2b4a
commit 245c3452a2
15 changed files with 47 additions and 47 deletions

View file

@ -10,12 +10,12 @@ module Fog
model Fog::Compute::Cloudstack::Flavor
def all
data = connection.list_service_offerings["listserviceofferingsresponse"]["serviceoffering"] || []
data = service.list_service_offerings["listserviceofferingsresponse"]["serviceoffering"] || []
load(data)
end
def get(flavor_id)
if flavor = connection.list_service_offerings('id' => flavor_id)["listserviceofferingsresponse"]["serviceoffering"].first
if flavor = service.list_service_offerings('id' => flavor_id)["listserviceofferingsresponse"]["serviceoffering"].first
new(flavor)
end
rescue Fog::Compute::Cloudstack::BadRequest

View file

@ -57,13 +57,13 @@ module Fog
'virtualmachineid' => virtual_machine_id,
'volumeid' => volume_id
}
data = connection.create_template(options)
data = service.create_template(options)
merge_attributes(data['createtemplateresponse'])
end
def destroy
requires :id
connection.delete_template('id' => self.id)
service.delete_template('id' => self.id)
true
end
end # Server

View file

@ -12,7 +12,7 @@ module Fog
def all(filters={})
options = get_filter_options(filters)
data = connection.list_templates(options)["listtemplatesresponse"]["template"] || []
data = service.list_templates(options)["listtemplatesresponse"]["template"] || []
load(data)
end
@ -20,7 +20,7 @@ module Fog
filter_option = get_filter_options(filters)
options = filter_option.merge('id' => template_id)
if template = connection.list_templates(options)["listtemplatesresponse"]["template"].first
if template = service.list_templates(options)["listtemplatesresponse"]["template"].first
new(template)
end
rescue Fog::Compute::Cloudstack::BadRequest

View file

@ -17,7 +17,7 @@ module Fog
def reload
requires :id
merge_attributes(connection.query_async_job_result('jobid' => self.id)['queryasyncjobresultresponse'])
merge_attributes(service.query_async_job_result('jobid' => self.id)['queryasyncjobresultresponse'])
end
def ready?
@ -32,7 +32,7 @@ module Fog
def result
if successful? && model = Fog::Compute::Cloudstack.constants.find{|c| c.to_s.downcase == self.job_result.keys.first.to_s}.to_s
collection = model.gsub(/.[A-Z]/){|w| "#{w[0,1]}_#{w[1,1].downcase}"}.downcase + "s" # cheap underscorize, assume simple pluralization
connection.send(collection).new(self.job_result.values.first)
service.send(collection).new(self.job_result.values.first)
else self.job_result
end
end

View file

@ -10,12 +10,12 @@ module Fog
model Fog::Compute::Cloudstack::Job
def all
data = connection.list_async_jobs["listasyncjobsresponse"]["asyncjobs"] || []
data = service.list_async_jobs["listasyncjobsresponse"]["asyncjobs"] || []
load(data)
end
def get(job_id)
if job = connection.query_async_job_result('jobid' => job_id)["queryasyncjobresultresponse"]
if job = service.query_async_job_result('jobid' => job_id)["queryasyncjobresultresponse"]
new(job)
end
rescue Fog::Compute::Cloudstack::BadRequest

View file

@ -15,7 +15,7 @@ module Fog
def destroy
requires :id
connection.delete_security_group('id' => self.id)
service.delete_security_group('id' => self.id)
true
end
@ -37,12 +37,12 @@ module Fog
'projectid' => self.project_id,
'domainid' => self.domain_id,
}
data = connection.create_security_group(options)
data = service.create_security_group(options)
merge_attributes(data['createsecuritygroupresponse']['securitygroup'])
end
def rules
connection.security_group_rules.all("security_group_id" => self.id)
service.security_group_rules.all("security_group_id" => self.id)
end
end # SecurityGroup
end # Cloudstack

View file

@ -13,8 +13,8 @@ module Fog
attribute :direction, :type => :string
def destroy
data = connection.send("revoke_security_group_#{self.direction}", "id" => self.id)
job = connection.jobs.new(data["revokesecuritygroup#{self.direction}"])
data = service.send("revoke_security_group_#{self.direction}", "id" => self.id)
job = service.jobs.new(data["revokesecuritygroup#{self.direction}"])
job.wait_for { ready? }
job.successful?
end
@ -26,8 +26,8 @@ module Fog
def save
requires :security_group_id, :cidr, :direction
data = connection.send("authorize_security_group_#{self.direction}".to_sym, params)
job = connection.jobs.new(data["authorizesecuritygroup#{self.direction}response"])
data = service.send("authorize_security_group_#{self.direction}".to_sym, params)
job = service.jobs.new(data["authorizesecuritygroup#{self.direction}response"])
job.wait_for { ready? }
# durty
merge_attributes(job.result.send("#{self.direction}_rules").last)
@ -35,7 +35,7 @@ module Fog
end
def security_group
connection.security_groups.get(self.security_group_id)
service.security_groups.get(self.security_group_id)
end
def reload

View file

@ -12,7 +12,7 @@ module Fog
attribute :security_group_id, :type => :string
def security_group
connection.security_groups.get(self.security_group_id)
service.security_groups.get(self.security_group_id)
end
def create(attributes)

View file

@ -9,12 +9,12 @@ module Fog
model Fog::Compute::Cloudstack::SecurityGroup
def all(options={})
data = connection.list_security_groups(options)["listsecuritygroupsresponse"]["securitygroup"] || []
data = service.list_security_groups(options)["listsecuritygroupsresponse"]["securitygroup"] || []
load(data)
end
def get(security_group_id)
if security_group = connection.list_security_groups('id' => security_group_id)["listsecuritygroupsresponse"]["securitygroup"].first
if security_group = service.list_security_groups('id' => security_group_id)["listsecuritygroupsresponse"]["securitygroup"].first
new(security_group)
end
rescue Fog::Compute::Cloudstack::BadRequest

View file

@ -46,12 +46,12 @@ module Fog
def destroy
requires :id
data = connection.destroy_virtual_machine("id" => id)
connection.jobs.new(data["destroyvirtualmachineresponse"])
data = service.destroy_virtual_machine("id" => id)
service.jobs.new(data["destroyvirtualmachineresponse"])
end
def flavor
connection.flavors.get(self.flavor_id)
service.flavors.get(self.flavor_id)
end
def ready?
@ -60,8 +60,8 @@ module Fog
def reboot
requires :id
data = connection.reboot_virtual_machine('id' => self.id) # FIXME: does this ever fail?
connection.jobs.new(data["rebootvirtualmachineresponse"])
data = service.reboot_virtual_machine('id' => self.id) # FIXME: does this ever fail?
service.jobs.new(data["rebootvirtualmachineresponse"])
end
def security_groups=(security_groups)
@ -73,7 +73,7 @@ module Fog
end
def security_groups
security_group_ids.map{|id| self.connection.security_groups.get(id)}
security_group_ids.map{|id| service.security_groups.get(id)}
end
def save
@ -97,20 +97,20 @@ module Fog
options.merge!('networkids' => network_ids) if network_ids
options.merge!('securitygroupids' => security_group_ids) unless security_group_ids.empty?
data = connection.deploy_virtual_machine(options)
data = service.deploy_virtual_machine(options)
merge_attributes(data['deployvirtualmachineresponse'])
end
def start
requires :id
data = connection.start_virtual_machine("id" => self.id)
connection.jobs.new(data["startvirtualmachineresponse"])
data = service.start_virtual_machine("id" => self.id)
service.jobs.new(data["startvirtualmachineresponse"])
end
def stop(force=false)
requires :id
data = connection.stop_virtual_machine("id" => self.id, "force" => force)
connection.jobs.new(data["stopvirtualmachineresponse"])
data = service.stop_virtual_machine("id" => self.id, "force" => force)
service.jobs.new(data["stopvirtualmachineresponse"])
end
end # Server
end # Cloudstack

View file

@ -10,7 +10,7 @@ module Fog
model Fog::Compute::Cloudstack::Server
def all
data = connection.list_virtual_machines["listvirtualmachinesresponse"]["virtualmachine"] || []
data = service.list_virtual_machines["listvirtualmachinesresponse"]["virtualmachine"] || []
load(data)
end
@ -21,7 +21,7 @@ module Fog
end
def get(server_id)
if server = connection.list_virtual_machines('id' => server_id)["listvirtualmachinesresponse"]["virtualmachine"].first
if server = service.list_virtual_machines('id' => server_id)["listvirtualmachinesresponse"]["virtualmachine"].first
new(server)
end
rescue Fog::Compute::Cloudstack::BadRequest

View file

@ -39,7 +39,7 @@ module Fog
'snapshotid' => snapshot_id,
'projectid' => project_id
}
data = connection.create_volume(options)
data = service.create_volume(options)
merge_attributes(data['createvolumeresponse'])
end
@ -48,13 +48,13 @@ module Fog
end
def flavor
connection.disk_offerings.get(self.disk_offering_id)
service.disk_offerings.get(self.disk_offering_id)
end
alias disk_offering flavor
def server
if server_id
connection.servers.get(server_id)
service.servers.get(server_id)
end
end
@ -91,22 +91,22 @@ module Fog
}
options.merge!('deviceid' => mountpoint) if mountpoint
data = connection.attach_volume(options)
data = service.attach_volume(options)
connection.jobs.new(data["attachvolumeresponse"])
service.jobs.new(data["attachvolumeresponse"])
end
def detach
requires :id
data = connection.detach_volume('id' => id)
data = service.detach_volume('id' => id)
connection.jobs.new(data["detachvolumeresponse"])
service.jobs.new(data["detachvolumeresponse"])
end
def destroy
requires :id
connection.delete_volume('id' => id)
service.delete_volume('id' => id)
true
end
end # Volume

View file

@ -10,12 +10,12 @@ module Fog
model Fog::Compute::Cloudstack::Volume
def all
data = connection.list_volumes["listvolumesresponse"]["volume"] || []
data = service.list_volumes["listvolumesresponse"]["volume"] || []
load(data)
end
def get(volume_id)
if volume = connection.list_volumes('id' => volume_id)["listvolumesresponse"]["volume"].first
if volume = service.list_volumes('id' => volume_id)["listvolumesresponse"]["volume"].first
new(volume)
end
rescue Fog::Compute::Cloudstack::BadRequest

View file

@ -28,7 +28,7 @@ module Fog
'internaldns2' => internaldns2,
'securitygroupenabled' => security_groups_enabled,
}
data = connection.create_zone(options)
data = service.create_zone(options)
merge_attributes(data['createzoneresponse'])
end
end # Zone

View file

@ -14,12 +14,12 @@ module Fog
'templatefilter' => 'self'
}.merge(filters)
data = connection.list_zones(options)["listzonesresponse"]["zone"] || []
data = service.list_zones(options)["listzonesresponse"]["zone"] || []
load(data)
end
def get(zone_id)
if zone = connection.list_zones('id' => zone_id)["listzonesresponse"]["zone"].first
if zone = service.list_zones('id' => zone_id)["listzonesresponse"]["zone"].first
new(zone)
end
rescue Fog::Compute::Cloudstack::BadRequest