├── .document
├── .gitignore
├── lib
└── fog
│ ├── vcloud
│ ├── terremark
│ │ ├── all.rb
│ │ ├── ecloud
│ │ │ └── requests
│ │ │ │ └── login.rb
│ │ └── vcloud
│ │ │ └── parsers
│ │ │ └── get_vdc.rb
│ ├── parsers
│ │ ├── get_vdc.rb
│ │ ├── get_organization.rb
│ │ ├── login.rb
│ │ └── get_versions.rb
│ ├── parser.rb
│ └── requests
│ │ └── get_versions.rb
│ ├── webbynode
│ ├── models
│ │ ├── job.rb
│ │ ├── image.rb
│ │ ├── flavors.rb
│ │ ├── flavor.rb
│ │ ├── servers.rb
│ │ └── images.rb
│ ├── parsers
│ │ ├── get_job.rb
│ │ ├── get_flavor.rb
│ │ ├── create_webby.rb
│ │ ├── get_images.rb
│ │ ├── get_flavors.rb
│ │ ├── get_webbies.rb
│ │ ├── get_backups.rb
│ │ ├── get_image.rb
│ │ └── get_webby.rb
│ ├── requests
│ │ ├── get_images.rb
│ │ ├── reboot_webby.rb
│ │ ├── get_flavors.rb
│ │ ├── get_webbies.rb
│ │ ├── get_flavor.rb
│ │ └── get_image.rb
│ └── bin.rb
│ ├── slicehost
│ ├── models
│ │ ├── image.rb
│ │ ├── flavors.rb
│ │ ├── flavor.rb
│ │ ├── servers.rb
│ │ └── images.rb
│ ├── parsers
│ │ ├── get_image.rb
│ │ ├── get_flavor.rb
│ │ ├── get_images.rb
│ │ ├── get_flavors.rb
│ │ ├── get_backups.rb
│ │ ├── get_slice.rb
│ │ ├── create_slice.rb
│ │ └── get_slices.rb
│ ├── requests
│ │ ├── get_images.rb
│ │ ├── get_flavors.rb
│ │ ├── get_image.rb
│ │ ├── get_backups.rb
│ │ └── get_flavor.rb
│ └── bin.rb
│ ├── aws
│ ├── models
│ │ └── ec2
│ │ │ ├── flavor.rb
│ │ │ ├── image.rb
│ │ │ ├── key_pair.rb
│ │ │ ├── images.rb
│ │ │ ├── key_pairs.rb
│ │ │ └── security_groups.rb
│ ├── parsers
│ │ ├── s3
│ │ │ ├── get_request_payment.rb
│ │ │ ├── get_bucket_location.rb
│ │ │ ├── copy_object.rb
│ │ │ ├── get_bucket_versioning.rb
│ │ │ ├── get_service.rb
│ │ │ └── get_bucket_logging.rb
│ │ ├── ec2
│ │ │ ├── allocate_address.rb
│ │ │ ├── create_key_pair.rb
│ │ │ ├── attach_volume.rb
│ │ │ ├── detach_volume.rb
│ │ │ ├── basic.rb
│ │ │ ├── create_volume.rb
│ │ │ ├── create_snapshot.rb
│ │ │ ├── describe_key_pairs.rb
│ │ │ ├── get_console_output.rb
│ │ │ ├── describe_regions.rb
│ │ │ ├── describe_addresses.rb
│ │ │ ├── describe_availability_zones.rb
│ │ │ ├── describe_snapshots.rb
│ │ │ └── describe_reserved_instances.rb
│ │ ├── elb
│ │ │ ├── delete_load_balancer.rb
│ │ │ ├── create_load_balancer.rb
│ │ │ ├── register_instances_with_load_balancer.rb
│ │ │ ├── deregister_instances_from_load_balancer.rb
│ │ │ ├── disable_availability_zones_for_load_balancer.rb
│ │ │ ├── enable_availability_zones_for_load_balancer.rb
│ │ │ └── describe_instance_health.rb
│ │ └── simpledb
│ │ │ ├── basic.rb
│ │ │ ├── list_domains.rb
│ │ │ ├── domain_metadata.rb
│ │ │ ├── get_attributes.rb
│ │ │ └── select.rb
│ └── requests
│ │ ├── s3
│ │ └── put_bucket_versioning.rb
│ │ ├── ec2
│ │ ├── delete_key_pair.rb
│ │ └── release_address.rb
│ │ ├── elb
│ │ └── delete_load_balancer.rb
│ │ └── simpledb
│ │ ├── create_domain.rb
│ │ └── delete_domain.rb
│ ├── terremark.rb
│ ├── terremark
│ ├── parser.rb
│ ├── models
│ │ └── shared
│ │ │ ├── address.rb
│ │ │ ├── network.rb
│ │ │ ├── vdc.rb
│ │ │ └── addresses.rb
│ ├── parsers
│ │ └── shared
│ │ │ ├── public_ip.rb
│ │ │ ├── get_network_ips.rb
│ │ │ ├── get_organizations.rb
│ │ │ ├── get_public_ips.rb
│ │ │ ├── node_service.rb
│ │ │ ├── get_node_services.rb
│ │ │ ├── task.rb
│ │ │ └── instantiate_vapp_template.rb
│ ├── requests
│ │ └── shared
│ │ │ ├── delete_vapp.rb
│ │ │ ├── delete_public_ip.rb
│ │ │ ├── delete_node_service.rb
│ │ │ ├── power_shutdown.rb
│ │ │ ├── delete_internet_service.rb
│ │ │ ├── get_node_services.rb
│ │ │ ├── get_network_ips.rb
│ │ │ ├── get_catalog.rb
│ │ │ ├── get_tasks_list.rb
│ │ │ ├── get_public_ip.rb
│ │ │ ├── get_catalog_item.rb
│ │ │ └── get_vapp_template.rb
│ └── bin.rb
│ ├── parser.rb
│ ├── deprecation.rb
│ ├── connection.rb
│ ├── local
│ ├── bin.rb
│ └── models
│ │ ├── directory.rb
│ │ └── directories.rb
│ ├── rackspace
│ ├── requests
│ │ ├── files
│ │ │ ├── delete_container.rb
│ │ │ ├── put_container.rb
│ │ │ ├── delete_object.rb
│ │ │ ├── head_object.rb
│ │ │ ├── get_object.rb
│ │ │ ├── head_containers.rb
│ │ │ ├── put_object.rb
│ │ │ └── head_container.rb
│ │ └── servers
│ │ │ ├── list_flavors.rb
│ │ │ ├── reboot_server.rb
│ │ │ ├── list_flavors_detail.rb
│ │ │ ├── get_flavor_details.rb
│ │ │ ├── get_image_details.rb
│ │ │ ├── list_images.rb
│ │ │ ├── list_servers.rb
│ │ │ ├── delete_image.rb
│ │ │ ├── list_public_addresses.rb
│ │ │ ├── delete_server.rb
│ │ │ └── list_private_addresses.rb
│ ├── models
│ │ ├── servers
│ │ │ ├── flavor.rb
│ │ │ ├── image.rb
│ │ │ ├── flavors.rb
│ │ │ ├── servers.rb
│ │ │ └── images.rb
│ │ └── files
│ │ │ ├── directory.rb
│ │ │ └── directories.rb
│ └── bin.rb
│ └── rackspace.rb
├── spec
├── vcloud
│ ├── requests
│ │ ├── login_spec.rb
│ │ └── get_versions_spec.rb
│ ├── terremark
│ │ └── ecloud
│ │ │ └── requests
│ │ │ └── login_spec.rb
│ ├── vcloud_spec.rb
│ └── bin_spec.rb
├── aws
│ ├── requests
│ │ ├── simpledb
│ │ │ ├── select_spec.rb
│ │ │ ├── delete_domain_spec.rb
│ │ │ ├── create_domain_spec.rb
│ │ │ ├── list_domains_spec.rb
│ │ │ ├── put_attributes_spec.rb
│ │ │ └── batch_put_attributes_spec.rb
│ │ ├── s3
│ │ │ ├── put_bucket_spec.rb
│ │ │ ├── put_request_payment_spec.rb
│ │ │ ├── get_request_payment_spec.rb
│ │ │ ├── get_bucket_location_spec.rb
│ │ │ ├── head_object_spec.rb
│ │ │ ├── get_service_spec.rb
│ │ │ ├── delete_bucket_spec.rb
│ │ │ └── delete_object_spec.rb
│ │ └── ec2
│ │ │ ├── delete_key_pair_spec.rb
│ │ │ ├── describe_regions_spec.rb
│ │ │ ├── delete_security_group_spec.rb
│ │ │ ├── describe_availability_zones_spec.rb
│ │ │ ├── reboot_instances_spec.rb
│ │ │ ├── get_console_output_spec.rb
│ │ │ ├── revoke_security_group_ingress_spec.rb
│ │ │ ├── create_key_pair_spec.rb
│ │ │ └── create_security_group_spec.rb
│ └── models
│ │ └── ec2
│ │ ├── flavors_spec.rb
│ │ └── servers_spec.rb
├── slicehost
│ └── models
│ │ ├── flavors_spec.rb
│ │ └── servers_spec.rb
├── rackspace
│ ├── models
│ │ └── servers
│ │ │ ├── flavors_spec.rb
│ │ │ └── servers_spec.rb
│ └── requests
│ │ └── files
│ │ ├── put_container_spec.rb
│ │ ├── head_containers_spec.rb
│ │ ├── put_object_spec.rb
│ │ ├── get_containers_spec.rb
│ │ ├── get_object_spec.rb
│ │ ├── head_object_spec.rb
│ │ ├── delete_container_spec.rb
│ │ ├── head_container_spec.rb
│ │ ├── get_container_spec.rb
│ │ └── delete_object_spec.rb
├── shared_examples
│ ├── flavors_examples.rb
│ ├── servers_examples.rb
│ └── server_examples.rb
└── lorem.txt
├── Gemfile
├── tests
├── slicehost
│ ├── requests
│ │ ├── get_images_tests.rb
│ │ ├── get_slices_tests.rb
│ │ ├── get_backups_tests.rb
│ │ ├── get_flavors_tests.rb
│ │ ├── get_image_tests.rb
│ │ ├── get_flavor_tests.rb
│ │ ├── create_slice_tests.rb
│ │ ├── delete_slice_tests.rb
│ │ ├── get_slice_tests.rb
│ │ └── reboot_slice_tests.rb
│ └── helper.rb
└── rackspace
│ └── requests
│ └── servers
│ ├── list_images_tests.rb
│ ├── list_flavors_tests.rb
│ ├── list_images_detail_tests.rb
│ ├── list_flavors_detail_tests.rb
│ ├── get_image_details_tests.rb
│ ├── get_flavor_details_tests.rb
│ ├── list_servers_tests.rb
│ ├── create_server_tests.rb
│ ├── list_servers_detail_tests.rb
│ ├── delete_server_tests.rb
│ ├── create_image_tests.rb
│ ├── list_public_addresses_tests.rb
│ ├── list_addresses_tests.rb
│ ├── list_private_addresses_tests.rb
│ ├── get_server_details_tests.rb
│ ├── delete_image_tests.rb
│ ├── update_server_tests.rb
│ └── reboot_server_tests.rb
└── benchs
├── params.rb
└── parse_vs_push.rb
/.document:
--------------------------------------------------------------------------------
1 | README.rdoc
2 | lib/**/*.rb
3 | bin/*
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.sw?
2 | .DS_Store
3 | coverage
4 | rdoc
5 | pkg
6 | spec/credentials.yml
7 | .bundle
--------------------------------------------------------------------------------
/lib/fog/vcloud/terremark/all.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Vcloud
3 | module Terremark
4 | unless @required
5 | @required = true
6 | end
7 | end
8 | end
9 | end
10 |
--------------------------------------------------------------------------------
/spec/vcloud/requests/login_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe Fog::Vcloud, :type => :vcloud_request do
4 | subject { @vcloud }
5 |
6 | it_should_behave_like "all login requests"
7 | end
8 |
9 |
--------------------------------------------------------------------------------
/lib/fog/webbynode/models/job.rb:
--------------------------------------------------------------------------------
1 | require 'fog/model'
2 |
3 | module Fog
4 | module Slicehost
5 |
6 | class Job < Fog::Model
7 |
8 | identity :id
9 |
10 | end
11 |
12 | end
13 | end
14 |
--------------------------------------------------------------------------------
/spec/aws/requests/simpledb/select_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'SimpleDB.select' do
4 | describe 'success' do
5 |
6 | it "should have some specs"
7 |
8 | end
9 | end
--------------------------------------------------------------------------------
/spec/vcloud/terremark/ecloud/requests/login_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe Fog::Vcloud, :type => :tmrk_ecloud_request do
4 | subject { @vcloud }
5 |
6 | it_should_behave_like "all login requests"
7 | end
8 |
--------------------------------------------------------------------------------
/lib/fog/slicehost/models/image.rb:
--------------------------------------------------------------------------------
1 | require 'fog/model'
2 |
3 | module Fog
4 | module Slicehost
5 |
6 | class Image < Fog::Model
7 |
8 | identity :id
9 |
10 | attribute :name
11 |
12 | end
13 |
14 | end
15 | end
16 |
--------------------------------------------------------------------------------
/lib/fog/webbynode/models/image.rb:
--------------------------------------------------------------------------------
1 | require 'fog/model'
2 |
3 | module Fog
4 | module Webbynode
5 |
6 | class Image < Fog::Model
7 |
8 | identity :id
9 |
10 | attribute :name
11 |
12 | end
13 |
14 | end
15 | end
16 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source 'http://gemcutter.org'
2 |
3 | gem 'rake'
4 | gem 'excon', '>= 0.0.24'
5 | gem 'formatador', ">= 0.0.10"
6 | gem 'json', ">= 0"
7 | gem 'mime-types', ">= 0"
8 | gem 'net-ssh', ">= 0"
9 | gem 'nokogiri', ">= 0"
10 | gem 'ruby-hmac', ">= 0"
11 | gem 'rspec', '>= 0'
12 | gem 'shindo', '>= 0'
13 | gem 'builder', '>= 0'
14 |
--------------------------------------------------------------------------------
/tests/slicehost/requests/get_images_tests.rb:
--------------------------------------------------------------------------------
1 | Shindo.tests('Slicehost#get_images', 'slicehost') do
2 | tests('success') do
3 |
4 | before do
5 | @data = Slicehost[:slices].get_images.body
6 | end
7 |
8 | test('has proper output format') do
9 | has_format(@data, { 'images' => [Slicehost::Formats::IMAGE] })
10 | end
11 |
12 | end
13 | end
14 |
--------------------------------------------------------------------------------
/tests/slicehost/requests/get_slices_tests.rb:
--------------------------------------------------------------------------------
1 | Shindo.tests('Slicehost#get_slices', 'slicehost') do
2 | tests('success') do
3 |
4 | before do
5 | @data = Slicehost[:slices].get_slices.body
6 | end
7 |
8 | test('has proper output format') do
9 | has_format(@data, { 'slices' => [Slicehost::Formats::SLICE] })
10 | end
11 |
12 | end
13 | end
14 |
--------------------------------------------------------------------------------
/tests/slicehost/requests/get_backups_tests.rb:
--------------------------------------------------------------------------------
1 | Shindo.tests('Slicehost#get_backups', 'slicehost') do
2 | tests('success') do
3 |
4 | before do
5 | @data = Slicehost[:slices].get_backups.body
6 | end
7 |
8 | test('has proper output format') do
9 | has_format(@data, { 'backups' => [Slicehost::Formats::BACKUP] })
10 | end
11 |
12 | end
13 | end
14 |
--------------------------------------------------------------------------------
/tests/slicehost/requests/get_flavors_tests.rb:
--------------------------------------------------------------------------------
1 | Shindo.tests('Slicehost#get_flavors', 'slicehost') do
2 | tests('success') do
3 |
4 | before do
5 | @data = Slicehost[:slices].get_flavors.body
6 | end
7 |
8 | test('has proper output format') do
9 | has_format(@data, { 'flavors' => [Slicehost::Formats::FLAVOR] })
10 | end
11 |
12 | end
13 | end
14 |
--------------------------------------------------------------------------------
/lib/fog/aws/models/ec2/flavor.rb:
--------------------------------------------------------------------------------
1 | require 'fog/model'
2 |
3 | module Fog
4 | module AWS
5 | module EC2
6 |
7 | class Flavor < Fog::Model
8 |
9 | identity :id
10 |
11 | attribute :bits
12 | attribute :cores
13 | attribute :disk
14 | attribute :name
15 | attribute :ram
16 |
17 | end
18 |
19 | end
20 | end
21 | end
--------------------------------------------------------------------------------
/lib/fog/terremark.rb:
--------------------------------------------------------------------------------
1 | require 'fog/terremark/shared'
2 | require 'fog/terremark/parser'
3 | require 'fog/terremark/ecloud'
4 | require 'fog/terremark/vcloud'
5 |
6 | module Fog
7 | module Terremark
8 | ECLOUD_OPTIONS = [:terremark_ecloud_username, :terremark_ecloud_password]
9 | VCLOUD_OPTIONS = [:terremark_vcloud_username, :terremark_vcloud_password]
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/tests/rackspace/requests/servers/list_images_tests.rb:
--------------------------------------------------------------------------------
1 | Shindo.tests('Rackspace::Servers#list_images', 'rackspace') do
2 | tests('success') do
3 |
4 | before do
5 | @data = Rackspace[:servers].list_images.body['images']
6 | end
7 |
8 | test('has proper output format') do
9 | has_format(@data, Rackspace::Servers::Formats::SUMMARY)
10 | end
11 |
12 | end
13 | end
14 |
--------------------------------------------------------------------------------
/tests/rackspace/requests/servers/list_flavors_tests.rb:
--------------------------------------------------------------------------------
1 | Shindo.tests('Rackspace::Servers#list_flavors', 'rackspace') do
2 | tests('success') do
3 |
4 | before do
5 | @data = Rackspace[:servers].list_flavors.body['flavors']
6 | end
7 |
8 | test('has proper output format') do
9 | has_format(@data, Rackspace::Servers::Formats::SUMMARY)
10 | end
11 |
12 | end
13 | end
14 |
--------------------------------------------------------------------------------
/spec/aws/models/ec2/flavors_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 | require File.dirname(__FILE__) + '/../../../shared_examples/flavors_examples'
3 |
4 | describe 'Fog::AWS::EC2::Flavors' do
5 |
6 | it_should_behave_like "Flavors"
7 |
8 | subject { @flavor = @flavors.all.first }
9 |
10 | before(:each) do
11 | @flavors = AWS[:ec2].flavors
12 | end
13 |
14 | end
15 |
--------------------------------------------------------------------------------
/spec/slicehost/models/flavors_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../spec_helper'
2 | require File.dirname(__FILE__) + '/../../shared_examples/flavors_examples'
3 |
4 | describe 'Fog::AWS::Slicehost::Flavors' do
5 |
6 | it_should_behave_like "Flavors"
7 |
8 | subject { @flavor = @flavors.all.first }
9 |
10 | before(:each) do
11 | @flavors = Slicehost[:slices].flavors
12 | end
13 |
14 | end
15 |
--------------------------------------------------------------------------------
/tests/rackspace/requests/servers/list_images_detail_tests.rb:
--------------------------------------------------------------------------------
1 | Shindo.tests('Rackspace::Servers#list_images_detail', 'rackspace') do
2 | tests('success') do
3 |
4 | before do
5 | @data = Rackspace[:servers].list_images_detail.body['images']
6 | end
7 |
8 | test('has proper output format') do
9 | has_format(@data, Rackspace::Servers::Formats::IMAGE)
10 | end
11 |
12 | end
13 | end
14 |
--------------------------------------------------------------------------------
/tests/rackspace/requests/servers/list_flavors_detail_tests.rb:
--------------------------------------------------------------------------------
1 | Shindo.tests('Rackspace::Servers#list_flavors_detail', 'rackspace') do
2 | tests('success') do
3 |
4 | before do
5 | @data = Rackspace[:servers].list_flavors_detail.body['flavors']
6 | end
7 |
8 | test('has proper output format') do
9 | has_format(@data, [Rackspace::Servers::Formats::FLAVOR])
10 | end
11 |
12 | end
13 | end
14 |
--------------------------------------------------------------------------------
/lib/fog/terremark/parser.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Terremark
3 | module Shared
4 | module Parser
5 |
6 | def parse(data)
7 | case data['type']
8 | when 'application/vnd.vmware.vcloud.vApp+xml'
9 | servers.new(data.merge!(:connection => self))
10 | else
11 | data
12 | end
13 | end
14 |
15 | end
16 | end
17 | end
18 | end
19 |
--------------------------------------------------------------------------------
/spec/rackspace/models/servers/flavors_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 | require File.dirname(__FILE__) + '/../../../shared_examples/flavors_examples'
3 |
4 | describe 'Fog::AWS::Rackspace::Flavors' do
5 |
6 | it_should_behave_like "Flavors"
7 |
8 | subject { @flavor = @flavors.all.first }
9 |
10 | before(:each) do
11 | @flavors = Rackspace[:servers].flavors
12 | end
13 |
14 | end
--------------------------------------------------------------------------------
/spec/shared_examples/flavors_examples.rb:
--------------------------------------------------------------------------------
1 | shared_examples_for "Flavors" do
2 |
3 | describe "#get" do
4 |
5 | it "should return a matching flavor if one exists" do
6 | get = @flavors.get(subject.id)
7 | subject.attributes.should == get.attributes
8 | end
9 |
10 | it "should return nil if no matching server exists" do
11 | @flavors.get('0').should be_nil
12 | end
13 |
14 | end
15 |
16 | end
17 |
--------------------------------------------------------------------------------
/lib/fog/aws/parsers/s3/get_request_payment.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module AWS
4 | module S3
5 |
6 | class GetRequestPayment < Fog::Parsers::Base
7 |
8 | def end_element(name)
9 | case name
10 | when 'Payer'
11 | @response[name] = @value
12 | end
13 | end
14 |
15 | end
16 |
17 | end
18 | end
19 | end
20 | end
21 |
--------------------------------------------------------------------------------
/lib/fog/aws/parsers/ec2/allocate_address.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module AWS
4 | module EC2
5 |
6 | class AllocateAddress < Fog::Parsers::Base
7 |
8 | def end_element(name)
9 | case name
10 | when 'publicIp', 'requestId'
11 | @response[name] = @value
12 | end
13 | end
14 |
15 | end
16 | end
17 | end
18 | end
19 | end
20 |
--------------------------------------------------------------------------------
/lib/fog/aws/parsers/s3/get_bucket_location.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module AWS
4 | module S3
5 |
6 | class GetBucketLocation < Fog::Parsers::Base
7 |
8 | def end_element(name)
9 | case name
10 | when 'LocationConstraint'
11 | @response[name] = @value
12 | end
13 | end
14 |
15 | end
16 |
17 | end
18 | end
19 | end
20 | end
21 |
--------------------------------------------------------------------------------
/spec/lorem.txt:
--------------------------------------------------------------------------------
1 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
--------------------------------------------------------------------------------
/spec/rackspace/requests/files/put_container_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'Rackspace::Files.put_container' do
4 | describe 'success' do
5 |
6 | after(:each) do
7 | Rackspace[:files].delete_container('container_name')
8 | end
9 |
10 | it "should return proper attributes" do
11 | Rackspace[:files].put_container('container_name')
12 | end
13 |
14 | end
15 | end
16 |
--------------------------------------------------------------------------------
/lib/fog/webbynode/parsers/get_job.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module Webbynode
4 |
5 | class GetJob < Fog::Parsers::Base
6 |
7 | def reset
8 | @response = {}
9 | end
10 |
11 | def end_element(name)
12 | case name
13 | when 'job-id'
14 | @response['id'] = @value.to_i
15 | end
16 | end
17 |
18 | end
19 |
20 | end
21 | end
22 | end
23 |
--------------------------------------------------------------------------------
/lib/fog/aws/parsers/ec2/create_key_pair.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module AWS
4 | module EC2
5 |
6 | class CreateKeyPair < Fog::Parsers::Base
7 |
8 | def end_element(name)
9 | case name
10 | when 'keyFingerprint', 'keyMaterial', 'keyName', 'requestId'
11 | @response[name] = @value
12 | end
13 | end
14 |
15 | end
16 |
17 | end
18 | end
19 | end
20 | end
21 |
--------------------------------------------------------------------------------
/lib/fog/parser.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | class Base < Nokogiri::XML::SAX::Document
4 |
5 | attr_reader :response
6 |
7 | def initialize
8 | reset
9 | end
10 |
11 | def reset
12 | @response = {}
13 | end
14 |
15 | def characters(string)
16 | @value ||= ''
17 | @value << string.strip
18 | end
19 |
20 | def start_element(name, attrs = [])
21 | @value = nil
22 | end
23 |
24 | end
25 | end
26 | end
27 |
--------------------------------------------------------------------------------
/spec/aws/requests/s3/put_bucket_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'S3.put_bucket' do
4 | describe 'success' do
5 |
6 | before(:each) do
7 | @response = AWS[:s3].put_bucket('fogputbucket')
8 | end
9 |
10 | after(:each) do
11 | AWS[:s3].delete_bucket('fogputbucket')
12 | end
13 |
14 | it 'should not raise an error if the bucket already exists' do
15 | AWS[:s3].put_bucket('fogputbucket')
16 | end
17 |
18 | end
19 | end
20 |
--------------------------------------------------------------------------------
/lib/fog/slicehost/parsers/get_image.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module Slicehost
4 |
5 | class GetImage < Fog::Parsers::Base
6 |
7 | def reset
8 | @response = {}
9 | end
10 |
11 | def end_element(name)
12 | case name
13 | when 'id'
14 | @response[name] = @value.to_i
15 | when 'name'
16 | @response[name] = @value
17 | end
18 | end
19 |
20 | end
21 |
22 | end
23 | end
24 | end
25 |
--------------------------------------------------------------------------------
/lib/fog/aws/parsers/s3/copy_object.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module AWS
4 | module S3
5 |
6 | class CopyObject < Fog::Parsers::Base
7 |
8 | def end_element(name)
9 | case name
10 | when 'ETag'
11 | @response[name] = @value.gsub('"', '')
12 | when 'LastModified'
13 | @response[name] = Time.parse(@value)
14 | end
15 | end
16 |
17 | end
18 |
19 | end
20 | end
21 | end
22 | end
23 |
--------------------------------------------------------------------------------
/lib/fog/slicehost/parsers/get_flavor.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module Slicehost
4 |
5 | class GetFlavor < Fog::Parsers::Base
6 |
7 | def reset
8 | @response = {}
9 | end
10 |
11 | def end_element(name)
12 | case name
13 | when 'id', 'price', 'ram'
14 | @response[name] = @value.to_i
15 | when 'name'
16 | @response[name] = @value
17 | end
18 | end
19 |
20 | end
21 |
22 | end
23 | end
24 | end
25 |
--------------------------------------------------------------------------------
/lib/fog/webbynode/parsers/get_flavor.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module Slicehost
4 |
5 | class GetFlavor < Fog::Parsers::Base
6 |
7 | def reset
8 | @response = {}
9 | end
10 |
11 | def end_element(name)
12 | case name
13 | when 'id', 'price', 'ram'
14 | @response[name] = @value.to_i
15 | when 'name'
16 | @response[name] = @value
17 | end
18 | end
19 |
20 | end
21 |
22 | end
23 | end
24 | end
25 |
--------------------------------------------------------------------------------
/lib/fog/deprecation.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Deprecation
3 |
4 | def deprecate(older, newer)
5 | class_eval <<-EOS, __FILE__, __LINE__
6 | def #{older}(*args)
7 | location = caller.first
8 | warning = "[yellow][WARN] #{self} => ##{older} is deprecated, use ##{newer} instead[/]"
9 | warning << " [light_black](" << location << ")[/] "
10 | Formatador.display_line(warning)
11 | send(:#{newer}, *args)
12 | end
13 | EOS
14 | end
15 |
16 | end
17 | end
18 |
--------------------------------------------------------------------------------
/spec/rackspace/requests/files/head_containers_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'Rackspace::Files.head_containers' do
4 | describe 'success' do
5 |
6 | before(:each) do
7 | Rackspace[:files].put_container('container_name')
8 | end
9 |
10 | after(:each) do
11 | Rackspace[:files].delete_container('container_name')
12 | end
13 |
14 | it "should return proper attributes" do
15 | Rackspace[:files].head_containers
16 | end
17 |
18 | end
19 | end
20 |
--------------------------------------------------------------------------------
/spec/vcloud/vcloud_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe Fog::Vcloud do
4 | subject { Fog::Vcloud.new() }
5 |
6 | it { should be_an_instance_of Fog::Vcloud::Mock }
7 |
8 | it { should respond_to :default_organization_uri }
9 |
10 | it { should respond_to :supported_versions }
11 |
12 | it { should have_at_least(1).supported_versions }
13 |
14 | its(:default_organization_uri) { should == URI.parse(@mock_organization[:info][:href]) }
15 | its(:default_organization_uri) { should be_an_instance_of URI::HTTPS }
16 |
17 | end
18 |
--------------------------------------------------------------------------------
/lib/fog/aws/parsers/ec2/attach_volume.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module AWS
4 | module EC2
5 |
6 | class AttachVolume < Fog::Parsers::Base
7 |
8 | def end_element(name)
9 | case name
10 | when 'attachTime'
11 | @response[name] = Time.parse(@value)
12 | when 'device', 'instanceId', 'requestId', 'status', 'volumeId'
13 | @response[name] = @value
14 | end
15 | end
16 |
17 | end
18 |
19 | end
20 | end
21 | end
22 | end
23 |
--------------------------------------------------------------------------------
/lib/fog/aws/parsers/ec2/detach_volume.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module AWS
4 | module EC2
5 |
6 | class DetachVolume < Fog::Parsers::Base
7 |
8 | def end_element(name)
9 | case name
10 | when 'attachTime'
11 | @response[name] = Time.parse(@value)
12 | when 'device', 'instanceId', 'requestId', 'status', 'volumeId'
13 | @response[name] = @value
14 | end
15 | end
16 |
17 | end
18 |
19 | end
20 | end
21 | end
22 | end
23 |
--------------------------------------------------------------------------------
/lib/fog/terremark/models/shared/address.rb:
--------------------------------------------------------------------------------
1 | require 'fog/model'
2 |
3 | module Fog
4 | module Terremark
5 | module Shared
6 |
7 | class Address < Fog::Model
8 |
9 | identity :id
10 |
11 | attribute :ip, 'name'
12 |
13 | def destroy
14 | requires :id
15 | connection.delete_public_ip(@id)
16 | true
17 | end
18 |
19 | private
20 |
21 | def href=(new_href)
22 | @id = new_href.split('/').last.to_i
23 | end
24 |
25 | end
26 |
27 | end
28 | end
29 | end
30 |
--------------------------------------------------------------------------------
/lib/fog/aws/parsers/s3/get_bucket_versioning.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module AWS
4 | module S3
5 |
6 | class GetBucketVersioning < Fog::Parsers::Base
7 |
8 | def reset
9 | @response = { 'VersioningConfiguration' => {} }
10 | end
11 |
12 | def end_element(name)
13 | case name
14 | when 'Status'
15 | @response['VersioningConfiguration'][name] = @value
16 | end
17 | end
18 |
19 | end
20 |
21 | end
22 | end
23 | end
24 | end
25 |
--------------------------------------------------------------------------------
/tests/slicehost/requests/get_image_tests.rb:
--------------------------------------------------------------------------------
1 | Shindo.tests('Slicehost#get_image', 'slicehost') do
2 | tests('success') do
3 |
4 | before do
5 | @data = Slicehost[:slices].get_image(3).body
6 | end
7 |
8 | test('has proper output format') do
9 | has_format(@data, Slicehost::Formats::IMAGE)
10 | end
11 |
12 | end
13 |
14 | tests('failure') do
15 |
16 | test('raises Forbidden error if flavor does not exist') do
17 | has_error(Excon::Errors::Forbidden)
18 | Slicehost[:slices].get_image(0)
19 | end
20 | end
21 |
22 | end
23 | end
24 |
--------------------------------------------------------------------------------
/lib/fog/aws/parsers/elb/delete_load_balancer.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module AWS
4 | module ELB
5 |
6 | class DeleteLoadBalancer < Fog::Parsers::Base
7 |
8 | def reset
9 | @response = { 'DeleteLoadBalancerResult' => nil, 'ResponseMetadata' => {} }
10 | end
11 |
12 | def end_element(name)
13 | case name
14 | when 'RequestId'
15 | @response['ResponseMetadata'][name] = @value
16 | end
17 | end
18 |
19 | end
20 |
21 | end
22 | end
23 | end
24 | end
25 |
--------------------------------------------------------------------------------
/spec/aws/models/ec2/servers_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 | require File.dirname(__FILE__) + '/../../../shared_examples/servers_examples'
3 |
4 | describe 'Fog::AWS::EC2::Servers' do
5 |
6 | it_should_behave_like "Servers"
7 |
8 | subject { @server = @servers.new(:image_id => GENTOO_AMI) }
9 |
10 | before(:each) do
11 | @servers = AWS[:ec2].servers
12 | end
13 |
14 | after(:each) do
15 | if @server && !@server.new_record?
16 | @server.wait_for { ready? }
17 | @server.destroy.should be_true
18 | end
19 | end
20 |
21 | end
22 |
--------------------------------------------------------------------------------
/tests/slicehost/requests/get_flavor_tests.rb:
--------------------------------------------------------------------------------
1 | Shindo.tests('Slicehost#get_flavor', 'slicehost') do
2 | tests('success') do
3 |
4 | before do
5 | @data = Slicehost[:slices].get_flavor(1).body
6 | end
7 |
8 | test('has proper output format') do
9 | has_format(@data, Slicehost::Formats::FLAVOR)
10 | end
11 |
12 | end
13 |
14 | tests('failure') do
15 |
16 | test('raises Forbidden error if flavor does not exist') do
17 | has_error(Excon::Errors::Forbidden) do
18 | Slicehost[:slices].get_flavor(0)
19 | end
20 | end
21 |
22 | end
23 | end
24 |
--------------------------------------------------------------------------------
/lib/fog/terremark/parsers/shared/public_ip.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module Terremark
4 | module Shared
5 |
6 | class PublicIp < Fog::Parsers::Base
7 |
8 | def reset
9 | @response = {}
10 | end
11 |
12 | def end_element(name)
13 | case name
14 | when 'Href', 'Name'
15 | @response[name.downcase] = @value
16 | when 'Id'
17 | @response['id'] = @value.to_i
18 | end
19 | end
20 |
21 | end
22 |
23 | end
24 | end
25 | end
26 | end
27 |
--------------------------------------------------------------------------------
/lib/fog/webbynode/parsers/create_webby.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module Webbynode
4 |
5 | class CreateWebby < Fog::Parsers::Base
6 |
7 | def reset
8 | @response = {}
9 | end
10 |
11 | def end_element(name)
12 | case name
13 | when 'ip'
14 | @response['ip'] = @value
15 | when 'image-id'
16 | @response[name] = @value.to_i
17 | when 'name', 'status'
18 | @response[name] = @value
19 | end
20 | end
21 |
22 | end
23 |
24 | end
25 | end
26 | end
27 |
--------------------------------------------------------------------------------
/lib/fog/aws/parsers/ec2/basic.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module AWS
4 | module EC2
5 |
6 | class Basic < Fog::Parsers::Base
7 |
8 | def end_element(name)
9 | case name
10 | when 'requestId'
11 | @response[name] = @value
12 | when 'return'
13 | if @value == 'true'
14 | @response[name] = true
15 | else
16 | @response[name] = false
17 | end
18 | end
19 | end
20 |
21 | end
22 | end
23 | end
24 | end
25 | end
26 |
--------------------------------------------------------------------------------
/tests/slicehost/requests/create_slice_tests.rb:
--------------------------------------------------------------------------------
1 | Shindo.tests('Slicehost#create_slice', 'slicehost') do
2 | tests('success') do
3 |
4 | before do
5 | @data = Slicehost[:slices].create_slice(1, 3, 'fogcreateslice').body
6 | @id = @data['id']
7 | end
8 |
9 | after do
10 | Fog.wait_for { Slicehost[:slices].get_slice(@id).body['status'] == 'active' }
11 | Slicehost[:slices].delete_slice(@id)
12 | end
13 |
14 | test('has proper output format') do
15 | has_format(@data, Slicehost::Formats::SLICE.merge('root-password' => String))
16 | end
17 |
18 | end
19 | end
20 |
--------------------------------------------------------------------------------
/lib/fog/connection.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | class Connection
3 |
4 | def initialize(url)
5 | @excon = Excon.new(url)
6 | end
7 |
8 | def request(params, &block)
9 | unless block_given?
10 | if (parser = params.delete(:parser))
11 | body = Nokogiri::XML::SAX::PushParser.new(parser)
12 | block = lambda { |chunk| body << chunk }
13 | end
14 | end
15 |
16 | response = @excon.request(params, &block)
17 |
18 | if parser
19 | body.finish
20 | response.body = parser.response
21 | end
22 |
23 | response
24 | end
25 |
26 | end
27 | end
28 |
--------------------------------------------------------------------------------
/spec/rackspace/requests/files/put_object_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'Rackspace::Files.put_object' do
4 | describe 'success' do
5 |
6 | before(:each) do
7 | Rackspace[:files].put_container('container_name')
8 | end
9 |
10 | after(:each) do
11 | Rackspace[:files].delete_object('container_name', 'object_name')
12 | Rackspace[:files].delete_container('container_name')
13 | end
14 |
15 | it "should return proper attributes" do
16 | Rackspace[:files].put_object('container_name', 'object_name', lorem_file)
17 | end
18 |
19 | end
20 | end
21 |
--------------------------------------------------------------------------------
/lib/fog/aws/parsers/ec2/create_volume.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module AWS
4 | module EC2
5 |
6 | class CreateVolume < Fog::Parsers::Base
7 |
8 | def end_element(name)
9 | case name
10 | when 'availabilityZone', 'requestId', 'snapshotId', 'status', 'volumeId'
11 | @response[name] = @value
12 | when 'createTime'
13 | @response[name] = Time.parse(@value)
14 | when 'size'
15 | @response[name] = @value.to_i
16 | end
17 | end
18 |
19 | end
20 |
21 | end
22 | end
23 | end
24 | end
25 |
--------------------------------------------------------------------------------
/lib/fog/slicehost/parsers/get_images.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module Slicehost
4 |
5 | class GetImages < Fog::Parsers::Base
6 |
7 | def reset
8 | @image = {}
9 | @response = { 'images' => [] }
10 | end
11 |
12 | def end_element(name)
13 | case name
14 | when 'id'
15 | @image[name] = @value.to_i
16 | when 'image'
17 | @response['images'] << @image
18 | @image = {}
19 | when 'name'
20 | @image[name] = @value
21 | end
22 | end
23 |
24 | end
25 |
26 | end
27 | end
28 | end
29 |
--------------------------------------------------------------------------------
/lib/fog/webbynode/parsers/get_images.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module Webbynode
4 |
5 | class GetImages < Fog::Parsers::Base
6 |
7 | def reset
8 | @image = {}
9 | @response = { 'images' => [] }
10 | end
11 |
12 | def end_element(name)
13 | case name
14 | when 'id'
15 | @image[name] = @value.to_i
16 | when 'image'
17 | @response['images'] << @image
18 | @image = {}
19 | when 'name'
20 | @image[name] = @value
21 | end
22 | end
23 |
24 | end
25 |
26 | end
27 | end
28 | end
29 |
--------------------------------------------------------------------------------
/tests/rackspace/requests/servers/get_image_details_tests.rb:
--------------------------------------------------------------------------------
1 | Shindo.tests('Rackspace::Servers#get_image_details', 'rackspace') do
2 | tests('success') do
3 |
4 | before do
5 | @data = Rackspace[:servers].get_image_details(3).body['image']
6 | end
7 |
8 | test('has proper output format') do
9 | has_format(@data, Rackspace::Servers::Formats::IMAGE)
10 | end
11 |
12 | end
13 | tests('failure') do
14 |
15 | test('raises NotFound error if image does not exist') do
16 | has_error(Excon::Errors::NotFound) do
17 | Rackspace[:servers].get_image_details(0)
18 | end
19 | end
20 |
21 | end
22 | end
23 |
--------------------------------------------------------------------------------
/tests/rackspace/requests/servers/get_flavor_details_tests.rb:
--------------------------------------------------------------------------------
1 | Shindo.tests('Rackspace::Servers#get_flavor_details', 'rackspace') do
2 | tests('success') do
3 |
4 | before do
5 | @data = Rackspace[:servers].get_flavor_details(1).body['flavor']
6 | end
7 |
8 | test('has proper output format') do
9 | has_format(@data, Rackspace::Servers::Formats::FLAVOR)
10 | end
11 |
12 | end
13 | tests('failure') do
14 |
15 | test('raises NotFound error if flavor does not exist') do
16 | has_error(Excon::Errors::NotFound) do
17 | Rackspace[:servers].get_flavor_details(0)
18 | end
19 | end
20 |
21 | end
22 | end
23 |
--------------------------------------------------------------------------------
/lib/fog/slicehost/parsers/get_flavors.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module Slicehost
4 |
5 | class GetFlavors < Fog::Parsers::Base
6 |
7 | def reset
8 | @flavor = {}
9 | @response = { 'flavors' => [] }
10 | end
11 |
12 | def end_element(name)
13 | case name
14 | when 'flavor'
15 | @response['flavors'] << @flavor
16 | @flavor = {}
17 | when 'id', 'price', 'ram'
18 | @flavor[name] = @value.to_i
19 | when 'name'
20 | @flavor[name] = @value
21 | end
22 | end
23 |
24 | end
25 |
26 | end
27 | end
28 | end
29 |
--------------------------------------------------------------------------------
/lib/fog/webbynode/parsers/get_flavors.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module Slicehost
4 |
5 | class GetFlavors < Fog::Parsers::Base
6 |
7 | def reset
8 | @flavor = {}
9 | @response = { 'flavors' => [] }
10 | end
11 |
12 | def end_element(name)
13 | case name
14 | when 'flavor'
15 | @response['flavors'] << @flavor
16 | @flavor = {}
17 | when 'id', 'price', 'ram'
18 | @flavor[name] = @value.to_i
19 | when 'name'
20 | @flavor[name] = @value
21 | end
22 | end
23 |
24 | end
25 |
26 | end
27 | end
28 | end
29 |
--------------------------------------------------------------------------------
/lib/fog/webbynode/parsers/get_webbies.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module Webbynode
4 |
5 | class GetWebbies < Fog::Parsers::Base
6 |
7 | def reset
8 | @webby = {}
9 | @response = { 'webbies' => [] }
10 | end
11 |
12 | def end_element(name)
13 | case name
14 | when 'image-id'
15 | @webby[name] = @value.to_i
16 | when 'ip', 'name', 'status', 'notes'
17 | @webby[name] = @value
18 | when 'webby'
19 | @response['webbies'] << @webby
20 | @webby = {}
21 | end
22 | end
23 |
24 | end
25 |
26 | end
27 | end
28 | end
29 |
--------------------------------------------------------------------------------
/spec/aws/requests/ec2/delete_key_pair_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'EC2.delete_key_pair' do
4 | describe 'success' do
5 |
6 | before(:each) do
7 | AWS[:ec2].create_key_pair('fog_key_name')
8 | @response = AWS[:ec2].delete_key_pair('fog_key_name')
9 | end
10 |
11 | it "should return proper attributes" do
12 | @response.body['requestId'].should be_a(String)
13 | [false, true].should include(@response.body['return'])
14 | end
15 |
16 | it "should not raise an error if the key pair does not exist" do
17 | AWS[:ec2].delete_key_pair('not_a_key_name')
18 | end
19 |
20 | end
21 | end
22 |
--------------------------------------------------------------------------------
/spec/slicehost/models/servers_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../spec_helper'
2 | require File.dirname(__FILE__) + '/../../shared_examples/servers_examples'
3 |
4 | describe 'Fog::Slicehost::Servers' do
5 |
6 | it_should_behave_like "Servers"
7 |
8 | # flavor 1 = 256, image 3 = gentoo 2008.0
9 | subject { @server = @servers.new(:flavor_id => 1, :image_id => 3, :name => Time.now.to_i.to_s) }
10 |
11 | before(:each) do
12 | @servers = Slicehost[:slices].servers
13 | end
14 |
15 | after(:each) do
16 | if @server && !@server.new_record?
17 | @server.wait_for { ready? }
18 | @server.destroy.should be_true
19 | end
20 | end
21 |
22 | end
23 |
--------------------------------------------------------------------------------
/spec/rackspace/models/servers/servers_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 | require File.dirname(__FILE__) + '/../../../shared_examples/servers_examples'
3 |
4 | describe 'Fog::Rackspace::Servers::Servers' do
5 |
6 | it_should_behave_like "Servers"
7 |
8 | # flavor 1 = 256, image 3 = gentoo 2008.0
9 | subject { @server = @servers.new(:flavor_id => 1, :image_id => 3, :name => 'name') }
10 |
11 | before(:each) do
12 | @servers = Rackspace[:servers].servers
13 | end
14 |
15 | after(:each) do
16 | if @server && !@server.new_record?
17 | @server.wait_for { ready? }
18 | @server.destroy.should be_true
19 | end
20 | end
21 |
22 | end
23 |
--------------------------------------------------------------------------------
/lib/fog/aws/parsers/elb/create_load_balancer.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module AWS
4 | module ELB
5 |
6 | class CreateLoadBalancer < Fog::Parsers::Base
7 |
8 | def reset
9 | @response = { 'CreateLoadBalancerResult' => {}, 'ResponseMetadata' => {} }
10 | end
11 |
12 | def end_element(name)
13 | case name
14 | when 'DNSName'
15 | @response['CreateLoadBalancerResult'][name] = @value
16 | when 'RequestId'
17 | @response['ResponseMetadata'][name] = @value
18 | end
19 | end
20 |
21 | end
22 |
23 | end
24 | end
25 | end
26 | end
27 |
--------------------------------------------------------------------------------
/tests/rackspace/requests/servers/list_servers_tests.rb:
--------------------------------------------------------------------------------
1 | Shindo.tests('Rackspace::Servers#list_servers', 'rackspace') do
2 | tests('success') do
3 |
4 | before do
5 | @server_id = Rackspace[:servers].create_server(1, 3, 'foglistservers').body['server']['id']
6 | @data = Rackspace[:servers].list_servers.body['servers']
7 | end
8 |
9 | after do
10 | Fog.wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
11 | Rackspace[:servers].delete_server(@server_id)
12 | end
13 |
14 | test('has proper output format') do
15 | has_format(@data, Rackspace::Servers::Formats::SUMMARY)
16 | end
17 |
18 | end
19 | end
20 |
--------------------------------------------------------------------------------
/spec/rackspace/requests/files/get_containers_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'Rackspace::Files.get_containers' do
4 | describe 'success' do
5 |
6 | before(:each) do
7 | Rackspace[:files].put_container('container_name')
8 | end
9 |
10 | after(:each) do
11 | Rackspace[:files].delete_container('container_name')
12 | end
13 |
14 | it "should return proper attributes" do
15 | actual = Rackspace[:files].get_containers.body
16 | actual.first['bytes'].should be_an(Integer)
17 | actual.first['count'].should be_an(Integer)
18 | actual.first['name'].should be_a(String)
19 | end
20 |
21 | end
22 | end
23 |
--------------------------------------------------------------------------------
/tests/rackspace/requests/servers/create_server_tests.rb:
--------------------------------------------------------------------------------
1 | Shindo.tests('Rackspace::Servers#create_server', 'rackspace') do
2 | tests('success') do
3 |
4 | before do
5 | # 1 => 256MB, 3 => Gentoo
6 | @data = Rackspace[:servers].create_server(1, 3).body['server']
7 | @server_id = @data['id']
8 | end
9 |
10 | after do
11 | Fog.wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
12 | Rackspace[:servers].delete_server(@server_id)
13 | end
14 |
15 | test('has proper output format') do
16 | has_format(@data, Rackspace::Servers::Formats::SERVER.merge('adminPass' => String))
17 | end
18 |
19 | end
20 | end
21 |
--------------------------------------------------------------------------------
/spec/rackspace/requests/files/get_object_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'Rackspace::Files.get_object' do
4 | describe 'success' do
5 |
6 | before(:each) do
7 | Rackspace[:files].put_container('container_name')
8 | Rackspace[:files].put_object('container_name', 'object_name', lorem_file)
9 | end
10 |
11 | after(:each) do
12 | Rackspace[:files].delete_object('container_name', 'object_name')
13 | Rackspace[:files].delete_container('container_name')
14 | end
15 |
16 | it "should return proper attributes" do
17 | Rackspace[:files].get_object('container_name', 'object_name')
18 | end
19 |
20 | end
21 | end
22 |
--------------------------------------------------------------------------------
/spec/rackspace/requests/files/head_object_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'Rackspace::Files.head_object' do
4 | describe 'success' do
5 |
6 | before(:each) do
7 | Rackspace[:files].put_container('container_name')
8 | Rackspace[:files].put_object('container_name', 'object_name', lorem_file)
9 | end
10 |
11 | after(:each) do
12 | Rackspace[:files].delete_object('container_name', 'object_name')
13 | Rackspace[:files].delete_container('container_name')
14 | end
15 |
16 | it "should return proper attributes" do
17 | Rackspace[:files].head_object('container_name', 'object_name')
18 | end
19 |
20 | end
21 | end
22 |
--------------------------------------------------------------------------------
/lib/fog/terremark/requests/shared/delete_vapp.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Terremark
3 | module Shared
4 | module Real
5 |
6 | # Destroy a vapp
7 | #
8 | # ==== Parameters
9 | # * vapp_id<~Integer> - Id of vapp to destroy
10 | #
11 | def delete_vapp(vapp_id)
12 | request(
13 | :expects => 202,
14 | :method => 'DELETE',
15 | :path => "vApp/#{vapp_id}"
16 | )
17 | end
18 |
19 | end
20 |
21 | module Mock
22 |
23 | def delete_vapp(vapp_id)
24 | raise MockNotImplemented.new("Contributions welcome!")
25 | end
26 |
27 | end
28 | end
29 | end
30 | end
31 |
--------------------------------------------------------------------------------
/tests/rackspace/requests/servers/list_servers_detail_tests.rb:
--------------------------------------------------------------------------------
1 | Shindo.tests('Rackspace::Servers#list_servers_detail', 'rackspace') do
2 | tests('success') do
3 |
4 | before do
5 | @server_id = Rackspace[:servers].create_server(1, 3, 'foglistserversdetail').body['server']['id']
6 | @data = Rackspace[:servers].list_servers_detail.body['servers']
7 | end
8 |
9 | after do
10 | Fog.wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
11 | Rackspace[:servers].delete_server(@server_id)
12 | end
13 |
14 | test('has proper output format') do
15 | has_format(@data, Rackspace::Servers::Formats::SERVER)
16 | end
17 |
18 | end
19 | end
20 |
--------------------------------------------------------------------------------
/lib/fog/aws/parsers/ec2/create_snapshot.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module AWS
4 | module EC2
5 |
6 | class CreateSnapshot < Fog::Parsers::Base
7 |
8 | def end_element(name)
9 | case name
10 | when 'description', 'ownerId', 'progress', 'snapshotId', 'status', 'volumeId'
11 | @response[name] = @value
12 | when 'requestId'
13 | @response[name] = @value
14 | when 'startTime'
15 | @response[name] = Time.parse(@value)
16 | when 'volumeSize'
17 | @response[name] = @value.to_i
18 | end
19 | end
20 |
21 | end
22 |
23 | end
24 | end
25 | end
26 | end
--------------------------------------------------------------------------------
/tests/slicehost/requests/delete_slice_tests.rb:
--------------------------------------------------------------------------------
1 | Shindo.tests('Slicehost#delete_slice', 'slicehost') do
2 | tests('success') do
3 |
4 | before do
5 | @data = Slicehost[:slices].create_slice(1, 3, 'fogdeleteslice').body
6 | @id = @data['id']
7 | end
8 |
9 | test('has proper output format') do
10 | Fog.wait_for { Slicehost[:slices].get_slice(@id).body['status'] == 'active' }
11 | Slicehost[:slices].delete_slice(@id)
12 | end
13 |
14 | end
15 |
16 | tests('failure') do
17 |
18 | test('raises NotFound error if slice does not exist') do
19 | has_error(Excon::Errors::NotFound) do
20 | Slicehost[:slices].delete_slice(0)
21 | end
22 | end
23 |
24 | end
25 | end
26 |
--------------------------------------------------------------------------------
/lib/fog/aws/models/ec2/image.rb:
--------------------------------------------------------------------------------
1 | require 'fog/model'
2 |
3 | module Fog
4 | module AWS
5 | module EC2
6 |
7 | class Image < Fog::Model
8 |
9 | identity :id, 'imageId'
10 |
11 | attribute :architecture
12 | attribute :location, 'imageLocation'
13 | attribute :owner_id, 'imageOwnerId'
14 | attribute :state, 'imageState'
15 | attribute :type, 'imageType'
16 | attribute :is_public, 'isPublic'
17 | attribute :kernel_id, 'kernelId'
18 | attribute :platform
19 | attribute :product_codes, 'productCodes'
20 | attribute :ramdisk_id, 'ramdiskId'
21 |
22 | end
23 |
24 | end
25 | end
26 | end
--------------------------------------------------------------------------------
/lib/fog/terremark/parsers/shared/get_network_ips.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module Terremark
4 | module Shared
5 |
6 | class GetNetworkIps< Fog::Parsers::Base
7 |
8 | def reset
9 | @ip_address = {}
10 | @response = { 'IpAddresses' => [] }
11 | end
12 |
13 | def end_element(name)
14 | case name
15 | when 'Name', 'Status', 'Server'
16 | @ip_address[name.downcase] = @value
17 | when 'IpAddress'
18 | @response['IpAddresses'] << @ip_address
19 | @ip_address = {}
20 | end
21 | end
22 |
23 | end
24 |
25 | end
26 | end
27 | end
28 | end
29 |
30 |
--------------------------------------------------------------------------------
/lib/fog/terremark/parsers/shared/get_organizations.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module Terremark
4 | module Shared
5 |
6 | class GetOrganizations < Fog::Parsers::Base
7 |
8 | def reset
9 | @response = { 'OrgList' => [] }
10 | end
11 |
12 | def start_element(name, attributes)
13 | super
14 | if name == 'Org'
15 | organization = {}
16 | until attributes.empty?
17 | organization[attributes.shift] = attributes.shift
18 | end
19 | @response['OrgList'] << organization
20 | end
21 | end
22 |
23 | end
24 | end
25 | end
26 | end
27 | end
28 |
--------------------------------------------------------------------------------
/spec/rackspace/requests/files/delete_container_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'Rackspace::Files.delete_container' do
4 | describe 'success' do
5 |
6 | before(:each) do
7 | Rackspace[:files].put_container('container_name')
8 | end
9 |
10 | it "should return proper attributes" do
11 | Rackspace[:files].delete_container('container_name')
12 | end
13 |
14 | end
15 | describe 'failure' do
16 |
17 | it "should raise a NotFound error if the container does not exist" do
18 | lambda do
19 | Rackspace[:files].delete_container('container_name')
20 | end.should raise_error(Excon::Errors::NotFound)
21 | end
22 |
23 | end
24 | end
25 |
--------------------------------------------------------------------------------
/lib/fog/aws/parsers/simpledb/basic.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module AWS
4 | module SimpleDB
5 |
6 | class Basic < Fog::Parsers::Base
7 |
8 | def initialize(nil_string)
9 | @nil_string = nil_string
10 | reset
11 | end
12 |
13 | def end_element(name)
14 | case(name)
15 | when 'BoxUsage'
16 | response[name] = @value.to_f
17 | when 'RequestId'
18 | response[name] = @value
19 | end
20 | end
21 |
22 | def sdb_decode(value)
23 | value.eql?(@nil_string) ? nil : value
24 | end
25 |
26 | end
27 |
28 | end
29 | end
30 | end
31 | end
--------------------------------------------------------------------------------
/lib/fog/aws/parsers/ec2/describe_key_pairs.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module AWS
4 | module EC2
5 |
6 | class DescribeKeyPairs < Fog::Parsers::Base
7 |
8 | def reset
9 | @key = {}
10 | @response = { 'keySet' => [] }
11 | end
12 |
13 | def end_element(name)
14 | case name
15 | when 'item'
16 | @response['keySet'] << @key
17 | @key = {}
18 | when 'keyFingerprint', 'keyName'
19 | @key[name] = @value
20 | when 'requestId'
21 | @response[name] = @value
22 | end
23 | end
24 |
25 | end
26 |
27 | end
28 | end
29 | end
30 | end
31 |
--------------------------------------------------------------------------------
/lib/fog/aws/parsers/ec2/get_console_output.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module AWS
4 | module EC2
5 |
6 | class GetConsoleOutput < Fog::Parsers::Base
7 |
8 | def reset
9 | @response = {}
10 | end
11 |
12 | def end_element(name)
13 | case name
14 | when 'instanceId', 'requestId'
15 | @response[name] = @value
16 | when 'output'
17 | if @value
18 | @response[name] = Base64.decode64(@value)
19 | end
20 | when 'timestamp'
21 | @response[name] = Time.parse(@value)
22 | end
23 | end
24 |
25 | end
26 |
27 | end
28 | end
29 | end
30 | end
--------------------------------------------------------------------------------
/lib/fog/slicehost/parsers/get_backups.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module Slicehost
4 |
5 | class GetBackups < Fog::Parsers::Base
6 |
7 | def reset
8 | @backup = {}
9 | @response = { 'backups' => [] }
10 | end
11 |
12 | def end_element(name)
13 | case name
14 | when 'backup'
15 | @response['backups'] << @backup
16 | @backup = {}
17 | when 'date'
18 | @backup[name] = Time.parse(@value)
19 | when 'id', 'slice-id'
20 | @backup[name] = @value.to_i
21 | when 'name'
22 | @backup[name] = @value
23 | end
24 | end
25 |
26 | end
27 |
28 | end
29 | end
30 | end
31 |
--------------------------------------------------------------------------------
/lib/fog/webbynode/parsers/get_backups.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module Slicehost
4 |
5 | class GetBackups < Fog::Parsers::Base
6 |
7 | def reset
8 | @backup = {}
9 | @response = { 'backups' => [] }
10 | end
11 |
12 | def end_element(name)
13 | case name
14 | when 'backup'
15 | @response['backups'] << @backup
16 | @backup = {}
17 | when 'date'
18 | @backup[name] = Time.parse(@value)
19 | when 'id', 'slice-id'
20 | @backup[name] = @value.to_i
21 | when 'name'
22 | @backup[name] = @value
23 | end
24 | end
25 |
26 | end
27 |
28 | end
29 | end
30 | end
31 |
--------------------------------------------------------------------------------
/lib/fog/aws/parsers/ec2/describe_regions.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module AWS
4 | module EC2
5 |
6 | class DescribeRegions < Fog::Parsers::Base
7 |
8 | def reset
9 | @region = {}
10 | @response = { 'regionInfo' => [] }
11 | end
12 |
13 | def end_element(name)
14 | case name
15 | when 'item'
16 | @response['regionInfo'] << @region
17 | @region = {}
18 | when 'regionEndpoint', 'regionName'
19 | @region[name] = @value
20 | when 'requestId'
21 | @response[name] = @value
22 | end
23 | end
24 |
25 | end
26 |
27 | end
28 | end
29 | end
30 | end
--------------------------------------------------------------------------------
/lib/fog/local/bin.rb:
--------------------------------------------------------------------------------
1 | module Local
2 | class << self
3 | if Fog.credentials[:local_root]
4 |
5 | def initialized?
6 | true
7 | end
8 |
9 | def [](service)
10 | @@connections ||= Hash.new do |hash, key|
11 | credentials = Fog.credentials.reject do |k,v|
12 | ![:local_root].include?(k)
13 | end
14 | hash[key] = case key
15 | when :files
16 | Fog::Local.new(credentials)
17 | end
18 | end
19 | @@connections[service]
20 | end
21 |
22 | def directories
23 | self[:files].directories
24 | end
25 |
26 | else
27 |
28 | def initialized?
29 | false
30 | end
31 |
32 | end
33 | end
34 | end
35 |
--------------------------------------------------------------------------------
/lib/fog/aws/parsers/simpledb/list_domains.rb:
--------------------------------------------------------------------------------
1 | require 'fog/aws/parsers/simpledb/basic'
2 |
3 | module Fog
4 | module Parsers
5 | module AWS
6 | module SimpleDB
7 |
8 | class ListDomains < Fog::Parsers::AWS::SimpleDB::Basic
9 |
10 | def reset
11 | @response = { 'Domains' => [] }
12 | end
13 |
14 | def end_element(name)
15 | case(name)
16 | when 'BoxUsage'
17 | response[name] = @value.to_f
18 | when 'DomainName'
19 | response['Domains'] << @value
20 | when 'NextToken', 'RequestId'
21 | response[name] = @value
22 | end
23 | end
24 |
25 | end
26 |
27 | end
28 | end
29 | end
30 | end
--------------------------------------------------------------------------------
/lib/fog/terremark/requests/shared/delete_public_ip.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Terremark
3 | module Shared
4 | module Real
5 |
6 | # Destroy a public ip
7 | #
8 | # ==== Parameters
9 | # * public_ip_id<~Integer> - Id of public ip to destroy
10 | #
11 | def delete_public_ip(public_ip_id)
12 | request(
13 | :expects => 200,
14 | :method => 'DELETE',
15 | :path => "publicIps/#{public_ip_id}"
16 | )
17 | end
18 |
19 | end
20 |
21 | module Mock
22 |
23 | def delete_public_ip(public_ip_id)
24 | raise MockNotImplemented.new("Contributions welcome!")
25 | end
26 |
27 | end
28 | end
29 | end
30 | end
31 |
--------------------------------------------------------------------------------
/lib/fog/webbynode/parsers/get_image.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module Webbynode
4 |
5 | class GetImage < Fog::Parsers::Base
6 | def initialize(image_id)
7 | @image_id = image_id
8 | @image = {}
9 | end
10 |
11 | def reset
12 | @image = {}
13 | @response = nil
14 | end
15 |
16 | def end_element(name)
17 | case name
18 | when 'id'
19 | @image[name] = @value.to_i
20 | when 'image'
21 | @response = @image if @image['id'] == @image_id
22 | @image = {}
23 | when 'name'
24 | @image[name] = @value
25 | end
26 | end
27 |
28 | end
29 |
30 | end
31 | end
32 | end
33 |
--------------------------------------------------------------------------------
/lib/fog/aws/parsers/ec2/describe_addresses.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module AWS
4 | module EC2
5 |
6 | class DescribeAddresses < Fog::Parsers::Base
7 |
8 | def reset
9 | @address = {}
10 | @response = { 'addressesSet' => [] }
11 | end
12 |
13 | def end_element(name)
14 | case name
15 | when 'instanceId', 'publicIp'
16 | @address[name] = @value
17 | when 'item'
18 | @response['addressesSet'] << @address
19 | @address = {}
20 | when 'requestId'
21 | @response[name] = @value
22 | end
23 | end
24 |
25 | end
26 |
27 | end
28 | end
29 | end
30 | end
31 |
--------------------------------------------------------------------------------
/lib/fog/terremark/requests/shared/delete_node_service.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Terremark
3 | module Shared
4 | module Real
5 |
6 | # Destroy a node
7 | #
8 | # ==== Parameters
9 | # * node_service_id<~Integer> - Id of node to destroy
10 | #
11 | def delete_node_service(node_service_id)
12 | request(
13 | :expects => 200,
14 | :method => 'DELETE',
15 | :path => "nodeServices/#{node_service_id}"
16 | )
17 | end
18 |
19 | end
20 |
21 | module Mock
22 |
23 | def delete_node_service(node_id)
24 | raise MockNotImplemented.new("Contributions welcome!")
25 | end
26 |
27 | end
28 | end
29 | end
30 | end
31 |
--------------------------------------------------------------------------------
/spec/aws/requests/ec2/describe_regions_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'EC2.describe_availability_zones' do
4 | describe 'success' do
5 |
6 | it "should return proper attributes with no params" do
7 | actual = AWS[:ec2].describe_regions
8 | zone = actual.body['regionInfo'].first
9 | zone['regionEndpoint'].should be_a(String)
10 | zone['regionName'].should be_a(String)
11 | end
12 |
13 | it "should return proper attribute with params" do
14 | actual = AWS[:ec2].describe_regions(['us-east-1'])
15 | zone = actual.body['regionInfo'].first
16 | zone['regionEndpoint'].should be_a(String)
17 | zone['regionName'].should be_a(String)
18 | end
19 |
20 | end
21 | end
22 |
--------------------------------------------------------------------------------
/tests/rackspace/requests/servers/delete_server_tests.rb:
--------------------------------------------------------------------------------
1 | Shindo.tests('Rackspace::Servers#delete_server', 'rackspace') do
2 | tests('success') do
3 |
4 | before do
5 | @server_id = Rackspace[:servers].create_server(1, 3, 'fogdeleteserver').body['server']['id']
6 | end
7 |
8 | test('has proper output format') do
9 | Fog.wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
10 | Rackspace[:servers].delete_server(@server_id)
11 | end
12 |
13 | end
14 | tests('failure') do
15 |
16 | test('raises NotFound error if server does not exist') do
17 | has_error(Excon::Errors::NotFound) do
18 | Rackspace[:servers].delete_server(0)
19 | end
20 | end
21 |
22 | end
23 | end
24 |
--------------------------------------------------------------------------------
/lib/fog/rackspace/requests/files/delete_container.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Rackspace
3 | module Files
4 | class Real
5 |
6 | # Delete an existing container
7 | #
8 | # ==== Parameters
9 | # * name<~String> - Name of container to delete
10 | #
11 | def delete_container(name)
12 | response = storage_request(
13 | :expects => 204,
14 | :method => 'DELETE',
15 | :path => CGI.escape(name)
16 | )
17 | response
18 | end
19 |
20 | end
21 |
22 | class Mock
23 |
24 | def delete_container(name)
25 | raise MockNotImplemented.new("Contributions welcome!")
26 | end
27 |
28 | end
29 | end
30 | end
31 | end
32 |
--------------------------------------------------------------------------------
/lib/fog/slicehost/parsers/get_slice.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module Slicehost
4 |
5 | class GetSlice < Fog::Parsers::Base
6 |
7 | def reset
8 | @response = {}
9 | end
10 |
11 | def end_element(name)
12 | case name
13 | when 'address'
14 | @response['addresses'] ||= []
15 | @response['addresses'] << @value
16 | when 'backup-id', 'flavor-id', 'id', 'image-id', 'progress'
17 | @response[name] = @value.to_i
18 | when 'bw-in', 'bw-out'
19 | @response[name] = @value.to_f
20 | when 'name', 'status'
21 | @response[name] = @value
22 | end
23 | end
24 |
25 | end
26 |
27 | end
28 | end
29 | end
30 |
--------------------------------------------------------------------------------
/lib/fog/terremark/models/shared/network.rb:
--------------------------------------------------------------------------------
1 | require 'fog/model'
2 |
3 | module Fog
4 | module Terremark
5 | module Shared
6 |
7 | class Network < Fog::Model
8 |
9 | identity :id
10 |
11 | attribute :name
12 | attribute :subnet
13 | attribute :gateway
14 | attribute :netmask
15 | attribute :fencemode
16 | attribute :links
17 |
18 | def ips
19 | #Until there is a real model for these ?
20 | connection.get_network_ips(@id).body['IpAddresses']
21 | end
22 |
23 | private
24 |
25 | def href=(new_href)
26 | @id = new_href.split('/').last.to_i
27 | end
28 |
29 | def type=(new_type); end
30 |
31 | end
32 |
33 | end
34 | end
35 | end
36 |
--------------------------------------------------------------------------------
/lib/fog/vcloud/terremark/ecloud/requests/login.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Vcloud
3 | module Terremark
4 | module Ecloud
5 | module Real
6 |
7 | # See /lib/fog/vcloud/requests/get_organizations.rb
8 | def login
9 | unauthenticated_request({
10 | :expects => 200,
11 | :headers => {
12 | 'Authorization' => authorization_header,
13 | 'Content-Type' => "application/vnd.vmware.vcloud.orgList+xml"
14 | },
15 | :method => 'POST',
16 | :parser => Fog::Parsers::Vcloud::Login.new,
17 | :uri => @login_uri
18 | })
19 | end
20 |
21 | end
22 | end
23 | end
24 | end
25 | end
26 |
27 |
28 |
--------------------------------------------------------------------------------
/spec/vcloud/requests/get_versions_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe Fog::Vcloud, :type => :vcloud_request do
4 | subject { @vcloud }
5 |
6 | it { should respond_to :get_versions }
7 |
8 | describe "#get_versions" do
9 | before { @versions = @vcloud.get_versions }
10 | subject { @versions }
11 |
12 | it_should_behave_like "all requests"
13 |
14 | its(:body) { should have(1).version }
15 |
16 | describe "body.first" do
17 | let(:version) { @versions.body.first }
18 | subject { version }
19 |
20 | its(:login_url) { should == @mock_version[:login_url] }
21 |
22 | its(:version) { should == @mock_version[:version] }
23 |
24 | its(:supported) { should == @mock_version[:supported] }
25 |
26 | end
27 | end
28 | end
29 |
--------------------------------------------------------------------------------
/lib/fog/terremark/models/shared/vdc.rb:
--------------------------------------------------------------------------------
1 | require 'fog/model'
2 |
3 | module Fog
4 | module Terremark
5 | module Shared
6 |
7 | class Vdc < Fog::Model
8 |
9 | identity :id
10 |
11 | attribute :name
12 |
13 | def networks
14 | connection.networks(:vdc_id => @id)
15 | end
16 |
17 | def addresses
18 | connection.addresses(:vdc_id => @id)
19 | end
20 |
21 | def servers
22 | connection.servers(:vdc_id => @id)
23 | end
24 |
25 | private
26 |
27 | def href=(new_href)
28 | @id = new_href.split('/').last.to_i
29 | end
30 |
31 | def type=(new_type); end
32 |
33 | def rel=(new_rel); end
34 |
35 | end
36 |
37 | end
38 | end
39 | end
40 |
--------------------------------------------------------------------------------
/lib/fog/aws/parsers/elb/register_instances_with_load_balancer.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module AWS
4 | module ELB
5 |
6 | class RegisterInstancesWithLoadBalancer < Fog::Parsers::Base
7 |
8 | def reset
9 | @response = { 'RegisterInstancesWithLoadBalancerResult' => { 'Instances' => [] }, 'ResponseMetadata' => {} }
10 | end
11 |
12 | def end_element(name)
13 | case name
14 | when 'InstanceId'
15 | @response['RegisterInstancesWithLoadBalancerResult']['Instances'] << {name => @value}
16 | when 'RequestId'
17 | @response['ResponseMetadata'][name] = @value
18 | end
19 | end
20 |
21 | end
22 |
23 | end
24 | end
25 | end
26 | end
27 |
--------------------------------------------------------------------------------
/lib/fog/terremark/requests/shared/power_shutdown.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Terremark
3 | module Shared
4 | module Real
5 |
6 | # Shutdown a vapp
7 | #
8 | # ==== Parameters
9 | # * vapp_id<~Integer> - Id of vapp to shutdown
10 | #
11 | # ==== Returns
12 | # Nothing
13 | def power_shutdown(vapp_id)
14 | request(
15 | :expects => 204,
16 | :method => 'POST',
17 | :path => "vApp/#{vapp_id}/power/action/shutdown"
18 | )
19 | end
20 |
21 | end
22 |
23 | module Mock
24 |
25 | def power_shutdown(vapp_id)
26 | raise MockNotImplemented.new("Contributions welcome!")
27 | end
28 |
29 | end
30 | end
31 | end
32 | end
33 |
--------------------------------------------------------------------------------
/lib/fog/webbynode/parsers/get_webby.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module Webbynode
4 | class GetWebby < Fog::Parsers::Base
5 | def initialize(webby_id)
6 | @webby_id = webby_id
7 | @webby = {}
8 | end
9 |
10 | def reset
11 | @webby = {}
12 | @response = nil
13 | end
14 |
15 | def end_element(name)
16 | case name
17 | when 'image-id'
18 | @webby[name] = @value.to_i
19 | when 'ip', 'name', 'status', 'notes'
20 | @webby[name] = @value
21 | when 'webby'
22 | @response = @webby if @webby['name'] == @webby_id
23 | @webby = {}
24 | end
25 | end
26 |
27 | end
28 |
29 | end
30 | end
31 | end
32 |
--------------------------------------------------------------------------------
/lib/fog/slicehost/parsers/create_slice.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module Slicehost
4 |
5 | class CreateSlice < Fog::Parsers::Base
6 |
7 | def reset
8 | @response = {}
9 | end
10 |
11 | def end_element(name)
12 | case name
13 | when 'address'
14 | @response['addresses'] ||= []
15 | @response['addresses'] << @value
16 | when 'backup-id', 'flavor-id', 'id', 'image-id', 'progress'
17 | @response[name] = @value.to_i
18 | when 'bw-in', 'bw-out'
19 | @response[name] = @value.to_f
20 | when 'name', 'root-password', 'status'
21 | @response[name] = @value
22 | end
23 | end
24 |
25 | end
26 |
27 | end
28 | end
29 | end
30 |
--------------------------------------------------------------------------------
/spec/aws/requests/simpledb/delete_domain_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'SimpleDB.delete_domain' do
4 | describe 'success' do
5 |
6 | before(:each) do
7 | @domain_name = "fog_domain_#{Time.now.to_i}"
8 | end
9 |
10 | before(:each) do
11 | AWS[:sdb].create_domain(@domain_name)
12 | end
13 |
14 | it 'should return proper attributes' do
15 | actual = AWS[:sdb].delete_domain(@domain_name)
16 | actual.body['RequestId'].should be_a(String)
17 | actual.body['BoxUsage'].should be_a(Float)
18 | end
19 |
20 | end
21 | describe 'failure' do
22 |
23 | it 'should not raise an error if the domain does not exist' do
24 | AWS[:sdb].delete_domain('notadomain')
25 | end
26 |
27 | end
28 | end
29 |
--------------------------------------------------------------------------------
/lib/fog/aws/parsers/elb/deregister_instances_from_load_balancer.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module AWS
4 | module ELB
5 |
6 | class DeregisterInstancesFromLoadBalancer < Fog::Parsers::Base
7 |
8 | def reset
9 | @response = { 'DeregisterInstancesFromLoadBalancerResult' => { 'Instances' => [] }, 'ResponseMetadata' => {} }
10 | end
11 |
12 | def end_element(name)
13 | case name
14 | when 'InstanceId'
15 | @response['DeregisterInstancesFromLoadBalancerResult']['Instances'] << {name => @value}
16 | when 'RequestId'
17 | @response['ResponseMetadata'][name] = @value
18 | end
19 | end
20 |
21 | end
22 |
23 | end
24 | end
25 | end
26 | end
27 |
--------------------------------------------------------------------------------
/lib/fog/rackspace/requests/files/put_container.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Rackspace
3 | module Files
4 | class Real
5 |
6 | # Create a new container
7 | #
8 | # ==== Parameters
9 | # * name<~String> - Name for container, should be < 256 bytes and must not contain '/'
10 | #
11 | def put_container(name)
12 | response = storage_request(
13 | :expects => [201, 202],
14 | :method => 'PUT',
15 | :path => CGI.escape(name)
16 | )
17 | response
18 | end
19 |
20 | end
21 |
22 | class Mock
23 |
24 | def put_container(name)
25 | raise MockNotImplemented.new("Contributions welcome!")
26 | end
27 |
28 | end
29 | end
30 | end
31 | end
32 |
--------------------------------------------------------------------------------
/lib/fog/terremark/parsers/shared/get_public_ips.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module Terremark
4 | module Shared
5 |
6 | class GetPublicIps< Fog::Parsers::Base
7 |
8 | def reset
9 | @ip_address = {}
10 | @response = { 'PublicIpAddresses' => [] }
11 | end
12 |
13 | def end_element(name)
14 | case name
15 | when 'Href', 'Name'
16 | @ip_address[name.downcase] = @value
17 | when 'Id'
18 | @ip_address['id'] = @value.to_i
19 | when 'PublicIPAddress'
20 | @response['PublicIpAddresses'] << @ip_address
21 | @ip_address = {}
22 | end
23 | end
24 |
25 | end
26 |
27 | end
28 | end
29 | end
30 | end
31 |
--------------------------------------------------------------------------------
/lib/fog/aws/parsers/elb/disable_availability_zones_for_load_balancer.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module AWS
4 | module ELB
5 |
6 | class DisableAvailabilityZonesForLoadBalancer < Fog::Parsers::Base
7 |
8 | def reset
9 | @response = { 'DisableAvailabilityZonesForLoadBalancerResult' => { 'AvailabilityZones' => [] }, 'ResponseMetadata' => {} }
10 | end
11 |
12 | def end_element(name)
13 | case name
14 | when 'member'
15 | @response['DisableAvailabilityZonesForLoadBalancerResult']['AvailabilityZones'] << @value
16 | when 'RequestId'
17 | @response['ResponseMetadata'][name] = @value
18 | end
19 | end
20 |
21 | end
22 |
23 | end
24 | end
25 | end
26 | end
27 |
--------------------------------------------------------------------------------
/lib/fog/aws/parsers/elb/enable_availability_zones_for_load_balancer.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module AWS
4 | module ELB
5 |
6 | class EnableAvailabilityZonesForLoadBalancer < Fog::Parsers::Base
7 |
8 | def reset
9 | @response = { 'EnableAvailabilityZonesForLoadBalancerResult' => { 'AvailabilityZones' => [] }, 'ResponseMetadata' => {} }
10 | end
11 |
12 | def end_element(name)
13 | case name
14 | when 'member'
15 | @response['EnableAvailabilityZonesForLoadBalancerResult']['AvailabilityZones'] << @value
16 | when 'RequestId'
17 | @response['ResponseMetadata'][name] = @value
18 | end
19 | end
20 |
21 | end
22 |
23 | end
24 | end
25 | end
26 | end
27 |
--------------------------------------------------------------------------------
/lib/fog/slicehost/models/flavors.rb:
--------------------------------------------------------------------------------
1 | require 'fog/collection'
2 | require 'fog/slicehost/models/flavor'
3 |
4 | module Fog
5 | module Slicehost
6 |
7 | class Mock
8 | def flavors
9 | Fog::Slicehost::Flavors.new(:connection => self)
10 | end
11 | end
12 |
13 | class Real
14 | def flavors
15 | Fog::Slicehost::Flavors.new(:connection => self)
16 | end
17 | end
18 |
19 | class Flavors < Fog::Collection
20 |
21 | model Fog::Slicehost::Flavor
22 |
23 | def all
24 | data = connection.get_flavors.body['flavors']
25 | load(data)
26 | end
27 |
28 | def get(flavor_id)
29 | connection.get_flavor(flavor_id)
30 | rescue Excon::Errors::Forbidden
31 | nil
32 | end
33 |
34 | end
35 |
36 | end
37 | end
38 |
--------------------------------------------------------------------------------
/lib/fog/webbynode/models/flavors.rb:
--------------------------------------------------------------------------------
1 | require 'fog/collection'
2 | require 'fog/slicehost/models/flavor'
3 |
4 | module Fog
5 | module Webbynode
6 |
7 | class Mock
8 | def flavors
9 | Fog::Webbynode::Flavors.new(:connection => self)
10 | end
11 | end
12 |
13 | class Real
14 | def flavors
15 | Fog::Webbynode::Flavors.new(:connection => self)
16 | end
17 | end
18 |
19 | class Flavors < Fog::Collection
20 |
21 | model Fog::Webbynode::Flavor
22 |
23 | def all
24 | data = connection.get_flavors.body['flavors']
25 | load(data)
26 | end
27 |
28 | def get(flavor_id)
29 | connection.get_flavor(flavor_id)
30 | rescue Excon::Errors::Forbidden
31 | nil
32 | end
33 |
34 | end
35 |
36 | end
37 | end
38 |
--------------------------------------------------------------------------------
/lib/fog/terremark/requests/shared/delete_internet_service.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Terremark
3 | module Shared
4 | module Real
5 |
6 | # Destroy an internet service
7 | #
8 | # ==== Parameters
9 | # * internet_service_id<~Integer> - Id of service to destroy
10 | #
11 | def delete_internet_service(internet_service_id)
12 | request(
13 | :expects => 200,
14 | :method => 'DELETE',
15 | :path => "InternetServices/#{internet_service_id}"
16 | )
17 | end
18 |
19 | end
20 |
21 | module Mock
22 |
23 | def delete_internet_service(internet_service_id)
24 | raise MockNotImplemented.new("Contributions welcome!")
25 | end
26 |
27 | end
28 | end
29 | end
30 | end
31 |
--------------------------------------------------------------------------------
/lib/fog/rackspace/requests/servers/list_flavors.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Rackspace
3 | module Servers
4 | class Real
5 |
6 | # List all flavors (IDs and names only)
7 | #
8 | # ==== Returns
9 | # * response<~Excon::Response>:
10 | # * body<~Hash>:
11 | # * 'id'<~Integer> - Id of the flavor
12 | # * 'name'<~String> - Name of the flavor
13 | def list_flavors
14 | request(
15 | :expects => [200, 203],
16 | :method => 'GET',
17 | :path => 'flavors.json'
18 | )
19 | end
20 |
21 | end
22 |
23 | class Mock
24 |
25 | def list_flavors
26 | raise MockNotImplemented.new("Contributions welcome!")
27 | end
28 |
29 | end
30 | end
31 | end
32 | end
33 |
--------------------------------------------------------------------------------
/spec/aws/requests/simpledb/create_domain_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'SimpleDB.create_domain' do
4 | before(:each) do
5 | @domain_name = "fog_domain_#{Time.now.to_i}"
6 | end
7 |
8 | after(:each) do
9 | AWS[:sdb].delete_domain(@domain_name)
10 | end
11 |
12 | describe 'success' do
13 |
14 | it 'should return proper attributes' do
15 | actual = AWS[:sdb].create_domain(@domain_name)
16 | actual.body['RequestId'].should be_a(String)
17 | actual.body['BoxUsage'].should be_a(Float)
18 | end
19 |
20 | end
21 | describe 'failure' do
22 |
23 | it 'should not raise an error if the domain already exists' do
24 | AWS[:sdb].create_domain(@domain_name)
25 | AWS[:sdb].create_domain(@domain_name)
26 | end
27 |
28 | end
29 | end
30 |
--------------------------------------------------------------------------------
/lib/fog/aws/models/ec2/key_pair.rb:
--------------------------------------------------------------------------------
1 | require 'fog/model'
2 |
3 | module Fog
4 | module AWS
5 | module EC2
6 |
7 | class KeyPair < Fog::Model
8 |
9 | identity :name, 'keyName'
10 |
11 | attribute :fingerprint, 'keyFingerprint'
12 | attribute :material, 'keyMaterial'
13 |
14 | def destroy
15 | requires :name
16 |
17 | connection.delete_key_pair(@name)
18 | true
19 | end
20 |
21 | def save
22 | requires :name
23 |
24 | data = connection.create_key_pair(@name).body
25 | new_attributes = data.reject {|key,value| !['keyFingerprint', 'keyMaterial', 'keyName'].include?(key)}
26 | merge_attributes(new_attributes)
27 | true
28 | end
29 |
30 | end
31 |
32 | end
33 | end
34 | end
35 |
--------------------------------------------------------------------------------
/lib/fog/slicehost/requests/get_images.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Slicehost
3 | class Real
4 |
5 | require 'fog/slicehost/parsers/get_images'
6 |
7 | # Get list of images
8 | #
9 | # ==== Returns
10 | # * response<~Excon::Response>:
11 | # * body<~Array>:
12 | # * 'id'<~Integer> - Id of the image
13 | # * 'name'<~String> - Name of the image
14 | def get_images
15 | request(
16 | :expects => 200,
17 | :method => 'GET',
18 | :parser => Fog::Parsers::Slicehost::GetImages.new,
19 | :path => 'images.xml'
20 | )
21 | end
22 |
23 | end
24 |
25 | class Mock
26 |
27 | def get_images
28 | raise MockNotImplemented.new("Contributions welcome!")
29 | end
30 |
31 | end
32 | end
33 | end
34 |
--------------------------------------------------------------------------------
/lib/fog/terremark/parsers/shared/node_service.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module Terremark
4 | module Shared
5 |
6 | class NodeService < Fog::Parsers::Base
7 |
8 | def reset
9 | @response = {}
10 | end
11 |
12 | def end_element(name)
13 | case name
14 | when 'Description', 'Href', 'IpAddress', 'Name', 'Protocol'
15 | @response[name] = @value
16 | when 'Enabled'
17 | if @value == 'false'
18 | @response[name] = false
19 | else
20 | @response[name] = true
21 | end
22 | when 'Id', 'Port'
23 | @response[name] = @value.to_i
24 | end
25 | end
26 |
27 | end
28 |
29 | end
30 | end
31 | end
32 | end
33 |
--------------------------------------------------------------------------------
/lib/fog/aws/parsers/ec2/describe_availability_zones.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module AWS
4 | module EC2
5 |
6 | class DescribeAvailabilityZones < Fog::Parsers::Base
7 |
8 | def reset
9 | @availability_zone = {}
10 | @response = { 'availabilityZoneInfo' => [] }
11 | end
12 |
13 | def end_element(name)
14 | case name
15 | when 'item'
16 | @response['availabilityZoneInfo'] << @availability_zone
17 | @availability_zone = {}
18 | when 'regionName', 'zoneName', 'zoneState'
19 | @availability_zone[name] = @value
20 | when 'requestId'
21 | @response[name] = @value
22 | end
23 | end
24 |
25 | end
26 |
27 | end
28 | end
29 | end
30 | end
--------------------------------------------------------------------------------
/lib/fog/aws/parsers/s3/get_service.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module AWS
4 | module S3
5 |
6 | class GetService < Fog::Parsers::Base
7 |
8 | def reset
9 | @bucket = {}
10 | @response = { 'Owner' => {}, 'Buckets' => [] }
11 | end
12 |
13 | def end_element(name)
14 | case name
15 | when 'Bucket'
16 | @response['Buckets'] << @bucket
17 | @bucket = {}
18 | when 'CreationDate'
19 | @bucket['CreationDate'] = Time.parse(@value)
20 | when 'DisplayName', 'ID'
21 | @response['Owner'][name] = @value
22 | when 'Name'
23 | @bucket[name] = @value
24 | end
25 | end
26 |
27 | end
28 |
29 | end
30 | end
31 | end
32 | end
33 |
--------------------------------------------------------------------------------
/spec/aws/requests/s3/put_request_payment_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'S3.put_request_payment' do
4 | describe 'success' do
5 |
6 | before(:each) do
7 | AWS[:s3].put_bucket('fogputrequestpayment')
8 | end
9 |
10 | after(:each) do
11 | AWS[:s3].delete_bucket('fogputrequestpayment')
12 | end
13 |
14 | it 'should return proper attributes' do
15 | actual = AWS[:s3].put_request_payment('fogputrequestpayment', 'Requester')
16 | actual.status.should == 200
17 | end
18 |
19 | end
20 | describe 'failure' do
21 |
22 | it 'should raise a NotFound error if bucket does not exist' do
23 | lambda {
24 | AWS[:s3].put_request_payment('fognotabucket', 'Requester')
25 | }.should raise_error(Excon::Errors::NotFound)
26 | end
27 |
28 | end
29 | end
30 |
--------------------------------------------------------------------------------
/tests/slicehost/requests/get_slice_tests.rb:
--------------------------------------------------------------------------------
1 | Shindo.tests('Slicehost#get_slice', 'slicehost') do
2 | tests('success') do
3 |
4 | before do
5 | @data = Slicehost[:slices].create_slice(1, 3, 'foggetslice').body
6 | @id = @data['id']
7 | @data = Slicehost[:slices].get_slice(@id).body
8 | end
9 |
10 | after do
11 | Fog.wait_for { Slicehost[:slices].get_slice(@id).body['status'] == 'active' }
12 | Slicehost[:slices].delete_slice(@id)
13 | end
14 |
15 | test('has proper output format') do
16 | has_format(@data, Slicehost::Formats::SLICE)
17 | end
18 |
19 | end
20 |
21 | tests('failure') do
22 |
23 | test('raises Forbidden error if flavor does not exist') do
24 | has_error(Excon::Errors::Forbidden)
25 | Slicehost[:slices].get_slice(0)
26 | end
27 | end
28 |
29 | end
30 | end
31 |
--------------------------------------------------------------------------------
/lib/fog/rackspace/requests/files/delete_object.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Rackspace
3 | module Files
4 | class Real
5 |
6 | # Delete an existing container
7 | #
8 | # ==== Parameters
9 | # * container<~String> - Name of container to delete
10 | # * object<~String> - Name of object to delete
11 | #
12 | def delete_object(container, object)
13 | response = storage_request(
14 | :expects => 204,
15 | :method => 'DELETE',
16 | :path => "#{CGI.escape(container)}/#{CGI.escape(object)}"
17 | )
18 | response
19 | end
20 |
21 | end
22 |
23 | class Mock
24 |
25 | def delete_object(container, object)
26 | raise MockNotImplemented.new("Contributions welcome!")
27 | end
28 |
29 | end
30 | end
31 | end
32 | end
33 |
--------------------------------------------------------------------------------
/lib/fog/rackspace/requests/files/head_object.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Rackspace
3 | module Files
4 | class Real
5 |
6 | # Get headers for object
7 | #
8 | # ==== Parameters
9 | # * container<~String> - Name of container to look in
10 | # * object<~String> - Name of object to look for
11 | #
12 | def head_object(container, object)
13 | response = storage_request({
14 | :expects => 200,
15 | :method => 'GET',
16 | :path => "#{CGI.escape(container)}/#{CGI.escape(object)}"
17 | }, false)
18 | response
19 | end
20 |
21 | end
22 |
23 | class Mock
24 |
25 | def head_object(container, object)
26 | raise MockNotImplemented.new("Contributions welcome!")
27 | end
28 |
29 | end
30 | end
31 | end
32 | end
33 |
--------------------------------------------------------------------------------
/lib/fog/webbynode/requests/get_images.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Webbynode
3 | class Real
4 |
5 | require 'fog/webbynode/parsers/get_images'
6 |
7 | # Get list of images
8 | #
9 | # ==== Returns
10 | # * response<~Excon::Response>:
11 | # * body<~Array>:
12 | # * 'id'<~Integer> - Id of the image
13 | # * 'name'<~String> - Name of the image
14 | # * 'image'<~String> - Image identifier
15 | def get_images
16 | request(
17 | :expects => 200,
18 | :method => 'POST',
19 | :parser => Fog::Parsers::Webbynode::GetImages.new,
20 | :path => 'images'
21 | )
22 | end
23 | end
24 |
25 | class Mock
26 |
27 | def get_images
28 | raise MockNotImplemented.new("Contributions welcome!")
29 | end
30 |
31 | end
32 | end
33 | end
34 |
--------------------------------------------------------------------------------
/spec/vcloud/bin_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe Vcloud do
4 | it { should be_initialized }
5 |
6 | it { should have(2).services }
7 |
8 | describe "#registered_services" do
9 | subject { Vcloud.registered_services }
10 |
11 | it { should == ":ecloud, :vcloud" }
12 | end
13 |
14 | describe "when indexing it like an array" do
15 | describe "with a service that exists" do
16 | before do
17 | Fog::Vcloud.should_receive(:new).and_return(true)
18 | end
19 | it "should return something when indexed with a configured service" do
20 | Vcloud[:ecloud].should_not be_nil
21 | end
22 | end
23 |
24 | describe "with a service that does not exist" do
25 | it "should raise an ArgumentError" do
26 | lambda {Vcloud[:foozle]}.should raise_error(ArgumentError)
27 | end
28 | end
29 |
30 | end
31 | end
32 |
--------------------------------------------------------------------------------
/spec/aws/requests/ec2/delete_security_group_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'EC2.delete_security_group' do
4 | describe 'success' do
5 |
6 | before(:each) do
7 | AWS[:ec2].create_security_group('fog_security_group', 'a security group for testing fog')
8 | end
9 |
10 | it "should return proper attributes" do
11 | actual = AWS[:ec2].delete_security_group('fog_security_group')
12 | actual.body['requestId'].should be_a(String)
13 | [false, true].should include(actual.body['return'])
14 | end
15 |
16 | end
17 | describe 'failure' do
18 |
19 | it "should raise a BadRequest error if the security group does not exist" do
20 | lambda {
21 | AWS[:ec2].delete_security_group('fog_not_a_security_group')
22 | }.should raise_error(Excon::Errors::BadRequest)
23 | end
24 |
25 | end
26 | end
27 |
--------------------------------------------------------------------------------
/spec/aws/requests/s3/get_request_payment_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'S3.get_request_payment' do
4 | describe 'success' do
5 |
6 | before(:each) do
7 | AWS[:s3].put_bucket('foggetrequestpayment')
8 | end
9 |
10 | after(:each) do
11 | AWS[:s3].delete_bucket('foggetrequestpayment')
12 | end
13 |
14 | it 'should return proper attributes' do
15 | actual = AWS[:s3].get_request_payment('foggetrequestpayment')
16 | actual.status.should == 200
17 | actual.body['Payer'].should == 'BucketOwner'
18 | end
19 |
20 | end
21 | describe 'failure' do
22 |
23 | it 'should raise a NotFound error if the bucket does not exist' do
24 | lambda {
25 | AWS[:s3].get_request_payment('fognotabucket')
26 | }.should raise_error(Excon::Errors::NotFound)
27 | end
28 |
29 | end
30 | end
31 |
--------------------------------------------------------------------------------
/tests/rackspace/requests/servers/create_image_tests.rb:
--------------------------------------------------------------------------------
1 | Shindo.tests('Rackspace::Servers#create_image', 'rackspace') do
2 | tests('success') do
3 |
4 | before do
5 | @server_id = Rackspace[:servers].create_server(1, 3, 'fogcreateimage').body['server']['id']
6 | Fog.wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
7 | @data = Rackspace[:servers].create_image(@server_id).body['image']
8 | @image_id = @data['id']
9 | end
10 |
11 | after do
12 | Rackspace[:servers].delete_server(@server_id)
13 | Fog.wait_for { Rackspace[:servers].get_image_details(@image_id).body['image']['status'] == 'ACTIVE' }
14 | Rackspace[:servers].delete_image(@image_id)
15 | end
16 |
17 | test('has proper output format') do
18 | has_format(@data, Rackspace::Servers::Formats::IMAGE)
19 | end
20 |
21 | end
22 | end
23 |
--------------------------------------------------------------------------------
/lib/fog/slicehost/parsers/get_slices.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module Slicehost
4 |
5 | class GetSlices < Fog::Parsers::Base
6 |
7 | def reset
8 | @slice = {}
9 | @response = { 'slices' => [] }
10 | end
11 |
12 | def end_element(name)
13 | case name
14 | when 'address'
15 | @slice['addresses'] ||= []
16 | @slice['addresses'] << @value
17 | when 'backup-id', 'flavor-id', 'id', 'image-id', 'progress'
18 | @slice[name] = @value.to_i
19 | when 'bw-in', 'bw-out'
20 | @slice[name] = @value.to_f
21 | when 'name', 'status'
22 | @slice[name] = @value
23 | when 'slice'
24 | @response['slices'] << @slice
25 | @slice = {}
26 | end
27 | end
28 |
29 | end
30 |
31 | end
32 | end
33 | end
34 |
--------------------------------------------------------------------------------
/lib/fog/webbynode/requests/reboot_webby.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Webbynode
3 | class Real
4 |
5 | require 'fog/webbynode/parsers/get_job'
6 |
7 | # Reboot Webby
8 | # ==== Parameters
9 | # * slice_id<~Integer> - Id of server to reboot
10 | #
11 | # ==== Returns
12 | # * response<~Excon::Response>:
13 | # * body<~Hash>:
14 | # * 'job-id'<~String> - Id of the rebooting job
15 | def reboot_webby(webby_id)
16 | request(
17 | :expects => 200,
18 | :method => 'POST',
19 | :parser => Fog::Parsers::Webbynode::GetJob.new,
20 | :path => "webby/#{webby_id}/reboot"
21 | )
22 | end
23 |
24 | end
25 |
26 | class Mock
27 |
28 | def reboot_webby(id)
29 | raise MockNotImplemented.new("Contributions welcome!")
30 | end
31 |
32 | end
33 | end
34 | end
35 |
--------------------------------------------------------------------------------
/spec/aws/requests/ec2/describe_availability_zones_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'EC2.describe_availability_zones' do
4 | describe 'success' do
5 |
6 | it "should return proper attributes with no params" do
7 | actual = AWS[:ec2].describe_availability_zones
8 | zone = actual.body['availabilityZoneInfo'].first
9 | zone['regionName'].should be_a(String)
10 | zone['zoneName'].should be_a(String)
11 | zone['zoneState'].should be_a(String)
12 | end
13 |
14 | it "should return proper attribute with params" do
15 | actual = AWS[:ec2].describe_availability_zones(['us-east-1a'])
16 | zone = actual.body['availabilityZoneInfo'].first
17 | zone['regionName'].should be_a(String)
18 | zone['zoneName'].should be_a(String)
19 | zone['zoneState'].should be_a(String)
20 | end
21 |
22 | end
23 | end
24 |
--------------------------------------------------------------------------------
/spec/aws/requests/s3/get_bucket_location_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'S3.get_bucket_location' do
4 | describe 'success' do
5 |
6 | before(:each) do
7 | AWS[:s3].put_bucket('foggetlocation', 'LocationConstraint' => 'EU')
8 | end
9 |
10 | after(:each) do
11 | AWS[:eu_s3].delete_bucket('foggetlocation')
12 | end
13 |
14 | it 'should return proper attributes' do
15 | actual = AWS[:s3].get_bucket_location('foggetlocation')
16 | actual.status.should == 200
17 | actual.body['LocationConstraint'].should == 'EU'
18 | end
19 |
20 | end
21 | describe 'failure' do
22 |
23 | it 'should raise NotFound error if bucket does not exist' do
24 | lambda {
25 | AWS[:s3].get_bucket_location('fognotabucket')
26 | }.should raise_error(Excon::Errors::NotFound)
27 | end
28 |
29 | end
30 | end
31 |
--------------------------------------------------------------------------------
/spec/aws/requests/s3/head_object_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'S3.head_object' do
4 | describe 'success' do
5 |
6 | before(:each) do
7 | AWS[:s3].put_bucket('fogheadobject')
8 | AWS[:s3].put_object('fogheadobject', 'fog_head_object', lorem_file)
9 | end
10 |
11 | after(:each) do
12 | AWS[:s3].delete_object('fogheadobject', 'fog_head_object')
13 | AWS[:s3].delete_bucket('fogheadobject')
14 | end
15 |
16 | it 'should return proper attributes' do
17 | actual = AWS[:s3].head_object('fogheadobject', 'fog_head_object')
18 | actual.status.should == 200
19 | data = lorem_file.read
20 | actual.headers['Content-Length'].should == data.length.to_s
21 | actual.headers['ETag'].should be_a(String)
22 | actual.headers['Last-Modified'].should be_a(String)
23 | end
24 |
25 | end
26 | end
27 |
--------------------------------------------------------------------------------
/lib/fog/slicehost/models/flavor.rb:
--------------------------------------------------------------------------------
1 | require 'fog/model'
2 |
3 | module Fog
4 | module Slicehost
5 |
6 | class Flavor < Fog::Model
7 |
8 | identity :id
9 |
10 | attribute :name
11 | attribute :price
12 | attribute :ram
13 |
14 | def bits
15 | # 64
16 | raise StandardError.new("Figure me out!?!")
17 | end
18 |
19 | def cores
20 | # # 2 quad-cores >= 2Ghz = 8 cores
21 | # 8 * case ram
22 | # when 256
23 | # 1/64.0
24 | # when 512
25 | # 1/32.0
26 | # when 1024
27 | # 1/16.0
28 | # when 2048
29 | # 1/8.0
30 | # when 4096
31 | # 1/4.0
32 | # when 8192
33 | # 1/2.0
34 | # when 15872
35 | # 1
36 | # end
37 | raise StandardError.new("Figure me out!?!")
38 | end
39 |
40 | end
41 |
42 | end
43 | end
44 |
--------------------------------------------------------------------------------
/lib/fog/webbynode/models/flavor.rb:
--------------------------------------------------------------------------------
1 | require 'fog/model'
2 |
3 | module Fog
4 | module Webbynode
5 |
6 | class Flavor < Fog::Model
7 |
8 | identity :id
9 |
10 | attribute :name
11 | attribute :price
12 | attribute :ram
13 |
14 | def bits
15 | # 64
16 | raise StandardError.new("Figure me out!?!")
17 | end
18 |
19 | def cores
20 | # # 2 quad-cores >= 2Ghz = 8 cores
21 | # 8 * case ram
22 | # when 256
23 | # 1/64.0
24 | # when 512
25 | # 1/32.0
26 | # when 1024
27 | # 1/16.0
28 | # when 2048
29 | # 1/8.0
30 | # when 4096
31 | # 1/4.0
32 | # when 8192
33 | # 1/2.0
34 | # when 15872
35 | # 1
36 | # end
37 | raise StandardError.new("Figure me out!?!")
38 | end
39 |
40 | end
41 |
42 | end
43 | end
44 |
--------------------------------------------------------------------------------
/spec/aws/requests/simpledb/list_domains_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'SimpleDB.list_domains' do
4 | describe 'success' do
5 |
6 | before(:each) do
7 | @domain_name = "fog_domain_#{Time.now.to_i}"
8 | end
9 |
10 | after(:each) do
11 | AWS[:sdb].delete_domain(@domain_name)
12 | end
13 |
14 | it 'should return proper attributes' do
15 | results = AWS[:sdb].list_domains
16 | results.body['BoxUsage'].should be_a(Float)
17 | results.body['Domains'].should be_an(Array)
18 | results.body['RequestId'].should be_a(String)
19 | end
20 |
21 | it 'should include created domains' do
22 | AWS[:sdb].create_domain(@domain_name)
23 | eventually do
24 | actual = AWS[:sdb].list_domains
25 | actual.body['Domains'].should include(@domain_name)
26 | end
27 | end
28 |
29 | end
30 | end
31 |
--------------------------------------------------------------------------------
/lib/fog/rackspace/requests/servers/reboot_server.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Rackspace
3 | module Servers
4 | class Real
5 |
6 | # Reboot an existing server
7 | #
8 | # ==== Parameters
9 | # * server_id<~Integer> - Id of server to reboot
10 | # * type<~String> - Type of reboot, must be in ['HARD', 'SOFT']
11 | #
12 | def reboot_server(server_id, type = 'SOFT')
13 | request(
14 | :body => { 'reboot' => { 'type' => type }}.to_json,
15 | :expects => 202,
16 | :method => 'POST',
17 | :path => "servers/#{server_id}/action.json"
18 | )
19 | end
20 |
21 | end
22 |
23 | class Mock
24 |
25 | def reboot_server(server_id, type)
26 | raise MockNotImplemented.new("Contributions welcome!")
27 | end
28 |
29 | end
30 | end
31 | end
32 | end
33 |
--------------------------------------------------------------------------------
/lib/fog/rackspace/models/servers/flavor.rb:
--------------------------------------------------------------------------------
1 | require 'fog/model'
2 |
3 | module Fog
4 | module Rackspace
5 | module Servers
6 |
7 | class Flavor < Fog::Model
8 |
9 | identity :id
10 |
11 | attribute :bits
12 | attribute :cores
13 | attribute :disk
14 | attribute :name
15 | attribute :ram
16 |
17 | def bits
18 | 64
19 | end
20 |
21 | def cores
22 | # 2 quad-cores >= 2Ghz = 8 cores
23 | 8 * case ram
24 | when 256
25 | 1/64.0
26 | when 512
27 | 1/32.0
28 | when 1024
29 | 1/16.0
30 | when 2048
31 | 1/8.0
32 | when 4096
33 | 1/4.0
34 | when 8192
35 | 1/2.0
36 | when 15872
37 | 1
38 | end
39 | end
40 |
41 | end
42 |
43 | end
44 | end
45 | end
46 |
--------------------------------------------------------------------------------
/lib/fog/slicehost/bin.rb:
--------------------------------------------------------------------------------
1 | module Slicehost
2 | class << self
3 | if Fog.credentials[:slicehost_password]
4 |
5 | def initialized?
6 | true
7 | end
8 |
9 | def [](service)
10 | @@connections ||= Hash.new do |hash, key|
11 | credentials = Fog.credentials.reject do |k,v|
12 | ![:slicehost_password].include?(k)
13 | end
14 | hash[key] = case key
15 | when :slices
16 | Fog::Slicehost.new(credentials)
17 | end
18 | end
19 | @@connections[service]
20 | end
21 |
22 | def flavors
23 | self[:slices].flavors
24 | end
25 |
26 | def images
27 | self[:slices].images
28 | end
29 |
30 | def servers
31 | self[:slices].servers
32 | end
33 |
34 | else
35 |
36 | def initialized?
37 | false
38 | end
39 |
40 | end
41 | end
42 | end
43 |
--------------------------------------------------------------------------------
/lib/fog/rackspace/requests/files/get_object.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Rackspace
3 | module Files
4 | class Real
5 |
6 | # Get details for object
7 | #
8 | # ==== Parameters
9 | # * container<~String> - Name of container to look in
10 | # * object<~String> - Name of object to look for
11 | #
12 | def get_object(container, object, &block)
13 | response = storage_request({
14 | :block => block,
15 | :expects => 200,
16 | :method => 'GET',
17 | :path => "#{CGI.escape(container)}/#{CGI.escape(object)}"
18 | }, false, &block)
19 | response
20 | end
21 |
22 | end
23 |
24 | class Mock
25 |
26 | def get_object(container, object)
27 | raise MockNotImplemented.new("Contributions welcome!")
28 | end
29 |
30 | end
31 | end
32 | end
33 | end
34 |
--------------------------------------------------------------------------------
/lib/fog/slicehost/models/servers.rb:
--------------------------------------------------------------------------------
1 | require 'fog/collection'
2 | require 'fog/slicehost/models/server'
3 |
4 | module Fog
5 | module Slicehost
6 |
7 | class Mock
8 | def servers
9 | Fog::Slicehost::Servers.new(:connection => self)
10 | end
11 | end
12 |
13 | class Real
14 | def servers
15 | Fog::Slicehost::Servers.new(:connection => self)
16 | end
17 | end
18 |
19 | class Servers < Fog::Collection
20 |
21 | model Fog::Slicehost::Server
22 |
23 | def all
24 | data = connection.get_slices.body['slices']
25 | load(data)
26 | end
27 |
28 | def get(server_id)
29 | if server_id && server = connection.get_slice(server_id).body
30 | new(server)
31 | elsif !server_id
32 | nil
33 | end
34 | rescue Excon::Errors::Forbidden
35 | nil
36 | end
37 |
38 | end
39 |
40 | end
41 | end
42 |
--------------------------------------------------------------------------------
/lib/fog/webbynode/models/servers.rb:
--------------------------------------------------------------------------------
1 | require 'fog/collection'
2 | require 'fog/slicehost/models/server'
3 |
4 | module Fog
5 | module Webbynode
6 |
7 | class Mock
8 | def servers
9 | Fog::Webbynode::Servers.new(:connection => self)
10 | end
11 | end
12 |
13 | class Real
14 | def servers
15 | Fog::Webbynode::Servers.new(:connection => self)
16 | end
17 | end
18 |
19 | class Servers < Fog::Collection
20 |
21 | model Fog::Webbynode::Server
22 |
23 | def all
24 | data = connection.get_webbies.body['webbies']
25 | load(data)
26 | end
27 |
28 | def get(server_id)
29 | if server_id && server = connection.get_webby(server_id).body
30 | new(server)
31 | elsif !server_id
32 | nil
33 | end
34 | rescue Excon::Errors::Forbidden
35 | nil
36 | end
37 |
38 | end
39 |
40 | end
41 | end
42 |
--------------------------------------------------------------------------------
/spec/shared_examples/servers_examples.rb:
--------------------------------------------------------------------------------
1 | shared_examples_for "Servers" do
2 |
3 | describe "#all" do
4 |
5 | it "should include persisted servers" do
6 | subject.save
7 | @servers.all.map {|server| server.id}.should include(subject.id)
8 | end
9 |
10 | end
11 |
12 | describe "#get" do
13 |
14 | it "should return a matching server if one exists" do
15 | subject.save
16 | get = @servers.get(subject.id)
17 | subject.attributes.should == get.attributes
18 | end
19 |
20 | it "should return nil if no matching server exists" do
21 | @servers.get('0').should be_nil
22 | end
23 |
24 | end
25 |
26 | describe "#reload" do
27 |
28 | it "should reset attributes to remote state" do
29 | subject.save
30 | servers = @servers.all
31 | reloaded = servers.reload
32 | servers.attributes.should == reloaded.attributes
33 | end
34 |
35 | end
36 |
37 | end
38 |
--------------------------------------------------------------------------------
/lib/fog/slicehost/models/images.rb:
--------------------------------------------------------------------------------
1 | require 'fog/collection'
2 | require 'fog/slicehost/models/image'
3 |
4 | module Fog
5 | module Slicehost
6 |
7 | class Mock
8 | def images(attributes = {})
9 | Fog::Slicehost::Images.new({
10 | :connection => self
11 | }.merge!(attributes))
12 | end
13 | end
14 |
15 | class Real
16 | def images(attributes = {})
17 | Fog::Slicehost::Images.new({
18 | :connection => self
19 | }.merge!(attributes))
20 | end
21 | end
22 |
23 | class Images < Fog::Collection
24 |
25 | model Fog::Slicehost::Image
26 |
27 | def all
28 | data = connection.get_images.body['images']
29 | load(data)
30 | end
31 |
32 | def get(image_id)
33 | connection.get_image(image_id)
34 | rescue Excon::Errors::Forbidden
35 | nil
36 | end
37 |
38 | end
39 |
40 | end
41 | end
42 |
--------------------------------------------------------------------------------
/lib/fog/webbynode/models/images.rb:
--------------------------------------------------------------------------------
1 | require 'fog/collection'
2 | require 'fog/webbynode/models/image'
3 |
4 | module Fog
5 | module Webbynode
6 |
7 | class Mock
8 | def images(attributes = {})
9 | Fog::Webbynode::Images.new({
10 | :connection => self
11 | }.merge!(attributes))
12 | end
13 | end
14 |
15 | class Real
16 | def images(attributes = {})
17 | Fog::Webbynode::Images.new({
18 | :connection => self
19 | }.merge!(attributes))
20 | end
21 | end
22 |
23 | class Images < Fog::Collection
24 |
25 | model Fog::Webbynode::Image
26 |
27 | def all
28 | data = connection.get_images.body['images']
29 | load(data)
30 | end
31 |
32 | def get(image_id)
33 | connection.get_image(image_id)
34 | rescue Excon::Errors::Forbidden
35 | nil
36 | end
37 |
38 | end
39 |
40 | end
41 | end
42 |
--------------------------------------------------------------------------------
/lib/fog/aws/parsers/elb/describe_instance_health.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module AWS
4 | module ELB
5 |
6 | class DescribeInstanceHealth < Fog::Parsers::Base
7 |
8 | def reset
9 | @response = { 'DescribeInstanceHealthResult' => { 'InstanceStates' => [] }, 'ResponseMetadata' => {} }
10 | @instance_state = {}
11 | end
12 |
13 | def end_element(name)
14 | case name
15 | when 'Description', 'State', 'InstanceId', 'ReasonCode'
16 | @instance_state[name] = @value
17 | when 'member'
18 | @response['DescribeInstanceHealthResult']['InstanceStates'] << @instance_state
19 | @instance_state = {}
20 | when 'RequestId'
21 | @response['ResponseMetadata'][name] = @value
22 | end
23 | end
24 |
25 | end
26 |
27 | end
28 | end
29 | end
30 | end
31 |
--------------------------------------------------------------------------------
/lib/fog/aws/parsers/simpledb/domain_metadata.rb:
--------------------------------------------------------------------------------
1 | require 'fog/aws/parsers/simpledb/basic'
2 |
3 | module Fog
4 | module Parsers
5 | module AWS
6 | module SimpleDB
7 |
8 | class DomainMetadata < Fog::Parsers::AWS::SimpleDB::Basic
9 |
10 | def reset
11 | @response = {}
12 | end
13 |
14 | def end_element(name)
15 | case name
16 | when 'AttributeNameCount', 'AttributeNamesSizeBytes', 'AttributeValueCount', 'AttributeValuesSizeBytes', 'ItemCount', 'ItemNamesSizeBytes'
17 | response[name] = @value.to_i
18 | when 'BoxUsage'
19 | response[name] = @value.to_f
20 | when 'RequestId'
21 | response[name] = @value
22 | when 'Timestamp'
23 | response[name] = Time.at(@value.to_i)
24 | end
25 | end
26 |
27 | end
28 |
29 | end
30 | end
31 | end
32 | end
--------------------------------------------------------------------------------
/lib/fog/rackspace/models/servers/image.rb:
--------------------------------------------------------------------------------
1 | require 'fog/model'
2 |
3 | module Fog
4 | module Rackspace
5 | module Servers
6 |
7 | class Image < Fog::Model
8 |
9 | identity :id
10 |
11 | attribute :name
12 | attribute :created_at, 'created'
13 | attribute :updated_at, 'updated'
14 | attribute :status
15 | attribute :server_id, 'serverId'
16 |
17 | def server=(new_server)
18 | requires :id
19 |
20 | @server_id = new_server.id
21 | end
22 |
23 | def destroy
24 | requires :id
25 |
26 | connection.delete_image(@id)
27 | true
28 | end
29 |
30 | def save
31 | requires :server_id
32 |
33 | data = connection.create_image(@server_id, 'name' => name)
34 | merge_attributes(data.body['image'])
35 | true
36 | end
37 |
38 | end
39 |
40 | end
41 | end
42 | end
43 |
--------------------------------------------------------------------------------
/lib/fog/rackspace/requests/files/head_containers.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Rackspace
3 | module Files
4 | class Real
5 |
6 | # List number of containers and total bytes stored
7 | #
8 | # ==== Returns
9 | # * response<~Excon::Response>:
10 | # * headers<~Hash>:
11 | # * 'X-Account-Container-Count'<~String> - Count of containers
12 | # * 'X-Account-Bytes-Used'<~String> - Bytes used
13 | def head_containers
14 | response = storage_request(
15 | :expects => 204,
16 | :method => 'HEAD',
17 | :path => '',
18 | :query => 'format=json'
19 | )
20 | response
21 | end
22 |
23 | end
24 |
25 | class Mock
26 |
27 | def head_containers
28 | raise MockNotImplemented.new("Contributions welcome!")
29 | end
30 |
31 | end
32 | end
33 | end
34 | end
35 |
--------------------------------------------------------------------------------
/spec/aws/requests/ec2/reboot_instances_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'EC2.reboot_instances' do
4 | describe 'success' do
5 |
6 | before(:each) do
7 | @instance_id = AWS[:ec2].run_instances(GENTOO_AMI, 1, 1).body['instancesSet'].first['instanceId']
8 | end
9 |
10 | after(:each) do
11 | AWS[:ec2].terminate_instances(@instance_id)
12 | end
13 |
14 | it "should return proper attributes" do
15 | actual = AWS[:ec2].reboot_instances(@instance_id)
16 | actual.body['requestId'].should be_a(String)
17 | [false, true].should include(actual.body['return'])
18 | end
19 |
20 | end
21 | describe 'failure' do
22 |
23 | it "should raise a BadRequest error if the instance does not exist" do
24 | lambda {
25 | AWS[:ec2].reboot_instances('i-00000000')
26 | }.should raise_error(Excon::Errors::BadRequest)
27 | end
28 |
29 | end
30 | end
31 |
--------------------------------------------------------------------------------
/tests/rackspace/requests/servers/list_public_addresses_tests.rb:
--------------------------------------------------------------------------------
1 | Shindo.tests('Rackspace::Servers#list_public_addresses', 'rackspace') do
2 | tests('success') do
3 |
4 | before do
5 | @server_id = Rackspace[:servers].create_server(1, 3, 'foglistpublicaddresses').body['server']['id']
6 | @data = Rackspace[:servers].list_public_addresses(@server_id).body
7 | end
8 |
9 | after do
10 | Fog.wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
11 | Rackspace[:servers].delete_server(@server_id)
12 | end
13 |
14 | test('has proper output format') do
15 | has_format(@data, [String])
16 | end
17 |
18 | end
19 | tests('failure') do
20 |
21 | test('raises NotFound error if server does not exist') do
22 | has_error(Excon::Errors::NotFound) do
23 | Rackspace[:servers].list_public_addresses(0)
24 | end
25 | end
26 |
27 | end
28 |
29 | end
30 |
--------------------------------------------------------------------------------
/lib/fog/vcloud/parsers/get_vdc.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module Vcloud
4 |
5 | class GetVdc < Fog::Parsers::Vcloud::Base
6 | #WARNING: Incomplete
7 | #Based off of:
8 | #vCloud API Guide v0.9 - Page 27
9 |
10 | def reset
11 | @response = Struct::VcloudVdc.new([])
12 | end
13 |
14 | def start_element(name, attributes)
15 | @value = ''
16 | case name
17 | when 'Link'
18 | @response.links << generate_link(attributes)
19 | when 'Vdc'
20 | handle_root(attributes)
21 | end
22 | end
23 |
24 | def end_element(name)
25 | case name
26 | when "AllocationModel"
27 | @response.allocation_model = @value
28 | when "Description"
29 | @response.description = @value
30 | end
31 | end
32 |
33 | end
34 |
35 | end
36 | end
37 | end
38 |
--------------------------------------------------------------------------------
/tests/rackspace/requests/servers/list_addresses_tests.rb:
--------------------------------------------------------------------------------
1 | Shindo.tests('Rackspace::Servers#list_addresses', 'rackspace') do
2 | tests('success') do
3 |
4 | before do
5 | @server_id = Rackspace[:servers].create_server(1, 3, 'foglistaddresses').body['server']['id']
6 | @data = Rackspace[:servers].list_addresses(@server_id).body
7 | end
8 |
9 | after do
10 | Fog.wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
11 | Rackspace[:servers].delete_server(@server_id)
12 | end
13 |
14 | test('has proper output format') do
15 | has_format(@data, {'private' => [String], 'public' => [String]})
16 | end
17 |
18 | end
19 | tests('failure') do
20 |
21 | test('raises NotFound error if server does not exist') do
22 | has_error(Excon::Errors::NotFound) do
23 | Rackspace[:servers].list_addresses(0)
24 | end
25 | end
26 |
27 | end
28 |
29 | end
30 |
--------------------------------------------------------------------------------
/tests/rackspace/requests/servers/list_private_addresses_tests.rb:
--------------------------------------------------------------------------------
1 | Shindo.tests('Rackspace::Servers#list_private_addresses', 'rackspace') do
2 | tests('success') do
3 |
4 | before do
5 | @server_id = Rackspace[:servers].create_server(1, 3, 'foglistprivateaddresses').body['server']['id']
6 | @data = Rackspace[:servers].list_private_addresses(@server_id).body
7 | end
8 |
9 | after do
10 | Fog.wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
11 | Rackspace[:servers].delete_server(@server_id)
12 | end
13 |
14 | test('has proper output format') do
15 | has_format(@data, [String])
16 | end
17 |
18 | end
19 | tests('failure') do
20 |
21 | test('raises NotFound error if server does not exist') do
22 | has_error(Excon::Errors::NotFound) do
23 | Rackspace[:servers].list_private_addresses(0)
24 | end
25 | end
26 |
27 | end
28 |
29 | end
30 |
--------------------------------------------------------------------------------
/lib/fog/slicehost/requests/get_flavors.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Slicehost
3 | class Real
4 |
5 | require 'fog/slicehost/parsers/get_flavors'
6 |
7 | # Get list of flavors
8 | #
9 | # ==== Returns
10 | # * response<~Excon::Response>:
11 | # * body<~Array>:
12 | # * 'id'<~Integer> - Id of the flavor
13 | # * 'name'<~String> - Name of the flavor
14 | # * 'price'<~Integer> - Price in cents
15 | # * 'ram'<~Integer> - Amount of ram for the flavor
16 | def get_flavors
17 | request(
18 | :expects => 200,
19 | :method => 'GET',
20 | :parser => Fog::Parsers::Slicehost::GetFlavors.new,
21 | :path => 'flavors.xml'
22 | )
23 | end
24 |
25 | end
26 |
27 | class Mock
28 |
29 | def get_flavors
30 | raise MockNotImplemented.new("Contributions welcome!")
31 | end
32 |
33 | end
34 | end
35 | end
36 |
--------------------------------------------------------------------------------
/tests/slicehost/requests/reboot_slice_tests.rb:
--------------------------------------------------------------------------------
1 | Shindo.tests('Slicehost#reboot_slice', 'slicehost') do
2 | tests('success') do
3 |
4 | before do
5 | @data = Slicehost[:slices].create_slice(1, 3, 'fogrebootslice').body
6 | @id = @data['id']
7 | Fog.wait_for { Slicehost[:slices].get_slice(@id).body['status'] == 'active' }
8 | @data = Slicehost[:slices].reboot_slice(@id).body
9 | end
10 |
11 | after do
12 | Fog.wait_for { Slicehost[:slices].get_slice(@id).body['status'] == 'active' }
13 | Slicehost[:slices].delete_slice(@id)
14 | end
15 |
16 | test('has proper output format') do
17 | has_format(@data, Slicehost::Formats::SLICE)
18 | end
19 |
20 | end
21 |
22 | tests('failure') do
23 |
24 | test('raises Forbidden error if flavor does not exist') do
25 | has_error(Excon::Errors::Forbidden) do
26 | Slicehost[:slices].reboot_slice(0)
27 | end
28 | end
29 |
30 | end
31 | end
32 |
--------------------------------------------------------------------------------
/lib/fog/slicehost/requests/get_image.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Slicehost
3 | class Real
4 |
5 | require 'fog/slicehost/parsers/get_image'
6 |
7 | # Get details of an image
8 | #
9 | # ==== Parameters
10 | # * image_id<~Integer> - Id of image to lookup
11 | #
12 | # ==== Returns
13 | # * response<~Excon::Response>:
14 | # * body<~Array>:
15 | # * 'id'<~Integer> - Id of the image
16 | # * 'name'<~String> - Name of the image
17 | def get_image(image_id)
18 | request(
19 | :expects => 200,
20 | :method => 'GET',
21 | :parser => Fog::Parsers::Slicehost::GetImage.new,
22 | :path => "images/#{image_id}.xml"
23 | )
24 | end
25 |
26 | end
27 |
28 | class Mock
29 |
30 | def get_image(image_id)
31 | raise MockNotImplemented.new("Contributions welcome!")
32 | end
33 |
34 | end
35 | end
36 | end
37 |
--------------------------------------------------------------------------------
/lib/fog/vcloud/parsers/get_organization.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module Vcloud
4 |
5 | class GetOrganization < Fog::Parsers::Vcloud::Base
6 | #
7 | # Based off of:
8 | # http://support.theenterprisecloud.com/kb/default.asp?id=540&Lang=1&SID=
9 | #
10 | # vCloud API Guide v0.9 - Page 26
11 | #
12 |
13 | def reset
14 | @response = Struct::VcloudOrganization.new([])
15 | end
16 |
17 | def start_element(name, attributes)
18 | @value = ''
19 | case name
20 | when 'Link'
21 | @response.links << generate_link(attributes)
22 | when 'Org'
23 | handle_root(attributes)
24 | end
25 | end
26 |
27 | def end_element(name)
28 | if name == 'Description'
29 | @response.description = @value
30 | end
31 | end
32 |
33 | end
34 |
35 | end
36 | end
37 | end
38 |
--------------------------------------------------------------------------------
/tests/rackspace/requests/servers/get_server_details_tests.rb:
--------------------------------------------------------------------------------
1 | Shindo.tests('Rackspace::Servers#get_server_details', 'rackspace') do
2 | tests('success') do
3 |
4 | before do
5 | @server_id = Rackspace[:servers].create_server(1, 3, 'foggetserverdetails').body['server']['id']
6 | @data = Rackspace[:servers].get_server_details(@server_id).body['server']
7 | end
8 |
9 | after do
10 | Fog.wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
11 | Rackspace[:servers].delete_server(@server_id)
12 | end
13 |
14 | test('has proper output format') do
15 | has_format(@data, Rackspace::Servers::Formats::SERVER)
16 | end
17 |
18 | end
19 | tests('failure') do
20 |
21 | test('raises NotFound error if server does not exist') do
22 | has_error(Excon::Errors::NotFound) do
23 | Rackspace[:servers].get_server_details(0)
24 | end
25 | end
26 |
27 | end
28 | end
29 |
--------------------------------------------------------------------------------
/lib/fog/rackspace/requests/servers/list_flavors_detail.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Rackspace
3 | module Servers
4 | class Real
5 |
6 | # List all flavors
7 | #
8 | # ==== Returns
9 | # * response<~Excon::Response>:
10 | # * body<~Hash>:
11 | # * 'id'<~Integer> - Id of the flavor
12 | # * 'name'<~String> - Name of the flavor
13 | # * 'ram'<~Integer> - Amount of ram for the flavor
14 | # * 'disk'<~Integer> - Amount of diskspace for the flavor
15 | def list_flavors_detail
16 | request(
17 | :expects => [200, 203],
18 | :method => 'GET',
19 | :path => 'flavors/detail.json'
20 | )
21 | end
22 |
23 | end
24 |
25 | class Mock
26 |
27 | def list_flavors_detail
28 | raise MockNotImplemented.new("Contributions welcome!")
29 | end
30 |
31 | end
32 | end
33 | end
34 | end
35 |
--------------------------------------------------------------------------------
/lib/fog/aws/parsers/ec2/describe_snapshots.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module AWS
4 | module EC2
5 |
6 | class DescribeSnapshots < Fog::Parsers::Base
7 |
8 | def reset
9 | @response = { 'snapshotSet' => [] }
10 | @snapshot = {}
11 | end
12 |
13 | def end_element(name)
14 | case name
15 | when 'item'
16 | @response['snapshotSet'] << @snapshot
17 | @snapshot = {}
18 | when 'description', 'ownerId', 'progress', 'snapshotId', 'status', 'volumeId'
19 | @snapshot[name] = @value
20 | when 'requestId'
21 | @response[name] = @value
22 | when 'startTime'
23 | @snapshot[name] = Time.parse(@value)
24 | when 'volumeSize'
25 | @snapshot[name] = @value.to_i
26 | end
27 | end
28 |
29 | end
30 |
31 | end
32 | end
33 | end
34 | end
35 |
--------------------------------------------------------------------------------
/lib/fog/slicehost/requests/get_backups.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Slicehost
3 | class Real
4 |
5 | require 'fog/slicehost/parsers/get_backups'
6 |
7 | # Get list of backups
8 | #
9 | # ==== Returns
10 | # * response<~Excon::Response>:
11 | # * body<~Array>:
12 | # * 'date'<~Time> - Timestamp of backup creation
13 | # * 'id'<~Integer> - Id of the backup
14 | # * 'name'<~String> - Name of the backup
15 | # * 'slice-id'<~Integer> - Id of slice the backup was made from
16 | def get_backups
17 | request(
18 | :expects => 200,
19 | :method => 'GET',
20 | :parser => Fog::Parsers::Slicehost::GetBackups.new,
21 | :path => 'backups.xml'
22 | )
23 | end
24 |
25 | end
26 |
27 | class Mock
28 |
29 | def get_backups
30 | raise MockNotImplemented.new("Contributions welcome!")
31 | end
32 |
33 | end
34 | end
35 | end
36 |
--------------------------------------------------------------------------------
/spec/rackspace/requests/files/head_container_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'Rackspace::Files.head_container' do
4 | describe 'success' do
5 |
6 | before(:each) do
7 | Rackspace[:files].put_container('container_name')
8 | Rackspace[:files].put_object('container_name', 'object_name', lorem_file)
9 | end
10 |
11 | after(:each) do
12 | Rackspace[:files].delete_object('container_name', 'object_name')
13 | Rackspace[:files].delete_container('container_name')
14 | end
15 |
16 | it "should return proper attributes" do
17 | Rackspace[:files].head_container('container_name')
18 | end
19 |
20 | end
21 | describe 'failure' do
22 |
23 | it "should raise a NotFound error if the container does not exist" do
24 | lambda do
25 | Rackspace[:files].head_container('container_name')
26 | end.should raise_error(Excon::Errors::NotFound)
27 | end
28 |
29 | end
30 | end
31 |
--------------------------------------------------------------------------------
/lib/fog/rackspace/models/servers/flavors.rb:
--------------------------------------------------------------------------------
1 | require 'fog/collection'
2 | require 'fog/rackspace/models/servers/flavor'
3 |
4 | module Fog
5 | module Rackspace
6 | module Servers
7 |
8 | class Real
9 | def flavors
10 | Fog::Rackspace::Servers::Flavors.new(:connection => self)
11 | end
12 | end
13 |
14 | class Mock
15 | def flavors
16 | Fog::Rackspace::Servers::Flavors.new(:connection => self)
17 | end
18 | end
19 |
20 | class Flavors < Fog::Collection
21 |
22 | model Fog::Rackspace::Servers::Flavor
23 |
24 | def all
25 | data = connection.list_flavors_detail.body['flavors']
26 | load(data)
27 | end
28 |
29 | def get(flavor_id)
30 | data = connection.get_flavor_details(flavor_id).body['flavor']
31 | new(data)
32 | rescue Excon::Errors::NotFound
33 | nil
34 | end
35 |
36 | end
37 |
38 | end
39 | end
40 | end
41 |
--------------------------------------------------------------------------------
/lib/fog/vcloud/terremark/vcloud/parsers/get_vdc.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module Vcloud
4 | module Terremark
5 | module Vcloud
6 |
7 | class GetVdc < Fog::Parsers::Vcloud::Base
8 |
9 | def reset
10 | @target = nil
11 | @response = Struct::TmrkVcloudVdc.new([],[],[])
12 | end
13 |
14 | def start_element(name, attributes)
15 | @value = ''
16 | case name
17 | when 'Link'
18 | @response.links << generate_link(attributes)
19 | when 'Network'
20 | @response.networks << generate_link(attributes)
21 | when 'ResourceEntity'
22 | @response.resource_entities << generate_link(attributes)
23 | when 'Vdc'
24 | handle_root(attributes)
25 | end
26 | end
27 |
28 | end
29 | end
30 | end
31 | end
32 | end
33 | end
34 |
35 |
--------------------------------------------------------------------------------
/lib/fog/rackspace/requests/files/put_object.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Rackspace
3 | module Files
4 | class Real
5 |
6 | # Create a new object
7 | #
8 | # ==== Parameters
9 | # * container<~String> - Name for container, should be < 256 bytes and must not contain '/'
10 | #
11 | def put_object(container, object, data)
12 | data = Fog::Rackspace::Files.parse_data(data)
13 | response = storage_request(
14 | :body => data[:body],
15 | :expects => 201,
16 | :headers => data[:headers],
17 | :method => 'PUT',
18 | :path => "#{CGI.escape(container)}/#{CGI.escape(object)}"
19 | )
20 | response
21 | end
22 |
23 | end
24 |
25 | class Mock
26 |
27 | def put_object(container, object, data)
28 | raise MockNotImplemented.new("Contributions welcome!")
29 | end
30 |
31 | end
32 | end
33 | end
34 | end
35 |
--------------------------------------------------------------------------------
/lib/fog/aws/parsers/simpledb/get_attributes.rb:
--------------------------------------------------------------------------------
1 | require 'fog/aws/parsers/simpledb/basic'
2 |
3 | module Fog
4 | module Parsers
5 | module AWS
6 | module SimpleDB
7 |
8 | class GetAttributes < Fog::Parsers::AWS::SimpleDB::Basic
9 |
10 | def reset
11 | @attribute = nil
12 | @response = { 'Attributes' => {} }
13 | end
14 |
15 | def end_element(name)
16 | case name
17 | when 'Attribute'
18 | @attribute = nil
19 | when 'BoxUsage'
20 | response[name] = @value.to_f
21 | when 'Name'
22 | @attribute = @value
23 | response['Attributes'][@attribute] = []
24 | when 'RequestId'
25 | response[name] = @value
26 | when 'Value'
27 | response['Attributes'][@attribute] << sdb_decode(@value)
28 | end
29 | end
30 |
31 | end
32 |
33 | end
34 | end
35 | end
36 | end
37 |
--------------------------------------------------------------------------------
/lib/fog/local/models/directory.rb:
--------------------------------------------------------------------------------
1 | require 'fog/model'
2 | # require 'fog/local/models/files'
3 |
4 | module Fog
5 | module Local
6 |
7 | class Directory < Fog::Model
8 | extend Fog::Deprecation
9 | deprecate(:name, :key)
10 | deprecate(:name=, :key=)
11 |
12 | identity :key
13 |
14 | def destroy
15 | requires :key
16 |
17 | if ::File.directory?(path)
18 | Dir.rmdir(path)
19 | true
20 | else
21 | false
22 | end
23 | end
24 |
25 | def files
26 | @files ||= begin
27 | Fog::Local::Files.new(
28 | :directory => self,
29 | :connection => connection
30 | )
31 | end
32 | end
33 |
34 | def save
35 | requires :key
36 |
37 | Dir.mkdir(path)
38 | true
39 | end
40 |
41 | private
42 |
43 | def path
44 | connection.path_to(key)
45 | end
46 |
47 | end
48 |
49 | end
50 | end
51 |
--------------------------------------------------------------------------------
/lib/fog/rackspace/requests/servers/get_flavor_details.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Rackspace
3 | module Servers
4 | class Real
5 |
6 | # Get details for flavor by id
7 | #
8 | # ==== Returns
9 | # * response<~Excon::Response>:
10 | # * body<~Hash>:
11 | # * 'id'<~Integer> - Id of the flavor
12 | # * 'name'<~String> - Name of the flavor
13 | # * 'ram'<~Integer> - Amount of ram for the flavor
14 | # * 'disk'<~Integer> - Amount of diskspace for the flavor
15 | def get_flavor_details(flavor_id)
16 | request(
17 | :expects => [200, 203],
18 | :method => 'GET',
19 | :path => "flavors/#{flavor_id}.json"
20 | )
21 | end
22 |
23 | end
24 |
25 | class Mock
26 |
27 | def get_flavor_details(flavor_id)
28 | raise MockNotImplemented.new("Contributions welcome!")
29 | end
30 |
31 | end
32 | end
33 | end
34 | end
35 |
--------------------------------------------------------------------------------
/lib/fog/local/models/directories.rb:
--------------------------------------------------------------------------------
1 | require 'fog/collection'
2 | require 'fog/local/models/directory'
3 |
4 | module Fog
5 | module Local
6 |
7 | class Real
8 | def directories
9 | Fog::Local::Directories.new(:connection => self)
10 | end
11 | end
12 |
13 | class Mock
14 | def directories
15 | Fog::Local::Directories.new(:connection => self)
16 | end
17 | end
18 |
19 | class Directories < Fog::Collection
20 |
21 | model Fog::Local::Directory
22 |
23 | def all
24 | data = Dir.entries(connection.local_root).select do |entry|
25 | entry[0...1] != '.' && ::File.directory?(connection.path_to(entry))
26 | end.map do |entry|
27 | {:key => entry}
28 | end
29 | load(data)
30 | end
31 |
32 | def get(key)
33 | if ::File.directory?(connection.path_to(key))
34 | new(:key => key)
35 | else
36 | nil
37 | end
38 | end
39 |
40 | end
41 |
42 | end
43 | end
44 |
--------------------------------------------------------------------------------
/lib/fog/rackspace/models/servers/servers.rb:
--------------------------------------------------------------------------------
1 | require 'fog/collection'
2 | require 'fog/rackspace/models/servers/server'
3 |
4 | module Fog
5 | module Rackspace
6 | module Servers
7 |
8 | class Mock
9 | def servers
10 | Fog::Rackspace::Servers::Servers.new(:connection => self)
11 | end
12 | end
13 |
14 | class Real
15 | def servers
16 | Fog::Rackspace::Servers::Servers.new(:connection => self)
17 | end
18 | end
19 |
20 | class Servers < Fog::Collection
21 |
22 | model Fog::Rackspace::Servers::Server
23 |
24 | def all
25 | data = connection.list_servers_detail.body['servers']
26 | load(data)
27 | end
28 |
29 | def get(server_id)
30 | if server = connection.get_server_details(server_id).body['server']
31 | new(server)
32 | end
33 | rescue Excon::Errors::NotFound
34 | nil
35 | end
36 |
37 | end
38 |
39 | end
40 | end
41 | end
42 |
--------------------------------------------------------------------------------
/lib/fog/vcloud/parser.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module Vcloud
4 | class Base < Fog::Parsers::Base
5 |
6 | private
7 |
8 | def generate_link(attributes)
9 | link = Struct::VcloudLink.new
10 | until attributes.empty?
11 | link[attributes.shift.downcase] = attributes.shift
12 | end
13 | link
14 | end
15 |
16 | def handle_root(attributes)
17 | root = {}
18 | until attributes.empty?
19 | if attributes.first.is_a?(Array)
20 | attribute = attributes.shift
21 | root[attribute.first.downcase] = attribute.last
22 | else
23 | root[attributes.shift.downcase] = attributes.shift
24 | end
25 | end
26 | @response.href = root['href']
27 | @response.name = root['name']
28 | @response.type = root['type']
29 | @response.xmlns = root['xmlns']
30 | end
31 | end
32 | end
33 | end
34 | end
35 |
--------------------------------------------------------------------------------
/spec/aws/requests/simpledb/put_attributes_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'SimpleDB.put_attributes' do
4 | describe 'success' do
5 |
6 | before(:each) do
7 | @domain_name = "fog_domain_#{Time.now.to_i}"
8 | AWS[:sdb].create_domain(@domain_name)
9 | end
10 |
11 | after(:each) do
12 | AWS[:sdb].delete_domain(@domain_name)
13 | end
14 |
15 | it 'should return proper attributes from put_attributes' do
16 | actual = AWS[:sdb].put_attributes(@domain_name, 'foo', { 'bar' => 'baz' })
17 | actual.body['RequestId'].should be_a(String)
18 | actual.body['BoxUsage'].should be_a(Float)
19 | end
20 |
21 | end
22 | describe 'failure' do
23 |
24 | it 'should raise a BadRequest error if the domain does not exist' do
25 | lambda {
26 | AWS[:sdb].put_attributes(@domain_name, 'notadomain', { 'notanattribute' => 'value' })
27 | }.should raise_error(Excon::Errors::BadRequest)
28 | end
29 |
30 | end
31 | end
32 |
--------------------------------------------------------------------------------
/spec/shared_examples/server_examples.rb:
--------------------------------------------------------------------------------
1 | shared_examples_for "Server" do
2 |
3 | describe "#reboot" do
4 |
5 | it "should succeed" do
6 | subject.save
7 | subject.wait_for { ready? }
8 | subject.reboot.should be_true
9 | end
10 |
11 | end
12 |
13 | describe "#reload" do
14 |
15 | it "should reset attributes to remote state" do
16 | subject.save
17 | subject.wait_for { ready? }
18 | @reloaded = subject.reload
19 | subject.attributes.should == @reloaded.attributes
20 | end
21 |
22 | end
23 |
24 | describe "#save" do
25 |
26 | it "should return true when it succeeds" do
27 | subject.save.should be_true
28 | end
29 |
30 | it "should not exist remotely before save" do
31 | @servers.get(subject.id).should be_nil
32 | end
33 |
34 | it "should exist remotely after save" do
35 | subject.save
36 | subject.wait_for { ready? }
37 | @servers.get(subject.id).should_not be_nil
38 | end
39 |
40 | end
41 |
42 | end
43 |
44 |
--------------------------------------------------------------------------------
/lib/fog/webbynode/requests/get_flavors.rb:
--------------------------------------------------------------------------------
1 | # module Fog
2 | # module Slicehost
3 | # class Real
4 | #
5 | # require 'fog/slicehost/parsers/get_flavors'
6 | #
7 | # # Get list of flavors
8 | # #
9 | # # ==== Returns
10 | # # * response<~Excon::Response>:
11 | # # * body<~Array>:
12 | # # * 'id'<~Integer> - Id of the flavor
13 | # # * 'name'<~String> - Name of the flavor
14 | # # * 'price'<~Integer> - Price in cents
15 | # # * 'ram'<~Integer> - Amount of ram for the flavor
16 | # def get_flavors
17 | # request(
18 | # :expects => 200,
19 | # :method => 'GET',
20 | # :parser => Fog::Parsers::Slicehost::GetFlavors.new,
21 | # :path => 'flavors.xml'
22 | # )
23 | # end
24 | #
25 | # end
26 | #
27 | # class Mock
28 | #
29 | # def get_flavors
30 | # raise MockNotImplemented.new("Contributions welcome!")
31 | # end
32 | #
33 | # end
34 | # end
35 | # end
36 |
--------------------------------------------------------------------------------
/lib/fog/terremark/parsers/shared/get_node_services.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module Terremark
4 | module Shared
5 |
6 | class GetNodeServices < Fog::Parsers::Base
7 |
8 | def reset
9 | @node_service = {}
10 | @response = { 'NodeServices' => [] }
11 | end
12 |
13 | def end_element(name)
14 | case name
15 | when 'Description', 'Href', 'Name', 'IpAddress'
16 | @node_service[name] = @value
17 | when 'Enabled'
18 | if @value == 'true'
19 | @node_service[name] = true
20 | else
21 | @node_service[name] = false
22 | end
23 | when 'Id', 'Port'
24 | @node_service[name] = @value.to_i
25 | when 'NodeService'
26 | @response['NodeServices'] << @node_service
27 | @node_service = {}
28 | end
29 | end
30 |
31 | end
32 |
33 | end
34 | end
35 | end
36 | end
37 |
--------------------------------------------------------------------------------
/spec/aws/requests/simpledb/batch_put_attributes_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'SimpleDB.batch_put_attributes' do
4 | describe 'success' do
5 |
6 | before(:all) do
7 | @domain_name = "fog_domain_#{Time.now.to_i}"
8 | AWS[:sdb].create_domain(@domain_name)
9 | end
10 |
11 | after(:all) do
12 | AWS[:sdb].delete_domain(@domain_name)
13 | end
14 |
15 | it 'should return proper attributes' do
16 | actual = AWS[:sdb].batch_put_attributes(@domain_name, { 'a' => { 'b' => 'c' }, 'x' => { 'y' => 'z' } })
17 | actual.body['RequestId'].should be_a(String)
18 | actual.body['BoxUsage'].should be_a(Float)
19 | end
20 |
21 | end
22 | describe 'failure' do
23 |
24 | it 'should raise a BadRequest error if the domain does not exist' do
25 | lambda {
26 | AWS[:sdb].batch_put_attributes('notadomain', { 'a' => { 'b' => 'c' }, 'x' => { 'y' => 'z' } })
27 | }.should raise_error(Excon::Errors::BadRequest)
28 | end
29 |
30 | end
31 | end
--------------------------------------------------------------------------------
/tests/rackspace/requests/servers/delete_image_tests.rb:
--------------------------------------------------------------------------------
1 | Shindo.tests('Rackspace::Servers#delete_image', 'rackspace') do
2 | tests('success') do
3 |
4 | before do
5 | @server_id = Rackspace[:servers].create_server(1, 3, 'fogdeleteimage').body['server']['id']
6 | @image_id = Rackspace[:servers].create_image(@server_id).body['image']['id']
7 | end
8 |
9 | after do
10 | Fog.wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
11 | Rackspace[:servers].delete_server(@server_id)
12 | end
13 |
14 | test('has proper output format') do
15 | Fog.wait_for { Rackspace[:servers].get_image_details(@image_id).body['image']['status'] == 'ACTIVE' }
16 | Rackspace[:servers].delete_image(@image_id)
17 | end
18 |
19 | end
20 | tests('failure') do
21 |
22 | test('raises NotFound error if image does not exist') do
23 | has_error(Excon::Errors::NotFound) do
24 | Rackspace[:servers].delete_image(0)
25 | end
26 | end
27 |
28 | end
29 | end
30 |
--------------------------------------------------------------------------------
/benchs/params.rb:
--------------------------------------------------------------------------------
1 | require 'benchmark'
2 |
3 | def hash(options)
4 | result = "#{options.delete(:name)}"
5 | for key, value in options
6 | result << " #{key} => #{value} "
7 | end
8 | result
9 | end
10 |
11 | def optional(name, a = nil, b = nil, c = nil)
12 | result = "#{name}"
13 | options = { :a => a, :b => b, :c => c }
14 | for key, value in options
15 | result << " #{key} => #{value} "
16 | end
17 | result
18 | end
19 |
20 | COUNT = 100_000
21 | data = "Content-Length: 100"
22 | Benchmark.bmbm(25) do |bench|
23 | bench.report('hash') do
24 | COUNT.times do
25 | hash({:name => 'name'})
26 | end
27 | end
28 | bench.report('optional') do
29 | COUNT.times do
30 | optional('name')
31 | end
32 | end
33 | bench.report('hash_with_option') do
34 | COUNT.times do
35 | hash({:name => 'name', :a => 'a', :b => 'b', :c => 'c'})
36 | end
37 | end
38 | bench.report('optional_with_option') do
39 | COUNT.times do
40 | optional('name', :a => 'a', :b => 'b', :c => 'c')
41 | end
42 | end
43 | end
44 |
--------------------------------------------------------------------------------
/lib/fog/rackspace/requests/servers/get_image_details.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Rackspace
3 | module Servers
4 | class Real
5 |
6 | # Get details for image by id
7 | #
8 | # ==== Returns
9 | # * response<~Excon::Response>:
10 | # * body<~Hash>:
11 | # * 'id'<~Integer> - Id of the image
12 | # * 'name'<~String> - Name of the image
13 | # * 'serverId'<~Integer> - Id of server image was created from
14 | # * 'status'<~Integer> - Status of image
15 | # * 'updated'<~String> - Timestamp of last update
16 | def get_image_details(image_id)
17 | request(
18 | :expects => [200, 203],
19 | :method => 'GET',
20 | :path => "images/#{image_id}.json"
21 | )
22 | end
23 |
24 | end
25 |
26 | class Mock
27 |
28 | def get_image_details(image_id)
29 | raise MockNotImplemented.new("Contributions welcome!")
30 | end
31 |
32 | end
33 | end
34 | end
35 | end
36 |
--------------------------------------------------------------------------------
/tests/rackspace/requests/servers/update_server_tests.rb:
--------------------------------------------------------------------------------
1 | Shindo.tests('Rackspace::Servers#update_server', 'rackspace') do
2 | tests('success') do
3 |
4 | before do
5 | @server_id = Rackspace[:servers].create_server(1, 3, 'fogupdateserver').body['server']['id']
6 | Fog.wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
7 | @data = Rackspace[:servers].update_server(@server_id, :name => 'fogupdatedserver', :adminPass => 'fogupdatedserver')
8 | end
9 |
10 | after do
11 | Rackspace[:servers].delete_server(@server_id)
12 | end
13 |
14 | test('has proper output format') do
15 | has_format(@data, {'name' => String, 'adminPass' => String})
16 | end
17 |
18 | end
19 | tests('failure') do
20 |
21 | test('raises NotFound error if server does not exist') do
22 | has_error(Excon::Errors::NotFound) do
23 | Rackspace[:servers].update_server(0, :name => 'fogupdatedserver', :adminPass => 'fogupdatedserver')
24 | end
25 | end
26 |
27 | end
28 |
29 | end
30 |
--------------------------------------------------------------------------------
/spec/aws/requests/ec2/get_console_output_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'EC2.get_console_output' do
4 | describe 'success' do
5 |
6 | before(:each) do
7 | @instance = AWS[:ec2].servers.create(:image_id => GENTOO_AMI)
8 | @instance.wait_for { ready? }
9 | end
10 |
11 | after(:each) do
12 | @instance.destroy
13 | end
14 |
15 | it "should return proper attributes" do
16 | actual = AWS[:ec2].get_console_output(@instance.id).body
17 | actual['instanceId'].should be_a(String)
18 | if actual['output']
19 | actual['output'].should be_a(String)
20 | end
21 | actual['requestId'].should be_a(String)
22 | actual['timestamp'].should be_a(Time)
23 | end
24 |
25 | end
26 | describe 'failure' do
27 |
28 | it "should raise a BadRequest error if the instance does not exist" do
29 | lambda {
30 | AWS[:ec2].get_console_output('i-00000000')
31 | }.should raise_error(Excon::Errors::BadRequest)
32 | end
33 |
34 | end
35 | end
36 |
--------------------------------------------------------------------------------
/lib/fog/rackspace/models/files/directory.rb:
--------------------------------------------------------------------------------
1 | require 'fog/model'
2 | require 'fog/rackspace/models/files/files'
3 |
4 | module Fog
5 | module Rackspace
6 | module Files
7 |
8 | class Directory < Fog::Model
9 | extend Fog::Deprecation
10 | deprecate(:name, :key)
11 | deprecate(:name=, :key=)
12 |
13 | identity :key, ['name']
14 |
15 | attribute :bytes
16 | attribute :count
17 |
18 | def destroy
19 | requires :key
20 | connection.delete_container(key)
21 | true
22 | rescue Excon::Errors::NotFound
23 | false
24 | end
25 |
26 | def files
27 | @files ||= begin
28 | Fog::Rackspace::Files::Files.new(
29 | :directory => self,
30 | :connection => connection
31 | )
32 | end
33 | end
34 |
35 | def save
36 | requires :key
37 | connection.put_container(key)
38 | true
39 | end
40 |
41 | end
42 |
43 | end
44 | end
45 | end
46 |
--------------------------------------------------------------------------------
/lib/fog/webbynode/bin.rb:
--------------------------------------------------------------------------------
1 | module Webbynode
2 | class << self
3 | if Fog.credentials[:webbynode_api_key] && Fog.credentials[:webbynode_username]
4 |
5 | def initialized?
6 | true
7 | end
8 |
9 | def [](service)
10 | @@connections ||= Hash.new do |hash, key|
11 | credentials = Fog.credentials.reject do |k,v|
12 | ![:webbynode_api_key, :webbynode_username].include?(k)
13 | end
14 | hash[key] = case key
15 | when :webbies
16 | Fog::Webbynode.new(credentials)
17 | end
18 | end
19 | @@connections[service]
20 | end
21 |
22 | def directories
23 | self[:files].directories
24 | end
25 |
26 | def flavors
27 | self[:servers].flavors
28 | end
29 |
30 | def images
31 | self[:servers].images
32 | end
33 |
34 | def servers
35 | self[:servers].servers
36 | end
37 |
38 | else
39 |
40 | def initialized?
41 | false
42 | end
43 |
44 | end
45 | end
46 | end
--------------------------------------------------------------------------------
/spec/aws/requests/ec2/revoke_security_group_ingress_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'EC2.revoke_security_group_ingress' do
4 | describe 'success' do
5 |
6 | before(:each) do
7 | AWS[:ec2].create_security_group('fog_security_group', 'a security group for testing fog')
8 | AWS[:ec2].authorize_security_group_ingress({
9 | 'FromPort' => 80,
10 | 'GroupName' => 'fog_security_group',
11 | 'IpProtocol' => 'tcp',
12 | 'ToPort' => 80
13 | })
14 | end
15 |
16 | after(:each) do
17 | AWS[:ec2].delete_security_group('fog_security_group')
18 | end
19 |
20 | it "should return proper attributes" do
21 | actual = AWS[:ec2].revoke_security_group_ingress({
22 | 'FromPort' => 80,
23 | 'GroupName' => 'fog_security_group',
24 | 'IpProtocol' => 'tcp',
25 | 'ToPort' => 80
26 | })
27 | actual.body['requestId'].should be_a(String)
28 | [false, true].should include(actual.body['return'])
29 | end
30 |
31 | end
32 | end
33 |
--------------------------------------------------------------------------------
/lib/fog/rackspace/requests/files/head_container.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Rackspace
3 | module Files
4 | class Real
5 |
6 | # List number of objects and total bytes stored
7 | #
8 | # ==== Parameters
9 | # * container<~String> - Name of container to retrieve info for
10 | #
11 | # ==== Returns
12 | # * response<~Excon::Response>:
13 | # * headers<~Hash>:
14 | # * 'X-Container-Object-Count'<~String> - Count of containers
15 | # * 'X-Container-Bytes-Used'<~String> - Bytes used
16 | def head_container(container)
17 | response = storage_request(
18 | :expects => 204,
19 | :method => 'HEAD',
20 | :path => container,
21 | :query => 'format=json'
22 | )
23 | response
24 | end
25 |
26 | end
27 |
28 | class Mock
29 |
30 | def head_container(container)
31 | raise MockNotImplemented.new("Contributions welcome!")
32 | end
33 |
34 | end
35 | end
36 | end
37 | end
38 |
--------------------------------------------------------------------------------
/lib/fog/slicehost/requests/get_flavor.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Slicehost
3 | class Real
4 |
5 | require 'fog/slicehost/parsers/get_flavor'
6 |
7 | # Get details of a flavor
8 | #
9 | # ==== Parameters
10 | # * flavor_id<~Integer> - Id of flavor to lookup
11 | #
12 | # ==== Returns
13 | # * response<~Excon::Response>:
14 | # * body<~Array>:
15 | # * 'id'<~Integer> - Id of the flavor
16 | # * 'name'<~String> - Name of the flavor
17 | # * 'price'<~Integer> - Price in cents
18 | # * 'ram'<~Integer> - Amount of ram for the flavor
19 | def get_flavor(flavor_id)
20 | request(
21 | :expects => 200,
22 | :method => 'GET',
23 | :parser => Fog::Parsers::Slicehost::GetFlavor.new,
24 | :path => "flavors/#{flavor_id}.xml"
25 | )
26 | end
27 |
28 | end
29 |
30 | class Mock
31 |
32 | def get_flavor(flavor_id)
33 | raise MockNotImplemented.new("Contributions welcome!")
34 | end
35 |
36 | end
37 | end
38 | end
39 |
--------------------------------------------------------------------------------
/spec/aws/requests/ec2/create_key_pair_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'EC2.create_key_pair' do
4 | describe 'success' do
5 |
6 | after(:each) do
7 | AWS[:ec2].delete_key_pair('fog_key_pair')
8 | end
9 |
10 | it "should return proper attributes" do
11 | actual = AWS[:ec2].create_key_pair('fog_key_pair')
12 | actual.body['keyFingerprint'].should be_a(String)
13 | actual.body['keyMaterial'].should be_a(String)
14 | actual.body['keyName'].should be_a(String)
15 | actual.body['requestId'].should be_a(String)
16 | end
17 |
18 | end
19 | describe 'failure' do
20 |
21 | before(:each) do
22 | AWS[:ec2].create_key_pair('fog_key_pair')
23 | end
24 |
25 | after(:each) do
26 | AWS[:ec2].delete_key_pair('fog_key_pair')
27 | end
28 |
29 | it "should raise a BadRequest when the key pair already exists" do
30 | lambda {
31 | AWS[:ec2].create_key_pair('fog_key_pair')
32 | }.should raise_error(Excon::Errors::BadRequest)
33 | end
34 |
35 | end
36 | end
37 |
--------------------------------------------------------------------------------
/lib/fog/terremark/requests/shared/get_node_services.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Terremark
3 | module Shared
4 | module Real
5 |
6 | require 'fog/terremark/parsers/shared/get_node_services'
7 |
8 | # Get a list of all internet services for a vdc
9 | #
10 | # ==== Parameters
11 | # * service_id<~Integer> - Id of internet service that we want a list of nodes for
12 | #
13 | # ==== Returns
14 | # * response<~Excon::Response>:
15 | # * body<~Hash>:
16 |
17 | #
18 | def get_node_services(service_id)
19 | request(
20 | :expects => 200,
21 | :method => 'GET',
22 | :parser => Fog::Parsers::Terremark::Shared::GetNodeServices.new,
23 | :path => "InternetServices/#{service_id}/nodes"
24 | )
25 | end
26 |
27 | end
28 |
29 | module Mock
30 |
31 | def get_node_services(vdc_id)
32 | raise MockNotImplemented.new("Contributions welcome!")
33 | end
34 |
35 | end
36 | end
37 | end
38 | end
39 |
--------------------------------------------------------------------------------
/lib/fog/aws/models/ec2/images.rb:
--------------------------------------------------------------------------------
1 | require 'fog/collection'
2 | require 'fog/aws/models/ec2/image'
3 |
4 | module Fog
5 | module AWS
6 | module EC2
7 |
8 | class Mock
9 | def images
10 | Fog::AWS::EC2::Images.new(:connection => self)
11 | end
12 | end
13 |
14 | class Real
15 | def images
16 | Fog::AWS::EC2::Images.new(:connection => self)
17 | end
18 | end
19 |
20 | class Images < Fog::Collection
21 |
22 | attribute :image_id
23 |
24 | model Fog::AWS::EC2::Image
25 |
26 | def initialize(attributes)
27 | @image_id ||= []
28 | super
29 | end
30 |
31 | def all(image_id = @image_id)
32 | @image_id = image_id
33 | data = connection.describe_images('ImageId' => image_id).body
34 | load(data['imagesSet'])
35 | end
36 |
37 | def get(image_id)
38 | if image_id
39 | all(image_id).first
40 | end
41 | rescue Excon::Errors::BadRequest
42 | nil
43 | end
44 | end
45 |
46 | end
47 | end
48 | end
49 |
--------------------------------------------------------------------------------
/lib/fog/webbynode/requests/get_webbies.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Webbynode
3 | class Real
4 |
5 | require 'fog/webbynode/parsers/get_webbies'
6 |
7 | # Get list of Webbies
8 | #
9 | # ==== Returns
10 | # * response<~Excon::Response>:
11 | # * body<~Array>:
12 | # * 'plan'<~String> - Plan
13 | # * 'status'<~String> - Current status of the Webby
14 | # * 'ip'<~String> - Ip addresses for the Webby
15 | # * 'name'<~String> - Name of the Webby
16 | # * 'notes'<~String> - Notes for the Webby
17 | # * 'id'<~Integer> - Id of the slice
18 | # * 'image-id'<~Integer> - Id of image Webby was booted from
19 | def get_webbies
20 | request(
21 | :expects => 200,
22 | :method => 'POST',
23 | :parser => Fog::Parsers::Webbynode::GetWebbies.new,
24 | :path => 'webbies'
25 | )
26 | end
27 |
28 | end
29 |
30 | class Mock
31 |
32 | def get_slices
33 | raise MockNotImplemented.new("Contributions welcome!")
34 | end
35 |
36 | end
37 | end
38 | end
39 |
--------------------------------------------------------------------------------
/spec/aws/requests/s3/get_service_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'S3.get_service' do
4 | describe 'success' do
5 |
6 | before(:all) do
7 | AWS[:s3].put_bucket('foggetservice')
8 | Fog.wait_for { AWS[:s3].directories.get('foggetservice') }
9 | end
10 |
11 | after(:all) do
12 | AWS[:s3].delete_bucket('foggetservice')
13 | end
14 |
15 | it 'should return proper_attributes' do
16 | actual = AWS[:s3].get_service
17 | actual.body['Buckets'].should be_an(Array)
18 | bucket = actual.body['Buckets'].select {|bucket| bucket['Name'] == 'foggetservice'}.first
19 | bucket['CreationDate'].should be_a(Time)
20 | bucket['Name'].should == 'foggetservice'
21 | owner = actual.body['Owner']
22 | owner['DisplayName'].should be_a(String)
23 | owner['ID'].should be_a(String)
24 | end
25 |
26 | it 'should include foggetservice in get_service' do
27 | actual = AWS[:s3].get_service
28 | actual.body['Buckets'].collect { |bucket| bucket['Name'] }.should include('foggetservice')
29 | end
30 |
31 | end
32 | end
33 |
--------------------------------------------------------------------------------
/lib/fog/aws/models/ec2/key_pairs.rb:
--------------------------------------------------------------------------------
1 | require 'fog/collection'
2 | require 'fog/aws/models/ec2/key_pair'
3 |
4 | module Fog
5 | module AWS
6 | module EC2
7 |
8 | class Mock
9 | def key_pairs
10 | Fog::AWS::EC2::KeyPairs.new(:connection => self)
11 | end
12 | end
13 |
14 | class Real
15 | def key_pairs
16 | Fog::AWS::EC2::KeyPairs.new(:connection => self)
17 | end
18 | end
19 |
20 | class KeyPairs < Fog::Collection
21 |
22 | attribute :key_name
23 |
24 | model Fog::AWS::EC2::KeyPair
25 |
26 | def initialize(attributes)
27 | @key_name ||= []
28 | super
29 | end
30 |
31 | def all(key_name = @key_name)
32 | @key_name = key_name
33 | data = connection.describe_key_pairs(key_name).body
34 | load(data['keySet'])
35 | end
36 |
37 | def get(key_name)
38 | if key_name
39 | all(key_name).first
40 | end
41 | rescue Excon::Errors::BadRequest
42 | nil
43 | end
44 |
45 | end
46 |
47 | end
48 | end
49 | end
50 |
--------------------------------------------------------------------------------
/lib/fog/rackspace.rb:
--------------------------------------------------------------------------------
1 | require 'fog/rackspace/files'
2 | require 'fog/rackspace/servers'
3 |
4 | module Fog
5 | module Rackspace
6 |
7 | def self.authenticate(options)
8 | unless @rackspace_api_key = options[:rackspace_api_key]
9 | raise ArgumentError.new('rackspace_api_key is required to access rackspace')
10 | end
11 | unless @rackspace_username = options[:rackspace_username]
12 | raise ArgumentError.new('rackspace_username is required to access rackspace')
13 | end
14 | connection = Fog::Connection.new("https://auth.api.rackspacecloud.com")
15 | response = connection.request({
16 | :expects => 204,
17 | :headers => {
18 | 'X-Auth-Key' => @rackspace_api_key,
19 | 'X-Auth-User' => @rackspace_username
20 | },
21 | :host => 'auth.api.rackspacecloud.com',
22 | :method => 'GET',
23 | :path => 'v1.0'
24 | })
25 | response.headers.reject do |key, value|
26 | !['X-Server-Management-Url', 'X-Storage-Url', 'X-CDN-Management-Url', 'X-Auth-Token'].include?(key)
27 | end
28 | end
29 |
30 | end
31 | end
32 |
--------------------------------------------------------------------------------
/lib/fog/rackspace/requests/servers/list_images.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Rackspace
3 | module Servers
4 | class Real
5 |
6 | # List all images (IDs and names only)
7 | #
8 | # ==== Returns
9 | # * response<~Excon::Response>:
10 | # * body<~Hash>:
11 | # * 'id'<~Integer> - Id of the image
12 | # * 'name'<~String> - Name of the image
13 | def list_images
14 | request(
15 | :expects => [200, 203],
16 | :method => 'GET',
17 | :path => 'images.json'
18 | )
19 | end
20 |
21 | end
22 |
23 | class Mock
24 |
25 | def list_images
26 | response = Excon::Response.new
27 | data = list_images_detail.body['images']
28 | images = []
29 | for image in data
30 | images << image.reject { |key, value| !['id', 'name'].include?(key) }
31 | end
32 | response.status = [200, 203][rand(1)]
33 | response.body = { 'images' => images }
34 | response
35 | end
36 |
37 | end
38 | end
39 | end
40 | end
41 |
--------------------------------------------------------------------------------
/lib/fog/aws/requests/s3/put_bucket_versioning.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module AWS
3 | module S3
4 | class Real
5 |
6 | # Change versioning status for an S3 bucket
7 | #
8 | # ==== Parameters
9 | # * bucket_name<~String> - name of bucket to modify
10 | # * status<~String> - Status to change to in ['Enabled', 'Suspended']
11 | def put_bucket_versioning(bucket_name, status)
12 | data =
13 | <<-DATA
14 |
15 | #{status}
16 |
17 | DATA
18 |
19 | request({
20 | :body => data,
21 | :expects => 200,
22 | :headers => {},
23 | :host => "#{bucket_name}.#{@host}",
24 | :method => 'PUT',
25 | :query => 'versioning'
26 | })
27 | end
28 |
29 | end
30 |
31 | class Mock
32 |
33 | def put_bucket_versioning(bucket_name, status)
34 | raise MockNotImplemented.new("Contributions welcome!")
35 | end
36 |
37 | end
38 | end
39 | end
40 | end
41 |
--------------------------------------------------------------------------------
/lib/fog/terremark/requests/shared/get_network_ips.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Terremark
3 | module Shared
4 | module Real
5 |
6 | # Get details for a Network
7 | #
8 | # ==== Parameters
9 | # * network_id<~Integer> - Id of the network to look up
10 | #
11 | # ==== Returns
12 | # * response<~Excon::Response>:
13 | # * body<~Hash>:
14 | # FIXME
15 | def get_network_ips(network_id)
16 | opts = {
17 | :expects => 200,
18 | :method => 'GET',
19 | :parser => Fog::Parsers::Terremark::Shared::GetNetworkIps.new,
20 | :path => "network/#{network_id}/ipAddresses"
21 | }
22 | if self.is_a?(Fog::Terremark::Ecloud::Real)
23 | opts[:path] = "/extensions/network/#{network_id}/ips"
24 | end
25 | request(opts)
26 | end
27 |
28 | end
29 |
30 | module Mock
31 |
32 | def get_network_ips(network_id)
33 | raise MockNotImplemented.new("Contributions welcome!")
34 | end
35 |
36 | end
37 | end
38 | end
39 | end
40 |
41 |
--------------------------------------------------------------------------------
/lib/fog/rackspace/bin.rb:
--------------------------------------------------------------------------------
1 | module Rackspace
2 | class << self
3 | if Fog.credentials[:rackspace_api_key] && Fog.credentials[:rackspace_username]
4 |
5 | def initialized?
6 | true
7 | end
8 |
9 | def [](service)
10 | @@connections ||= Hash.new do |hash, key|
11 | credentials = Fog.credentials.reject do |k,v|
12 | ![:rackspace_api_key, :rackspace_username].include?(k)
13 | end
14 | hash[key] = case key
15 | when :files
16 | Fog::Rackspace::Files.new(credentials)
17 | when :servers
18 | Fog::Rackspace::Servers.new(credentials)
19 | end
20 | end
21 | @@connections[service]
22 | end
23 |
24 | def directories
25 | self[:files].directories
26 | end
27 |
28 | def flavors
29 | self[:servers].flavors
30 | end
31 |
32 | def images
33 | self[:servers].images
34 | end
35 |
36 | def servers
37 | self[:servers].servers
38 | end
39 |
40 | else
41 |
42 | def initialized?
43 | false
44 | end
45 |
46 | end
47 | end
48 | end
--------------------------------------------------------------------------------
/lib/fog/webbynode/requests/get_flavor.rb:
--------------------------------------------------------------------------------
1 | # module Fog
2 | # module Slicehost
3 | # class Real
4 | #
5 | # require 'fog/slicehost/parsers/get_flavor'
6 | #
7 | # # Get details of a flavor
8 | # #
9 | # # ==== Parameters
10 | # # * flavor_id<~Integer> - Id of flavor to lookup
11 | # #
12 | # # ==== Returns
13 | # # * response<~Excon::Response>:
14 | # # * body<~Array>:
15 | # # * 'id'<~Integer> - Id of the flavor
16 | # # * 'name'<~String> - Name of the flavor
17 | # # * 'price'<~Integer> - Price in cents
18 | # # * 'ram'<~Integer> - Amount of ram for the flavor
19 | # def get_flavor(flavor_id)
20 | # request(
21 | # :expects => 200,
22 | # :method => 'GET',
23 | # :parser => Fog::Parsers::Slicehost::GetFlavor.new,
24 | # :path => "flavors/#{flavor_id}.xml"
25 | # )
26 | # end
27 | #
28 | # end
29 | #
30 | # class Mock
31 | #
32 | # def get_flavor(flavor_id)
33 | # raise MockNotImplemented.new("Contributions welcome!")
34 | # end
35 | #
36 | # end
37 | # end
38 | # end
39 |
--------------------------------------------------------------------------------
/spec/aws/requests/ec2/create_security_group_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'EC2.create_security_group' do
4 | describe 'success' do
5 |
6 | after(:each) do
7 | AWS[:ec2].delete_security_group('fog_security_group')
8 | end
9 |
10 | it "should return proper attributes" do
11 | actual = AWS[:ec2].create_security_group('fog_security_group', 'a security group for testing fog')
12 | actual.body['requestId'].should be_a(String)
13 | [false, true].should include(actual.body['return'])
14 | end
15 |
16 | end
17 | describe 'failure' do
18 |
19 | before(:each) do
20 | AWS[:ec2].create_security_group('fog_security_group', 'a security group for testing fog')
21 | end
22 |
23 | after(:each) do
24 | AWS[:ec2].delete_security_group('fog_security_group')
25 | end
26 |
27 | it "should raise a BadRequest error when the security group already exists" do
28 | lambda {
29 | AWS[:ec2].create_security_group('fog_security_group', 'a security group for testing fog')
30 | }.should raise_error(Excon::Errors::BadRequest)
31 | end
32 |
33 | end
34 | end
35 |
--------------------------------------------------------------------------------
/spec/aws/requests/s3/delete_bucket_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'S3.delete_bucket' do
4 | describe 'success' do
5 |
6 | before(:each) do
7 | AWS[:s3].put_bucket('fogdeletebucket')
8 | end
9 |
10 | it 'should return proper attributes' do
11 | actual = AWS[:s3].delete_bucket('fogdeletebucket')
12 | actual.status.should == 204
13 | end
14 |
15 | end
16 | describe 'failure' do
17 |
18 | it 'should raise a NotFound error if the bucket does not exist' do
19 | lambda {
20 | AWS[:s3].delete_bucket('fognotabucket')
21 | }.should raise_error(Excon::Errors::NotFound)
22 | end
23 |
24 | it 'should raise a Conflict error if the bucket is not empty' do
25 | AWS[:s3].put_bucket('fogdeletebucket')
26 | AWS[:s3].put_object('fogdeletebucket', 'fog_delete_object', lorem_file)
27 | lambda {
28 | AWS[:s3].delete_bucket('fogdeletebucket')
29 | }.should raise_error(Excon::Errors::Conflict)
30 | AWS[:s3].delete_object('fogdeletebucket', 'fog_delete_object')
31 | AWS[:s3].delete_bucket('fogdeletebucket')
32 | end
33 |
34 | end
35 | end
36 |
--------------------------------------------------------------------------------
/spec/rackspace/requests/files/get_container_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'Rackspace::Files.get_container' do
4 | describe 'success' do
5 |
6 | before(:each) do
7 | Rackspace[:files].put_container('container_name')
8 | Rackspace[:files].put_object('container_name', 'object_name', lorem_file)
9 | end
10 |
11 | after(:each) do
12 | Rackspace[:files].delete_object('container_name', 'object_name')
13 | Rackspace[:files].delete_container('container_name')
14 | end
15 |
16 | it "should return proper attributes" do
17 | actual = Rackspace[:files].get_container('container_name').body
18 | actual.first['bytes'].should be_an(Integer)
19 | actual.first['content_type'].should be_a(String)
20 | actual.first['hash'].should be_a(String)
21 | actual.first['last_modified'].should be_a(String)
22 | actual.first['name'].should be_a(String)
23 | end
24 |
25 | end
26 | describe 'failure' do
27 |
28 | it "should not raise an if the container does not exist" do
29 | Rackspace[:files].get_container('container_name')
30 | end
31 |
32 | end
33 | end
34 |
--------------------------------------------------------------------------------
/lib/fog/aws/requests/ec2/delete_key_pair.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module AWS
3 | module EC2
4 | class Real
5 |
6 | # Delete a key pair that you own
7 | #
8 | # ==== Parameters
9 | # * key_name<~String> - Name of the key pair.
10 | #
11 | # ==== Returns
12 | # * response<~Excon::Response>:
13 | # * body<~Hash>:
14 | # * 'requestId'<~String> id of request
15 | # * 'return'<~Boolean> - success?
16 | def delete_key_pair(key_name)
17 | request(
18 | 'Action' => 'DeleteKeyPair',
19 | 'KeyName' => key_name,
20 | :parser => Fog::Parsers::AWS::EC2::Basic.new
21 | )
22 | end
23 |
24 | end
25 |
26 | class Mock
27 |
28 | def delete_key_pair(key_name)
29 | response = Excon::Response.new
30 | @data[:key_pairs].delete(key_name)
31 | response.status = 200
32 | response.body = {
33 | 'requestId' => Fog::AWS::Mock.request_id,
34 | 'return' => true
35 | }
36 | response
37 | end
38 |
39 | end
40 | end
41 | end
42 | end
43 |
--------------------------------------------------------------------------------
/spec/aws/requests/s3/delete_object_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'S3.delete_object' do
4 | describe 'success' do
5 |
6 | before(:each) do
7 | AWS[:s3].put_bucket('fogdeleteobject')
8 | AWS[:s3].put_object('fogdeleteobject', 'fog_delete_object', lorem_file)
9 | end
10 |
11 | after(:each) do
12 | AWS[:s3].delete_bucket('fogdeleteobject')
13 | end
14 |
15 | it 'should return proper attributes' do
16 | actual = AWS[:s3].delete_object('fogdeleteobject', 'fog_delete_object')
17 | actual.status.should == 204
18 | end
19 |
20 | end
21 | describe 'failure' do
22 |
23 | it 'should raise a NotFound error if the bucket does not exist' do
24 | lambda {
25 | AWS[:s3].delete_object('fognotabucket', 'fog_delete_object')
26 | }.should raise_error(Excon::Errors::NotFound)
27 | end
28 |
29 | it 'should not raise an error if the object does not exist' do
30 | AWS[:s3].put_bucket('fogdeleteobject')
31 | AWS[:s3].delete_object('fogdeleteobject', 'fog_not_an_object')
32 | AWS[:s3].delete_bucket('fogdeleteobject')
33 | end
34 |
35 | end
36 | end
37 |
--------------------------------------------------------------------------------
/lib/fog/rackspace/requests/servers/list_servers.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Rackspace
3 | module Servers
4 | class Real
5 |
6 | # List all servers (IDs and names only)
7 | #
8 | # ==== Returns
9 | # * response<~Excon::Response>:
10 | # * body<~Hash>:
11 | # * 'servers'<~Array>:
12 | # * 'id'<~Integer> - Id of server
13 | # * 'name<~String> - Name of server
14 | def list_servers
15 | request(
16 | :expects => [200, 203],
17 | :method => 'GET',
18 | :path => 'servers.json'
19 | )
20 | end
21 |
22 | end
23 |
24 | class Mock
25 |
26 | def list_servers
27 | response = Excon::Response.new
28 | data = list_servers_detail.body['servers']
29 | servers = []
30 | for server in data
31 | servers << server.reject { |key, value| !['id', 'name'].include?(key) }
32 | end
33 | response.status = [200, 203][rand(1)]
34 | response.body = { 'servers' => servers }
35 | response
36 | end
37 |
38 | end
39 | end
40 | end
41 | end
42 |
--------------------------------------------------------------------------------
/lib/fog/aws/parsers/ec2/describe_reserved_instances.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module AWS
4 | module EC2
5 |
6 | class DescribeReservedInstances < Fog::Parsers::Base
7 |
8 | def reset
9 | @reserved_instance = {}
10 | @response = { 'reservedInstancesSet' => [] }
11 | end
12 |
13 | def end_element(name)
14 | case name
15 | when 'availabilityZone', 'instanceType', 'productDescription', 'reservedInstancesId', 'state'
16 | @reserved_instance[name] = @value
17 | when 'duration', 'instanceCount'
18 | @reserved_instance[name] = @value.to_i
19 | when 'fixedPrice', 'usagePrice'
20 | @reserved_instance[name] = @value.to_f
21 | when 'item'
22 | @response['reservedInstancesSet'] << @reserved_instance
23 | @reserved_instance = {}
24 | when 'requestId'
25 | @response[name] = @value
26 | when 'start'
27 | @response[name] = Time.parse(@value)
28 | end
29 | end
30 |
31 | end
32 |
33 | end
34 | end
35 | end
36 | end
37 |
--------------------------------------------------------------------------------
/benchs/parse_vs_push.rb:
--------------------------------------------------------------------------------
1 | require 'benchmark'
2 | require 'rubygems'
3 | require 'nokogiri'
4 |
5 | class Parser < Nokogiri::XML::SAX::Document
6 |
7 | attr_reader :response
8 |
9 | def initialize
10 | reset
11 | end
12 |
13 | def reset
14 | @item = {}
15 | @response = { :items => [] }
16 | end
17 |
18 | def characters(string)
19 | @value << string.strip
20 | end
21 |
22 | def start_element(name, attrs = [])
23 | @value = nil
24 | end
25 |
26 | def end_element(name)
27 | case name
28 | when 'item'
29 | @response[:items] << @item
30 | @item = {}
31 | when 'key'
32 | @item[:key] = @value
33 | end
34 | end
35 |
36 | end
37 |
38 | data = <<-DATA
39 |
40 | -
41 | value
42 |
43 |
44 | DATA
45 |
46 | COUNT = 100
47 |
48 | Benchmark.bmbm(25) do |bench|
49 | bench.report('parse') do
50 | parser = Parser.new
51 | Nokogiri::XML::SAX::Parser.new(parser).parse(data)
52 | parser.response
53 | end
54 |
55 | bench.report('push') do
56 | parser = Parser.new
57 | Nokogiri::XML::SAX::PushParser.new(parser).write(data, true)
58 | parser.response
59 | end
60 | end
61 |
--------------------------------------------------------------------------------
/lib/fog/aws/models/ec2/security_groups.rb:
--------------------------------------------------------------------------------
1 | require 'fog/collection'
2 | require 'fog/aws/models/ec2/security_group'
3 |
4 | module Fog
5 | module AWS
6 | module EC2
7 |
8 | class Mock
9 | def security_groups
10 | Fog::AWS::EC2::SecurityGroups.new(:connection => self)
11 | end
12 | end
13 |
14 | class Real
15 | def security_groups
16 | Fog::AWS::EC2::SecurityGroups.new(:connection => self)
17 | end
18 | end
19 |
20 | class SecurityGroups < Fog::Collection
21 |
22 | attribute :group_name
23 |
24 | model Fog::AWS::EC2::SecurityGroup
25 |
26 | def initialize(attributes)
27 | @group_name ||= []
28 | super
29 | end
30 |
31 | def all(group_name = @group_name)
32 | @group_name = group_name
33 | data = connection.describe_security_groups(group_name).body
34 | load(data['securityGroupInfo'])
35 | end
36 |
37 | def get(group_name)
38 | if group_name
39 | all(group_name).first
40 | end
41 | rescue Excon::Errors::BadRequest
42 | nil
43 | end
44 |
45 | end
46 |
47 | end
48 | end
49 | end
50 |
--------------------------------------------------------------------------------
/lib/fog/terremark/requests/shared/get_catalog.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Terremark
3 | module Shared
4 | module Real
5 |
6 | # Get details of a catalog
7 | #
8 | # ==== Parameters
9 | # * vdc_id<~Integer> - Id of vdc to view catalog for
10 | #
11 | # ==== Returns
12 | # * response<~Excon::Response>:
13 | # * body<~Hash>:
14 | # * 'CatalogItems'<~Array>
15 | # * 'href'<~String> - linke to item
16 | # * 'name'<~String> - name of item
17 | # * 'type'<~String> - type of item
18 | # * 'description'<~String> - Description of catalog
19 | # * 'name'<~String> - Name of catalog
20 | def get_catalog(vdc_id)
21 | request(
22 | :expects => 200,
23 | :method => 'GET',
24 | :parser => Fog::Parsers::Terremark::Shared::GetCatalog.new,
25 | :path => "vdc/#{vdc_id}/catalog"
26 | )
27 | end
28 |
29 | end
30 |
31 | module Mock
32 |
33 | def get_catalog(vdc_id)
34 | raise MockNotImplemented.new("Contributions welcome!")
35 | end
36 |
37 | end
38 | end
39 | end
40 | end
41 |
--------------------------------------------------------------------------------
/lib/fog/terremark/models/shared/addresses.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Terremark
3 | module Shared
4 |
5 | module Mock
6 | def addresses(options = {})
7 | Fog::Terremark::Shared::Addresses.new(options.merge(:connection => self))
8 | end
9 | end
10 |
11 | module Real
12 | def addresses(options = {})
13 | Fog::Terremark::Shared::Addresses.new(options.merge(:connection => self))
14 | end
15 | end
16 |
17 | class Addresses < Fog::Collection
18 |
19 | model Fog::Terremark::Shared::Address
20 |
21 | def all
22 | load(connection.get_public_ips(vdc_id).body['PublicIpAddresses'])
23 | end
24 |
25 | def get(ip_id)
26 | if ip_id && ip = connection.get_public_ip(ip_id).body
27 | new(ip)
28 | elsif !ip_id
29 | nil
30 | end
31 | rescue Excon::Errors::Forbidden
32 | nil
33 | end
34 |
35 | def vdc_id
36 | @vdc_id ||= connection.default_vdc_id
37 | end
38 |
39 | private
40 |
41 | def vdc_id=(new_vdc_id)
42 | @vdc_id = new_vdc_id
43 | end
44 |
45 | end
46 |
47 | end
48 | end
49 | end
50 |
--------------------------------------------------------------------------------
/lib/fog/terremark/parsers/shared/task.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module Terremark
4 | module Shared
5 |
6 | class Task < Fog::Parsers::Base
7 |
8 | def reset
9 | @response = {}
10 | end
11 |
12 | def start_element(name, attributes)
13 | super
14 | case name
15 | when 'Owner', 'Result', 'Link', 'Error'
16 | data = {}
17 | until attributes.empty?
18 | data[attributes.shift] = attributes.shift
19 | end
20 | @response[name] = data
21 | when 'Task'
22 | task = {}
23 | until attributes.empty?
24 | if attributes.first.is_a?(Array)
25 | attribute = attributes.shift
26 | task[attribute.first] = attribute.last
27 | else
28 | task[attributes.shift] = attributes.shift
29 | end
30 | end
31 | @response.merge!(task.reject {|key,value| !['endTime', 'href', 'startTime', 'status', 'type'].include?(key)})
32 | end
33 | end
34 |
35 | end
36 |
37 | end
38 | end
39 | end
40 | end
41 |
--------------------------------------------------------------------------------
/lib/fog/aws/parsers/simpledb/select.rb:
--------------------------------------------------------------------------------
1 | require 'fog/aws/parsers/simpledb/basic'
2 |
3 | module Fog
4 | module Parsers
5 | module AWS
6 | module SimpleDB
7 |
8 | class Select < Fog::Parsers::AWS::SimpleDB::Basic
9 |
10 | def reset
11 | @item_name = @attribute_name = nil
12 | @response = { 'Items' => {} }
13 | end
14 |
15 | def end_element(name)
16 | case name
17 | when 'BoxUsage'
18 | response[name] = @value.to_f
19 | when 'Item'
20 | @item_name = @attribute_name = nil
21 | when 'Name'
22 | if @item_name.nil?
23 | @item_name = @value
24 | response['Items'][@item_name] = {}
25 | else
26 | @attribute_name = @value
27 | response['Items'][@item_name][@attribute_name] = []
28 | end
29 | when 'NextToken', 'RequestId'
30 | response[name] = @value
31 | when 'Value'
32 | response['Items'][@item_name][@attribute_name] << sdb_decode(@value)
33 | end
34 | end
35 |
36 | end
37 |
38 | end
39 | end
40 | end
41 | end
42 |
--------------------------------------------------------------------------------
/tests/slicehost/helper.rb:
--------------------------------------------------------------------------------
1 | module Slicehost
2 |
3 | def self.[](service)
4 | @@connections ||= Hash.new do |hash, key|
5 | credentials = Fog.credentials.reject do |k, v|
6 | ![:slicehost_password].include?(k)
7 | end
8 | hash[key] = case key
9 | when :slices
10 | Fog::Slicehost.new(credentials)
11 | end
12 | end
13 | @@connections[service]
14 | end
15 |
16 | module Formats
17 |
18 | BACKUP = {
19 | 'date' => String,
20 | 'id' => Integer,
21 | 'name' => String,
22 | 'slice-id' => Integer
23 | }
24 |
25 | FLAVOR = {
26 | 'id' => Integer,
27 | 'name' => String,
28 | 'price' => Integer,
29 | 'ram' => Integer
30 | }
31 |
32 | IMAGE = {
33 | 'id' => Integer,
34 | 'name' => String
35 | }
36 |
37 | SLICE = {
38 | 'addresses' => [String],
39 | 'bw-in' => Float,
40 | 'bw-out' => Float,
41 | 'flavor-id' => Integer,
42 | 'id' => Integer,
43 | 'image-id' => Integer,
44 | 'name' => String,
45 | 'progress' => Integer,
46 | 'status' => String
47 | }
48 |
49 | end
50 |
51 | end
--------------------------------------------------------------------------------
/lib/fog/webbynode/requests/get_image.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Webbynode
3 | class Real
4 |
5 | require 'fog/webbynode/parsers/get_image'
6 |
7 | # Get details of an image
8 | #
9 | # ==== Parameters
10 | # * image_id<~Integer> - Id of image to lookup
11 | #
12 | # ==== Returns
13 | # * response<~Excon::Response>:
14 | # * body<~Array>:
15 | # * 'id'<~Integer> - Id of the image
16 | # * 'name'<~String> - Name of the image
17 | def get_image(image_id)
18 | response = request(
19 | :expects => 200,
20 | :method => 'POST',
21 | :parser => Fog::Parsers::Webbynode::GetImage.new(image_id),
22 | :path => "images"
23 | )
24 |
25 | # image = response.body['images'].select { |i| i["id"] == image_id }
26 | # response.body.delete('image')
27 | # response.body['image'] = image.first if image.any?
28 | #
29 | # pp response
30 |
31 | response
32 | end
33 |
34 | end
35 |
36 | class Mock
37 |
38 | def get_image(image_id)
39 | raise MockNotImplemented.new("Contributions welcome!")
40 | end
41 |
42 | end
43 | end
44 | end
45 |
--------------------------------------------------------------------------------
/lib/fog/terremark/bin.rb:
--------------------------------------------------------------------------------
1 | module Terremark
2 | class << self
3 | if (Fog::Terremark::ECLOUD_OPTIONS.all? { |option| Fog.credentials.has_key?(option) } ) ||
4 | (Fog::Terremark::VCLOUD_OPTIONS.all? { |option| Fog.credentials.has_key?(option) } )
5 |
6 | def initialized?
7 | true
8 | end
9 |
10 | def terremark_service(service)
11 | case service
12 | when :ecloud
13 | Fog::Terremark::Ecloud
14 | when :vcloud
15 | Fog::Terremark::Vcloud
16 | else
17 | raise "Unsupported Terremark Service"
18 | end
19 | end
20 |
21 | def [](service)
22 | @@connections ||= Hash.new do |hash, key|
23 | credentials = Fog.credentials.reject do |k,v|
24 | case key
25 | when :ecloud
26 | !Fog::Terremark::ECLOUD_OPTIONS.include?(k)
27 | when :vcloud
28 | !Fog::Terremark::VCLOUD_OPTIONS.include?(k)
29 | end
30 | end
31 | hash[key] = terremark_service(key).new(credentials)
32 | end
33 | @@connections[service]
34 | end
35 |
36 | else
37 |
38 | def initialized?
39 | false
40 | end
41 |
42 | end
43 | end
44 | end
45 |
--------------------------------------------------------------------------------
/lib/fog/terremark/requests/shared/get_tasks_list.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Terremark
3 | module Shared
4 | module Real
5 |
6 | # Get list of tasks
7 | #
8 | # ==== Parameters
9 | # * tasks_list_id<~Integer> - Id of tasks lists to view
10 | #
11 | # ==== Returns
12 | # * response<~Excon::Response>:
13 | # * body<~Hash>:
14 | # * 'CatalogItems'<~Array>
15 | # * 'href'<~String> - linke to item
16 | # * 'name'<~String> - name of item
17 | # * 'type'<~String> - type of item
18 | # * 'description'<~String> - Description of catalog
19 | # * 'name'<~String> - Name of catalog
20 | def get_tasks_list(tasks_list_id)
21 | request(
22 | :expects => 200,
23 | :method => 'GET',
24 | :parser => Fog::Parsers::Terremark::Shared::GetTasksList.new,
25 | :path => "tasksList/#{tasks_list_id}"
26 | )
27 | end
28 |
29 | end
30 |
31 | module Mock
32 |
33 | def get_tasks_list(tasks_list_id)
34 | raise MockNotImplemented.new("Contributions welcome!")
35 | end
36 |
37 | end
38 | end
39 | end
40 | end
41 |
--------------------------------------------------------------------------------
/lib/fog/vcloud/parsers/login.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module Vcloud
4 |
5 | class Login < Fog::Parsers::Base
6 | #
7 | # Based off of:
8 | # http://support.theenterprisecloud.com/kb/default.asp?id=536&Lang=1&SID=
9 | # https://community.vcloudexpress.terremark.com/en-us/product_docs/w/wiki/01-get-login-token.aspx
10 | # vCloud API Guide v0.9 - Page 17
11 | #
12 |
13 | def reset
14 | @response = Struct::VcloudOrgList.new([])
15 | end
16 |
17 | def start_element(name, attributes)
18 | @value = ''
19 | case name
20 | when 'OrgList'
21 | until attributes.empty?
22 | if at = attributes.shift
23 | if at[0] == "xmlns"
24 | @response.xmlns = at[1]
25 | end
26 | end
27 | end
28 | when 'Org'
29 | organization = Struct::VcloudOrgLink.new
30 | until attributes.empty?
31 | organization[attributes.shift.downcase.to_sym] = attributes.shift
32 | end
33 | @response.organizations << organization
34 | end
35 | end
36 |
37 | end
38 | end
39 | end
40 | end
41 |
--------------------------------------------------------------------------------
/lib/fog/terremark/requests/shared/get_public_ip.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Terremark
3 | module Shared
4 | module Real
5 |
6 | # Get details for a public ip
7 | #
8 | # ==== Parameters
9 | # * public_ip_id<~Integer> - Id of public ip to look up
10 | #
11 | # ==== Returns
12 | # * response<~Excon::Response>:
13 | # * body<~Hash>:
14 | # * 'PublicIpAddresses'<~Array>
15 | # * 'href'<~String> - linke to item
16 | # * 'name'<~String> - name of item
17 | def get_public_ip(public_ip_id)
18 | opts = {
19 | :expects => 200,
20 | :method => 'GET',
21 | :parser => Fog::Parsers::Terremark::Shared::PublicIp.new,
22 | :path => "publicIps/#{public_ip_id}"
23 | }
24 | if self.class == Fog::Terremark::Ecloud::Real
25 | opts[:path] = "extensions/publicIp/#{public_ip_id}"
26 | end
27 | request(opts)
28 | end
29 |
30 | end
31 |
32 | module Mock
33 |
34 | def get_public_ip(public_ip_id)
35 | raise MockNotImplemented.new("Contributions welcome!")
36 | end
37 |
38 | end
39 | end
40 | end
41 | end
42 |
--------------------------------------------------------------------------------
/lib/fog/aws/requests/ec2/release_address.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module AWS
3 | module EC2
4 | class Real
5 |
6 | # Release an elastic IP address.
7 | #
8 | # ==== Returns
9 | # * response<~Excon::Response>:
10 | # * body<~Hash>:
11 | # * 'requestId'<~String> - Id of request
12 | # * 'return'<~Boolean> - success?
13 | def release_address(public_ip)
14 | request(
15 | 'Action' => 'ReleaseAddress',
16 | 'PublicIp' => public_ip,
17 | :parser => Fog::Parsers::AWS::EC2::Basic.new
18 | )
19 | end
20 |
21 | end
22 |
23 | class Mock
24 |
25 | def release_address(public_ip)
26 | response = Excon::Response.new
27 | if (address = @data[:addresses].delete(public_ip))
28 | response.status = 200
29 | response.body = {
30 | 'requestId' => Fog::AWS::Mock.request_id,
31 | 'return' => true
32 | }
33 | else
34 | response.status = 400
35 | raise(Excon::Errors.status_error({:expects => 200}, response))
36 | end
37 | response
38 | end
39 |
40 | end
41 | end
42 | end
43 | end
44 |
--------------------------------------------------------------------------------
/lib/fog/rackspace/models/files/directories.rb:
--------------------------------------------------------------------------------
1 | require 'fog/collection'
2 | require 'fog/rackspace/models/files/directory'
3 |
4 | module Fog
5 | module Rackspace
6 | module Files
7 |
8 | class Real
9 | def directories
10 | Fog::Rackspace::Files::Directories.new(:connection => self)
11 | end
12 | end
13 |
14 | class Mock
15 | def directories
16 | Fog::Rackspace::Files::Directories.new(:connection => self)
17 | end
18 | end
19 |
20 | class Directories < Fog::Collection
21 |
22 | model Fog::Rackspace::Files::Directory
23 |
24 | def all
25 | data = connection.get_containers.body
26 | load(data)
27 | end
28 |
29 | def get(key, options = {})
30 | data = connection.get_container(key, options).body
31 | directory = new(:key => key)
32 | directory.files.merge_attributes(options)
33 | directory.files.instance_variable_set(:@loaded, true)
34 | data.each do |file|
35 | directory.files << directory.files.new(file)
36 | end
37 | directory
38 | rescue Excon::Errors::NotFound
39 | nil
40 | end
41 |
42 | end
43 |
44 | end
45 | end
46 | end
47 |
--------------------------------------------------------------------------------
/lib/fog/aws/requests/elb/delete_load_balancer.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module AWS
3 | module ELB
4 | class Real
5 |
6 | # Delete an existing Elastic Load Balancer
7 | #
8 | # Note that this API call, as defined by Amazon, is idempotent.
9 | # That is, it will not return an error if you try to delete an
10 | # ELB that does not exist.
11 | #
12 | # ==== Parameters
13 | # * lb_name<~String> - Name of the ELB to be deleted
14 | # ==== Returns
15 | # * response<~Excon::Response>:
16 | # * body<~Hash>:
17 | # * 'DeleteLoadBalancerResponse'<~nil>
18 | # * 'ResponseMetadata'<~Hash>:
19 | # * 'RequestId'<~String> - Id of request
20 | def delete_load_balancer(lb_name)
21 | request({
22 | 'Action' => 'DeleteLoadBalancer',
23 | 'LoadBalancerName' => lb_name,
24 | :parser => Fog::Parsers::AWS::ELB::DeleteLoadBalancer.new
25 | })
26 | end
27 |
28 | end
29 |
30 | class Mock
31 |
32 | def delete_load_balancer(lb_name)
33 | raise MockNotImplemented.new("Contributions welcome!")
34 | end
35 |
36 | end
37 |
38 | end
39 | end
40 | end
41 |
--------------------------------------------------------------------------------
/lib/fog/rackspace/models/servers/images.rb:
--------------------------------------------------------------------------------
1 | require 'fog/collection'
2 | require 'fog/rackspace/models/servers/image'
3 |
4 | module Fog
5 | module Rackspace
6 | module Servers
7 |
8 | class Real
9 | def images(attributes = {})
10 | Fog::Rackspace::Servers::Images.new({
11 | :connection => self
12 | }.merge!(attributes))
13 | end
14 | end
15 |
16 | class Mock
17 | def images(attributes = {})
18 | Fog::Rackspace::Servers::Images.new({
19 | :connection => self
20 | }.merge!(attributes))
21 | end
22 | end
23 |
24 | class Images < Fog::Collection
25 |
26 | model Fog::Rackspace::Servers::Image
27 |
28 | attribute :server
29 |
30 | def all
31 | data = connection.list_images_detail.body['images']
32 | load(data)
33 | if server
34 | self.replace(self.select {|image| image.server_id == server.id})
35 | end
36 | end
37 |
38 | def get(image_id)
39 | data = connection.get_image_details(image_id).body['image']
40 | new(data)
41 | rescue Excon::Errors::NotFound
42 | nil
43 | end
44 |
45 | end
46 |
47 | end
48 | end
49 | end
50 |
--------------------------------------------------------------------------------
/lib/fog/aws/requests/simpledb/create_domain.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module AWS
3 | module SimpleDB
4 | class Real
5 |
6 | # Create a SimpleDB domain
7 | #
8 | # ==== Parameters
9 | # * domain_name<~String>:: Name of domain. Must be between 3 and 255 of the
10 | # following characters: a-z, A-Z, 0-9, '_', '-' and '.'.
11 | #
12 | # ==== Returns
13 | # * response<~Excon::Response>:
14 | # * body<~Hash>:
15 | # * 'BoxUsage'
16 | # * 'RequestId'
17 | def create_domain(domain_name)
18 | request(
19 | 'Action' => 'CreateDomain',
20 | 'DomainName' => domain_name,
21 | :parser => Fog::Parsers::AWS::SimpleDB::Basic.new(@nil_string)
22 | )
23 | end
24 |
25 | end
26 |
27 | class Mock
28 |
29 | def create_domain(domain_name)
30 | response = Excon::Response.new
31 | @data[:domains][domain_name] = {}
32 | response.status = 200
33 | response.body = {
34 | 'BoxUsage' => Fog::AWS::Mock.box_usage,
35 | 'RequestId' => Fog::AWS::Mock.request_id
36 | }
37 | response
38 | end
39 |
40 | end
41 | end
42 | end
43 | end
44 |
--------------------------------------------------------------------------------
/lib/fog/vcloud/requests/get_versions.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Vcloud
3 |
4 | class Real
5 |
6 | def get_versions
7 | unauthenticated_request({
8 | :expects => 200,
9 | :method => 'GET',
10 | :parser => Fog::Parsers::Vcloud::GetVersions.new,
11 | :uri => @versions_uri
12 | })
13 | end
14 |
15 | end
16 |
17 | class Mock
18 |
19 | def get_versions
20 | #
21 | # Based off of:
22 | # http://support.theenterprisecloud.com/kb/default.asp?id=535&Lang=1&SID=
23 | # https://community.vcloudexpress.terremark.com/en-us/product_docs/w/wiki/02-get-versions.aspx
24 | # vCloud API Guide v0.9 - Page 89
25 | #
26 | xml = Builder::XmlMarkup.new
27 |
28 | mock_it Fog::Parsers::Vcloud::GetVersions.new, 200,
29 | xml.SupportedVersions( xmlns.merge("xmlns" => "http://www.vmware.com/vcloud/versions")) {
30 |
31 | DATA[:versions].select {|version| version[:supported] }.each do |version|
32 | xml.VersionInfo {
33 | xml.Version(version[:version])
34 | xml.LoginUrl(version[:login_url])
35 | }
36 | end
37 | }
38 |
39 | end
40 |
41 | end
42 | end
43 | end
44 |
--------------------------------------------------------------------------------
/spec/rackspace/requests/files/delete_object_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../../../spec_helper'
2 |
3 | describe 'Rackspace::Files.delete_object' do
4 | describe 'success' do
5 |
6 | before(:each) do
7 | Rackspace[:files].put_container('container_name')
8 | Rackspace[:files].put_object('container_name', 'object_name', lorem_file)
9 | end
10 |
11 | after(:each) do
12 | Rackspace[:files].delete_container('container_name')
13 | end
14 |
15 | it "should return proper attributes" do
16 | Rackspace[:files].delete_object('container_name', 'object_name')
17 | end
18 |
19 | end
20 | describe 'failure' do
21 |
22 | it "should raise a NotFound error if the container does not exist" do
23 | lambda do
24 | Rackspace[:files].delete_object('container_name', 'object_name')
25 | end.should raise_error(Excon::Errors::NotFound)
26 | end
27 |
28 | it "should raise a NotFound error if the object does not exist" do
29 | Rackspace[:files].put_container('container_name')
30 | lambda do
31 | Rackspace[:files].delete_object('container_name', 'object_name')
32 | end.should raise_error(Excon::Errors::NotFound)
33 | Rackspace[:files].delete_container('container_name')
34 | end
35 |
36 | end
37 | end
38 |
--------------------------------------------------------------------------------
/lib/fog/aws/parsers/s3/get_bucket_logging.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module AWS
4 | module S3
5 |
6 | class AccessControlList < Fog::Parsers::Base
7 |
8 | def reset
9 | @grant = { 'Grantee' => {} }
10 | @response = { 'BucketLoggingStatus' => {} }
11 | end
12 |
13 | def end_element(name)
14 | case name
15 | when 'DisplayName', 'ID'
16 | if @in_access_control_list
17 | @grant['Grantee'][name] = @value
18 | else
19 | @response['Owner'][name] = @value
20 | end
21 | when 'Grant'
22 | @response['BucketLoggingStatus']['LoggingEnabled']['TargetGrants'] << @grant
23 | @grant = { 'Grantee' => {} }
24 | when 'LoggingEnabled'
25 | @response['BucketLoggingStatus']['LoggingEnabled'] = { 'TargetGrants' => [] }
26 | when 'Permission'
27 | @grant[name] = @value
28 | when 'TargetBucket', 'TargetPrefix'
29 | @response['BucketLoggingStatus'][name] = @value
30 | when 'URI'
31 | @grant['Grantee'][name] = @value
32 | end
33 | end
34 |
35 | end
36 |
37 | end
38 | end
39 | end
40 | end
41 |
--------------------------------------------------------------------------------
/tests/rackspace/requests/servers/reboot_server_tests.rb:
--------------------------------------------------------------------------------
1 | Shindo.tests('Rackspace::Servers#reboot_server', 'rackspace') do
2 | tests('success') do
3 |
4 | before do
5 | @server_id = Rackspace[:servers].create_server(1, 3, 'fogrebootserver').body['server']['id']
6 | end
7 |
8 | after do
9 | Fog.wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
10 | Rackspace[:servers].delete_server(@server_id)
11 | end
12 |
13 | tests('HARD') do
14 | test('has proper output format') do
15 | Fog.wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
16 | Rackspace[:servers].reboot_server(@server_id, 'HARD')
17 | end
18 | end
19 |
20 | tests('SOFT') do
21 | test('has proper output format') do
22 | Fog.wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
23 | Rackspace[:servers].reboot_server(@server_id, 'SOFT')
24 | end
25 | end
26 |
27 | end
28 | tests('failure') do
29 |
30 | test('raises NotFound error if server does not exist') do
31 | has_error(Excon::Errors::NotFound) do
32 | Rackspace[:servers].reboot_server(0)
33 | end
34 | end
35 |
36 | end
37 |
38 | end
39 |
--------------------------------------------------------------------------------
/lib/fog/terremark/parsers/shared/instantiate_vapp_template.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module Terremark
4 | module Shared
5 |
6 | class InstantiateVappTemplate < Fog::Parsers::Base
7 |
8 | def reset
9 | @property_key
10 | @response = { 'Links' => [] }
11 | end
12 |
13 | def start_element(name, attributes)
14 | super
15 | case name
16 | when 'Link'
17 | link = {}
18 | until attributes.empty?
19 | link[attributes.shift] = attributes.shift
20 | end
21 | @response['Links'] << link
22 | when 'VApp'
23 | vapp_template = {}
24 | until attributes.empty?
25 | if attributes.first.is_a?(Array)
26 | attribute = attributes.shift
27 | vapp_template[attribute.first] = attribute.last
28 | else
29 | vapp_template[attributes.shift] = attributes.shift
30 | end
31 | end
32 | @response.merge!(vapp_template.reject {|key, value| !['href', 'name', 'size', 'status', 'type'].include?(key)})
33 | end
34 | end
35 |
36 | end
37 |
38 | end
39 | end
40 | end
41 | end
42 |
--------------------------------------------------------------------------------
/lib/fog/terremark/requests/shared/get_catalog_item.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Terremark
3 | module Shared
4 | module Real
5 |
6 | # Get details of a catalog item
7 | #
8 | # ==== Parameters
9 | # * catalog_item_id<~Integer> - Id of catalog item to lookup
10 | #
11 | # ==== Returns
12 | # * response<~Excon::Response>:
13 | # * body<~Hash>:
14 |
15 | # FIXME
16 |
17 | # * 'CatalogItems'<~Array>
18 | # * 'href'<~String> - linke to item
19 | # * 'name'<~String> - name of item
20 | # * 'type'<~String> - type of item
21 | # * 'description'<~String> - Description of catalog
22 | # * 'name'<~String> - Name of catalog
23 | def get_catalog_item(catalog_item_id)
24 | request(
25 | :expects => 200,
26 | :method => 'GET',
27 | :parser => Fog::Parsers::Terremark::Shared::GetCatalogItem.new,
28 | :path => "catalogItem/#{catalog_item_id}"
29 | )
30 | end
31 |
32 | end
33 |
34 | module Mock
35 |
36 | def get_catalog_item(catalog_item_id)
37 | raise MockNotImplemented.new("Contributions welcome!")
38 | end
39 |
40 | end
41 | end
42 | end
43 | end
44 |
--------------------------------------------------------------------------------
/lib/fog/aws/requests/simpledb/delete_domain.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module AWS
3 | module SimpleDB
4 | class Real
5 |
6 | # Delete a SimpleDB domain
7 | #
8 | # ==== Parameters
9 | # * domain_name<~String>:: Name of domain. Must be between 3 and 255 of the
10 | # following characters: a-z, A-Z, 0-9, '_', '-' and '.'.
11 | #
12 | # ==== Returns
13 | # * response<~Excon::Response>:
14 | # * body<~Hash>:
15 | # * 'BoxUsage'
16 | # * 'RequestId'
17 | def delete_domain(domain_name)
18 | request(
19 | 'Action' => 'DeleteDomain',
20 | 'DomainName' => domain_name,
21 | :parser => Fog::Parsers::AWS::SimpleDB::Basic.new(@nil_string)
22 | )
23 | end
24 |
25 | end
26 |
27 | class Mock
28 |
29 | def delete_domain(domain_name)
30 | response = Excon::Response.new
31 | if @data[:domains].delete(domain_name)
32 | response.status = 200
33 | response.body = {
34 | 'BoxUsage' => Fog::AWS::Mock.box_usage,
35 | 'RequestId' => Fog::AWS::Mock.request_id
36 | }
37 | end
38 | response
39 | end
40 |
41 | end
42 | end
43 | end
44 | end
45 |
--------------------------------------------------------------------------------
/lib/fog/terremark/requests/shared/get_vapp_template.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Terremark
3 | module Shared
4 | module Real
5 |
6 | # Get details of a vapp template
7 | #
8 | # ==== Parameters
9 | # * vapp_template_id<~Integer> - Id of vapp template to lookup
10 | #
11 | # ==== Returns
12 | # * response<~Excon::Response>:
13 | # * body<~Hash>:
14 |
15 | # FIXME
16 |
17 | # * 'CatalogItems'<~Array>
18 | # * 'href'<~String> - linke to item
19 | # * 'name'<~String> - name of item
20 | # * 'type'<~String> - type of item
21 | # * 'description'<~String> - Description of catalog
22 | # * 'name'<~String> - Name of catalog
23 | def get_vapp_template(vapp_template_id)
24 | request(
25 | :expects => 200,
26 | :method => 'GET',
27 | :parser => Fog::Parsers::Terremark::Shared::GetVappTemplate.new,
28 | :path => "vAppTemplate/#{vapp_template_id}"
29 | )
30 | end
31 |
32 | end
33 |
34 | module Mock
35 |
36 | def get_vapp_template(vapp_template_id)
37 | raise MockNotImplemented.new("Contributions welcome!")
38 | end
39 |
40 | end
41 | end
42 | end
43 | end
44 |
--------------------------------------------------------------------------------
/lib/fog/vcloud/parsers/get_versions.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Parsers
3 | module Vcloud
4 |
5 | class GetVersions < Fog::Parsers::Base
6 | #
7 | # Based off of:
8 | # http://support.theenterprisecloud.com/kb/default.asp?id=535&Lang=1&SID=
9 | # https://community.vcloudexpress.terremark.com/en-us/product_docs/w/wiki/02-get-versions.aspx
10 | # vCloud API Guide v0.9 - Page 89
11 | #
12 |
13 | def reset
14 | @response = []
15 | @supported = false
16 | end
17 |
18 | def start_element(name, attributes = {})
19 | @value = ''
20 | case name
21 | when "Version"
22 | @version = Struct::VcloudVersion.new
23 | when "SupportedVersions"
24 | @supported = true
25 | end
26 | end
27 |
28 | def end_element(name)
29 | case name
30 | when "Version"
31 | @version.version = @value
32 | @version.supported = @supported
33 | when "LoginUrl"
34 | @version.login_url = @value
35 | when "VersionInfo"
36 | @response << @version
37 | when "SupportedVersions"
38 | @supported = false
39 | end
40 | end
41 |
42 | end
43 |
44 | end
45 | end
46 | end
47 |
--------------------------------------------------------------------------------
/lib/fog/rackspace/requests/servers/delete_image.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Rackspace
3 | module Servers
4 | class Real
5 |
6 | # Delete an image
7 | #
8 | # ==== Parameters
9 | # * image_id<~Integer> - Id of image to delete
10 | #
11 | def delete_image(image_id)
12 | request(
13 | :expects => 204,
14 | :method => 'DELETE',
15 | :path => "images/#{image_id}"
16 | )
17 | end
18 |
19 | end
20 |
21 | class Mock
22 |
23 | def delete_image(image_id)
24 | response = Excon::Response.new
25 | if image = list_images_detail.body['images'].detect {|image| image['id'] == image_id}
26 | if image['status'] == 'SAVING'
27 | response.status = 409
28 | raise(Excon::Errors.status_error({:expects => 202}, response))
29 | else
30 | @data[:last_modified][:images].delete(image_id)
31 | @data[:images].delete(image_id)
32 | response.status = 202
33 | end
34 | else
35 | response.status = 400
36 | raise(Excon::Errors.status_error({:expects => 202}, response))
37 | end
38 | response
39 | end
40 |
41 | end
42 | end
43 | end
44 | end
45 |
--------------------------------------------------------------------------------
/lib/fog/rackspace/requests/servers/list_public_addresses.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Rackspace
3 | module Servers
4 | class Real
5 |
6 | # List public server addresses
7 | #
8 | # ==== Parameters
9 | # * server_id<~Integer> - Id of server to list addresses for
10 | #
11 | # ==== Returns
12 | # * response<~Excon::Response>:
13 | # * body<~Hash>:
14 | # * 'public'<~Array> - Public ip addresses
15 | def list_public_addresses(server_id)
16 | request(
17 | :expects => [200, 203],
18 | :method => 'GET',
19 | :path => "servers/#{server_id}/ips/public.json"
20 | )
21 | end
22 |
23 | end
24 |
25 | class Mock
26 |
27 | def list_public_addresses(server_id)
28 | response = Excon::Response.new
29 | if server = list_servers_detail.body['servers'].detect { |server| server['id'] == server_id }
30 | response.status = [200, 203][rand(1)]
31 | response.body = { 'public' => server['addresses']['public'] }
32 | else
33 | response.status = 404
34 | raise(Excon::Errors.status_error({:expects => 202}, response))
35 | end
36 | response
37 | end
38 |
39 | end
40 | end
41 | end
42 | end
43 |
--------------------------------------------------------------------------------
/lib/fog/rackspace/requests/servers/delete_server.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Rackspace
3 | module Servers
4 | class Real
5 |
6 | # Delete an existing server
7 | #
8 | # ==== Parameters
9 | # * id<~Integer> - Id of server to delete
10 | #
11 | def delete_server(server_id)
12 | request(
13 | :expects => 202,
14 | :method => 'DELETE',
15 | :path => "servers/#{server_id}"
16 | )
17 | end
18 |
19 | end
20 |
21 | class Mock
22 |
23 | def delete_server(server_id)
24 | response = Excon::Response.new
25 | if server = list_servers_detail.body['servers'].detect { |server| server['id'] == server_id }
26 | if server['status'] == 'BUILD'
27 | response.status = 409
28 | raise(Excon::Errors.status_error({:expects => 202}, response))
29 | else
30 | @data[:last_modified][:servers].delete(server_id)
31 | @data[:servers].delete(server_id)
32 | response.status = 202
33 | end
34 | else
35 | response.status = 404
36 | raise(Excon::Errors.status_error({:expects => 202}, response))
37 | end
38 | response
39 | end
40 |
41 | end
42 | end
43 | end
44 | end
45 |
--------------------------------------------------------------------------------
/lib/fog/rackspace/requests/servers/list_private_addresses.rb:
--------------------------------------------------------------------------------
1 | module Fog
2 | module Rackspace
3 | module Servers
4 | class Real
5 |
6 | # List private server addresses
7 | #
8 | # ==== Parameters
9 | # * server_id<~Integer> - Id of server to list addresses for
10 | #
11 | # ==== Returns
12 | # * response<~Excon::Response>:
13 | # * body<~Hash>:
14 | # * 'private'<~Array> - Public ip addresses
15 | def list_private_addresses(server_id)
16 | request(
17 | :expects => [200, 203],
18 | :method => 'GET',
19 | :path => "servers/#{server_id}/ips/private.json"
20 | )
21 | end
22 |
23 | end
24 |
25 | class Mock
26 |
27 | def list_private_addresses(server_id)
28 | response = Excon::Response.new
29 | if server = list_servers_detail.body['servers'].detect { |server| server['id'] == server_id }
30 | response.status = [200, 203][rand(1)]
31 | response.body = { 'private' => server['addresses']['private'] }
32 | else
33 | response.status = 404
34 | raise(Excon::Errors.status_error({:expects => 202}, response))
35 | end
36 | response
37 | end
38 |
39 | end
40 | end
41 | end
42 | end
43 |
--------------------------------------------------------------------------------