diff --git a/Gemfile b/Gemfile index 97f3c4c161..c80ee36970 100644 --- a/Gemfile +++ b/Gemfile @@ -1,13 +1,3 @@ -source 'http://gemcutter.org' +source "http://rubygems.org" -gem 'rake' -gem 'builder', '>= 0' -gem 'excon', '>= 0.2.0' -gem 'formatador', ">= 0.0.15" -gem 'json', ">= 0" -gem 'mime-types', ">= 0" -gem 'net-ssh', ">= 0" -gem 'nokogiri', ">= 1.4.3.1" -gem 'rspec', '>= 0' -gem 'ruby-hmac', '>= 0' -gem 'shindo', '>= 0.1.6' +gemspec diff --git a/Gemfile.lock b/Gemfile.lock index 7a3d3b6766..08043a6458 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,75 +1,48 @@ ---- -dependencies: - formatador: - group: - - :default - version: ">= 0.0.15" - rake: - group: - - :default - version: ">= 0" - rspec: - group: - - :default - version: ">= 0" - mime-types: - group: - - :default - version: ">= 0" - ruby-hmac: - group: - - :default - version: ">= 0" - net-ssh: - group: - - :default - version: ">= 0" - json: - group: - - :default - version: ">= 0" - excon: - group: - - :default - version: ">= 0.2.0" - shindo: - group: - - :default - version: ">= 0.1.6" - builder: - group: - - :default - version: ">= 0" - nokogiri: - group: - - :default - version: ">= 1.4.3.1" -specs: -- rake: - version: 0.8.7 -- builder: - version: 2.1.2 -- excon: - version: 0.2.0 -- formatador: - version: 0.0.15 -- gestalt: - version: 0.0.11 -- json: - version: 1.4.3 -- mime-types: - version: "1.16" -- net-ssh: - version: 2.0.23 -- nokogiri: - version: 1.4.3.1 -- rspec: - version: 1.3.0 -- ruby-hmac: - version: 0.4.0 -- shindo: - version: 0.1.6 -hash: b335ed8d32bece98ea7a84d858b85cbf21025c82 -sources: -- Rubygems: - uri: http://gemcutter.org +PATH + remote: . + specs: + fog (0.3.7) + builder + excon (>= 0.2.3) + formatador (>= 0.0.15) + json + mime-types + net-ssh + nokogiri (>= 1.4.3.1) + ruby-hmac + +GEM + remote: http://rubygems.org/ + specs: + builder (2.1.2) + excon (0.2.3) + formatador (0.0.15) + gestalt (0.0.11) + formatador (>= 0.0.12) + json (1.4.6) + mime-types (1.16) + net-ssh (2.0.23) + nokogiri (1.4.3.1) + rake (0.8.7) + rspec (1.3.0) + ruby-hmac (0.4.0) + shindo (0.1.6) + formatador (>= 0.0.14) + gestalt (>= 0.0.11) + +PLATFORMS + ruby + +DEPENDENCIES + builder + excon (>= 0.2.3) + fog! + formatador (>= 0.0.15) + json + mime-types + net-ssh + nokogiri (>= 1.4.3.1) + rake + rspec + ruby-hmac + shindo (= 0.1.6) diff --git a/README.rdoc b/README.rdoc index 447860a8fb..404a27c32a 100644 --- a/README.rdoc +++ b/README.rdoc @@ -3,7 +3,7 @@ http://geemus.com/fog.png fog is the Ruby cloud computing library. The quick and dirty, top to bottom: -* Models provide a simplified interface, making clouds easier to work with and switch between. +* Collections provide a simplified interface, making clouds easier to work with and switch between. * Requests allow power users to get the most out of the features of each individual cloud. * Mocks make testing and integrating a breeze. @@ -24,10 +24,11 @@ Now just type 'fog' to trying stuff out, confident that fog should let you know == Collections -Nouns like Images and Servers are collections, which form the interface to the cloud. +A high level interface to each cloud is provided through collections, such as images and servers. +You can see a list of available collections by calling #collections on the connection object. Some of these collections are shared across multiple providers. -The shared collections for compute resources are flavors, images and servers. -Shared collections for storage are directory and file. +Shared collections for compute are: flavors, images and servers. +Shared collections for storage are: directory and file. Some common methods for all of these collections are: * #all - fetch every object of that type from the provider. @@ -58,7 +59,7 @@ As an example, we'll try initializing and persisting a Rackspace Cloud server: == Models -Many of the collection methods return individual objects, which provide destroy, save and wait_for methods. +Many of the collection methods return individual objects, which also provide some common methods: * #destroy - will destroy the persisted object from the provider * #save - persist the object to the provider * #wait_for - takes a block and waits for either the block to return true for the object or for a timeout (defaults to 10 minutes) @@ -77,6 +78,7 @@ Some mocks are not implemented just yet, but fog will raise an error to let you == Requests Requests allow you to dive deeper when the models just can't cut it. +You can see a list of available requests by calling #requests on the connection object. For instance, ec2 provides methods related to reserved instances that don't have any models (yet). Here is how you can lookup your reserved instances: @@ -91,19 +93,27 @@ It will return an {excon}[http://github.com/geemus/excon] response, which has #h Play around and use the console to explore or check out the {getting started guide}[http://wiki.github.com/geemus/fog/getting-started-with-fog] for more details. You should try out the (varying) support fog has for: -* {AWS}[http://aws.amazon.com] [{EC2}[http://aws.amazon.com/ec2], {ELB}[http://aws.amazon.com/elasticloadbalancing], {S3}[http://aws.amazon.com/s3], {SimpleDB}[http://aws.amazon.com/simpledb]] -* {Rackspace}[http://www.rackspace.com] [{Files}[http://www.rackspacecloud.com/cloud_hosting_products/files], {Servers}[http://www.rackspacecloud.com/cloud_hosting_products/servers]] -* {Slicehost}[http://www.slicehost.com] +* {AWS}[http://aws.amazon.com] [{Compute}[http://aws.amazon.com/ec2], {ELB}[http://aws.amazon.com/elasticloadbalancing], {Storage}[http://aws.amazon.com/s3], {SimpleDB}[http://aws.amazon.com/simpledb]] +* {Blue Box Group}[http://www.blueboxgrp.com] [{Compute}[http://www.blueboxgrp.com/blocks]] +* {Google}[http://www.google.com] [{Storage}[http://code.google.com/apis/storage]] +* {Rackspace}[http://www.rackspace.com] [{Compute}[http://www.rackspacecloud.com/cloud_hosting_products/servers], {Storage}[http://www.rackspacecloud.com/cloud_hosting_products/files]] +* {Slicehost}[http://www.slicehost.com] [{Compute}[http://www.slicehost.com]] * {Terremark}[http://www.terremark.com] [{vCloud Express}[http://vcloudexpress.terremark.com]] -* {Blue Box Group}[http://www.blueboxgrp.com] [{Blocks}[http://www.blueboxgrp.com/blocks]] + +There are also the basics of these providers (that could use your love): +* {GoGrid}[http://www.gogrid.com] [{Compute}[http://www.gogrid.com]] +* {Linode}[http://www.linode.com] [{Compute}[http://www.linode.com]] +* Local [Storage] +* {New Servers}[http://www.newservers.com] [{Compute}[http://www.newservers.com]] Enjoy, and let me know what I can do to continue improving fog! -* Work for {twitter}[http://twitter.com]? I'd love to reclaim the unused {@fog}[http://twitter.com/fog] account! -* Follow {@geemus}[http://twitter.com/geemus] on Twitter. -* See upcoming work in the {tracker}[http://www.pivotaltracker.com/projects/54635]. -* Report bugs in {issues}[http://github.com/geemus/fog/issues]. -* Learn about {contributing}[http://wiki.github.com/geemus/fog/contributors-guide]. +* Follow {@fog}[http://twitter.com/fog] and/or {@geemus}[http://twitter.com/geemus] on Twitter +* Discuss in irc on the {#ruby-fog}[irc://irc.freenode.net/ruby-fog] channel on Freenode or via email on the {mailing list}[http://groups.google.com/group/ruby-fog] +* See upcoming work in the {tracker}[http://www.pivotaltracker.com/projects/54635] +* Report bugs in {issues}[http://github.com/geemus/fog/issues] +* Learn about {contributing}[http://wiki.github.com/geemus/fog/contributors-guide] or find more info about the {Providers}[http://github.com/geemus/fog/wiki/Providers] (including some todo items) +* See what already uses fog and add your own stuff to {the list}[http://wiki.github.com/geemus/fog/in-the-wild] == Copyright diff --git a/Rakefile b/Rakefile index f2ec0e1081..042a8b8645 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,5 @@ require 'rubygems' -require 'rake' +require 'bundler/setup' require 'date' ############################################################################# @@ -45,11 +45,18 @@ end task :default => :test -require 'rake/testtask' -Rake::TestTask.new(:test) do |test| - test.libs << 'lib' << 'test' - test.pattern = 'test/**/test_*.rb' - test.verbose = true +task :test do + sh("export FOG_MOCK=true && bundle exec spec -cfs spec") && + sh("export FOG_MOCK=true && bundle exec shindo tests") && + sh("export FOG_MOCK=false && bundle exec spec -cfs spec") && + sh("export FOG_MOCK=false && bundle exec shindo tests") +end + +task :ci do + sh("export FOG_MOCK=true && bundle exec spec spec") && + sh("export FOG_MOCK=true && bundle exec shindont tests") && + sh("export FOG_MOCK=false && bundle exec spec spec") && + sh("export FOG_MOCK=false && bundle exec shindont tests") end desc "Generate RCov test coverage and open in your browser" @@ -73,20 +80,6 @@ task :console do sh "irb -rubygems -r ./lib/#{name}.rb" end -############################################################################# -# -# Custom tasks (add your own tasks here) -# -############################################################################# - -require 'spec/rake/spectask' -Spec::Rake::SpecTask.new(:spec) do |spec| - spec.libs << 'lib' << 'spec' - spec.spec_opts = ['--colour', "--format", "specdoc"] - spec.spec_files = FileList['spec/**/*_spec.rb'] -end - - ############################################################################# # # Packaging tasks diff --git a/bin/fog b/bin/fog index e673bdbfd0..3896bc6bf4 100755 --- a/bin/fog +++ b/bin/fog @@ -3,7 +3,8 @@ require File.join(File.dirname(__FILE__), '..', 'lib', 'fog') require 'irb' require 'yaml' require File.join('fog', 'credentials') -Fog.credential = ARGV.first ? :"#{ARGV.first}" : :default +Fog.credential = ARGV.first +Fog.bin = true unless Fog.credentials exit end @@ -23,17 +24,17 @@ else @irb.context.prompt_mode = :FOG @irb.context.workspace = IRB::WorkSpace.new(binding) - services = Fog.services.map{|service| service.to_s} - available_services = if services.length > 1 - services[0...-1].join(', ') << ' and ' << services[-1] + modules = Fog.modules.map{|_module_| _module_.to_s} + modules = if modules.length > 1 + modules[0...-1].join(', ') << ' and ' << modules[-1] else - services.first + modules.first end - print "Welcome to fog interactive!\n" - print "Your '#{Fog.credential.to_s}' configuration provides access to #{available_services}.\n" - Fog.services.each do |service| - if service.respond_to?(:startup_notice) - service.send(:startup_notice) + Formatador.display_line('Welcome to fog interactive!') + Formatador.display_line(":#{Fog.credential.to_s} credentials provide #{modules}") + Fog.modules.each do |_module_| + if _module_.respond_to?(:startup_notice) + _module_.send(:startup_notice) end end diff --git a/fog.gemspec b/fog.gemspec index 4c73b6fb4d..0e79c3c8f9 100644 --- a/fog.gemspec +++ b/fog.gemspec @@ -7,8 +7,8 @@ Gem::Specification.new do |s| ## If your rubyforge_project name is different, then edit it and comment out ## the sub! line in the Rakefile s.name = 'fog' - s.version = '0.2.21' - s.date = '2010-07-29' + s.version = '0.3.7' + s.date = '2010-09-29' s.rubyforge_project = 'fog' ## Make sure your summary is short. The description may be as long @@ -43,7 +43,7 @@ Gem::Specification.new do |s| ## List your runtime dependencies here. Runtime dependencies are those ## that are needed for an end user to actually USE your code. s.add_dependency('builder') - s.add_dependency('excon', '>=0.2.0') + s.add_dependency('excon', '>=0.2.3') s.add_dependency('formatador', '>=0.0.15') s.add_dependency('json') s.add_dependency('mime-types') @@ -53,6 +53,7 @@ Gem::Specification.new do |s| ## List your development dependencies here. Development dependencies are ## those that are only needed during development + s.add_development_dependency('rake') s.add_development_dependency('rspec') s.add_development_dependency('shindo', '0.1.6') @@ -75,51 +76,54 @@ Gem::Specification.new do |s| lib/fog/attributes.rb lib/fog/aws.rb lib/fog/aws/bin.rb + lib/fog/aws/compute.rb lib/fog/aws/ec2.rb lib/fog/aws/elb.rb - lib/fog/aws/models/ec2/address.rb - lib/fog/aws/models/ec2/addresses.rb - lib/fog/aws/models/ec2/flavor.rb - lib/fog/aws/models/ec2/flavors.rb - lib/fog/aws/models/ec2/image.rb - lib/fog/aws/models/ec2/images.rb - lib/fog/aws/models/ec2/key_pair.rb - lib/fog/aws/models/ec2/key_pairs.rb - lib/fog/aws/models/ec2/security_group.rb - lib/fog/aws/models/ec2/security_groups.rb - lib/fog/aws/models/ec2/server.rb - lib/fog/aws/models/ec2/servers.rb - lib/fog/aws/models/ec2/snapshot.rb - lib/fog/aws/models/ec2/snapshots.rb - lib/fog/aws/models/ec2/volume.rb - lib/fog/aws/models/ec2/volumes.rb - lib/fog/aws/models/s3/directories.rb - lib/fog/aws/models/s3/directory.rb - lib/fog/aws/models/s3/file.rb - lib/fog/aws/models/s3/files.rb - lib/fog/aws/parsers/ec2/allocate_address.rb - lib/fog/aws/parsers/ec2/attach_volume.rb - lib/fog/aws/parsers/ec2/basic.rb - lib/fog/aws/parsers/ec2/create_image.rb - lib/fog/aws/parsers/ec2/create_key_pair.rb - lib/fog/aws/parsers/ec2/create_snapshot.rb - lib/fog/aws/parsers/ec2/create_volume.rb - lib/fog/aws/parsers/ec2/deregister_image.rb - lib/fog/aws/parsers/ec2/describe_addresses.rb - lib/fog/aws/parsers/ec2/describe_availability_zones.rb - lib/fog/aws/parsers/ec2/describe_images.rb - lib/fog/aws/parsers/ec2/describe_instances.rb - lib/fog/aws/parsers/ec2/describe_key_pairs.rb - lib/fog/aws/parsers/ec2/describe_regions.rb - lib/fog/aws/parsers/ec2/describe_reserved_instances.rb - lib/fog/aws/parsers/ec2/describe_security_groups.rb - lib/fog/aws/parsers/ec2/describe_snapshots.rb - lib/fog/aws/parsers/ec2/describe_volumes.rb - lib/fog/aws/parsers/ec2/detach_volume.rb - lib/fog/aws/parsers/ec2/get_console_output.rb - lib/fog/aws/parsers/ec2/run_instances.rb - lib/fog/aws/parsers/ec2/start_stop_instances.rb - lib/fog/aws/parsers/ec2/terminate_instances.rb + lib/fog/aws/models/compute/address.rb + lib/fog/aws/models/compute/addresses.rb + lib/fog/aws/models/compute/flavor.rb + lib/fog/aws/models/compute/flavors.rb + lib/fog/aws/models/compute/image.rb + lib/fog/aws/models/compute/images.rb + lib/fog/aws/models/compute/key_pair.rb + lib/fog/aws/models/compute/key_pairs.rb + lib/fog/aws/models/compute/security_group.rb + lib/fog/aws/models/compute/security_groups.rb + lib/fog/aws/models/compute/server.rb + lib/fog/aws/models/compute/servers.rb + lib/fog/aws/models/compute/snapshot.rb + lib/fog/aws/models/compute/snapshots.rb + lib/fog/aws/models/compute/volume.rb + lib/fog/aws/models/compute/volumes.rb + lib/fog/aws/models/storage/directories.rb + lib/fog/aws/models/storage/directory.rb + lib/fog/aws/models/storage/file.rb + lib/fog/aws/models/storage/files.rb + lib/fog/aws/parsers/compute/allocate_address.rb + lib/fog/aws/parsers/compute/attach_volume.rb + lib/fog/aws/parsers/compute/basic.rb + lib/fog/aws/parsers/compute/create_image.rb + lib/fog/aws/parsers/compute/create_key_pair.rb + lib/fog/aws/parsers/compute/create_snapshot.rb + lib/fog/aws/parsers/compute/create_volume.rb + lib/fog/aws/parsers/compute/deregister_image.rb + lib/fog/aws/parsers/compute/describe_addresses.rb + lib/fog/aws/parsers/compute/describe_availability_zones.rb + lib/fog/aws/parsers/compute/describe_images.rb + lib/fog/aws/parsers/compute/describe_instances.rb + lib/fog/aws/parsers/compute/describe_key_pairs.rb + lib/fog/aws/parsers/compute/describe_regions.rb + lib/fog/aws/parsers/compute/describe_reserved_instances.rb + lib/fog/aws/parsers/compute/describe_security_groups.rb + lib/fog/aws/parsers/compute/describe_snapshots.rb + lib/fog/aws/parsers/compute/describe_volumes.rb + lib/fog/aws/parsers/compute/detach_volume.rb + lib/fog/aws/parsers/compute/get_console_output.rb + lib/fog/aws/parsers/compute/import_key_pair.rb + lib/fog/aws/parsers/compute/register_image.rb + lib/fog/aws/parsers/compute/run_instances.rb + lib/fog/aws/parsers/compute/start_stop_instances.rb + lib/fog/aws/parsers/compute/terminate_instances.rb lib/fog/aws/parsers/elb/create_load_balancer.rb lib/fog/aws/parsers/elb/delete_load_balancer.rb lib/fog/aws/parsers/elb/deregister_instances_from_load_balancer.rb @@ -128,55 +132,58 @@ Gem::Specification.new do |s| lib/fog/aws/parsers/elb/disable_availability_zones_for_load_balancer.rb lib/fog/aws/parsers/elb/enable_availability_zones_for_load_balancer.rb lib/fog/aws/parsers/elb/register_instances_with_load_balancer.rb - lib/fog/aws/parsers/s3/access_control_list.rb - lib/fog/aws/parsers/s3/copy_object.rb - lib/fog/aws/parsers/s3/get_bucket.rb - lib/fog/aws/parsers/s3/get_bucket_location.rb - lib/fog/aws/parsers/s3/get_bucket_logging.rb - lib/fog/aws/parsers/s3/get_bucket_object_versions.rb - lib/fog/aws/parsers/s3/get_bucket_versioning.rb - lib/fog/aws/parsers/s3/get_request_payment.rb - lib/fog/aws/parsers/s3/get_service.rb lib/fog/aws/parsers/simpledb/basic.rb lib/fog/aws/parsers/simpledb/domain_metadata.rb lib/fog/aws/parsers/simpledb/get_attributes.rb lib/fog/aws/parsers/simpledb/list_domains.rb lib/fog/aws/parsers/simpledb/select.rb - lib/fog/aws/requests/ec2/allocate_address.rb - lib/fog/aws/requests/ec2/associate_address.rb - lib/fog/aws/requests/ec2/attach_volume.rb - lib/fog/aws/requests/ec2/authorize_security_group_ingress.rb - lib/fog/aws/requests/ec2/create_image.rb - lib/fog/aws/requests/ec2/create_key_pair.rb - lib/fog/aws/requests/ec2/create_security_group.rb - lib/fog/aws/requests/ec2/create_snapshot.rb - lib/fog/aws/requests/ec2/create_volume.rb - lib/fog/aws/requests/ec2/delete_key_pair.rb - lib/fog/aws/requests/ec2/delete_security_group.rb - lib/fog/aws/requests/ec2/delete_snapshot.rb - lib/fog/aws/requests/ec2/delete_volume.rb - lib/fog/aws/requests/ec2/deregister_image.rb - lib/fog/aws/requests/ec2/describe_addresses.rb - lib/fog/aws/requests/ec2/describe_availability_zones.rb - lib/fog/aws/requests/ec2/describe_images.rb - lib/fog/aws/requests/ec2/describe_instances.rb - lib/fog/aws/requests/ec2/describe_key_pairs.rb - lib/fog/aws/requests/ec2/describe_regions.rb - lib/fog/aws/requests/ec2/describe_reserved_instances.rb - lib/fog/aws/requests/ec2/describe_security_groups.rb - lib/fog/aws/requests/ec2/describe_snapshots.rb - lib/fog/aws/requests/ec2/describe_volumes.rb - lib/fog/aws/requests/ec2/detach_volume.rb - lib/fog/aws/requests/ec2/disassociate_address.rb - lib/fog/aws/requests/ec2/get_console_output.rb - lib/fog/aws/requests/ec2/modify_image_attributes.rb - lib/fog/aws/requests/ec2/reboot_instances.rb - lib/fog/aws/requests/ec2/release_address.rb - lib/fog/aws/requests/ec2/revoke_security_group_ingress.rb - lib/fog/aws/requests/ec2/run_instances.rb - lib/fog/aws/requests/ec2/start_instances.rb - lib/fog/aws/requests/ec2/stop_instances.rb - lib/fog/aws/requests/ec2/terminate_instances.rb + lib/fog/aws/parsers/storage/access_control_list.rb + lib/fog/aws/parsers/storage/copy_object.rb + lib/fog/aws/parsers/storage/get_bucket.rb + lib/fog/aws/parsers/storage/get_bucket_location.rb + lib/fog/aws/parsers/storage/get_bucket_logging.rb + lib/fog/aws/parsers/storage/get_bucket_object_versions.rb + lib/fog/aws/parsers/storage/get_bucket_versioning.rb + lib/fog/aws/parsers/storage/get_request_payment.rb + lib/fog/aws/parsers/storage/get_service.rb + lib/fog/aws/requests/compute/allocate_address.rb + lib/fog/aws/requests/compute/associate_address.rb + lib/fog/aws/requests/compute/attach_volume.rb + lib/fog/aws/requests/compute/authorize_security_group_ingress.rb + lib/fog/aws/requests/compute/create_image.rb + lib/fog/aws/requests/compute/create_key_pair.rb + lib/fog/aws/requests/compute/create_security_group.rb + lib/fog/aws/requests/compute/create_snapshot.rb + lib/fog/aws/requests/compute/create_volume.rb + lib/fog/aws/requests/compute/delete_key_pair.rb + lib/fog/aws/requests/compute/delete_security_group.rb + lib/fog/aws/requests/compute/delete_snapshot.rb + lib/fog/aws/requests/compute/delete_volume.rb + lib/fog/aws/requests/compute/deregister_image.rb + lib/fog/aws/requests/compute/describe_addresses.rb + lib/fog/aws/requests/compute/describe_availability_zones.rb + lib/fog/aws/requests/compute/describe_images.rb + lib/fog/aws/requests/compute/describe_instances.rb + lib/fog/aws/requests/compute/describe_key_pairs.rb + lib/fog/aws/requests/compute/describe_regions.rb + lib/fog/aws/requests/compute/describe_reserved_instances.rb + lib/fog/aws/requests/compute/describe_security_groups.rb + lib/fog/aws/requests/compute/describe_snapshots.rb + lib/fog/aws/requests/compute/describe_volumes.rb + lib/fog/aws/requests/compute/detach_volume.rb + lib/fog/aws/requests/compute/disassociate_address.rb + lib/fog/aws/requests/compute/get_console_output.rb + lib/fog/aws/requests/compute/import_key_pair.rb + lib/fog/aws/requests/compute/modify_image_attributes.rb + lib/fog/aws/requests/compute/modify_snapshot_attribute.rb + lib/fog/aws/requests/compute/reboot_instances.rb + lib/fog/aws/requests/compute/register_image.rb + lib/fog/aws/requests/compute/release_address.rb + lib/fog/aws/requests/compute/revoke_security_group_ingress.rb + lib/fog/aws/requests/compute/run_instances.rb + lib/fog/aws/requests/compute/start_instances.rb + lib/fog/aws/requests/compute/stop_instances.rb + lib/fog/aws/requests/compute/terminate_instances.rb lib/fog/aws/requests/elb/create_load_balancer.rb lib/fog/aws/requests/elb/delete_load_balancer.rb lib/fog/aws/requests/elb/deregister_instances_from_load_balancer.rb @@ -185,29 +192,6 @@ Gem::Specification.new do |s| lib/fog/aws/requests/elb/disable_availability_zones_for_load_balancer.rb lib/fog/aws/requests/elb/enable_availability_zones_for_load_balancer.rb lib/fog/aws/requests/elb/register_instances_with_load_balancer.rb - lib/fog/aws/requests/s3/copy_object.rb - lib/fog/aws/requests/s3/delete_bucket.rb - lib/fog/aws/requests/s3/delete_object.rb - lib/fog/aws/requests/s3/get_bucket.rb - lib/fog/aws/requests/s3/get_bucket_acl.rb - lib/fog/aws/requests/s3/get_bucket_location.rb - lib/fog/aws/requests/s3/get_bucket_logging.rb - lib/fog/aws/requests/s3/get_bucket_object_versions.rb - lib/fog/aws/requests/s3/get_bucket_versioning.rb - lib/fog/aws/requests/s3/get_object.rb - lib/fog/aws/requests/s3/get_object_acl.rb - lib/fog/aws/requests/s3/get_object_torrent.rb - lib/fog/aws/requests/s3/get_object_url.rb - lib/fog/aws/requests/s3/get_request_payment.rb - lib/fog/aws/requests/s3/get_service.rb - lib/fog/aws/requests/s3/head_object.rb - lib/fog/aws/requests/s3/put_bucket.rb - lib/fog/aws/requests/s3/put_bucket_acl.rb - lib/fog/aws/requests/s3/put_bucket_logging.rb - lib/fog/aws/requests/s3/put_bucket_versioning.rb - lib/fog/aws/requests/s3/put_object.rb - lib/fog/aws/requests/s3/put_object_url.rb - lib/fog/aws/requests/s3/put_request_payment.rb lib/fog/aws/requests/simpledb/batch_put_attributes.rb lib/fog/aws/requests/simpledb/create_domain.rb lib/fog/aws/requests/simpledb/delete_attributes.rb @@ -217,26 +201,51 @@ Gem::Specification.new do |s| lib/fog/aws/requests/simpledb/list_domains.rb lib/fog/aws/requests/simpledb/put_attributes.rb lib/fog/aws/requests/simpledb/select.rb + lib/fog/aws/requests/storage/copy_object.rb + lib/fog/aws/requests/storage/delete_bucket.rb + lib/fog/aws/requests/storage/delete_object.rb + lib/fog/aws/requests/storage/get_bucket.rb + lib/fog/aws/requests/storage/get_bucket_acl.rb + lib/fog/aws/requests/storage/get_bucket_location.rb + lib/fog/aws/requests/storage/get_bucket_logging.rb + lib/fog/aws/requests/storage/get_bucket_object_versions.rb + lib/fog/aws/requests/storage/get_bucket_versioning.rb + lib/fog/aws/requests/storage/get_object.rb + lib/fog/aws/requests/storage/get_object_acl.rb + lib/fog/aws/requests/storage/get_object_torrent.rb + lib/fog/aws/requests/storage/get_object_url.rb + lib/fog/aws/requests/storage/get_request_payment.rb + lib/fog/aws/requests/storage/get_service.rb + lib/fog/aws/requests/storage/head_object.rb + lib/fog/aws/requests/storage/put_bucket.rb + lib/fog/aws/requests/storage/put_bucket_acl.rb + lib/fog/aws/requests/storage/put_bucket_logging.rb + lib/fog/aws/requests/storage/put_bucket_versioning.rb + lib/fog/aws/requests/storage/put_object.rb + lib/fog/aws/requests/storage/put_object_url.rb + lib/fog/aws/requests/storage/put_request_payment.rb lib/fog/aws/s3.rb lib/fog/aws/simpledb.rb + lib/fog/aws/storage.rb lib/fog/bin.rb lib/fog/bluebox.rb lib/fog/bluebox/bin.rb - lib/fog/bluebox/models/flavor.rb - lib/fog/bluebox/models/flavors.rb - lib/fog/bluebox/models/image.rb - lib/fog/bluebox/models/images.rb - lib/fog/bluebox/models/server.rb - lib/fog/bluebox/models/servers.rb - lib/fog/bluebox/requests/create_block.rb - lib/fog/bluebox/requests/destroy_block.rb - lib/fog/bluebox/requests/get_block.rb - lib/fog/bluebox/requests/get_blocks.rb - lib/fog/bluebox/requests/get_product.rb - lib/fog/bluebox/requests/get_products.rb - lib/fog/bluebox/requests/get_template.rb - lib/fog/bluebox/requests/get_templates.rb - lib/fog/bluebox/requests/reboot_block.rb + lib/fog/bluebox/compute.rb + lib/fog/bluebox/models/compute/flavor.rb + lib/fog/bluebox/models/compute/flavors.rb + lib/fog/bluebox/models/compute/image.rb + lib/fog/bluebox/models/compute/images.rb + lib/fog/bluebox/models/compute/server.rb + lib/fog/bluebox/models/compute/servers.rb + lib/fog/bluebox/requests/compute/create_block.rb + lib/fog/bluebox/requests/compute/destroy_block.rb + lib/fog/bluebox/requests/compute/get_block.rb + lib/fog/bluebox/requests/compute/get_blocks.rb + lib/fog/bluebox/requests/compute/get_product.rb + lib/fog/bluebox/requests/compute/get_products.rb + lib/fog/bluebox/requests/compute/get_template.rb + lib/fog/bluebox/requests/compute/get_templates.rb + lib/fog/bluebox/requests/compute/reboot_block.rb lib/fog/collection.rb lib/fog/connection.rb lib/fog/credentials.rb @@ -244,113 +253,151 @@ Gem::Specification.new do |s| lib/fog/errors.rb lib/fog/go_grid.rb lib/fog/go_grid/bin.rb - lib/fog/go_grid/requests/common_lookup_list.rb - lib/fog/go_grid/requests/grid_image_list.rb - lib/fog/go_grid/requests/grid_ip_list.rb - lib/fog/go_grid/requests/grid_loadbalancer_list.rb - lib/fog/go_grid/requests/grid_server_add.rb - lib/fog/go_grid/requests/grid_server_delete.rb - lib/fog/go_grid/requests/grid_server_get.rb - lib/fog/go_grid/requests/grid_server_list.rb - lib/fog/go_grid/requests/grid_server_power.rb + lib/fog/go_grid/compute.rb + lib/fog/go_grid/requests/compute/common_lookup_list.rb + lib/fog/go_grid/requests/compute/grid_image_list.rb + lib/fog/go_grid/requests/compute/grid_ip_list.rb + lib/fog/go_grid/requests/compute/grid_loadbalancer_list.rb + lib/fog/go_grid/requests/compute/grid_server_add.rb + lib/fog/go_grid/requests/compute/grid_server_delete.rb + lib/fog/go_grid/requests/compute/grid_server_get.rb + lib/fog/go_grid/requests/compute/grid_server_list.rb + lib/fog/go_grid/requests/compute/grid_server_power.rb + lib/fog/google.rb + lib/fog/google/bin.rb + lib/fog/google/models/storage/directories.rb + lib/fog/google/models/storage/directory.rb + lib/fog/google/models/storage/file.rb + lib/fog/google/models/storage/files.rb + lib/fog/google/parsers/storage/access_control_list.rb + lib/fog/google/parsers/storage/copy_object.rb + lib/fog/google/parsers/storage/get_bucket.rb + lib/fog/google/parsers/storage/get_bucket_logging.rb + lib/fog/google/parsers/storage/get_bucket_object_versions.rb + lib/fog/google/parsers/storage/get_bucket_versioning.rb + lib/fog/google/parsers/storage/get_request_payment.rb + lib/fog/google/parsers/storage/get_service.rb + lib/fog/google/requests/storage/copy_object.rb + lib/fog/google/requests/storage/delete_bucket.rb + lib/fog/google/requests/storage/delete_object.rb + lib/fog/google/requests/storage/get_bucket.rb + lib/fog/google/requests/storage/get_bucket_acl.rb + lib/fog/google/requests/storage/get_object.rb + lib/fog/google/requests/storage/get_object_acl.rb + lib/fog/google/requests/storage/get_object_torrent.rb + lib/fog/google/requests/storage/get_object_url.rb + lib/fog/google/requests/storage/get_service.rb + lib/fog/google/requests/storage/head_object.rb + lib/fog/google/requests/storage/put_bucket.rb + lib/fog/google/requests/storage/put_bucket_acl.rb + lib/fog/google/requests/storage/put_object.rb + lib/fog/google/requests/storage/put_object_url.rb + lib/fog/google/storage.rb lib/fog/hmac.rb lib/fog/linode.rb lib/fog/linode/bin.rb - lib/fog/linode/requests/avail_datacenters.rb - lib/fog/linode/requests/avail_distributions.rb - lib/fog/linode/requests/avail_kernels.rb - lib/fog/linode/requests/avail_linodeplans.rb - lib/fog/linode/requests/avail_stackscripts.rb - lib/fog/linode/requests/linode_create.rb - lib/fog/linode/requests/linode_delete.rb - lib/fog/linode/requests/linode_list.rb - lib/fog/linode/requests/linode_reboot.rb + lib/fog/linode/compute.rb + lib/fog/linode/requests/compute/avail_datacenters.rb + lib/fog/linode/requests/compute/avail_distributions.rb + lib/fog/linode/requests/compute/avail_kernels.rb + lib/fog/linode/requests/compute/avail_linodeplans.rb + lib/fog/linode/requests/compute/avail_stackscripts.rb + lib/fog/linode/requests/compute/linode_create.rb + lib/fog/linode/requests/compute/linode_delete.rb + lib/fog/linode/requests/compute/linode_list.rb + lib/fog/linode/requests/compute/linode_reboot.rb lib/fog/local.rb lib/fog/local/bin.rb - lib/fog/local/models/directories.rb - lib/fog/local/models/directory.rb - lib/fog/local/models/file.rb - lib/fog/local/models/files.rb + lib/fog/local/models/storage/directories.rb + lib/fog/local/models/storage/directory.rb + lib/fog/local/models/storage/file.rb + lib/fog/local/models/storage/files.rb + lib/fog/local/storage.rb lib/fog/model.rb lib/fog/new_servers.rb lib/fog/new_servers/bin.rb - lib/fog/new_servers/requests/add_server.rb - lib/fog/new_servers/requests/cancel_server.rb - lib/fog/new_servers/requests/get_server.rb - lib/fog/new_servers/requests/list_images.rb - lib/fog/new_servers/requests/list_plans.rb - lib/fog/new_servers/requests/list_servers.rb - lib/fog/new_servers/requests/reboot_server.rb + lib/fog/new_servers/compute.rb + lib/fog/new_servers/requests/compute/add_server.rb + lib/fog/new_servers/requests/compute/cancel_server.rb + lib/fog/new_servers/requests/compute/get_server.rb + lib/fog/new_servers/requests/compute/list_images.rb + lib/fog/new_servers/requests/compute/list_plans.rb + lib/fog/new_servers/requests/compute/list_servers.rb + lib/fog/new_servers/requests/compute/reboot_server.rb lib/fog/parser.rb + lib/fog/provider.rb lib/fog/rackspace.rb lib/fog/rackspace/bin.rb + lib/fog/rackspace/compute.rb lib/fog/rackspace/files.rb - lib/fog/rackspace/models/files/directories.rb - lib/fog/rackspace/models/files/directory.rb - lib/fog/rackspace/models/files/file.rb - lib/fog/rackspace/models/files/files.rb - lib/fog/rackspace/models/servers/flavor.rb - lib/fog/rackspace/models/servers/flavors.rb - lib/fog/rackspace/models/servers/image.rb - lib/fog/rackspace/models/servers/images.rb - lib/fog/rackspace/models/servers/server.rb - lib/fog/rackspace/models/servers/servers.rb - lib/fog/rackspace/requests/files/delete_container.rb - lib/fog/rackspace/requests/files/delete_object.rb - lib/fog/rackspace/requests/files/get_container.rb - lib/fog/rackspace/requests/files/get_containers.rb - lib/fog/rackspace/requests/files/get_object.rb - lib/fog/rackspace/requests/files/head_container.rb - lib/fog/rackspace/requests/files/head_containers.rb - lib/fog/rackspace/requests/files/head_object.rb - lib/fog/rackspace/requests/files/put_container.rb - lib/fog/rackspace/requests/files/put_object.rb - lib/fog/rackspace/requests/servers/create_image.rb - lib/fog/rackspace/requests/servers/create_server.rb - lib/fog/rackspace/requests/servers/delete_image.rb - lib/fog/rackspace/requests/servers/delete_server.rb - lib/fog/rackspace/requests/servers/get_flavor_details.rb - lib/fog/rackspace/requests/servers/get_image_details.rb - lib/fog/rackspace/requests/servers/get_server_details.rb - lib/fog/rackspace/requests/servers/list_addresses.rb - lib/fog/rackspace/requests/servers/list_flavors.rb - lib/fog/rackspace/requests/servers/list_flavors_detail.rb - lib/fog/rackspace/requests/servers/list_images.rb - lib/fog/rackspace/requests/servers/list_images_detail.rb - lib/fog/rackspace/requests/servers/list_private_addresses.rb - lib/fog/rackspace/requests/servers/list_public_addresses.rb - lib/fog/rackspace/requests/servers/list_servers.rb - lib/fog/rackspace/requests/servers/list_servers_detail.rb - lib/fog/rackspace/requests/servers/reboot_server.rb - lib/fog/rackspace/requests/servers/update_server.rb + lib/fog/rackspace/models/compute/flavor.rb + lib/fog/rackspace/models/compute/flavors.rb + lib/fog/rackspace/models/compute/image.rb + lib/fog/rackspace/models/compute/images.rb + lib/fog/rackspace/models/compute/server.rb + lib/fog/rackspace/models/compute/servers.rb + lib/fog/rackspace/models/storage/directories.rb + lib/fog/rackspace/models/storage/directory.rb + lib/fog/rackspace/models/storage/file.rb + lib/fog/rackspace/models/storage/files.rb + lib/fog/rackspace/requests/compute/create_image.rb + lib/fog/rackspace/requests/compute/create_server.rb + lib/fog/rackspace/requests/compute/delete_image.rb + lib/fog/rackspace/requests/compute/delete_server.rb + lib/fog/rackspace/requests/compute/get_flavor_details.rb + lib/fog/rackspace/requests/compute/get_image_details.rb + lib/fog/rackspace/requests/compute/get_server_details.rb + lib/fog/rackspace/requests/compute/list_addresses.rb + lib/fog/rackspace/requests/compute/list_flavors.rb + lib/fog/rackspace/requests/compute/list_flavors_detail.rb + lib/fog/rackspace/requests/compute/list_images.rb + lib/fog/rackspace/requests/compute/list_images_detail.rb + lib/fog/rackspace/requests/compute/list_private_addresses.rb + lib/fog/rackspace/requests/compute/list_public_addresses.rb + lib/fog/rackspace/requests/compute/list_servers.rb + lib/fog/rackspace/requests/compute/list_servers_detail.rb + lib/fog/rackspace/requests/compute/reboot_server.rb + lib/fog/rackspace/requests/compute/update_server.rb + lib/fog/rackspace/requests/storage/delete_container.rb + lib/fog/rackspace/requests/storage/delete_object.rb + lib/fog/rackspace/requests/storage/get_container.rb + lib/fog/rackspace/requests/storage/get_containers.rb + lib/fog/rackspace/requests/storage/get_object.rb + lib/fog/rackspace/requests/storage/head_container.rb + lib/fog/rackspace/requests/storage/head_containers.rb + lib/fog/rackspace/requests/storage/head_object.rb + lib/fog/rackspace/requests/storage/put_container.rb + lib/fog/rackspace/requests/storage/put_object.rb lib/fog/rackspace/servers.rb + lib/fog/rackspace/storage.rb lib/fog/service.rb lib/fog/slicehost.rb lib/fog/slicehost/bin.rb - lib/fog/slicehost/models/flavor.rb - lib/fog/slicehost/models/flavors.rb - lib/fog/slicehost/models/image.rb - lib/fog/slicehost/models/images.rb - lib/fog/slicehost/models/server.rb - lib/fog/slicehost/models/servers.rb - lib/fog/slicehost/parsers/create_slice.rb - lib/fog/slicehost/parsers/get_backups.rb - lib/fog/slicehost/parsers/get_flavor.rb - lib/fog/slicehost/parsers/get_flavors.rb - lib/fog/slicehost/parsers/get_image.rb - lib/fog/slicehost/parsers/get_images.rb - lib/fog/slicehost/parsers/get_slice.rb - lib/fog/slicehost/parsers/get_slices.rb - lib/fog/slicehost/requests/create_slice.rb - lib/fog/slicehost/requests/delete_slice.rb - lib/fog/slicehost/requests/get_backups.rb - lib/fog/slicehost/requests/get_flavor.rb - lib/fog/slicehost/requests/get_flavors.rb - lib/fog/slicehost/requests/get_image.rb - lib/fog/slicehost/requests/get_images.rb - lib/fog/slicehost/requests/get_slice.rb - lib/fog/slicehost/requests/get_slices.rb - lib/fog/slicehost/requests/reboot_slice.rb + lib/fog/slicehost/compute.rb + lib/fog/slicehost/models/compute/flavor.rb + lib/fog/slicehost/models/compute/flavors.rb + lib/fog/slicehost/models/compute/image.rb + lib/fog/slicehost/models/compute/images.rb + lib/fog/slicehost/models/compute/server.rb + lib/fog/slicehost/models/compute/servers.rb + lib/fog/slicehost/parsers/compute/create_slice.rb + lib/fog/slicehost/parsers/compute/get_backups.rb + lib/fog/slicehost/parsers/compute/get_flavor.rb + lib/fog/slicehost/parsers/compute/get_flavors.rb + lib/fog/slicehost/parsers/compute/get_image.rb + lib/fog/slicehost/parsers/compute/get_images.rb + lib/fog/slicehost/parsers/compute/get_slice.rb + lib/fog/slicehost/parsers/compute/get_slices.rb + lib/fog/slicehost/requests/compute/create_slice.rb + lib/fog/slicehost/requests/compute/delete_slice.rb + lib/fog/slicehost/requests/compute/get_backups.rb + lib/fog/slicehost/requests/compute/get_flavor.rb + lib/fog/slicehost/requests/compute/get_flavors.rb + lib/fog/slicehost/requests/compute/get_image.rb + lib/fog/slicehost/requests/compute/get_images.rb + lib/fog/slicehost/requests/compute/get_slice.rb + lib/fog/slicehost/requests/compute/get_slices.rb + lib/fog/slicehost/requests/compute/reboot_slice.rb lib/fog/ssh.rb lib/fog/terremark.rb lib/fog/terremark/bin.rb @@ -417,7 +464,6 @@ Gem::Specification.new do |s| lib/fog/vcloud.rb lib/fog/vcloud/bin.rb lib/fog/vcloud/collection.rb - lib/fog/vcloud/extension.rb lib/fog/vcloud/generators.rb lib/fog/vcloud/model.rb lib/fog/vcloud/models/vdc.rb @@ -485,36 +531,23 @@ Gem::Specification.new do |s| lib/fog/vcloud/terremark/ecloud/requests/power_shutdown.rb lib/fog/vcloud/terremark/vcloud.rb lib/fog/vcloud/terremark/vcloud/requests/get_vdc.rb - spec/aws/models/ec2/address_spec.rb - spec/aws/models/ec2/addresses_spec.rb - spec/aws/models/ec2/flavors_spec.rb - spec/aws/models/ec2/key_pair_spec.rb - spec/aws/models/ec2/key_pairs_spec.rb - spec/aws/models/ec2/security_group_spec.rb - spec/aws/models/ec2/security_groups_spec.rb - spec/aws/models/ec2/server_spec.rb - spec/aws/models/ec2/servers_spec.rb - spec/aws/models/ec2/snapshot_spec.rb - spec/aws/models/ec2/snapshots_spec.rb - spec/aws/models/ec2/volume_spec.rb - spec/aws/models/ec2/volumes_spec.rb - spec/aws/models/s3/directories_spec.rb - spec/aws/models/s3/directory_spec.rb - spec/aws/models/s3/file_spec.rb - spec/aws/models/s3/files_spec.rb - spec/aws/requests/ec2/describe_images_spec.rb - spec/aws/requests/s3/copy_object_spec.rb - spec/aws/requests/s3/delete_bucket_spec.rb - spec/aws/requests/s3/delete_object_spec.rb - spec/aws/requests/s3/get_bucket_location_spec.rb - spec/aws/requests/s3/get_bucket_spec.rb - spec/aws/requests/s3/get_object_spec.rb - spec/aws/requests/s3/get_request_payment_spec.rb - spec/aws/requests/s3/get_service_spec.rb - spec/aws/requests/s3/head_object_spec.rb - spec/aws/requests/s3/put_bucket_spec.rb - spec/aws/requests/s3/put_object_spec.rb - spec/aws/requests/s3/put_request_payment_spec.rb + spec/aws/models/compute/address_spec.rb + spec/aws/models/compute/addresses_spec.rb + spec/aws/models/compute/flavors_spec.rb + spec/aws/models/compute/key_pair_spec.rb + spec/aws/models/compute/key_pairs_spec.rb + spec/aws/models/compute/security_group_spec.rb + spec/aws/models/compute/security_groups_spec.rb + spec/aws/models/compute/server_spec.rb + spec/aws/models/compute/servers_spec.rb + spec/aws/models/compute/snapshot_spec.rb + spec/aws/models/compute/snapshots_spec.rb + spec/aws/models/compute/volume_spec.rb + spec/aws/models/compute/volumes_spec.rb + spec/aws/models/storage/directories_spec.rb + spec/aws/models/storage/directory_spec.rb + spec/aws/models/storage/file_spec.rb + spec/aws/models/storage/files_spec.rb spec/aws/requests/simpledb/batch_put_attributes_spec.rb spec/aws/requests/simpledb/create_domain_spec.rb spec/aws/requests/simpledb/delete_attributes_spec.rb @@ -524,30 +557,55 @@ Gem::Specification.new do |s| spec/aws/requests/simpledb/list_domains_spec.rb spec/aws/requests/simpledb/put_attributes_spec.rb spec/aws/requests/simpledb/select_spec.rb - spec/bluebox/models/flavors_spec.rb - spec/bluebox/models/server_spec.rb - spec/bluebox/models/servers_spec.rb + spec/aws/requests/storage/copy_object_spec.rb + spec/aws/requests/storage/delete_bucket_spec.rb + spec/aws/requests/storage/delete_object_spec.rb + spec/aws/requests/storage/get_bucket_location_spec.rb + spec/aws/requests/storage/get_bucket_spec.rb + spec/aws/requests/storage/get_object_spec.rb + spec/aws/requests/storage/get_request_payment_spec.rb + spec/aws/requests/storage/get_service_spec.rb + spec/aws/requests/storage/head_object_spec.rb + spec/aws/requests/storage/put_bucket_spec.rb + spec/aws/requests/storage/put_object_spec.rb + spec/aws/requests/storage/put_request_payment_spec.rb + spec/bluebox/models/compute/flavors_spec.rb + spec/bluebox/models/compute/server_spec.rb + spec/bluebox/models/compute/servers_spec.rb spec/compact_progress_bar_formatter.rb + spec/google/models/storage/directories_spec.rb + spec/google/models/storage/directory_spec.rb + spec/google/models/storage/file_spec.rb + spec/google/models/storage/files_spec.rb + spec/google/requests/storage/copy_object_spec.rb + spec/google/requests/storage/delete_bucket_spec.rb + spec/google/requests/storage/delete_object_spec.rb + spec/google/requests/storage/get_bucket_spec.rb + spec/google/requests/storage/get_object_spec.rb + spec/google/requests/storage/get_service_spec.rb + spec/google/requests/storage/head_object_spec.rb + spec/google/requests/storage/put_bucket_spec.rb + spec/google/requests/storage/put_object_spec.rb spec/lorem.txt - spec/rackspace/models/servers/flavors_spec.rb - spec/rackspace/models/servers/server_spec.rb - spec/rackspace/models/servers/servers_spec.rb - spec/rackspace/requests/files/delete_container_spec.rb - spec/rackspace/requests/files/delete_object_spec.rb - spec/rackspace/requests/files/get_container_spec.rb - spec/rackspace/requests/files/get_containers_spec.rb - spec/rackspace/requests/files/get_object_spec.rb - spec/rackspace/requests/files/head_container_spec.rb - spec/rackspace/requests/files/head_containers_spec.rb - spec/rackspace/requests/files/head_object_spec.rb - spec/rackspace/requests/files/put_container_spec.rb - spec/rackspace/requests/files/put_object_spec.rb + spec/rackspace/models/compute/flavors_spec.rb + spec/rackspace/models/compute/server_spec.rb + spec/rackspace/models/compute/servers_spec.rb + spec/rackspace/requests/storage/delete_container_spec.rb + spec/rackspace/requests/storage/delete_object_spec.rb + spec/rackspace/requests/storage/get_container_spec.rb + spec/rackspace/requests/storage/get_containers_spec.rb + spec/rackspace/requests/storage/get_object_spec.rb + spec/rackspace/requests/storage/head_container_spec.rb + spec/rackspace/requests/storage/head_containers_spec.rb + spec/rackspace/requests/storage/head_object_spec.rb + spec/rackspace/requests/storage/put_container_spec.rb + spec/rackspace/requests/storage/put_object_spec.rb spec/shared_examples/flavors_examples.rb spec/shared_examples/server_examples.rb spec/shared_examples/servers_examples.rb - spec/slicehost/models/flavors_spec.rb - spec/slicehost/models/server_spec.rb - spec/slicehost/models/servers_spec.rb + spec/slicehost/models/compute/flavors_spec.rb + spec/slicehost/models/compute/server_spec.rb + spec/slicehost/models/compute/servers_spec.rb spec/spec_helper.rb spec/vcloud/bin_spec.rb spec/vcloud/models/vdc_spec.rb @@ -588,37 +646,38 @@ Gem::Specification.new do |s| spec/vcloud/terremark/ecloud/requests/login_spec.rb spec/vcloud/vcloud_spec.rb tests/aws/helper.rb - tests/aws/models/s3/directory_tests.rb - tests/aws/requests/ec2/address_tests.rb - tests/aws/requests/ec2/availability_zone_tests.rb - tests/aws/requests/ec2/instance_tests.rb - tests/aws/requests/ec2/key_pair_tests.rb - tests/aws/requests/ec2/region_tests.rb - tests/aws/requests/ec2/security_group_tests.rb - tests/aws/requests/ec2/snapshot_tests.rb - tests/aws/requests/ec2/volume_tests.rb + tests/aws/models/storage/directory_tests.rb + tests/aws/requests/compute/address_tests.rb + tests/aws/requests/compute/availability_zone_tests.rb + tests/aws/requests/compute/image_tests.rb + tests/aws/requests/compute/instance_tests.rb + tests/aws/requests/compute/key_pair_tests.rb + tests/aws/requests/compute/region_tests.rb + tests/aws/requests/compute/security_group_tests.rb + tests/aws/requests/compute/snapshot_tests.rb + tests/aws/requests/compute/volume_tests.rb tests/bluebox/helper.rb - tests/bluebox/requests/block_tests.rb - tests/bluebox/requests/product_tests.rb - tests/bluebox/requests/template_tests.rb + tests/bluebox/requests/compute/block_tests.rb + tests/bluebox/requests/compute/product_tests.rb + tests/bluebox/requests/compute/template_tests.rb tests/helper.rb tests/helper_tests.rb tests/helpers/model_helper.rb tests/linode/helper.rb - tests/linode/requests/datacenter_tests.rb - tests/linode/requests/distribution_tests.rb - tests/linode/requests/linode_tests.rb - tests/linode/requests/linodeplans_tests.rb + tests/linode/requests/compute/datacenter_tests.rb + tests/linode/requests/compute/distribution_tests.rb + tests/linode/requests/compute/linode_tests.rb + tests/linode/requests/compute/linodeplans_tests.rb tests/rackspace/helper.rb - tests/rackspace/requests/servers/address_tests.rb - tests/rackspace/requests/servers/flavor_tests.rb - tests/rackspace/requests/servers/image_tests.rb - tests/rackspace/requests/servers/server_tests.rb + tests/rackspace/requests/compute/address_tests.rb + tests/rackspace/requests/compute/flavor_tests.rb + tests/rackspace/requests/compute/image_tests.rb + tests/rackspace/requests/compute/server_tests.rb tests/slicehost/helper.rb - tests/slicehost/requests/backup_tests.rb - tests/slicehost/requests/flavor_tests.rb - tests/slicehost/requests/image_tests.rb - tests/slicehost/requests/slice_tests.rb + tests/slicehost/requests/compute/backup_tests.rb + tests/slicehost/requests/compute/flavor_tests.rb + tests/slicehost/requests/compute/image_tests.rb + tests/slicehost/requests/compute/slice_tests.rb ] # = MANIFEST = diff --git a/lib/fog.rb b/lib/fog.rb index b73693d8c8..5abf4b3ee4 100644 --- a/lib/fog.rb +++ b/lib/fog.rb @@ -24,6 +24,7 @@ require 'fog/hmac' require 'fog/model' require 'fog/parser' +require 'fog/provider' require 'fog/service' require 'fog/ssh' @@ -37,11 +38,12 @@ require 'fog/slicehost' require 'fog/terremark' require 'fog/vcloud' +require 'fog/xenserver' module Fog unless const_defined?(:VERSION) - VERSION = '0.2.21' + VERSION = '0.3.7' end module Mock @@ -61,6 +63,14 @@ def self.not_implemented end + def self.bin + @bin ||= false + end + + def self.bin=(new_bin) + @bin = new_bin + end + def self.mock! @mocking = true end diff --git a/lib/fog/attributes.rb b/lib/fog/attributes.rb index c0cd7dd380..f22151111c 100644 --- a/lib/fog/attributes.rb +++ b/lib/fog/attributes.rb @@ -15,10 +15,6 @@ def attributes end def attribute(name, options = {}) - # FIXME: handle legacy where options would have been one or more aliases - if !options.is_a?(Hash) - options = {:aliases => options} - end class_eval <<-EOS, __FILE__, __LINE__ attr_reader :#{name} EOS @@ -55,10 +51,10 @@ def #{name}=(new_#{name}) when :time class_eval <<-EOS, __FILE__, __LINE__ def #{name}=(new_#{name}) - if !new_#{name}.is_a?(Time) - @#{name} = Time.parse(new_#{name}) - else + if new_#{name}.nil? || new_#{name}.is_a?(Time) @#{name} = new_#{name} + else + @#{name} = Time.parse(new_#{name}) end end EOS @@ -100,9 +96,9 @@ def #{name}=(new_data) end end - def identity(name, other_names = []) + def identity(name, options = {}) @identity = name - self.attribute(name, {:aliases => other_names}) + self.attribute(name, options) end def ignore_attributes(*args) diff --git a/lib/fog/aws.rb b/lib/fog/aws.rb index 223c997203..9a52bd0e6d 100644 --- a/lib/fog/aws.rb +++ b/lib/fog/aws.rb @@ -1,11 +1,14 @@ -require 'fog/aws/ec2.rb' -require 'fog/aws/elb.rb' -require 'fog/aws/s3' -require 'fog/aws/simpledb' - module Fog module AWS + extend Fog::Provider + + service_path 'fog/aws' + service 'ec2' + service 'elb' + service 's3' + service 'simpledb' + def self.indexed_param(key, values, offset = 0) params = {} unless key.include?('%d') diff --git a/lib/fog/aws/bin.rb b/lib/fog/aws/bin.rb index 7fb4cbaa0b..fccd4be884 100644 --- a/lib/fog/aws/bin.rb +++ b/lib/fog/aws/bin.rb @@ -1,6 +1,6 @@ module AWS class << self - credential = (ARGV.first && :"#{ARGV.first}") || :default + if Fog.credentials[:aws_access_key_id] && Fog.credentials[:aws_secret_access_key] def initialized? @@ -9,57 +9,38 @@ def initialized? def [](service) @@connections ||= Hash.new do |hash, key| - credentials = Fog.credentials.reject do |k, v| - ![:aws_access_key_id, :aws_secret_access_key].include?(k) - end hash[key] = case key when :ec2 - Fog::AWS::EC2.new(credentials) + Fog::AWS::EC2.new when :elb - Fog::AWS::ELB.new(credentials) + Fog::AWS::ELB.new when :simpledb - Fog::AWS::SimpleDB.new(credentials) + Fog::AWS::SimpleDB.new when :s3 - Fog::AWS::S3.new(credentials) + Fog::AWS::S3.new end end @@connections[service] end - def addresses - self[:ec2].addresses + def services + [:ec2, :elb, :simpledb, :s3] end - def directories - self[:s3].directories - end - - def flavors - self[:ec2].flavors - end - - def images - self[:ec2].images - end - - def servers - self[:ec2].servers - end - - def key_pairs - self[:ec2].key_pairs - end - - def security_groups - self[:ec2].security_groups - end - - def snapshots - self[:ec2].snapshots + for collection in Fog::AWS::EC2.collections + module_eval <<-EOS, __FILE__, __LINE__ + def #{collection} + self[:ec2].#{collection} + end + EOS end - def volumes - self[:ec2].volumes + for collection in Fog::AWS::S3.collections + module_eval <<-EOS, __FILE__, __LINE__ + def #{collection} + self[:s3].#{collection} + end + EOS end else @@ -70,4 +51,5 @@ def initialized? end end + end diff --git a/lib/fog/aws/ec2.rb b/lib/fog/aws/ec2.rb index 21eb408a38..0a33edbe3b 100644 --- a/lib/fog/aws/ec2.rb +++ b/lib/fog/aws/ec2.rb @@ -6,61 +6,63 @@ module EC2 requires :aws_access_key_id, :aws_secret_access_key model_path 'fog/aws/models/ec2' - model 'address' - model 'addresses' - model 'flavor' - model 'flavors' - model 'image' - model 'images' - model 'key_pair' - model 'key_pairs' - model 'security_group' - model 'security_groups' - model 'server' - model 'servers' - model 'snapshot' - model 'snapshots' - model 'volume' - model 'volumes' + model :address + collection :addresses + model :flavor + collection :flavors + model :image + collection :images + model :key_pair + collection :key_pairs + model :security_group + collection :security_groups + model :server + collection :servers + model :snapshot + collection :snapshots + model :volume + collection :volumes require 'fog/aws/parsers/ec2/basic' request_path 'fog/aws/requests/ec2' - request 'allocate_address' - request 'associate_address' - request 'attach_volume' - request 'authorize_security_group_ingress' - request 'create_key_pair' - request 'create_security_group' - request 'create_snapshot' - request 'create_image' - request 'create_volume' - request 'delete_key_pair' - request 'delete_security_group' - request 'delete_snapshot' - request 'delete_volume' - request 'deregister_image' - request 'describe_addresses' - request 'describe_availability_zones' - request 'describe_images' - request 'describe_instances' - request 'describe_reserved_instances' - request 'describe_key_pairs' - request 'describe_regions' - request 'describe_security_groups' - request 'describe_snapshots' - request 'describe_volumes' - request 'detach_volume' - request 'disassociate_address' - request 'get_console_output' - request 'modify_image_attributes' - request 'reboot_instances' - request 'release_address' - request 'revoke_security_group_ingress' - request 'run_instances' - request 'terminate_instances' - request 'start_instances' - request 'stop_instances' + request :allocate_address + request :associate_address + request :attach_volume + request :authorize_security_group_ingress + request :create_key_pair + request :create_security_group + request :create_snapshot + request :create_image + request :create_volume + request :delete_key_pair + request :delete_security_group + request :delete_snapshot + request :delete_volume + request :deregister_image + request :describe_addresses + request :describe_availability_zones + request :describe_images + request :describe_instances + request :describe_reserved_instances + request :describe_key_pairs + request :describe_regions + request :describe_security_groups + request :describe_snapshots + request :describe_volumes + request :detach_volume + request :disassociate_address + request :get_console_output + request :modify_image_attributes + request :modify_snapshot_attribute + request :reboot_instances + request :release_address + request :register_image + request :revoke_security_group_ingress + request :run_instances + request :terminate_instances + request :start_instances + request :stop_instances class Mock include Collections diff --git a/lib/fog/aws/elb.rb b/lib/fog/aws/elb.rb index f9f67b29ca..04464b5418 100644 --- a/lib/fog/aws/elb.rb +++ b/lib/fog/aws/elb.rb @@ -6,14 +6,14 @@ module ELB requires :aws_access_key_id, :aws_secret_access_key request_path 'fog/aws/requests/elb' - request 'create_load_balancer' - request 'delete_load_balancer' - request 'deregister_instances_from_load_balancer' - request 'describe_instance_health' - request 'describe_load_balancers' - request 'disable_availability_zones_for_load_balancer' - request 'enable_availability_zones_for_load_balancer' - request 'register_instances_with_load_balancer' + request :create_load_balancer + request :delete_load_balancer + request :deregister_instances_from_load_balancer + request :describe_instance_health + request :describe_load_balancers + request :disable_availability_zones_for_load_balancer + request :enable_availability_zones_for_load_balancer + request :register_instances_with_load_balancer class Mock include Collections diff --git a/lib/fog/aws/models/ec2/address.rb b/lib/fog/aws/models/ec2/address.rb index 6150443f7c..32aaf51eb6 100644 --- a/lib/fog/aws/models/ec2/address.rb +++ b/lib/fog/aws/models/ec2/address.rb @@ -6,9 +6,9 @@ module EC2 class Address < Fog::Model - identity :public_ip, 'publicIp' + identity :public_ip, :aliases => 'publicIp' - attribute :server_id, 'instanceId' + attribute :server_id, :aliases => 'instanceId' def initialize(attributes = {}) # assign server first to prevent race condition with new_record? diff --git a/lib/fog/aws/models/ec2/image.rb b/lib/fog/aws/models/ec2/image.rb index b6638ca58b..fbcef51c8d 100644 --- a/lib/fog/aws/models/ec2/image.rb +++ b/lib/fog/aws/models/ec2/image.rb @@ -6,21 +6,21 @@ module EC2 class Image < Fog::Model - identity :id, 'imageId' + identity :id, :aliases => 'imageId' attribute :architecture - attribute :block_device_mapping, 'blockDeviceMapping' - attribute :location, 'imageLocation' - attribute :owner_id, 'imageOwnerId' - attribute :state, 'imageState' - attribute :type, 'imageType' - attribute :is_public, 'isPublic' - attribute :kernel_id, 'kernelId' + attribute :block_device_mapping, :aliases => 'blockDeviceMapping' + attribute :location, :aliases => 'imageLocation' + attribute :owner_id, :aliases => 'imageOwnerId' + attribute :state, :aliases => 'imageState' + attribute :type, :aliases => 'imageType' + attribute :is_public, :aliases => 'isPublic' + attribute :kernel_id, :aliases => 'kernelId' attribute :platform - attribute :product_codes, 'productCodes' - attribute :ramdisk_id, 'ramdiskId' - attribute :root_device_type, 'rootDeviceType' - attribute :root_device_name, 'rootDeviceName' + attribute :product_codes, :aliases => 'productCodes' + attribute :ramdisk_id, :aliases => 'ramdiskId' + attribute :root_device_type, :aliases => 'rootDeviceType' + attribute :root_device_name, :aliases => 'rootDeviceName' def deregister(delete_snapshot = false) connection.deregister_image(@id) diff --git a/lib/fog/aws/models/ec2/key_pair.rb b/lib/fog/aws/models/ec2/key_pair.rb index b76710d0e8..4d45afe1a5 100644 --- a/lib/fog/aws/models/ec2/key_pair.rb +++ b/lib/fog/aws/models/ec2/key_pair.rb @@ -6,10 +6,10 @@ module EC2 class KeyPair < Fog::Model - identity :name, 'keyName' + identity :name, :aliases => 'keyName' - attribute :fingerprint, 'keyFingerprint' - attribute :material, 'keyMaterial' + attribute :fingerprint, :aliases => 'keyFingerprint' + attribute :material, :aliases => 'keyMaterial' def destroy requires :name diff --git a/lib/fog/aws/models/ec2/security_group.rb b/lib/fog/aws/models/ec2/security_group.rb index d1bec8dfe4..e732703798 100644 --- a/lib/fog/aws/models/ec2/security_group.rb +++ b/lib/fog/aws/models/ec2/security_group.rb @@ -6,11 +6,11 @@ module EC2 class SecurityGroup < Fog::Model - identity :name, 'groupName' + identity :name, :aliases => 'groupName' - attribute :description, 'groupDescription' - attribute :ip_permissions, 'ipPermissions' - attribute :owner_id, 'ownerId' + attribute :description, :aliases => 'groupDescription' + attribute :ip_permissions, :aliases => 'ipPermissions' + attribute :owner_id, :aliases => 'ownerId' def authorize_group_and_owner(group, owner) requires :name diff --git a/lib/fog/aws/models/ec2/server.rb b/lib/fog/aws/models/ec2/server.rb index 3616606b9a..693654eb1f 100644 --- a/lib/fog/aws/models/ec2/server.rb +++ b/lib/fog/aws/models/ec2/server.rb @@ -6,33 +6,34 @@ module EC2 class Server < Fog::Model - identity :id, 'instanceId' + identity :id, :aliases => 'instanceId' attr_accessor :architecture - attribute :ami_launch_index, 'amiLaunchIndex' - attribute :availability_zone, 'availabilityZone' - attribute :block_device_mapping, 'blockDeviceMapping' - attribute :dns_name, 'dnsName' + attribute :ami_launch_index, :aliases => 'amiLaunchIndex' + attribute :availability_zone, :aliases => 'availabilityZone' + attribute :block_device_mapping, :aliases => 'blockDeviceMapping' + attribute :dns_name, :aliases => 'dnsName' attribute :groups - attribute :flavor_id, 'instanceType' - attribute :image_id, 'imageId' - attribute :ip_address, 'ipAddress' - attribute :kernel_id, 'kernelId' - attribute :key_name, 'keyName' - attribute :created_at, 'launchTime' + attribute :flavor_id, :aliases => 'instanceType' + attribute :image_id, :aliases => 'imageId' + attribute :ip_address, :aliases => 'ipAddress' + attribute :kernel_id, :aliases => 'kernelId' + attribute :key_name, :aliases => 'keyName' + attribute :created_at, :aliases => 'launchTime' attribute :monitoring - attribute :product_codes, 'productCodes' - attribute :private_dns_name, 'privateDnsName' - attribute :private_ip_address, 'privateIpAddress' - attribute :ramdisk_id, 'ramdiskId' + attribute :product_codes, :aliases => 'productCodes' + attribute :private_dns_name, :aliases => 'privateDnsName' + attribute :private_ip_address, :aliases => 'privateIpAddress' + attribute :ramdisk_id, :aliases => 'ramdiskId' attribute :reason - attribute :root_device_name, 'rootDeviceName' - attribute :root_device_type, 'rootDeviceType' - attribute :state, 'instanceState' + attribute :root_device_name, :aliases => 'rootDeviceName' + attribute :root_device_type, :aliases => 'rootDeviceType' + attribute :state, :aliases => 'instanceState' + attribute :subnet_id, :aliases => 'subnetId' attribute :user_data def initialize(attributes={}) - @groups ||= ["default"] + @groups ||= ["default"] unless attributes[:subnet_id] @flavor_id ||= 'm1.small' super end @@ -124,8 +125,18 @@ def save 'Placement.AvailabilityZone' => @availability_zone, 'RamdiskId' => @ramdisk_id, 'SecurityGroup' => @groups, + 'SubnetId' => subnet_id, 'UserData' => @user_data } + + # If subnet is defined we are working on a virtual private cloud. + # subnet & security group cannot co-exist. I wish VPC just ignored + # the security group parameter instead, it would be much easier! + if subnet_id + options.delete('SecurityGroup') + else + options.delete('SubnetId') + end data = connection.run_instances(@image_id, 1, 1, options) merge_attributes(data.body['instancesSet'].first) diff --git a/lib/fog/aws/models/ec2/snapshot.rb b/lib/fog/aws/models/ec2/snapshot.rb index ca23078eb6..ff79da39eb 100644 --- a/lib/fog/aws/models/ec2/snapshot.rb +++ b/lib/fog/aws/models/ec2/snapshot.rb @@ -8,15 +8,15 @@ class Snapshot < Fog::Model extend Fog::Deprecation deprecate(:status, :state) - identity :id, 'snapshotId' + identity :id, :aliases => 'snapshotId' attribute :description attribute :progress - attribute :created_at, 'startTime' - attribute :owner_id, 'ownerId' - attribute :state, 'status' - attribute :volume_id, 'volumeId' - attribute :volume_size, 'volumeSize' + attribute :created_at, :aliases => 'startTime' + attribute :owner_id, :aliases => 'ownerId' + attribute :state, :aliases => 'status' + attribute :volume_id, :aliases => 'volumeId' + attribute :volume_size, :aliases => 'volumeSize' def destroy requires :id @@ -32,7 +32,7 @@ def ready? def save requires :volume_id - data = connection.create_snapshot(@volume_id).body + data = connection.create_snapshot(@volume_id, @description).body new_attributes = data.reject {|key,value| key == 'requestId'} merge_attributes(new_attributes) true diff --git a/lib/fog/aws/models/ec2/volume.rb b/lib/fog/aws/models/ec2/volume.rb index 1b618b1f81..e6ec16bd31 100644 --- a/lib/fog/aws/models/ec2/volume.rb +++ b/lib/fog/aws/models/ec2/volume.rb @@ -8,16 +8,16 @@ class Volume < Fog::Model extend Fog::Deprecation deprecate(:status, :state) - identity :id, 'volumeId' + identity :id, :aliases => 'volumeId' - attribute :attached_at, 'attachTime' - attribute :availability_zone, 'availabilityZone' - attribute :created_at, 'createTime' + attribute :attached_at, :aliases => 'attachTime' + attribute :availability_zone, :aliases => 'availabilityZone' + attribute :created_at, :aliases => 'createTime' attribute :device - attribute :server_id, 'instanceId' + attribute :server_id, :aliases => 'instanceId' attribute :size - attribute :snapshot_id, 'snapshotId' - attribute :state, 'status' + attribute :snapshot_id, :aliases => 'snapshotId' + attribute :state, :aliases => 'status' def initialize(attributes = {}) # assign server first to prevent race condition with new_record? diff --git a/lib/fog/aws/models/s3/directory.rb b/lib/fog/aws/models/s3/directory.rb index 751cab23c3..d3f328ecf9 100644 --- a/lib/fog/aws/models/s3/directory.rb +++ b/lib/fog/aws/models/s3/directory.rb @@ -10,9 +10,9 @@ class Directory < Fog::Model deprecate(:name, :key) deprecate(:name=, :key=) - identity :key, ['Name', 'name'] + identity :key, :aliases => ['Name', 'name'] - attribute :creation_date, 'CreationDate' + attribute :creation_date, :aliases => 'CreationDate' def destroy requires :key diff --git a/lib/fog/aws/models/s3/file.rb b/lib/fog/aws/models/s3/file.rb index 1c627ec5e0..e7178ea752 100644 --- a/lib/fog/aws/models/s3/file.rb +++ b/lib/fog/aws/models/s3/file.rb @@ -6,16 +6,16 @@ module S3 class File < Fog::Model - identity :key, 'Key' + identity :key, :aliases => 'Key' attr_accessor :body - attribute :content_length, 'Content-Length' - attribute :content_type, 'Content-Type' - attribute :etag, ['Etag', 'ETag'] - attribute :last_modified, ['Last-Modified', 'LastModified'] - attribute :owner, 'Owner' - attribute :size, 'Size' - attribute :storage_class, 'StorageClass' + attribute :content_length, :aliases => 'Content-Length' + attribute :content_type, :aliases => 'Content-Type' + attribute :etag, :aliases => ['Etag', 'ETag'] + attribute :last_modified, :aliases => ['Last-Modified', 'LastModified'] + attribute :owner, :aliases => 'Owner' + attribute :size, :aliases => 'Size' + attribute :storage_class, :aliases => 'StorageClass' def body @body ||= if last_modified && (file = collection.get(identity)) diff --git a/lib/fog/aws/models/s3/files.rb b/lib/fog/aws/models/s3/files.rb index f6894cf8f5..788358af49 100644 --- a/lib/fog/aws/models/s3/files.rb +++ b/lib/fog/aws/models/s3/files.rb @@ -5,18 +5,25 @@ module Fog module AWS module S3 + module Collections + def files + Fog::AWS::S3::Files.new(:connection => self) + end + end + class Files < Fog::Collection - attribute :delimiter, 'Delimiter' + attribute :delimiter, :aliases => 'Delimiter' attribute :directory - attribute :is_truncated, 'IsTruncated' - attribute :marker, 'Marker' - attribute :max_keys, ['MaxKeys', 'max-keys'] - attribute :prefix, 'Prefix' + attribute :is_truncated, :aliases => 'IsTruncated' + attribute :marker, :aliases => 'Marker' + attribute :max_keys, :aliases => ['MaxKeys', 'max-keys'] + attribute :prefix, :aliases => 'Prefix' model Fog::AWS::S3::File def all(options = {}) + requires :directory options = { 'delimiter' => @delimiter, 'marker' => @marker, @@ -30,6 +37,7 @@ def all(options = {}) options ) if parent + merge_attributes(parent.files.attributes) load(parent.files.map {|file| file.attributes}) else nil @@ -37,6 +45,7 @@ def all(options = {}) end def get(key, options = {}, &block) + requires :directory data = connection.get_object(directory.key, key, options, &block) file_data = { :body => data.body, @@ -53,10 +62,12 @@ def get(key, options = {}, &block) end def get_url(key, expires) + requires :directory connection.get_object_url(directory.key, key, expires) end def head(key, options = {}) + requires :directory data = connection.head_object(directory.key, key, options) file_data = { :key => key @@ -72,6 +83,7 @@ def head(key, options = {}) end def new(attributes = {}) + requires :directory super({ :directory => directory }.merge!(attributes)) end diff --git a/lib/fog/aws/parsers/ec2/register_image.rb b/lib/fog/aws/parsers/ec2/register_image.rb new file mode 100644 index 0000000000..c5bfb7c512 --- /dev/null +++ b/lib/fog/aws/parsers/ec2/register_image.rb @@ -0,0 +1,20 @@ +module Fog + module Parsers + module AWS + module EC2 + + class RegisterImage < Fog::Parsers::Base + + def end_element(name) + case name + when 'requestId', 'imageId' + @response[name] = @value + end + end + + end + + end + end + end +end diff --git a/lib/fog/aws/parsers/ec2/run_instances.rb b/lib/fog/aws/parsers/ec2/run_instances.rb index 95de3c27fa..493915c208 100644 --- a/lib/fog/aws/parsers/ec2/run_instances.rb +++ b/lib/fog/aws/parsers/ec2/run_instances.rb @@ -76,6 +76,8 @@ def end_element(name) else @instance['monitoring'][name] = false end + when 'subnetId' + @response[name] = @value end end diff --git a/lib/fog/aws/requests/ec2/delete_volume.rb b/lib/fog/aws/requests/ec2/delete_volume.rb index c4c8360241..9626676645 100644 --- a/lib/fog/aws/requests/ec2/delete_volume.rb +++ b/lib/fog/aws/requests/ec2/delete_volume.rb @@ -29,6 +29,10 @@ class Mock def delete_volume(volume_id) response = Excon::Response.new if volume = @data[:volumes][volume_id] + if volume["attachmentSet"].any? + attach = volume["attachmentSet"].first + raise Fog::AWS::EC2::Error.new("Client.VolumeInUse => Volume #{volume_id} is currently attached to #{attach["instanceId"]}") + end @data[:deleted_at][volume_id] = Time.now volume['status'] = 'deleting' response.status = 200 diff --git a/lib/fog/aws/requests/ec2/modify_snapshot_attribute.rb b/lib/fog/aws/requests/ec2/modify_snapshot_attribute.rb new file mode 100644 index 0000000000..3810419a01 --- /dev/null +++ b/lib/fog/aws/requests/ec2/modify_snapshot_attribute.rb @@ -0,0 +1,38 @@ +module Fog + module AWS + module EC2 + class Real + + # Modify snapshot attributes + # + # ==== Parameters + # * snapshot_id<~String> - Id of snapshot to modify + # * attribute<~String> - Attribute to modify, in ['createVolumePermission'] + # * operation_type<~String> - Operation to perform on attribute, in ['add', 'remove'] + # + def modify_snapshot_attribute(snapshot_id, attribute, operation_type, options = {}) + params = {} + params.merge!(AWS.indexed_param('UserId', options['UserId'], 1)) + params.merge!(AWS.indexed_param('UserGroup', options['UserGroup'], 1)) + request({ + 'Action' => 'ModifySnapshotAttribute', + 'Attribute' => attribute, + 'SnapshotId' => snapshot_id, + 'OperationType' => operation_type, + :idempotent => true, + :parser => Fog::Parsers::AWS::EC2::Basic.new + }.merge!(params)) + end + + end + + class Mock + + def modify_snapshot_attribute(snapshot_id, attribute, operation_type, options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end diff --git a/lib/fog/aws/requests/ec2/register_image.rb b/lib/fog/aws/requests/ec2/register_image.rb new file mode 100644 index 0000000000..d5e3cabee7 --- /dev/null +++ b/lib/fog/aws/requests/ec2/register_image.rb @@ -0,0 +1,89 @@ +module Fog + module AWS + module EC2 + class Real + + require 'fog/aws/parsers/ec2/register_image' + + # register an image + # + # ==== Parameters + # * Name<~String> - Name of the AMI to be registered + # * Description<~String> - AMI description + # * Location<~String> - S3 manifest location (for S3 backed AMIs) + # or + # * RootDeviceName<~String> - Name of Root Device (for EBS snapshot backed AMIs) + # * BlockDevices<~Array>: + # * BlockDeviceOptions<~Hash>: + # * DeviceName<~String> - Name of the Block Device + # * VirtualName<~String> - Name of the Virtual Device + # * SnapshotId<~String> - id of the EBS Snapshot + # * VolumeSize<~Integer> - Size of the snapshot (optional) + # * NoDevice<~Boolean> - Do not use an ebs device (def: true) + # * DeleteOnTermation<~Boolean> - Delete EBS volume on instance term (def: true) + # * Options<~Hash>: + # * Architecture<~String> - i386 or x86_64 + # * KernelId<~String> - kernelId + # * RamdiskId<~String> - ramdiskId + # + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + # * 'return'<~Boolean> - Returns true if deregistration succeeded + # * 'imageId'<~String> - Id of newly created AMI + + def register_image(name, description, location, block_devices=[], options={}) + common_options = { + 'Action' => 'RegisterImage', + 'Name' => name, + 'Description' => description, + } + + # This determines if we are doing a snapshot or a S3 backed AMI. + if(location =~ /^\/dev\/sd[a-p]\d{0,2}$/) + common_options['RootDeviceName'] = location + else + common_options['ImageLocation'] = location + end + + bdi = 0 + block_devices.each do |bd| + bdi += 1 + ["DeviceName","VirtualName"].each do |n| + common_options["BlockDeviceMapping.#{bdi}.#{n}"] = bd["#{n}"] if bd["#{n}"] + end + ["SnapshotId","VolumeSize","NoDevice","DeleteOnTermination"].each do |n| + common_options["BlockDeviceMapping.#{bdi}.Ebs.#{n}"] = bd["#{n}"] if bd["#{n}"] + end + + end + + request(common_options.merge!(options)) + end + + end + + class Mock + + def register_image(name, description, location, block_devices=[], options={}) + response = Excon::Response.new + if !name.empty? + response.status = 200 + response.body = { + 'requestId' => Fog::AWS::Mock.request_id, + 'imageId' => Fog::AWS::Mock.image_id + } + response + else + message = 'MissingParameter => ' + if name.empty? + message << 'The request must contain the parameter name' + end + raise Fog::AWS::EC2::Error.new(message) + end + end + + end + end + end +end diff --git a/lib/fog/aws/requests/ec2/run_instances.rb b/lib/fog/aws/requests/ec2/run_instances.rb index c69a1fd826..ff7b09fcc8 100644 --- a/lib/fog/aws/requests/ec2/run_instances.rb +++ b/lib/fog/aws/requests/ec2/run_instances.rb @@ -26,7 +26,7 @@ class Real # * 'Ebs.SnapshotId'<~String> - id of snapshot to boot volume from # * 'Ebs.VolumeSize'<~String> - size of volume in GiBs required unless snapshot is specified # * 'Ebs.DeleteOnTermination'<~String> - specifies whether or not to delete the volume on instance termination - # * 'SecurityGroup'<~Array> or <~String> - Name of security group(s) for instances + # * 'SecurityGroup'<~Array> or <~String> - Name of security group(s) for instances (you must omit this parameter if using Virtual Private Clouds) # * 'InstanceInitiatedShutdownBehaviour'<~String> - specifies whether volumes are stopped or terminated when instance is shutdown # * 'InstanceType'<~String> - Type of instance to boot. Valid options # in ['m1.small', 'm1.large', 'm1.xlarge', 'c1.medium', 'c1.xlarge', 'm2.2xlarge', 'm2.4xlarge'] diff --git a/lib/fog/aws/requests/elb/create_load_balancer.rb b/lib/fog/aws/requests/elb/create_load_balancer.rb index a3715dfa5f..eb16fa91e4 100644 --- a/lib/fog/aws/requests/elb/create_load_balancer.rb +++ b/lib/fog/aws/requests/elb/create_load_balancer.rb @@ -33,9 +33,9 @@ def create_load_balancer(availability_zones, lb_name, listeners) listener_instance_port.push(listener['InstancePort']) end - params.merge!(AWS.indexed_param('Listeners.member.%.Protocol', listener_protocol, 1)) - params.merge!(AWS.indexed_param('Listeners.member.%.LoadBalancerPort', listener_lb_port, 1)) - params.merge!(AWS.indexed_param('Listeners.member.%.InstancePort', listener_instance_port, 1)) + params.merge!(AWS.indexed_param('Listeners.member.%d.Protocol', listener_protocol, 1)) + params.merge!(AWS.indexed_param('Listeners.member.%d.LoadBalancerPort', listener_lb_port, 1)) + params.merge!(AWS.indexed_param('Listeners.member.%d.InstancePort', listener_instance_port, 1)) request({ 'Action' => 'CreateLoadBalancer', diff --git a/lib/fog/aws/requests/elb/deregister_instances_from_load_balancer.rb b/lib/fog/aws/requests/elb/deregister_instances_from_load_balancer.rb index 5cceacbff2..7cd323792b 100644 --- a/lib/fog/aws/requests/elb/deregister_instances_from_load_balancer.rb +++ b/lib/fog/aws/requests/elb/deregister_instances_from_load_balancer.rb @@ -20,7 +20,7 @@ class Real # * 'Instances'<~Array> - array of hashes describing instances currently enabled # * 'InstanceId'<~String> def deregister_instances_from_load_balancer(instance_ids, lb_name) - params = AWS.indexed_param('Instances.member.%.InstanceId', [*instance_ids], 1) + params = AWS.indexed_param('Instances.member.%d.InstanceId', [*instance_ids], 1) request({ 'Action' => 'DeregisterInstancesFromLoadBalancer', 'LoadBalancerName' => lb_name, diff --git a/lib/fog/aws/requests/elb/describe_instance_health.rb b/lib/fog/aws/requests/elb/describe_instance_health.rb index 39abb30716..b8e0a3de9c 100644 --- a/lib/fog/aws/requests/elb/describe_instance_health.rb +++ b/lib/fog/aws/requests/elb/describe_instance_health.rb @@ -23,7 +23,7 @@ class Real # * 'InstanceId'<~String> # * 'ReasonCode'<~String> def describe_instance_health(lb_name, instance_ids = []) - params = AWS.indexed_param('Instances.member.%.InstanceId', [*instance_ids], 1) + params = AWS.indexed_param('Instances.member.%d.InstanceId', [*instance_ids], 1) request({ 'Action' => 'DescribeInstanceHealth', 'LoadBalancerName' => lb_name, diff --git a/lib/fog/aws/requests/elb/register_instances_with_load_balancer.rb b/lib/fog/aws/requests/elb/register_instances_with_load_balancer.rb index 46c2a92276..aead838135 100644 --- a/lib/fog/aws/requests/elb/register_instances_with_load_balancer.rb +++ b/lib/fog/aws/requests/elb/register_instances_with_load_balancer.rb @@ -20,7 +20,7 @@ class Real # * 'Instances'<~Array> - array of hashes describing instances currently enabled # * 'InstanceId'<~String> def register_instances_with_load_balancer(instance_ids, lb_name) - params = AWS.indexed_param('Instances.member.%.InstanceId', [*instance_ids], 1) + params = AWS.indexed_param('Instances.member.%d.InstanceId', [*instance_ids], 1) request({ 'Action' => 'RegisterInstancesWithLoadBalancer', 'LoadBalancerName' => lb_name, diff --git a/lib/fog/aws/requests/s3/get_bucket.rb b/lib/fog/aws/requests/s3/get_bucket.rb index 0c89909d37..4898c98e90 100644 --- a/lib/fog/aws/requests/s3/get_bucket.rb +++ b/lib/fog/aws/requests/s3/get_bucket.rb @@ -61,23 +61,28 @@ def get_bucket(bucket_name, options = {}) end response = Excon::Response.new if bucket = @data[:buckets][bucket_name] + contents = bucket[:objects].values.sort {|x,y| x['Key'] <=> y['Key']}.reject do |object| + (options['prefix'] && object['Key'][0...options['prefix'].length] != options['prefix']) || + (options['marker'] && object['Key'] <= options['marker']) + end.map do |object| + data = object.reject {|key, value| !['ETag', 'Key', 'LastModified', 'Size', 'StorageClass'].include?(key)} + data.merge!({ + 'LastModified' => Time.parse(data['LastModified']), + 'Owner' => bucket['Owner'], + 'Size' => data['Size'].to_i + }) + data + end + max_keys = options['max-keys'] || 1000 + size = [max_keys, 1000].min + truncated_contents = contents[0...size] + response.status = 200 response.body = { - 'Contents' => bucket[:objects].values.sort {|x,y| x['Key'] <=> y['Key']}.reject do |object| - (options['prefix'] && object['Key'][0...options['prefix'].length] != options['prefix']) || - (options['marker'] && object['Key'] <= options['marker']) - end.map do |object| - data = object.reject {|key, value| !['ETag', 'Key', 'LastModified', 'Size', 'StorageClass'].include?(key)} - data.merge!({ - 'LastModified' => Time.parse(data['LastModified']), - 'Owner' => bucket['Owner'], - 'Size' => data['Size'].to_i - }) - data - end, - 'IsTruncated' => false, + 'Contents' => truncated_contents, + 'IsTruncated' => truncated_contents.size != contents.size, 'Marker' => options['marker'], - 'MaxKeys' => options['max-keys'] || 1000, + 'MaxKeys' => max_keys, 'Name' => bucket['Name'], 'Prefix' => options['prefix'] } diff --git a/lib/fog/aws/s3.rb b/lib/fog/aws/s3.rb index 4716405da4..800d20ceff 100644 --- a/lib/fog/aws/s3.rb +++ b/lib/fog/aws/s3.rb @@ -6,35 +6,35 @@ module S3 requires :aws_access_key_id, :aws_secret_access_key model_path 'fog/aws/models/s3' - model 'directories' - model 'directory' - model 'files' - model 'file' + collection :directories + model :directory + collection :files + model :file request_path 'fog/aws/requests/s3' - request 'copy_object' - request 'delete_bucket' - request 'delete_object' - request 'get_bucket' - request 'get_bucket_acl' - request 'get_bucket_location' - request 'get_bucket_logging' - request 'get_bucket_object_versions' - request 'get_bucket_versioning' - request 'get_object' - request 'get_object_acl' - request 'get_object_torrent' - request 'get_object_url' - request 'get_request_payment' - request 'get_service' - request 'head_object' - request 'put_bucket' - request 'put_bucket_acl' - request 'put_bucket_logging' - request 'put_bucket_versioning' - request 'put_object' - request 'put_object_url' - request 'put_request_payment' + request :copy_object + request :delete_bucket + request :delete_object + request :get_bucket + request :get_bucket_acl + request :get_bucket_location + request :get_bucket_logging + request :get_bucket_object_versions + request :get_bucket_versioning + request :get_object + request :get_object_acl + request :get_object_torrent + request :get_object_url + request :get_request_payment + request :get_service + request :head_object + request :put_bucket + request :put_bucket_acl + request :put_bucket_logging + request :put_bucket_versioning + request :put_object + request :put_object_url + request :put_request_payment module Utils diff --git a/lib/fog/aws/simpledb.rb b/lib/fog/aws/simpledb.rb index 39ce0e8b16..b59f65076d 100644 --- a/lib/fog/aws/simpledb.rb +++ b/lib/fog/aws/simpledb.rb @@ -6,15 +6,15 @@ module SimpleDB requires :aws_access_key_id, :aws_secret_access_key request_path 'fog/aws/requests/simpledb' - request 'batch_put_attributes' - request 'create_domain' - request 'delete_attributes' - request 'delete_domain' - request 'domain_metadata' - request 'get_attributes' - request 'list_domains' - request 'put_attributes' - request 'select' + request :batch_put_attributes + request :create_domain + request :delete_attributes + request :delete_domain + request :domain_metadata + request :get_attributes + request :list_domains + request :put_attributes + request :select class Mock include Collections diff --git a/lib/fog/bin.rb b/lib/fog/bin.rb index a3dae49138..26f5af38e4 100644 --- a/lib/fog/bin.rb +++ b/lib/fog/bin.rb @@ -14,54 +14,20 @@ module Fog class << self - def services - services = [] - [::AWS, ::GoGrid, ::Linode, ::Local, ::NewServers, ::Rackspace, ::Slicehost, ::Terremark, ::Vcloud, ::Bluebox].each do |service| - if service.initialized? - services << service - end - end - services - end - - def directories - directories = {} - services.each do |service| - if service.respond_to?(:directories) - directories[service] = service.directories - end - end - directories - end - - def flavors - flavors = {} - services.each do |service| - if service.respond_to?(:flavors) - flavors[service] = service.flavors - end - end - flavors - end - - def images - images = {} - services.each do |service| - if service.respond_to?(:images) - images[service] = service.images - end - end - images - end + def modules + [ + ::AWS, + ::GoGrid, + ::Linode, + ::Local, + ::NewServers, + ::Rackspace, + ::Slicehost, + ::Terremark, + ::Vcloud, + ::Bluebox + ].select {|_module_| _module_.initialized?} - def servers - servers = {} - services.each do |service| - if service.respond_to?(:servers) - servers[service] = service.servers - end - end - servers end end diff --git a/lib/fog/bluebox.rb b/lib/fog/bluebox.rb index b7585a6174..c6018e9feb 100644 --- a/lib/fog/bluebox.rb +++ b/lib/fog/bluebox.rb @@ -5,22 +5,23 @@ module Bluebox requires :bluebox_api_key, :bluebox_customer_id model_path 'fog/bluebox/models' - model 'flavor' - model 'flavors' - model 'images' - model 'server' - model 'servers' + model :flavor + collection :flavors + model :image + collection :images + model :server + collection :servers request_path 'fog/bluebox/requests' - request 'create_block' - request 'destroy_block' - request 'get_block' - request 'get_blocks' - request 'get_product' - request 'get_products' - request 'get_template' - request 'get_templates' - request 'reboot_block' + request :create_block + request :destroy_block + request :get_block + request :get_blocks + request :get_product + request :get_products + request :get_template + request :get_templates + request :reboot_block class Mock include Collections diff --git a/lib/fog/bluebox/bin.rb b/lib/fog/bluebox/bin.rb index 2524f019a1..fb59b122d1 100644 --- a/lib/fog/bluebox/bin.rb +++ b/lib/fog/bluebox/bin.rb @@ -9,27 +9,24 @@ def initialized? def [](service) @@connections ||= Hash.new do |hash, key| - credentials = Fog.credentials.reject do |k,v| - ![:bluebox_api_key, :bluebox_customer_id].include?(k) - end hash[key] = case key when :blocks - Fog::Bluebox.new(credentials) + Fog::Bluebox.new end end @@connections[service] end - def flavors - self[:blocks].flavors - end - - def images - self[:blocks].images + def services + [:blocks] end - def servers - self[:blocks].servers + for collection in Fog::Bluebox.collections + module_eval <<-EOS, __FILE__, __LINE__ + def #{collection} + self[:blocks].#{collection} + end + EOS end else diff --git a/lib/fog/bluebox/models/image.rb b/lib/fog/bluebox/models/image.rb index 5fa21b933f..34813f699c 100644 --- a/lib/fog/bluebox/models/image.rb +++ b/lib/fog/bluebox/models/image.rb @@ -9,7 +9,7 @@ class Image < Fog::Model attribute :description attribute :public - attribute :created_at, 'created' + attribute :created_at, :aliases => 'created' end diff --git a/lib/fog/credentials.rb b/lib/fog/credentials.rb index 1addbb13f7..acc35864ed 100644 --- a/lib/fog/credentials.rb +++ b/lib/fog/credentials.rb @@ -44,6 +44,8 @@ def credentials :slicehost_password: INTENTIONALLY_LEFT_BLANK :terremark_username: INTENTIONALLY_LEFT_BLANK :terremark_password: INTENTIONALLY_LEFT_BLANK + :xenserver_username: INTENTIONALLY_LEFT_BLANK + :xenserver_password: INTENTIONALLY_LEFT_BLANK YML print(yml) raise(ArgumentError.new("Missing Credentials")) diff --git a/lib/fog/go_grid.rb b/lib/fog/go_grid.rb index ac3ec8cd5b..02499aa33b 100644 --- a/lib/fog/go_grid.rb +++ b/lib/fog/go_grid.rb @@ -8,15 +8,15 @@ module GoGrid model_path 'fog/go_grid/models' request_path 'fog/go_grid/requests' - request 'common_lookup_list' - request 'grid_image_list' - request 'grid_ip_list' - request 'grid_loadbalancer_list' - request 'grid_server_add' - request 'grid_server_delete' - request 'grid_server_get' - request 'grid_server_list' - request 'grid_server_power' + request :common_lookup_list + request :grid_image_list + request :grid_ip_list + request :grid_loadbalancer_list + request :grid_server_add + request :grid_server_delete + request :grid_server_get + request :grid_server_list + request :grid_server_power class Mock include Collections diff --git a/lib/fog/go_grid/bin.rb b/lib/fog/go_grid/bin.rb index 0af05c230f..a0cd680052 100644 --- a/lib/fog/go_grid/bin.rb +++ b/lib/fog/go_grid/bin.rb @@ -8,17 +8,18 @@ def initialized? def [](service) @@connections ||= Hash.new do |hash, key| - credentials = Fog.credentials.reject do |k,v| - ![:go_grid_api_key, :go_grid_shared_secret].include?(k) - end hash[key] = case key when :go_grid - Fog::GoGrid.new(credentials) + Fog::GoGrid.new end end @@connections[service] end + def services + [:go_grid] + end + else def initialized? diff --git a/lib/fog/linode.rb b/lib/fog/linode.rb index 3d8cbf9721..8cc489b67e 100644 --- a/lib/fog/linode.rb +++ b/lib/fog/linode.rb @@ -7,15 +7,15 @@ module Linode model_path 'fog/linode/models' request_path 'fog/linode/requests' - request 'avail_datacenters' - request 'avail_distributions' - request 'avail_kernels' - request 'avail_linodeplans' - request 'avail_stackscripts' - request 'linode_create' - request 'linode_delete' - request 'linode_list' - request 'linode_reboot' + request :avail_datacenters + request :avail_distributions + request :avail_kernels + request :avail_linodeplans + request :avail_stackscripts + request :linode_create + request :linode_delete + request :linode_list + request :linode_reboot class Mock include Collections diff --git a/lib/fog/linode/bin.rb b/lib/fog/linode/bin.rb index 751016482f..5064281424 100644 --- a/lib/fog/linode/bin.rb +++ b/lib/fog/linode/bin.rb @@ -8,17 +8,18 @@ def initialized? def [](service) @@connections ||= Hash.new do |hash, key| - credentials = Fog.credentials.reject do |k,v| - ![:linode_api_key].include?(k) - end hash[key] = case key when :linode - Fog::Linode.new(credentials) + Fog::Linode.new end end @@connections[service] end + def services + [:linode] + end + else def initialized? diff --git a/lib/fog/local.rb b/lib/fog/local.rb index 7ab967c8aa..3b725ef5ea 100644 --- a/lib/fog/local.rb +++ b/lib/fog/local.rb @@ -5,10 +5,10 @@ module Local requires :local_root model_path 'fog/local/models' - model 'directories' - model 'directory' - model 'file' - model 'files' + collection :directories + model :directory + model :file + collection :files class Mock include Collections diff --git a/lib/fog/local/bin.rb b/lib/fog/local/bin.rb index 8f79403920..dca9ee963b 100644 --- a/lib/fog/local/bin.rb +++ b/lib/fog/local/bin.rb @@ -8,19 +8,24 @@ def initialized? def [](service) @@connections ||= Hash.new do |hash, key| - credentials = Fog.credentials.reject do |k,v| - ![:local_root].include?(k) - end hash[key] = case key when :files - Fog::Local.new(credentials) + Fog::Local.new end end @@connections[service] end - def directories - self[:files].directories + def services + [:files] + end + + for collection in Fog::Local.collections + module_eval <<-EOS, __FILE__, __LINE__ + def #{collection} + self[:files].#{collection} + end + EOS end else diff --git a/lib/fog/local/models/file.rb b/lib/fog/local/models/file.rb index f2a5510b6f..ddad27fd12 100644 --- a/lib/fog/local/models/file.rb +++ b/lib/fog/local/models/file.rb @@ -8,9 +8,9 @@ class File < Fog::Model identity :key, 'Key' attr_accessor :body - attribute :content_length, 'Content-Length' - # attribute :content_type, 'Content-Type' - attribute :last_modified, 'Last-Modified' + attribute :content_length, :aliases => 'Content-Length' + # attribute :content_type, :aliases => 'Content-Type' + attribute :last_modified, :aliases => 'Last-Modified' def body @body ||= if last_modified diff --git a/lib/fog/local/models/files.rb b/lib/fog/local/models/files.rb index cf6c52111c..5135df83d2 100644 --- a/lib/fog/local/models/files.rb +++ b/lib/fog/local/models/files.rb @@ -4,11 +4,20 @@ module Fog module Local + module Collections + def files + Fog::Local::Files.new(:connection => self) + end + end + class Files < Fog::Collection + attribute :directory + model Fog::Local::File def all + requires :directory if directory.collection.get(directory.key) data = Dir.entries(connection.path_to(directory.key)).select do |key| key[0...1] != '.' && !::File.directory?(connection.path_to(key)) @@ -26,11 +35,8 @@ def all end end - def directory - @directory - end - def get(key, &block) + requires :directory path = file_path(key) if ::File.exists?(path) data = { @@ -56,15 +62,12 @@ def get(key, &block) end def new(attributes = {}) + requires :directory super({ :directory => directory }.merge!(attributes)) end private - def directory=(new_directory) - @directory = new_directory - end - def file_path(key) connection.path_to(::File.join(directory.key, key)) end diff --git a/lib/fog/model.rb b/lib/fog/model.rb index 41deb48c75..7eddb11963 100644 --- a/lib/fog/model.rb +++ b/lib/fog/model.rb @@ -42,7 +42,7 @@ def to_json def wait_for(timeout=600, interval=1, &block) reload Fog.wait_for(timeout, interval) do - reload or raise StandardError.new("Reload failed, #{self.class} #{self.identity} went away.") + reload or raise Fog::Errors::Error.new("Reload failed, #{self.class} #{self.identity} went away.") instance_eval(&block) end end diff --git a/lib/fog/new_servers.rb b/lib/fog/new_servers.rb index f774ab5dcd..deab193b06 100644 --- a/lib/fog/new_servers.rb +++ b/lib/fog/new_servers.rb @@ -10,13 +10,13 @@ module NewServers model_path 'fog/new_servers/models' request_path 'fog/new_servers/requests' - request 'add_server' - request 'cancel_server' - request 'get_server' - request 'list_images' - request 'list_plans' - request 'list_servers' - request 'reboot_server' + request :add_server + request :cancel_server + request :get_server + request :list_images + request :list_plans + request :list_servers + request :reboot_server class Mock include Collections diff --git a/lib/fog/new_servers/bin.rb b/lib/fog/new_servers/bin.rb index b30102e18b..03907c1ca6 100644 --- a/lib/fog/new_servers/bin.rb +++ b/lib/fog/new_servers/bin.rb @@ -8,17 +8,18 @@ def initialized? def [](service) @@connections ||= Hash.new do |hash, key| - credentials = Fog.credentials.reject do |k,v| - ![:new_servers_password, :new_servers_username].include?(k) - end hash[key] = case key when :new_servers - Fog::NewServers.new(credentials) + Fog::NewServers.new end end @@connections[service] end + def services + [:new_servers] + end + else def initialized? diff --git a/lib/fog/parser.rb b/lib/fog/parser.rb index 2cb7df3efa..6b0fa2f84d 100644 --- a/lib/fog/parser.rb +++ b/lib/fog/parser.rb @@ -85,6 +85,10 @@ def start_element(name, attributes = []) @stack.last[name.to_sym].merge!(parsed_attributes) @stack.last[name.to_sym] end + if data.is_a? Hash + pp data + puts "-+" * 20 + end @stack.push(data) end end diff --git a/lib/fog/provider.rb b/lib/fog/provider.rb new file mode 100644 index 0000000000..484a804152 --- /dev/null +++ b/lib/fog/provider.rb @@ -0,0 +1,18 @@ +module Fog + module Provider + + def service_path(new_path) + @service_path = new_path + end + + def service(new_service) + services << new_service + require File.join(@service_path, new_service.to_s) + end + + def services + @services ||= [] + end + + end +end diff --git a/lib/fog/rackspace.rb b/lib/fog/rackspace.rb index c17cb48b8f..3fa850d9aa 100644 --- a/lib/fog/rackspace.rb +++ b/lib/fog/rackspace.rb @@ -1,11 +1,15 @@ -require 'fog/rackspace/files' -require 'fog/rackspace/servers' - module Fog module Rackspace + extend Fog::Provider + + service_path 'fog/rackspace' + service 'files' + service 'servers' + def self.authenticate(options) - connection = Fog::Connection.new("https://auth.api.rackspacecloud.com") + rackspace_auth_url = options[:rackspace_auth_url] || "auth.api.rackspacecloud.com" + connection = Fog::Connection.new("https://" + rackspace_auth_url) @rackspace_api_key = options[:rackspace_api_key] @rackspace_username = options[:rackspace_username] response = connection.request({ @@ -14,7 +18,7 @@ def self.authenticate(options) 'X-Auth-Key' => @rackspace_api_key, 'X-Auth-User' => @rackspace_username }, - :host => 'auth.api.rackspacecloud.com', + :host => rackspace_auth_url, :method => 'GET', :path => 'v1.0' }) diff --git a/lib/fog/rackspace/bin.rb b/lib/fog/rackspace/bin.rb index 68a3b45cf1..69685a1948 100644 --- a/lib/fog/rackspace/bin.rb +++ b/lib/fog/rackspace/bin.rb @@ -8,35 +8,36 @@ def initialized? def [](service) @@connections ||= Hash.new do |hash, key| - credentials = Fog.credentials.reject do |k,v| - ![:rackspace_api_key, :rackspace_username].include?(k) - end hash[key] = case key when :files - Fog::Rackspace::Files.new(credentials) + Fog::Rackspace::Files.new when :servers - Fog::Rackspace::Servers.new(credentials) + Fog::Rackspace::Servers.new end end @@connections[service] end - def directories - self[:files].directories + def services + [:files, :servers] end - def flavors - self[:servers].flavors + for collection in Fog::Rackspace::Files.collections + module_eval <<-EOS, __FILE__, __LINE__ + def #{collection} + self[:files].#{collection} + end + EOS end - def images - self[:servers].images + for collection in Fog::Rackspace::Servers.collections + module_eval <<-EOS, __FILE__, __LINE__ + def #{collection} + self[:servers].#{collection} + end + EOS end - def servers - self[:servers].servers - end - else def initialized? diff --git a/lib/fog/rackspace/files.rb b/lib/fog/rackspace/files.rb index 778574349b..e028aa7903 100644 --- a/lib/fog/rackspace/files.rb +++ b/lib/fog/rackspace/files.rb @@ -6,22 +6,22 @@ module Files requires :rackspace_api_key, :rackspace_username model_path 'fog/rackspace/models/files' - model 'directory' - model 'directories' - model 'file' - model 'files' + model :directory + collection :directories + model :file + collection :files request_path 'fog/rackspace/requests/files' - request 'delete_container' - request 'delete_object' - request 'get_container' - request 'get_containers' - request 'get_object' - request 'head_container' - request 'head_containers' - request 'head_object' - request 'put_container' - request 'put_object' + request :delete_container + request :delete_object + request :get_container + request :get_containers + request :get_object + request :head_container + request :head_containers + request :head_object + request :put_container + request :put_object module Utils @@ -79,12 +79,14 @@ def initialize(options={}) credentials = Fog::Rackspace.authenticate(options) @auth_token = credentials['X-Auth-Token'] - cdn_uri = URI.parse(credentials['X-CDN-Management-Url']) - @cdn_host = cdn_uri.host - @cdn_path = cdn_uri.path - @cdn_port = cdn_uri.port - @cdn_scheme = cdn_uri.scheme - @cdn_connection = Fog::Connection.new("#{@cdn_scheme}://#{@cdn_host}:#{@cdn_port}", options[:persistent]) + if(credentials['X-CDN-Management-Url']) + cdn_uri = URI.parse(credentials['X-CDN-Management-Url']) + @cdn_host = cdn_uri.host + @cdn_path = cdn_uri.path + @cdn_port = cdn_uri.port + @cdn_scheme = cdn_uri.scheme + @cdn_connection = Fog::Connection.new("#{@cdn_scheme}://#{@cdn_host}:#{@cdn_port}", options[:persistent]) + end storage_uri = URI.parse(credentials['X-Storage-Url']) @storage_host = storage_uri.host diff --git a/lib/fog/rackspace/models/files/file.rb b/lib/fog/rackspace/models/files/file.rb index a0a63a4b23..8a787b3580 100644 --- a/lib/fog/rackspace/models/files/file.rb +++ b/lib/fog/rackspace/models/files/file.rb @@ -6,13 +6,13 @@ module Files class File < Fog::Model - identity :key, 'Key' + identity :key, :aliases => 'Key' attr_accessor :body - attribute :content_length, 'Content-Length' - attribute :content_type, 'Content-Type' - attribute :etag, 'Etag' - attribute :last_modified, 'Last-Modified' + attribute :content_length, :aliases => 'Content-Length' + attribute :content_type, :aliases => 'Content-Type' + attribute :etag, :aliases => 'Etag' + attribute :last_modified, :aliases => 'Last-Modified' def body @body ||= if last_modified diff --git a/lib/fog/rackspace/models/files/files.rb b/lib/fog/rackspace/models/files/files.rb index 6b030b16f3..1d56f41609 100644 --- a/lib/fog/rackspace/models/files/files.rb +++ b/lib/fog/rackspace/models/files/files.rb @@ -5,8 +5,15 @@ module Fog module Rackspace module Files + module Collections + def files + Fog::Rackspace::Files::Files.new(:connection => self) + end + end + class Files < Fog::Collection + attribute :directory attribute :limit attribute :marker attribute :path @@ -15,6 +22,7 @@ class Files < Fog::Collection model Fog::Rackspace::Files::File def all(options = {}) + requires :directory merge_attributes(options) parent = directory.collection.get( directory.key, @@ -27,11 +35,8 @@ def all(options = {}) end end - def directory - @directory - end - def get(key, options = {}, &block) + requires :directory options = { 'limit' => @limit, 'marker' => @marker, @@ -54,10 +59,12 @@ def get(key, options = {}, &block) end def get_url(key, expires) + requires :directory connection.get_object_url(directory.name, key, expires) end def head(key, options = {}) + requires :directory data = connection.head_object(directory.name, key, options) file_data = { :key => key } for key, value in data.headers @@ -71,15 +78,10 @@ def head(key, options = {}) end def new(attributes = {}) + requires :directory super({ :directory => directory }.merge!(attributes)) end - private - - def directory=(new_directory) - @directory = new_directory - end - end end diff --git a/lib/fog/rackspace/models/servers/image.rb b/lib/fog/rackspace/models/servers/image.rb index 312aeb756a..a3b259ade4 100644 --- a/lib/fog/rackspace/models/servers/image.rb +++ b/lib/fog/rackspace/models/servers/image.rb @@ -9,11 +9,11 @@ class Image < Fog::Model identity :id attribute :name - attribute :created_at, 'created' - attribute :updated_at, 'updated' + attribute :created_at, :aliases => 'created' + attribute :updated_at, :aliases => 'updated' attribute :progress attribute :status - attribute :server_id, 'serverId' + attribute :server_id, :aliases => 'serverId' def server=(new_server) requires :id diff --git a/lib/fog/rackspace/models/servers/server.rb b/lib/fog/rackspace/models/servers/server.rb index 647bffd58a..f59aa327f7 100644 --- a/lib/fog/rackspace/models/servers/server.rb +++ b/lib/fog/rackspace/models/servers/server.rb @@ -9,9 +9,9 @@ class Server < Fog::Model identity :id attribute :addresses - attribute :flavor_id, 'flavorId' - attribute :host_id, 'hostId' - attribute :image_id, 'imageId' + attribute :flavor_id, :aliases => 'flavorId' + attribute :host_id, :aliases => 'hostId' + attribute :image_id, :aliases => 'imageId' attribute :metadata attribute :name attribute :personality diff --git a/lib/fog/rackspace/servers.rb b/lib/fog/rackspace/servers.rb index fc98084d60..718aaba68c 100644 --- a/lib/fog/rackspace/servers.rb +++ b/lib/fog/rackspace/servers.rb @@ -6,32 +6,32 @@ module Servers requires :rackspace_api_key, :rackspace_username model_path 'fog/rackspace/models/servers' - model 'flavor' - model 'flavors' - model 'image' - model 'images' - model 'server' - model 'servers' + model :flavor + collection :flavors + model :image + collection :images + model :server + collection :servers request_path 'fog/rackspace/requests/servers' - request 'create_image' - request 'create_server' - request 'delete_image' - request 'delete_server' - request 'get_flavor_details' - request 'get_image_details' - request 'get_server_details' - request 'list_addresses' - request 'list_private_addresses' - request 'list_public_addresses' - request 'list_flavors' - request 'list_flavors_detail' - request 'list_images' - request 'list_images_detail' - request 'list_servers' - request 'list_servers_detail' - request 'reboot_server' - request 'update_server' + request :create_image + request :create_server + request :delete_image + request :delete_server + request :get_flavor_details + request :get_image_details + request :get_server_details + request :list_addresses + request :list_private_addresses + request :list_public_addresses + request :list_flavors + request :list_flavors_detail + request :list_images + request :list_images_detail + request :list_servers + request :list_servers_detail + request :reboot_server + request :update_server class Mock include Collections diff --git a/lib/fog/service.rb b/lib/fog/service.rb index 42825ebf27..568195b933 100644 --- a/lib/fog/service.rb +++ b/lib/fog/service.rb @@ -7,9 +7,12 @@ def self.extended(other) class Error < Fog::Errors::Error; end class NotFound < Fog::Errors::NotFound; end - module Collections; end - def self.new(options={}) + if Fog.bin + default_credentials = Fog.credentials.reject {|key, value| !requirements.include?(key)} + options = default_credentials.merge(options) + end + missing = [] for requirement in requirements missing << requirement unless options[requirement] @@ -23,6 +26,9 @@ def self.new(options={}) end unless @required + for collection in collections + require [@model_path, collection].join('/') + end for model in models require [@model_path, model].join('/') end @@ -43,6 +49,23 @@ def self.new(options={}) end instance end + + module Collections + + def collections + service.collections + end + + def requests + service.requests + end + + def service + @service ||= eval(self.class.to_s.split('::')[0...-1].join('::')) + end + + end + EOS end @@ -50,6 +73,14 @@ def model_path(new_path) @model_path = new_path end + def collection(new_collection) + collections << new_collection + end + + def collections + @collections ||= [] + end + def model(new_model) models << new_model end diff --git a/lib/fog/slicehost.rb b/lib/fog/slicehost.rb index 0afad97b33..71a4c32e99 100644 --- a/lib/fog/slicehost.rb +++ b/lib/fog/slicehost.rb @@ -5,24 +5,24 @@ module Slicehost requires :slicehost_password model_path 'fog/slicehost/models' - model 'flavor' - model 'flavors' - model 'image' - model 'images' - model 'server' - model 'servers' + model :flavor + collection :flavors + model :image + collection :images + model :server + collection :servers request_path 'fog/slicehost/requests' - request 'create_slice' - request 'delete_slice' - request 'get_backups' - request 'get_flavor' - request 'get_flavors' - request 'get_image' - request 'get_images' - request 'get_slice' - request 'get_slices' - request 'reboot_slice' + request :create_slice + request :delete_slice + request :get_backups + request :get_flavor + request :get_flavors + request :get_image + request :get_images + request :get_slice + request :get_slices + request :reboot_slice class Mock include Collections diff --git a/lib/fog/slicehost/bin.rb b/lib/fog/slicehost/bin.rb index 7593398a7b..7df93b21df 100644 --- a/lib/fog/slicehost/bin.rb +++ b/lib/fog/slicehost/bin.rb @@ -8,27 +8,24 @@ def initialized? def [](service) @@connections ||= Hash.new do |hash, key| - credentials = Fog.credentials.reject do |k,v| - ![:slicehost_password].include?(k) - end hash[key] = case key when :slices - Fog::Slicehost.new(credentials) + Fog::Slicehost.new end end @@connections[service] end - def flavors - self[:slices].flavors - end - - def images - self[:slices].images + def services + [:slices] end - def servers - self[:slices].servers + for collection in Fog::Slicehost.collections + module_eval <<-EOS, __FILE__, __LINE__ + def #{collection} + self[:slices].#{collection} + end + EOS end else diff --git a/lib/fog/slicehost/models/server.rb b/lib/fog/slicehost/models/server.rb index 93c64b510d..7868752614 100644 --- a/lib/fog/slicehost/models/server.rb +++ b/lib/fog/slicehost/models/server.rb @@ -8,13 +8,13 @@ class Server < Fog::Model identity :id attribute :addresses - attribute :backup_id, 'backup-id' - attribute :bandwidth_in, 'bw-in' - attribute :bandwidth_out, 'bw-out' - attribute :flavor_id, 'flavor-id' - attribute :image_id, 'image-id' + attribute :backup_id, :aliases => 'backup-id' + attribute :bandwidth_in, :aliases => 'bw-in' + attribute :bandwidth_out, :aliases => 'bw-out' + attribute :flavor_id, :aliases => 'flavor-id' + attribute :image_id, :aliases => 'image-id' attribute :name - attribute :password, 'root-password' + attribute :password, :aliases => 'root-password' attribute :progress attribute :status diff --git a/lib/fog/terremark/models/shared/address.rb b/lib/fog/terremark/models/shared/address.rb index 115b9cab1b..4f3ccb7fd1 100644 --- a/lib/fog/terremark/models/shared/address.rb +++ b/lib/fog/terremark/models/shared/address.rb @@ -8,7 +8,7 @@ class Address < Fog::Model identity :id - attribute :ip, 'name' + attribute :ip, :aliases => 'name' def destroy requires :id diff --git a/lib/fog/terremark/models/shared/task.rb b/lib/fog/terremark/models/shared/task.rb index 99c1895c4c..150f66f0a7 100644 --- a/lib/fog/terremark/models/shared/task.rb +++ b/lib/fog/terremark/models/shared/task.rb @@ -8,13 +8,13 @@ class Task < Fog::Model identity :id - attribute :end_time, 'endTime' - attribute :owner, 'Owner' - attribute :result, 'Result' - attribute :start_time, 'startTime' + attribute :end_time, :aliases => 'endTime' + attribute :owner, :aliases => 'Owner' + attribute :result, :aliases => 'Result' + attribute :start_time, :aliases => 'startTime' attribute :status - attribute :link, 'Link' - attribute :error, 'Error' + attribute :link, :aliases => 'Link' + attribute :error, :aliases => 'Error' def initialize(attributes = {}) new_owner = attributes.delete('Owner') diff --git a/lib/fog/vcloud.rb b/lib/fog/vcloud.rb index daba40d323..cd8b7e4deb 100644 --- a/lib/fog/vcloud.rb +++ b/lib/fog/vcloud.rb @@ -22,8 +22,8 @@ module Vcloud requires :username, :password, :versions_uri model_path 'fog/vcloud/models' - model 'vdc' - model 'vdcs' + model :vdc + model :vdcs request_path 'fog/vcloud/requests' request :login diff --git a/lib/fog/vcloud/terremark/ecloud/models/task.rb b/lib/fog/vcloud/terremark/ecloud/models/task.rb index 5253463ddd..5f59299f96 100644 --- a/lib/fog/vcloud/terremark/ecloud/models/task.rb +++ b/lib/fog/vcloud/terremark/ecloud/models/task.rb @@ -14,6 +14,7 @@ class Task < Fog::Vcloud::Model attribute :owner, :aliases => :Owner attribute :start_time, :aliases => :startTime, :type => :time attribute :end_time, :aliases => :endTime, :type => :time + attribute :error, :aliases => :Error end end diff --git a/lib/fog/xenserver.rb b/lib/fog/xenserver.rb new file mode 100644 index 0000000000..8861dbe0be --- /dev/null +++ b/lib/fog/xenserver.rb @@ -0,0 +1,90 @@ +module Fog + module Xenserver + extend Fog::Service + + require 'fog/xenserver/connection' + require 'fog/xenserver/utilities' + require 'fog/xenserver/parser' + + requires :xenserver_username + requires :xenserver_password + + model_path 'fog/xenserver/models' + model 'servers' + model 'hypervisors' + model 'images' + model 'networks' + model 'srs' + model 'vif' + model 'vm' + + request_path 'fog/xenserver/requests' + request 'create_server' + request 'create_vif' + request 'create_vm' + request 'get_host' + request 'get_hosts' + request 'get_network' + request 'get_networks' + request 'get_sr' + request 'get_srs' + request 'get_vif' + request 'get_vifs' + request 'get_vm' + request 'get_vms' + request 'start_vm' + + class Real + include Collections + + def initialize(options={}) + @host = options[:xenserver_pool_master] + @username = options[:xenserver_username] + @password = options[:xenserver_password] + @defaults = options[:xenserver_defaults] || {} + @connection = Fog::Xenserver::Connection.new(@host) + @connection.authenticate(@username, @password) + end + + def reload + @connection.authenticate(@username, @password) + end + + def default_image + Fog::Xenserver::Vm.new( get_vm( @defaults[:image] ) ) if @defaults[:image] + end + + def default_network + Fog::Xenserver::Network.new( get_network( @defaults[:network] ) ) if @defaults[:network] + end + + end + + class Mock + include Collections + + def self.data + @data ||= Hash.new do |hash, key| + hash[key] = {} + end + end + + def self.reset_data(keys=data.keys) + for key in [*keys] + data.delete(key) + end + end + + def initialize(options={}) + @host = options[:xenserver_pool_master] + @username = options[:xenserver_username] + @password = options[:xenserver_password] + @connection = Fog::Connection.new(@host) + @connection.authenticate(@username, @password) + end + + end + end +end + + diff --git a/lib/fog/xenserver/connection.rb b/lib/fog/xenserver/connection.rb new file mode 100644 index 0000000000..5364995697 --- /dev/null +++ b/lib/fog/xenserver/connection.rb @@ -0,0 +1,46 @@ +module Fog + module Xenserver + class Connection + require 'xmlrpc/client' + + def initialize(host) + @factory = XMLRPC::Client.new(host, '/') + @factory.set_parser(XMLRPC::XMLParser::REXMLStreamParser.new) + end + + def authenticate( username, password ) + begin + response = @factory.call('session.login_with_password', username, password ) + raise Fog::Xenserver::InvalidLogin unless response["Status"] =~ /Success/ + end + @credentials = response["Value"] + end + + def request(options, *params) + begin + parser = options.delete(:parser) + method = options.delete(:method) + + if params.empty? + response = @factory.call(method, @credentials) + else + if params.length.eql?(1) and params.first.is_a?(Hash) + response = @factory.call(method, @credentials, params.first) + else + response = eval("@factory.call('#{method}', '#{@credentials}', #{params.map {|p| p.is_a?(String) ? "'#{p}'" : p}.join(',')})") + end + end + + raise Fog::Xenserver::InvalidRequest unless response.first === ["Status", "Success"] + + if parser + parser.parse( response["Value"] ) + response = parser.response + end + + response + end + end + end + end +end \ No newline at end of file diff --git a/lib/fog/xenserver/models/host.rb b/lib/fog/xenserver/models/host.rb new file mode 100644 index 0000000000..1c442395be --- /dev/null +++ b/lib/fog/xenserver/models/host.rb @@ -0,0 +1,38 @@ +require 'fog/model' + +module Fog + module Xenserver + class Host < Fog::Model + # API Reference here: + # http://docs.vmd.citrix.com/XenServer/5.6.0/1.0/en_gb/api/?c=host + + identity :reference + + attribute :name_label + attribute :uuid + attribute :address + attribute :allowed_operations + attribute :enabled + attribute :hostname + attribute :metrics + attribute :name_description + attribute :other_config + attribute :PBDs + attribute :PIFs + attribute :resident_VMs + + ignore_attributes :API_version_major, :API_version_minor, :API_version_vendor, :API_version_vendor_implementation, + :blobs, :capabilities, :cpu_configuration, :crash_dump_sr, :crashdumps, :current_operations, + :external_auth_configuration, :external_auth_service_name, :external_auth_type, + :ha_network_peers, :ha_statefiles, :host_CPUs, :license_params, :logging, :patches, + :sched_policy, :software_version, :supported_bootloaders, :suspend_image_sr, :tags + + def initialize(attributes={}) + @uuid ||= 0 + super + end + + end + + end +end diff --git a/lib/fog/xenserver/models/hypervisors.rb b/lib/fog/xenserver/models/hypervisors.rb new file mode 100644 index 0000000000..b31c626908 --- /dev/null +++ b/lib/fog/xenserver/models/hypervisors.rb @@ -0,0 +1,33 @@ +require 'fog/collection' +require 'fog/xenserver/models/host' + +module Fog + module Xenserver + + module Collections + def hypervisors + Fog::Xenserver::Hypervisors.new(:connection => self) + end + end + + class Hypervisors < Fog::Collection + + model Fog::Xenserver::Host + + def all + data = connection.get_hosts + load(data) + end + + def get( host_ref ) + if host_ref && host = connection.get_host_by_ref( host_ref ) + new(host) + end + rescue Fog::Xenserver::NotFound + nil + end + + end + + end +end diff --git a/lib/fog/xenserver/models/images.rb b/lib/fog/xenserver/models/images.rb new file mode 100644 index 0000000000..6ed61809df --- /dev/null +++ b/lib/fog/xenserver/models/images.rb @@ -0,0 +1,34 @@ +require 'fog/collection' +require 'fog/xenserver/models/vm' + +module Fog + module Xenserver + + module Collections + def images + Fog::Xenserver::Images.new(:connection => self) + end + end + + class Images < Fog::Collection + + model Fog::Xenserver::Vm + + def all + data = connection.get_vms + data.delete_if {|vm| vm[:is_a_template].eql?(false)} + load(data) + end + + def get( vm_ref ) + if vm_ref && vm = connection.get_vm_by_ref( vm_ref ) + new(vm) + end + rescue Fog::Xenserver::NotFound + nil + end + + end + + end +end diff --git a/lib/fog/xenserver/models/network.rb b/lib/fog/xenserver/models/network.rb new file mode 100644 index 0000000000..f33b3bbcc1 --- /dev/null +++ b/lib/fog/xenserver/models/network.rb @@ -0,0 +1,30 @@ +require 'fog/model' + +module Fog + module Xenserver + + class Network < Fog::Model + # API Reference here: + # http://docs.vmd.citrix.com/XenServer/5.6.0/1.0/en_gb/api/?c=network + + identity :reference + + attribute :name_label + attribute :uuid + attribute :bridge + attribute :name_description + attribute :other_config + attribute :PIFs + attribute :VIFs + + ignore_attributes :allowed_operations, :blobs, :collection, :current_operations, :tags + + def initialize(attributes={}) + @uuid ||= 0 + super + end + + end + + end +end diff --git a/lib/fog/xenserver/models/networks.rb b/lib/fog/xenserver/models/networks.rb new file mode 100644 index 0000000000..d42ec016e1 --- /dev/null +++ b/lib/fog/xenserver/models/networks.rb @@ -0,0 +1,33 @@ +require 'fog/collection' +require 'fog/xenserver/models/network' + +module Fog + module Xenserver + + module Collections + def networks + Fog::Xenserver::Networks.new(:connection => self) + end + end + + class Networks < Fog::Collection + + model Fog::Xenserver::Network + + def all + data = connection.get_networks + load(data) + end + + def get( network_ref ) + if network_ref && network = connection.get_network_by_ref( network_ref ) + new(network) + end + rescue Fog::Xenserver::NotFound + nil + end + + end + + end +end diff --git a/lib/fog/xenserver/models/servers.rb b/lib/fog/xenserver/models/servers.rb new file mode 100644 index 0000000000..1127f4fe4a --- /dev/null +++ b/lib/fog/xenserver/models/servers.rb @@ -0,0 +1,36 @@ +require 'fog/collection' +require 'fog/xenserver/models/vm' + +module Fog + module Xenserver + + module Collections + def servers + Fog::Xenserver::Servers.new(:connection => self) + end + end + + class Servers < Fog::Collection + + model Fog::Xenserver::Vm + + def all + data = connection.get_vms + data.delete_if {|vm| vm[:is_a_template]} + data.delete_if {|vm| vm[:is_control_domain]} + data.delete_if {|vm| vm[:is_snapshot]} + load(data) + end + + def get( vm_ref ) + if vm_ref && vm = connection.get_vm_by_ref( vm_ref ) + new(vm) + end + rescue Fog::Xenserver::NotFound + nil + end + + end + + end +end diff --git a/lib/fog/xenserver/models/sr.rb b/lib/fog/xenserver/models/sr.rb new file mode 100644 index 0000000000..383e80d658 --- /dev/null +++ b/lib/fog/xenserver/models/sr.rb @@ -0,0 +1,34 @@ +require 'fog/model' + +module Fog + module Xenserver + + class Sr < Fog::Model + # API Reference here: + # http://docs.vmd.citrix.com/XenServer/5.6.0/1.0/en_gb/api/?c=SR + + identity :reference + + attribute :name_label + attribute :uuid + attribute :allowed_operations + attribute :content_type + attribute :name_description + attribute :other_config + attribute :PBDs + attribute :shared + attribute :type + attribute :VDIs + + ignore_attributes :blobs, :current_operations, :physical_size, :physical_utilisation, :sm_config, :tags, + :virtual_allocation + + def initialize(attributes={}) + @uuid ||= 0 + super + end + + end + + end +end \ No newline at end of file diff --git a/lib/fog/xenserver/models/srs.rb b/lib/fog/xenserver/models/srs.rb new file mode 100644 index 0000000000..ce71e36f57 --- /dev/null +++ b/lib/fog/xenserver/models/srs.rb @@ -0,0 +1,42 @@ +require 'fog/collection' +require 'fog/xenserver/models/sr' + +module Fog + module Xenserver + + module Collections + def srs + Fog::Xenserver::Srs.new(:connection => self) + end + end + + class Srs < Fog::Collection + + model Fog::Xenserver::Sr + + def all + data = connection.get_srs + load(data) + @response << sr if sr[:shared] and !sr[:content_type].eql?('iso') + + end + + def all + data = connection.get_srs + data.delete_if {|sr| sr[:shared].eql?(false)} + data.delete_if {|sr| sr[:content_type].eql?('iso')} + load(data) + end + + def get( sr_ref ) + if sr_ref && sr = connection.get_sr_by_ref( sr_ref ) + new(sr) + end + rescue Fog::Xenserver::NotFound + nil + end + + end + + end +end diff --git a/lib/fog/xenserver/models/vif.rb b/lib/fog/xenserver/models/vif.rb new file mode 100644 index 0000000000..9a5123bf2a --- /dev/null +++ b/lib/fog/xenserver/models/vif.rb @@ -0,0 +1,35 @@ +require 'fog/model' + +module Fog + module Xenserver + + class Vif < Fog::Model + # API Reference here: + # http://docs.vmd.citrix.com/XenServer/5.6.0/1.0/en_gb/api/?c=VIF + + identity :reference + + attribute :MAC + attribute :uuid + attribute :allowed_operations + attribute :currently_attached + attribute :device + attribute :MAC_autogenerated + attribute :metrics + attribute :MTU + attribute :network + attribute :status_code + attribute :status_detail + attribute :VM + + ignore_attributes :current_operations, :qos_supported_algorithms, :qos_algorithm_params, :qos_algorithm_type, :other_config, + :runtime_properties + + def initialize(attributes={}) + @uuid ||= 0 + super + end + end + + end +end \ No newline at end of file diff --git a/lib/fog/xenserver/models/vm.rb b/lib/fog/xenserver/models/vm.rb new file mode 100644 index 0000000000..f9442fcb95 --- /dev/null +++ b/lib/fog/xenserver/models/vm.rb @@ -0,0 +1,109 @@ +require 'fog/model' + +module Fog + module Xenserver + class Vm < Fog::Model + # API Reference here: + # http://docs.vmd.citrix.com/XenServer/5.6.0/1.0/en_gb/api/?c=VM + + identity :reference + + attribute :uuid + attribute :name_label + attribute :affinity + attribute :allowed_operations + attribute :consoles + attribute :domarch + attribute :domid + attribute :guest_metrics + attribute :is_a_snapshot + attribute :is_a_template + attribute :is_control_domain + attribute :memory_dynamic_max + attribute :memory_dynamic_min + attribute :memory_static_max + attribute :memory_static_min + attribute :memory_target + attribute :metrics + attribute :name_description + attribute :other_config + attribute :power_state + attribute :PV_args + attribute :resident_on + attribute :VBDs + attribute :VCPUs_at_startup + attribute :VCPUs_max + attribute :VIFs + + ignore_attributes :HVM_boot_params, :HVM_boot_policy, :HVM_shadow_multiplier, :PCI_bus, :PV_bootloader, + :PV_bootloader_args, :PV_kernel, :PV_legacy_args, :PV_ramdisk, :VCPUs_params, :VTPMs, + :actions_after_crash, :actions_after_reboot, :actions_after_shutdown, :blobs, + :blocked_operations, :crash_dumps, :current_operations, :ha_always_run, :ha_restart_priority, + :last_boot_CPU_flags, :last_booted_record, :platform, :recommendations, :snapshot_time, + :snapshots, :snapshot_of, :suspend_VDI, :tags, :transportable_snapshot_id, :user_version, + :xenstore_data + + def initialize(attributes={}) + @uuid ||= 0 + super + end + + def refresh + requires :reference + data = connection.get_vm_by_ref( @reference ) + merge_attributes( data ) + end + + # associations + def networks + @VIFs.collect {|vif| Fog::Xenserver::Vif.new(connection.get_vif_by_ref( vif ))} + end + + def running_on + Fog::Xenserver::Host.new(connection.get_host_by_ref( @resident_on )) + end + + def home_hypervisor + Fog::Xenserver::Host.new(connection.get_host_by_ref( @affinity )) + end + + # shortcuts + def name + @name_label + end + + def mac_address + networks.first.MAC + end + + def running? + @power_status =~ /Running/ + end + + def halted? + @power_status =~ /Halted/ + end + + # operations + def start + return false if halted? + connection.start_server( @reference ) + true + end + + # def reboot(type = 'SOFT') + # requires :reference + # connection.reboot_server(@id, type) + # true + # end + + # def snapshot + # requires :reference, :name_label + # data = connection.snapshot_server(@reference, @name_label) + # merge_attributes(data.body) + # true + # end + end + + end +end diff --git a/lib/fog/xenserver/parser.rb b/lib/fog/xenserver/parser.rb new file mode 100644 index 0000000000..9972e74de7 --- /dev/null +++ b/lib/fog/xenserver/parser.rb @@ -0,0 +1,29 @@ +module Fog + module Parsers + module Xenserver + class Base + + attr_reader :response + + def initialize + reset + end + + def reset + @response = {} + end + + def parse( data ) + if data.is_a? Hash + @response = data.symbolize_keys! + elsif data.is_a? Array + @response = data.first + end + + @response + end + + end + end + end +end \ No newline at end of file diff --git a/lib/fog/xenserver/parsers/get_hosts.rb b/lib/fog/xenserver/parsers/get_hosts.rb new file mode 100644 index 0000000000..98d2799f48 --- /dev/null +++ b/lib/fog/xenserver/parsers/get_hosts.rb @@ -0,0 +1,19 @@ +module Fog + module Parsers + module Xenserver + class GetHosts < Fog::Parsers::Xenserver::Base + + def reset + @response = [] + end + + def parse( data ) + parser = Fog::Parsers::Xenserver::Base.new + data.each_pair {|reference, host_hash| @response << parser.parse( host_hash ).merge(:reference => reference) } + end + + end + + end + end +end diff --git a/lib/fog/xenserver/parsers/get_networks.rb b/lib/fog/xenserver/parsers/get_networks.rb new file mode 100644 index 0000000000..c380a56203 --- /dev/null +++ b/lib/fog/xenserver/parsers/get_networks.rb @@ -0,0 +1,19 @@ +module Fog + module Parsers + module Xenserver + class GetNetworks < Fog::Parsers::Xenserver::Base + + def reset + @response = [] + end + + def parse( data ) + parser = Fog::Parsers::Xenserver::Base.new + data.each_pair {|reference, network_hash| @response << parser.parse( network_hash ).merge(:reference => reference) } + end + + end + + end + end +end diff --git a/lib/fog/xenserver/parsers/get_srs.rb b/lib/fog/xenserver/parsers/get_srs.rb new file mode 100644 index 0000000000..69c0055446 --- /dev/null +++ b/lib/fog/xenserver/parsers/get_srs.rb @@ -0,0 +1,19 @@ +module Fog + module Parsers + module Xenserver + class GetSrs < Fog::Parsers::Xenserver::Base + + def reset + @response = [] + end + + def parse( data ) + parser = Fog::Parsers::Xenserver::Base.new + data.each_pair {|reference, sr_hash| @response << parser.parse( sr_hash ).merge(:reference => reference) } + end + + end + + end + end +end diff --git a/lib/fog/xenserver/parsers/get_vifs.rb b/lib/fog/xenserver/parsers/get_vifs.rb new file mode 100644 index 0000000000..39dcbd24b3 --- /dev/null +++ b/lib/fog/xenserver/parsers/get_vifs.rb @@ -0,0 +1,19 @@ +module Fog + module Parsers + module Xenserver + class GetVifs < Fog::Parsers::Xenserver::Base + + def reset + @response = [] + end + + def parse( data ) + parser = Fog::Parsers::Xenserver::Base.new + data.each_pair {|reference, vif_hash| @response << parser.parse( vif_hash ).merge(:reference => reference) } + end + + end + + end + end +end diff --git a/lib/fog/xenserver/parsers/get_vms.rb b/lib/fog/xenserver/parsers/get_vms.rb new file mode 100644 index 0000000000..fa32c3f3b0 --- /dev/null +++ b/lib/fog/xenserver/parsers/get_vms.rb @@ -0,0 +1,19 @@ +module Fog + module Parsers + module Xenserver + class GetVms < Fog::Parsers::Xenserver::Base + + def reset + @response = [] + end + + def parse( data ) + parser = Fog::Parsers::Xenserver::Base.new + data.each_pair {|reference, vm_hash| @response << parser.parse( vm_hash ).merge(:reference => reference) } + end + + end + + end + end +end diff --git a/lib/fog/xenserver/requests/create_server.rb b/lib/fog/xenserver/requests/create_server.rb new file mode 100644 index 0000000000..3a114a2921 --- /dev/null +++ b/lib/fog/xenserver/requests/create_server.rb @@ -0,0 +1,19 @@ +module Fog + module Xenserver + class Real + + def create_server( name_label, image = nil, network = nil ) + create_vm( name_label, image, network ) + end + + end + + class Mock + + def create_server() + Fog::Mock.not_implemented + end + + end + end +end diff --git a/lib/fog/xenserver/requests/create_vif.rb b/lib/fog/xenserver/requests/create_vif.rb new file mode 100644 index 0000000000..ad4283ba8e --- /dev/null +++ b/lib/fog/xenserver/requests/create_vif.rb @@ -0,0 +1,32 @@ +module Fog + module Xenserver + class Real + + def create_vif( vm_ref, network_ref ) + @connection.request({:parser => Fog::Parsers::Xenserver::Base.new, :method => 'VIF.create'}, default_vif_config(vm_ref, network_ref) ) + end + + def default_vif_config( vm_ref, network_ref, device_number = '0' ) + { + 'MAC_autogenerated' => 'True', + 'VM' => vm_ref, + 'network' => network_ref, + 'device' => device_number, + 'MAC' => '', + 'MTU' => '0', + 'other_config' => {}, + 'qos_algorithm_type' => 'ratelimit', + 'qos_algorithm_params' => {} + } + end + end + + class Mock + + def create_vm() + Fog::Mock.not_implemented + end + + end + end +end diff --git a/lib/fog/xenserver/requests/create_vm.rb b/lib/fog/xenserver/requests/create_vm.rb new file mode 100644 index 0000000000..cee7d52a5c --- /dev/null +++ b/lib/fog/xenserver/requests/create_vm.rb @@ -0,0 +1,33 @@ +module Fog + module Xenserver + class Real + + def create_vm( name_label, image = nil, network = nil ) + image ||= default_image + network ||= default_network + + begin + raise Fog::Xenserver::OperationUnallowed unless image.allowed_operations.include?('clone') + @connection.request({:parser => Fog::Parsers::Xenserver::Base.new, :method => 'VM.clone'}, image.reference, name_label) + new_vm = Fog::Xenserver::Vm.new(get_vm( name_label )) + create_vif( new_vm.reference, network.reference ) + + raise Fog::Xenserver::OperationFailed unless new_vm.allowed_operations.include?('provision') + @connection.request({:parser => Fog::Parsers::Xenserver::Base.new, :method => 'VM.provision'}, new_vm.reference) + start_vm( new_vm.reference ) + + new_vm + end + end + + end + + class Mock + + def create_vm() + Fog::Mock.not_implemented + end + + end + end +end diff --git a/lib/fog/xenserver/requests/get_host.rb b/lib/fog/xenserver/requests/get_host.rb new file mode 100644 index 0000000000..67538c50e2 --- /dev/null +++ b/lib/fog/xenserver/requests/get_host.rb @@ -0,0 +1,26 @@ +module Fog + module Xenserver + class Real + + require 'fog/xenserver/parser' + + def get_host( name_label ) + host_ref = @connection.request({:parser => Fog::Parsers::Xenserver::Base.new, :method => 'host.get_by_name_label'}, name_label) + get_host_by_ref( host_ref ) + end + + def get_host_by_ref( host_ref ) + @connection.request({:parser => Fog::Parsers::Xenserver::Base.new, :method => 'host.get_record'}, host_ref).merge(:reference => host_ref) + end + + end + + class Mock + + def get_host( uuid ) + Fog::Mock.not_implemented + end + + end + end +end diff --git a/lib/fog/xenserver/requests/get_hosts.rb b/lib/fog/xenserver/requests/get_hosts.rb new file mode 100644 index 0000000000..d5a4c5c295 --- /dev/null +++ b/lib/fog/xenserver/requests/get_hosts.rb @@ -0,0 +1,23 @@ +module Fog + module Xenserver + class Real + + require 'fog/xenserver/parsers/get_hosts' + + def get_hosts( options = {} ) + options[:sort] ||= 'name_label' + result = @connection.request(:parser => Fog::Parsers::Xenserver::GetHosts.new, :method => 'host.get_all_records') + result.sort! {|a,b| a[ options[:sort].to_sym ] <=> b[ options[:sort].to_sym ]} + end + + end + + class Mock + + def get_hosts + Fog::Mock.not_implemented + end + + end + end +end diff --git a/lib/fog/xenserver/requests/get_network.rb b/lib/fog/xenserver/requests/get_network.rb new file mode 100644 index 0000000000..bd36fa3168 --- /dev/null +++ b/lib/fog/xenserver/requests/get_network.rb @@ -0,0 +1,26 @@ +module Fog + module Xenserver + class Real + + require 'fog/xenserver/parser' + + def get_network( name_label ) + network_ref = @connection.request({:parser => Fog::Parsers::Xenserver::Base.new, :method => 'network.get_by_name_label'}, name_label) + get_network_by_ref( network_ref ) + end + + def get_network_by_ref( network_ref ) + @connection.request({:parser => Fog::Parsers::Xenserver::Base.new, :method => 'network.get_record'}, network_ref).merge(:reference => network_ref) + end + + end + + class Mock + + def get_network( uuid ) + Fog::Mock.not_implemented + end + + end + end +end diff --git a/lib/fog/xenserver/requests/get_networks.rb b/lib/fog/xenserver/requests/get_networks.rb new file mode 100644 index 0000000000..9de0aecdbd --- /dev/null +++ b/lib/fog/xenserver/requests/get_networks.rb @@ -0,0 +1,23 @@ +module Fog + module Xenserver + class Real + + require 'fog/xenserver/parsers/get_networks' + + def get_networks( options = {} ) + options[:sort] ||= 'name_label' + result = @connection.request(:parser => Fog::Parsers::Xenserver::GetNetworks.new, :method => 'network.get_all_records') + result.sort! {|a,b| a[ options[:sort].to_sym ] <=> b[ options[:sort].to_sym ]} + end + + end + + class Mock + + def get_networks + Fog::Mock.not_implemented + end + + end + end +end diff --git a/lib/fog/xenserver/requests/get_sr.rb b/lib/fog/xenserver/requests/get_sr.rb new file mode 100644 index 0000000000..200513a4c3 --- /dev/null +++ b/lib/fog/xenserver/requests/get_sr.rb @@ -0,0 +1,29 @@ +module Fog + module Xenserver + class Real + + require 'fog/xenserver/parser' + + def get_sr( name_label ) + sr_ref = @connection.request({:parser => Fog::Parsers::Xenserver::Base.new, :method => 'SR.get_by_name_label'}, name_label) + get_sr_by_ref( sr_ref ) + end + + def get_sr_by_ref( sr_ref ) + @connection.request({:parser => Fog::Parsers::Xenserver::Base.new, :method => 'SR.get_record'}, sr_ref).merge(:reference => sr_ref) + end + end + + class Mock + + def get_sr( uuid ) + Fog::Mock.not_implemented + end + + def get_sr_by_ref( sr_ref ) + Fog::Mock.not_implemented + end + + end + end +end diff --git a/lib/fog/xenserver/requests/get_srs.rb b/lib/fog/xenserver/requests/get_srs.rb new file mode 100644 index 0000000000..6c68021c40 --- /dev/null +++ b/lib/fog/xenserver/requests/get_srs.rb @@ -0,0 +1,23 @@ +module Fog + module Xenserver + class Real + + require 'fog/xenserver/parsers/get_srs' + + def get_srs( options = {} ) + options[:sort] ||= 'name_label' + result = @connection.request(:parser => Fog::Parsers::Xenserver::GetSrs.new, :method => 'SR.get_all_records') + result.sort! {|a,b| a[ options[:sort].to_sym ] <=> b[ options[:sort].to_sym ]} + end + + end + + class Mock + + def get_srs + Fog::Mock.not_implemented + end + + end + end +end diff --git a/lib/fog/xenserver/requests/get_vif.rb b/lib/fog/xenserver/requests/get_vif.rb new file mode 100644 index 0000000000..9875032a77 --- /dev/null +++ b/lib/fog/xenserver/requests/get_vif.rb @@ -0,0 +1,30 @@ +module Fog + module Xenserver + class Real + + require 'fog/xenserver/parser' + + def get_vif( name_label ) + vif_ref = @connection.request({:parser => Fog::Parsers::Xenserver::Base.new, :method => 'VIF.get_by_name_label'}, name_label) + get_vif_by_ref( vif_ref ) + end + + def get_vif_by_ref( vif_ref ) + @connection.request({:parser => Fog::Parsers::Xenserver::Base.new, :method => 'VIF.get_record'}, vif_ref).merge(:reference => vif_ref) + end + + end + + class Mock + + def get_vif( uuid ) + Fog::Mock.not_implemented + end + + def get_vif_by_ref( uuid ) + Fog::Mock.not_implemented + end + + end + end +end diff --git a/lib/fog/xenserver/requests/get_vifs.rb b/lib/fog/xenserver/requests/get_vifs.rb new file mode 100644 index 0000000000..10d020db78 --- /dev/null +++ b/lib/fog/xenserver/requests/get_vifs.rb @@ -0,0 +1,23 @@ +module Fog + module Xenserver + class Real + + require 'fog/xenserver/parsers/get_vifs' + + def get_vifs( options = {} ) + options[:sort] ||= 'name_label' + result = @connection.request(:parser => Fog::Parsers::Xenserver::GetVifs.new, :method => 'VIF.get_all_records') + result.sort! {|a,b| a[ options[:sort].to_sym ] <=> b[ options[:sort].to_sym ]} + end + + end + + class Mock + + def get_vifs + Fog::Mock.not_implemented + end + + end + end +end diff --git a/lib/fog/xenserver/requests/get_vm.rb b/lib/fog/xenserver/requests/get_vm.rb new file mode 100644 index 0000000000..e5addda741 --- /dev/null +++ b/lib/fog/xenserver/requests/get_vm.rb @@ -0,0 +1,25 @@ +module Fog + module Xenserver + class Real + + require 'fog/xenserver/parser' + + def get_vm( name_label ) + vm_ref = @connection.request({:parser => Fog::Parsers::Xenserver::Base.new, :method => 'VM.get_by_name_label'}, name_label) + get_vm_by_ref( vm_ref ) + end + + def get_vm_by_ref( vm_ref ) + @connection.request({:parser => Fog::Parsers::Xenserver::Base.new, :method => 'VM.get_record'}, vm_ref).merge(:reference => vm_ref) + end + end + + class Mock + + def get_vm( uuid ) + Fog::Mock.not_implemented + end + + end + end +end diff --git a/lib/fog/xenserver/requests/get_vms.rb b/lib/fog/xenserver/requests/get_vms.rb new file mode 100644 index 0000000000..f22a0cf8e1 --- /dev/null +++ b/lib/fog/xenserver/requests/get_vms.rb @@ -0,0 +1,23 @@ +module Fog + module Xenserver + class Real + + require 'fog/xenserver/parsers/get_vms' + + def get_vms( options = {} ) + options[:sort] ||= 'name_label' + result = @connection.request(:parser => Fog::Parsers::Xenserver::GetVms.new, :method => 'VM.get_all_records') + result.sort! {|a,b| a[ options[:sort].to_sym ] <=> b[ options[:sort].to_sym ]} + end + + end + + class Mock + + def get_vms + Fog::Mock.not_implemented + end + + end + end +end diff --git a/lib/fog/xenserver/requests/start_server.rb b/lib/fog/xenserver/requests/start_server.rb new file mode 100644 index 0000000000..845a137f6b --- /dev/null +++ b/lib/fog/xenserver/requests/start_server.rb @@ -0,0 +1,19 @@ +module Fog + module Xenserver + class Real + + def start_server( vm_ref ) + start_vm( vm_ref ) + end + + end + + class Mock + + def start_server( vm_ref ) + Fog::Mock.not_implemented + end + + end + end +end diff --git a/lib/fog/xenserver/requests/start_vm.rb b/lib/fog/xenserver/requests/start_vm.rb new file mode 100644 index 0000000000..5b5176fe78 --- /dev/null +++ b/lib/fog/xenserver/requests/start_vm.rb @@ -0,0 +1,21 @@ +module Fog + module Xenserver + class Real + + # http://bit.ly/8ZPyCN + # VM.start( session, VM_ref, start_paused, force) + def start_vm( vm_ref ) + @connection.request({:parser => Fog::Parsers::Xenserver::Base.new, :method => 'VM.start'}, vm_ref, false, false) + end + + end + + class Mock + + def start_vm( vm_ref ) + Fog::Mock.not_implemented + end + + end + end +end diff --git a/lib/fog/xenserver/utilities.rb b/lib/fog/xenserver/utilities.rb new file mode 100644 index 0000000000..f681a1ad17 --- /dev/null +++ b/lib/fog/xenserver/utilities.rb @@ -0,0 +1,8 @@ +class Hash + def symbolize_keys! + keys.each do |key| + self[(key.to_sym rescue key)] = delete(key) if key.respond_to?(:to_sym) && !key.is_a?(Fixnum) + end + self + end +end \ No newline at end of file diff --git a/spec/aws/models/ec2/snapshot_spec.rb b/spec/aws/models/ec2/snapshot_spec.rb index 335dbfa015..8cf38c1cf5 100644 --- a/spec/aws/models/ec2/snapshot_spec.rb +++ b/spec/aws/models/ec2/snapshot_spec.rb @@ -24,11 +24,13 @@ snapshot = AWS[:ec2].snapshots.new( 'snapshotId' => 'snap-00000000', 'startTime' => 'now', - 'volumeId' => 'vol-00000000' + 'volumeId' => 'vol-00000000', + 'description' => 'taken for safety' ) snapshot.id.should == 'snap-00000000' snapshot.created_at.should == 'now' snapshot.volume_id.should == 'vol-00000000' + snapshot.description.should == 'taken for safety' end end @@ -60,16 +62,18 @@ describe "#save" do - before(:each) do - @snapshot = @volume.snapshots.new - end - it "should persist the snapshot" do + @snapshot = @volume.snapshots.new AWS[:ec2].snapshots.get(@snapshot.id).should be_nil @snapshot.save.should be_true AWS[:ec2].snapshots.get(@snapshot.id).should_not be_nil end + it "should allow a description" do + @snapshot = @volume.snapshots.create(:description => 'taken for safety') + AWS[:ec2].snapshots.get(@snapshot.id).description.should == 'taken for safety' + end + end end diff --git a/spec/aws/models/ec2/volume_spec.rb b/spec/aws/models/ec2/volume_spec.rb index 2b21c4f735..edcf7ab6cf 100644 --- a/spec/aws/models/ec2/volume_spec.rb +++ b/spec/aws/models/ec2/volume_spec.rb @@ -43,6 +43,14 @@ volume.destroy.should be_true end + it 'should fail if the volume is attached to an instance' do + server = AWS[:ec2].servers.create(:image_id => GENTOO_AMI) + server.wait_for { ready? } + volume = AWS[:ec2].volumes.create(:availability_zone => server.availability_zone, :size => 1, :device => '/dev/sdz1') + volume.server = server + lambda { volume.destroy }.should raise_error + end + end describe "#server=" do diff --git a/spec/aws/models/s3/files_spec.rb b/spec/aws/models/s3/files_spec.rb index 845788d55d..76094b5a97 100644 --- a/spec/aws/models/s3/files_spec.rb +++ b/spec/aws/models/s3/files_spec.rb @@ -3,10 +3,13 @@ describe 'Fog::AWS::S3::Files' do before(:each) do - @directory = AWS[:s3].directories.create(:key => 'fogdirectoryname') + @directory = AWS[:s3].directories.create(:key => "fog#{Time.now.to_f}") end after(:each) do + until @directory.files.reload.empty? + @directory.files.each {|file| file.destroy} + end @directory.destroy end @@ -34,6 +37,25 @@ directory.files.all.should be_nil end + it "should return 1000 files and report truncated" do + 1010.times do |n| + @directory.files.create(:key => "file-#{n}") + end + response = @directory.files.all + response.should have(1000).items + response.is_truncated.should be_true + end + + it "should limit the max_keys to 1000" do + 1010.times do |n| + @directory.files.create(:key => "file-#{n}") + end + response = @directory.files.all(:max_keys => 2000) + response.should have(1000).items + response.max_keys.should == 2000 + response.is_truncated.should be_true + end + end describe "#create" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 80254feaa1..f6306f64cc 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,16 +1,13 @@ require 'spec' require 'open-uri' - -current_directory = File.dirname(__FILE__) -require "#{current_directory}/../lib/fog" -require "#{current_directory}/../lib/fog/bin" +require 'fog' +require 'fog/bin' +require 'fog/vcloud/bin' if ENV["FOG_MOCK"] == "true" Fog.mock! end -require "#{current_directory}/../lib/fog/vcloud/bin" - module AWS class << self def [](service) diff --git a/tests/helpers/model_helper.rb b/tests/helpers/model_helper.rb index db5a650500..4e3a17794d 100644 --- a/tests/helpers/model_helper.rb +++ b/tests/helpers/model_helper.rb @@ -1,47 +1,16 @@ def tests_models - after do - if @model && !@model.new_record? - if @model.respond_to?(:ready?) - @model.wait_for { ready? } - end - @model.destroy - end - end - - tests('collection') do - - test('#all includes persisted models') do - @model.save - @collection.all.map {|model| model.identity}.include? @model.identity - end - - tests('#get') do - - test 'should return a matching model if one exists' do - @model.save - get = @collection.get(@model.identity) - @model.attributes == get.attributes - end - - test 'should return nil if no matching model exists' do - !@collection.get('0') - end + tests('model#save') do + test('does not exist remotely before save') do + !@collection.get(@model.identity) end - test('#reload') do + test('succeeds') do @model.save - @collection.all - reloaded = @collection.reload - @collection.attributes == reloaded.attributes end - end - - tests('model') do - - test('#reload') do + test('does exist remotely after save') do @model.save if @model.respond_to?(:ready?) @model.wait_for { ready? } @@ -50,27 +19,47 @@ def tests_models @model.attributes == reloaded.attributes end - tests('#save') do + end - test('does not exist remotely before save') do - !@collection.get(@model.identity) - end + test('model#reload') do + if @model.respond_to?(:ready?) + @model.wait_for { ready? } + end + reloaded = @model.reload + @model.attributes == reloaded.attributes + end - test('succeeds') do - @model.save - end + test('collection#all includes persisted models') do + @model.save + @collection.all.map {|model| model.identity}.include? @model.identity + end - test('does exist remotely after save') do - @model.save - if @model.respond_to?(:ready?) - @model.wait_for { ready? } - end - reloaded = @model.reload - @model.attributes == reloaded.attributes - end + tests('collection#get') do + test 'should return a matching model if one exists' do + @model.save + get = @collection.get(@model.identity) + @model.attributes == get.attributes + end + + test 'should return nil if no matching model exists' do + !@collection.get('0') end end + test('collection#reload') do + @model.save + @collection.all + reloaded = @collection.reload + @collection.attributes == reloaded.attributes + end + + test('model#destroy') do + if @model.respond_to?(:ready?) + @model.wait_for{ ready? } + end + @model.destroy + end + end