mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #1771 from dm1try/cloudstack_add_disk_offering_model
[cloudstack] add disk offering model
This commit is contained in:
commit
7b0cd244a8
7 changed files with 165 additions and 0 deletions
|
@ -19,6 +19,8 @@ module Fog
|
||||||
|
|
||||||
model_path 'fog/cloudstack/models/compute'
|
model_path 'fog/cloudstack/models/compute'
|
||||||
model :address
|
model :address
|
||||||
|
model :disk_offering
|
||||||
|
collection :disk_offerings
|
||||||
model :flavor
|
model :flavor
|
||||||
collection :flavors
|
collection :flavors
|
||||||
model :job
|
model :job
|
||||||
|
@ -46,6 +48,7 @@ module Fog
|
||||||
request :authorize_security_group_ingress
|
request :authorize_security_group_ingress
|
||||||
request :change_service_for_virtual_machine
|
request :change_service_for_virtual_machine
|
||||||
request :create_account
|
request :create_account
|
||||||
|
request :create_disk_offering
|
||||||
request :create_domain
|
request :create_domain
|
||||||
request :create_load_balancer_rule
|
request :create_load_balancer_rule
|
||||||
request :create_network
|
request :create_network
|
||||||
|
@ -58,6 +61,7 @@ module Fog
|
||||||
request :create_volume
|
request :create_volume
|
||||||
request :create_zone
|
request :create_zone
|
||||||
request :delete_account
|
request :delete_account
|
||||||
|
request :delete_disk_offering
|
||||||
request :delete_domain
|
request :delete_domain
|
||||||
request :delete_load_balancer_rule
|
request :delete_load_balancer_rule
|
||||||
request :delete_port_forwarding_rule
|
request :delete_port_forwarding_rule
|
||||||
|
|
46
lib/fog/cloudstack/models/compute/disk_offering.rb
Normal file
46
lib/fog/cloudstack/models/compute/disk_offering.rb
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
module Fog
|
||||||
|
module Compute
|
||||||
|
class Cloudstack
|
||||||
|
class DiskOffering < Fog::Model
|
||||||
|
identity :id, :aliases => 'id'
|
||||||
|
attribute :created
|
||||||
|
attribute :disk_size, :aliases => 'disk_size'
|
||||||
|
attribute :display_text, :aliases => 'display_text'
|
||||||
|
attribute :domain
|
||||||
|
attribute :domain_id, :aliases => 'domainid'
|
||||||
|
attribute :is_customized, :aliases => 'iscustomized'
|
||||||
|
attribute :name
|
||||||
|
attribute :storage_type, :aliases => 'storagetype'
|
||||||
|
attribute :tags
|
||||||
|
|
||||||
|
|
||||||
|
def save
|
||||||
|
requires :display_text, :name
|
||||||
|
|
||||||
|
options = {
|
||||||
|
'displaytext' => display_text,
|
||||||
|
'name' => name,
|
||||||
|
'customized' => is_customized,
|
||||||
|
'disksize' => disk_size,
|
||||||
|
'domain_id' => domain_id,
|
||||||
|
'storagetype' => storage_type,
|
||||||
|
'tags' => tags
|
||||||
|
}
|
||||||
|
|
||||||
|
response = service.create_disk_offering(options)
|
||||||
|
merge_attributes(response['creatediskofferingresponse'])
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
requires :id
|
||||||
|
|
||||||
|
response = service.delete_disk_offering('id' => id )
|
||||||
|
success_status = response['deletediskofferingresponse']['success']
|
||||||
|
|
||||||
|
success_status == 'true'
|
||||||
|
end
|
||||||
|
|
||||||
|
end # DiskOffering
|
||||||
|
end # Cloudstack
|
||||||
|
end # Compute
|
||||||
|
end # Fog
|
27
lib/fog/cloudstack/models/compute/disk_offerings.rb
Normal file
27
lib/fog/cloudstack/models/compute/disk_offerings.rb
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
require 'fog/core/collection'
|
||||||
|
require 'fog/cloudstack/models/compute/disk_offering'
|
||||||
|
|
||||||
|
module Fog
|
||||||
|
module Compute
|
||||||
|
class Cloudstack
|
||||||
|
|
||||||
|
class DiskOfferings < Fog::Collection
|
||||||
|
|
||||||
|
model Fog::Compute::Cloudstack::DiskOffering
|
||||||
|
|
||||||
|
def all(options = {})
|
||||||
|
response = service.list_disk_offerings(options)
|
||||||
|
disk_offerings_data = response["listdiskofferingsresponse"]["diskoffering"] || []
|
||||||
|
load(disk_offerings_data)
|
||||||
|
end
|
||||||
|
|
||||||
|
def get(disk_offering_id)
|
||||||
|
response = service.list_disk_offerings('id' => disk_offering_id)
|
||||||
|
disk_offering_data = response["listdiskofferingsresponse"]["diskoffering"].first
|
||||||
|
new(disk_offering_data)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
51
lib/fog/cloudstack/requests/compute/create_disk_offering.rb
Normal file
51
lib/fog/cloudstack/requests/compute/create_disk_offering.rb
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
module Fog
|
||||||
|
module Compute
|
||||||
|
class Cloudstack
|
||||||
|
class Real
|
||||||
|
|
||||||
|
# Creates a disk offering.
|
||||||
|
#
|
||||||
|
# {CloudStack API Reference}[http://cloudstack.apache.org/docs/api/apidocs-4.0.0/root_admin/createDiskOffering.html]
|
||||||
|
def create_disk_offering(options={})
|
||||||
|
options.merge!(
|
||||||
|
'command' => 'createDiskOffering'
|
||||||
|
)
|
||||||
|
request(options)
|
||||||
|
end
|
||||||
|
|
||||||
|
end # Real
|
||||||
|
|
||||||
|
class Mock
|
||||||
|
|
||||||
|
def create_disk_offering(options={})
|
||||||
|
disk_offering_id = Fog::Cloudstack.uuid
|
||||||
|
|
||||||
|
first_domain_data = data[:domains].first.last
|
||||||
|
domain_id = options['domainid'] || first_domain_data['id']
|
||||||
|
domain_name = data[:domains][domain_id]['name']
|
||||||
|
|
||||||
|
storage_type = options['storagetype'] || 'shared'
|
||||||
|
customized = options['customized'] || false
|
||||||
|
disk_size = options['disk_size'] || 1
|
||||||
|
|
||||||
|
disk_offering = {
|
||||||
|
"id" => disk_offering_id,
|
||||||
|
"domainid" => domain_id,
|
||||||
|
"domain" => domain_name,
|
||||||
|
"name" => options['name'],
|
||||||
|
"displaytext" => options['display_text'],
|
||||||
|
"disksize" => disk_size,
|
||||||
|
"created" => Time.now.iso8601,
|
||||||
|
"iscustomized" => customized,
|
||||||
|
"storagetype" => storage_type
|
||||||
|
}
|
||||||
|
|
||||||
|
self.data[:disk_offerings][disk_offering_id] = disk_offering
|
||||||
|
|
||||||
|
{'creatediskofferingresponse' => disk_offering}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end # Cloudstack
|
||||||
|
end # Compute
|
||||||
|
end # Fog
|
31
lib/fog/cloudstack/requests/compute/delete_disk_offering.rb
Normal file
31
lib/fog/cloudstack/requests/compute/delete_disk_offering.rb
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
module Fog
|
||||||
|
module Compute
|
||||||
|
class Cloudstack
|
||||||
|
class Real
|
||||||
|
|
||||||
|
# Updates a disk offering.
|
||||||
|
#
|
||||||
|
# {CloudStack API Reference}[http://cloudstack.apache.org/docs/api/apidocs-4.0.0/root_admin/deleteDiskOffering.html]
|
||||||
|
def delete_disk_offering(options={})
|
||||||
|
options.merge!(
|
||||||
|
'command' => 'deleteDiskOffering'
|
||||||
|
)
|
||||||
|
request(options)
|
||||||
|
end
|
||||||
|
|
||||||
|
end # Real
|
||||||
|
|
||||||
|
class Mock
|
||||||
|
|
||||||
|
def delete_disk_offering(options={})
|
||||||
|
disk_offering_id = options['id']
|
||||||
|
data[:disk_offerings].delete(disk_offering_id) if data[:disk_offerings][disk_offering_id]
|
||||||
|
|
||||||
|
{ 'deletediskofferingresponse' => { 'success' => 'true' } }
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end # Cloudstack
|
||||||
|
end # Compute
|
||||||
|
end # Fog
|
5
tests/cloudstack/compute/models/disk_offering_tests.rb
Normal file
5
tests/cloudstack/compute/models/disk_offering_tests.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
Shindo.tests("Fog::Compute[:cloudstack] | disk_offering", "cloudstack") do
|
||||||
|
config = compute_providers[:cloudstack]
|
||||||
|
compute = Fog::Compute[:cloudstack]
|
||||||
|
model_tests(compute.disk_offerings, config[:disk_offering_attributes], config[:mocked])
|
||||||
|
end
|
|
@ -75,6 +75,7 @@ def compute_providers
|
||||||
:end_port => 456,
|
:end_port => 456,
|
||||||
:protocol => 'tcp'
|
:protocol => 'tcp'
|
||||||
},
|
},
|
||||||
|
:disk_offering_attributes => { :name => "new disk offering", :display_text => 'New Disk Offering' },
|
||||||
:mocked => true
|
:mocked => true
|
||||||
},
|
},
|
||||||
:glesys => {
|
:glesys => {
|
||||||
|
|
Loading…
Reference in a new issue