fog-openstack-0.1.6/0000755000175600017570000000000012730051546013322 5ustar pravipravifog-openstack-0.1.6/.hound.yml0000644000175600017570000000004212730051546015234 0ustar pravipraviruby: config_file: .rubocop.yml fog-openstack-0.1.6/LICENSE.md0000644000175600017570000000220312730051546014723 0ustar pravipraviThe MIT License (MIT) Copyright (c) 2014-2015 [CONTRIBUTORS.md](https://github.com/fog/fog-rackspace/blob/master/CONTRIBUTORS.md) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. fog-openstack-0.1.6/CONTRIBUTING.md0000644000175600017570000000156512730051546015562 0ustar pravipravi## Getting Involved New contributors are always welcome, when it doubt please ask questions. We strive to be an open and welcoming community. Please be nice to one another. ### Coding * Pick a task: * Offer feedback on open [pull requests](https://github.com/fog/fog-openstack/pulls). * Review open [issues](https://github.com/fog/fog-openstack/issues) for things to help on. * [Create an issue](https://github.com/fog/fog-openstack/issues/new) to start a discussion on additions or features. * Fork the project, add your changes and tests to cover them in a topic branch. * Commit your changes and rebase against `fog/fog-openstack` to ensure everything is up to date. * [Submit a pull request](https://github.com/fog/fog-openstack/compare/). ### Non-Coding * Offer feedback on open [issues](https://github.com/fog/fog-openstack/issues). * Organize or volunteer at events. fog-openstack-0.1.6/.rubocop.yml0000644000175600017570000000332612730051546015600 0ustar pravipravi# # Overrides # AbcSize: Severity: refactor AlignHash: EnforcedHashRocketStyle: table EnforcedColonStyle: table BlockNesting: Severity: refactor ClassLength: Severity: refactor ClassCheck: EnforcedStyle: kind_of? CollectionMethods: PreferredMethods: find: detect find_all: select map: collect reduce: inject CyclomaticComplexity: Severity: refactor FormatString: EnforcedStyle: percent HashSyntax: EnforcedStyle: hash_rockets LineLength: Max: 120 Severity: refactor MethodLength: Max: 25 Severity: refactor ParameterLists: Severity: refactor PerceivedComplexity: Severity: refactor RedundantReturn: AllowMultipleReturnValues: true SignalException: EnforcedStyle: only_raise SingleLineMethods: AllowIfMethodIsEmpty: false SpaceInsideHashLiteralBraces: EnforcedStyle: no_space TrivialAccessors: AllowPredicates: true # # Enabled/Disabled # ClassAndModuleChildren: Enabled: false DefEndAlignment: AutoCorrect: true Documentation: Enabled: false Encoding: Enabled: false EndAlignment: AutoCorrect: true ExtraSpacing: AutoCorrect: false # https://github.com/bbatsov/rubocop/issues/2280 FindEach: Enabled: false GuardClause: Enabled: false IfUnlessModifier: Enabled: false NumericLiterals: AutoCorrect: false MinDigits: 7 ParallelAssignment: Enabled: false PerlBackrefs: Enabled: false ReadWriteAttribute: AutoCorrect: false RescueModifier: AutoCorrect: false SingleLineBlockParams: Enabled: false SpaceBeforeFirstArg: Enabled: false SpecialGlobalVars: AutoCorrect: false StringLiterals: Enabled: false StringLiteralsInInterpolation: Enabled: false TrailingCommaInLiteral: Enabled: false WhileUntilModifier: Enabled: false WordArray: AutoCorrect: falsefog-openstack-0.1.6/.travis.yml0000644000175600017570000000132212730051546015431 0ustar pravipravilanguage: ruby sudo: false script: - bundle exec rake test - bundle exec rake minitest - bundle exec rake spec env: - JRUBY_OPTS=--debug matrix: fast_finish: true include: - rvm: 1.9.3 gemfile: gemfiles/Gemfile-1.9 - rvm: 2.0.0 gemfile: Gemfile - rvm: 2.1.0 gemfile: Gemfile - rvm: 2.1.1 gemfile: Gemfile - rvm: 2.2.0 gemfile: Gemfile - rvm: 2.3.0 gemfile: Gemfile - rvm: jruby-19mode gemfile: gemfiles/Gemfile-1.9 - rvm: jruby-head gemfile: Gemfile allow_failures: - rvm: jruby-head notifications: webhooks: urls: - https://webhooks.gitter.im/e/af95aadff4470a9732b9 on_success: change on_failure: always on_start: never email: false fog-openstack-0.1.6/bin/0000755000175600017570000000000012730051546014072 5ustar pravipravifog-openstack-0.1.6/bin/setup0000755000175600017570000000020312730051546015153 0ustar pravipravi#!/usr/bin/env bash set -euo pipefail IFS=$'\n\t' set -vx bundle install # Do any other automated setup that you need to do here fog-openstack-0.1.6/bin/console0000755000175600017570000000052212730051546015461 0ustar pravipravi#!/usr/bin/env ruby require "bundler/setup" require "fog/openstack" # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. # (If you use this, don't forget to add pry to your Gemfile!) # require "pry" # Pry.start require "irb" IRB.start fog-openstack-0.1.6/tests/0000755000175600017570000000000012730051546014464 5ustar pravipravifog-openstack-0.1.6/tests/fixtures/0000755000175600017570000000000012730051546016335 5ustar pravipravifog-openstack-0.1.6/tests/fixtures/introspection.yaml0000644000175600017570000002240312730051546022122 0ustar pravipravi--- :rules: - description: Successful Rule actions: - action: set-attribute path: /extra/rule_success value: 'yes' conditions: - field: memory_mb op: ge value: 256 - field: local_gb op: ge value: 1 links: - href: /v1/rules/8dbc8e15-506e-4bd1-82e7-b090e0d33cae rel: self uuid: 8dbc8e15-506e-4bd1-82e7-b090e0d33cae - description: Failing Rule actions: - action: set-attribute path: /extra/rule_success value: 'no' - action: fail message: This rule should not have run conditions: - field: memory_mb op: lt value: 42 - field: local_gb op: eq value: 0 links: - href: /v1/rules/abf9337e-a38d-4041-ba7a-d4e5ac0cc134 rel: self uuid: abf9337e-a38d-4041-ba7a-d4e5ac0cc134 :introspection_data: cpu_arch: x86_64 macs: - 52:54:00:40:d0:11 root_disk: rotational: true vendor: '0x1af4' name: "/dev/vda" wwn_vendor_extension: wwn_with_extension: model: '' wwn: serial: size: 64424509440 extra: network: eth0: vlan-challenged: off [fixed] tx-udp_tnl-segmentation: off [fixed] ipv4-network: 192.0.2.0 rx-vlan-stag-filter: off [fixed] highdma: on [fixed] tx-nocache-copy: 'off' tx-gso-robust: off [fixed] fcoe-mtu: off [fixed] netns-local: off [fixed] udp-fragmentation-offload: 'on' serial: 52:54:00:40:d0:11 latency: 0 tx-checksumming/tx-checksum-ipv6: off [fixed] tx-checksumming/tx-checksum-ipv4: off [fixed] ipv4-netmask: 255.255.255.0 tcp-segmentation-offload/tx-tcp-segmentation: 'on' tx-ipip-segmentation: off [fixed] rx-vlan-offload: off [fixed] tx-gre-segmentation: off [fixed] tx-checksumming/tx-checksum-ip-generic: 'on' tcp-segmentation-offload/tx-tcp-ecn-segmentation: 'on' tx-checksumming/tx-checksum-fcoe-crc: off [fixed] ipv4: 192.0.2.100 businfo: pci@0000:00:03.0 rx-vlan-stag-hw-parse: off [fixed] tx-vlan-offload: off [fixed] product: Virtio network device vendor: Red Hat, Inc tx-checksumming/tx-checksum-sctp: off [fixed] driver: virtio_net tx-sit-segmentation: off [fixed] busy-poll: off [fixed] tx-vlan-stag-hw-insert: off [fixed] scatter-gather/tx-scatter-gather: 'on' link: 'yes' ntuple-filters: off [fixed] rx-all: off [fixed] tcp-segmentation-offload: 'on' tcp-segmentation-offload/tx-tcp6-segmentation: 'on' rx-checksumming: on [fixed] rx-fcs: off [fixed] tx-lockless: off [fixed] generic-segmentation-offload: 'on' tx-fcoe-segmentation: off [fixed] tx-checksumming: 'on' ipv4-cidr: 24 large-receive-offload: off [fixed] rx-vlan-filter: on [fixed] receive-hashing: off [fixed] scatter-gather/tx-scatter-gather-fraglist: off [fixed] generic-receive-offload: 'on' loopback: off [fixed] scatter-gather: 'on' tx-mpls-segmentation: off [fixed] eth1: vlan-challenged: off [fixed] tx-udp_tnl-segmentation: off [fixed] tx-vlan-stag-hw-insert: off [fixed] rx-vlan-stag-filter: off [fixed] highdma: on [fixed] tx-nocache-copy: 'off' tx-gso-robust: off [fixed] fcoe-mtu: off [fixed] netns-local: off [fixed] udp-fragmentation-offload: 'on' serial: 52:54:00:11:c5:d8 latency: 0 tx-checksumming/tx-checksum-ipv6: off [fixed] tx-checksumming/tx-checksum-ipv4: off [fixed] tx-fcoe-segmentation: off [fixed] tcp-segmentation-offload/tx-tcp-segmentation: 'on' tx-ipip-segmentation: off [fixed] rx-vlan-offload: off [fixed] tx-gre-segmentation: off [fixed] tx-checksumming/tx-checksum-ip-generic: 'on' tcp-segmentation-offload/tx-tcp-ecn-segmentation: 'on' tx-checksumming/tx-checksum-fcoe-crc: off [fixed] rx-vlan-stag-hw-parse: off [fixed] businfo: pci@0000:00:04.0 tx-vlan-offload: off [fixed] product: Virtio network device vendor: Red Hat, Inc tx-checksumming/tx-checksum-sctp: off [fixed] driver: virtio_net tx-sit-segmentation: off [fixed] busy-poll: off [fixed] scatter-gather/tx-scatter-gather: 'on' link: 'yes' ntuple-filters: off [fixed] rx-all: off [fixed] tcp-segmentation-offload: 'on' tcp-segmentation-offload/tx-tcp6-segmentation: 'on' rx-checksumming: on [fixed] tx-lockless: off [fixed] generic-segmentation-offload: 'on' loopback: off [fixed] tx-checksumming: 'on' large-receive-offload: off [fixed] rx-vlan-filter: on [fixed] receive-hashing: off [fixed] scatter-gather/tx-scatter-gather-fraglist: off [fixed] generic-receive-offload: 'on' rx-fcs: off [fixed] scatter-gather: 'on' tx-mpls-segmentation: off [fixed] firmware: bios: date: 01/01/2011 version: 0.5.1 vendor: Seabios system: kernel: cmdline: ipa-inspection-callback-url=http://192.0.2.1:5050/v1/continue ipa-inspection-collectors=default,extra-hardware,logs systemd.journald.forward_to_console=yes BOOTIF=52:54:00:40:d0:11 ipa-debug=1 version: 3.10.0-327.10.1.el7.x86_64 arch: x86_64 product: version: RHEL 7.0.0 PC (i440FX + PIIX, 1996) vendor: Red Hat name: KVM uuid: FB25FBC2-3FF7-45C0-8581-3EF1BA7E7839 os: version: Red Hat Enterprise Linux Server release 7.2 (Maipo) vendor: RedHatEnterpriseServer memory: total: size: 4294967296 disk: vda: optimal_io_size: 0 physical_block_size: 512 rotational: 1 vendor: '0x1af4' size: 64 logical: count: 1 cpu: logical: number: 4 physical_0: physid: 401 product: Intel Xeon E312xx (Sandy Bridge) frequency: 2000000000 vendor: Intel Corp. flags: fpu fpu_exception wp de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx rdtscp x86-64 constant_tsc rep_good nopl eagerfpu pni pclmulqdq vmx ssse3 cx16 sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx hypervisor lahf_lm tpr_shadow vnmi flexpriority ept xsaveopt xsavec xgetbv1 physical_1: physid: 402 product: Intel Xeon E312xx (Sandy Bridge) frequency: 2000000000 vendor: Intel Corp. flags: fpu fpu_exception wp de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx rdtscp x86-64 constant_tsc rep_good nopl eagerfpu pni pclmulqdq vmx ssse3 cx16 sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx hypervisor lahf_lm tpr_shadow vnmi flexpriority ept xsaveopt xsavec xgetbv1 physical_2: physid: 403 product: Intel Xeon E312xx (Sandy Bridge) frequency: 2000000000 vendor: Intel Corp. flags: fpu fpu_exception wp de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx rdtscp x86-64 constant_tsc rep_good nopl eagerfpu pni pclmulqdq vmx ssse3 cx16 sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx hypervisor lahf_lm tpr_shadow vnmi flexpriority ept xsaveopt xsavec xgetbv1 physical_3: physid: 404 product: Intel Xeon E312xx (Sandy Bridge) frequency: 2000000000 vendor: Intel Corp. flags: fpu fpu_exception wp de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx rdtscp x86-64 constant_tsc rep_good nopl eagerfpu pni pclmulqdq vmx ssse3 cx16 sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx hypervisor lahf_lm tpr_shadow vnmi flexpriority ept xsaveopt xsavec xgetbv1 physical: number: 4 interfaces: eth0: ip: 192.0.2.100 mac: 52:54:00:40:d0:11 cpus: 4 boot_interface: 52:54:00:40:d0:11 memory_mb: 4096 ipmi_address: '' inventory: bmc_address: '' interfaces: - ipv4_address: switch_port_descr: switch_chassis_descr: name: eth1 mac_address: 52:54:00:11:c5:d8 - ipv4_address: 192.0.2.100 switch_port_descr: switch_chassis_descr: name: eth0 mac_address: 52:54:00:40:d0:11 disks: - rotational: true vendor: '0x1af4' name: "/dev/vda" wwn_vendor_extension: wwn_with_extension: model: '' wwn: serial: size: 64424509440 system_vendor: serial_number: Not Specified product_name: KVM manufacturer: Red Hat memory: physical_mb: 4096 total: 4144173056 cpu: count: 4 frequency: '3408.032' model_name: Intel Xeon E312xx (Sandy Bridge) architecture: x86_64 error: local_gb: 59 all_interfaces: eth1: ip: mac: 52:54:00:11:c5:d8 eth0: ip: 192.0.2.100 mac: 52:54:00:40:d0:11 logs: Way too long... fog-openstack-0.1.6/tests/openstack/0000755000175600017570000000000012730051546016453 5ustar pravipravifog-openstack-0.1.6/tests/openstack/requests/0000755000175600017570000000000012730051546020326 5ustar pravipravifog-openstack-0.1.6/tests/openstack/requests/volume/0000755000175600017570000000000012730051546021635 5ustar pravipravifog-openstack-0.1.6/tests/openstack/requests/volume/volume_type_tests.rb0000644000175600017570000000206712730051546025761 0ustar pravipraviShindo.tests('Fog::Volume[:openstack] | volume_type requests', ['openstack']) do @volume_type_format = { 'name' => String, 'extra_specs' => Hash, 'id' => String } tests('success') do tests('#create_volume_type').formats(@volume_type_format) do @volume_type = Fog::Volume[:openstack].create_volume_type(:name => 'test_volume_type').body['volume_type'] @volume_type end tests('#update_volume_type').formats(@volume_type_format) do Fog::Volume[:openstack].update_volume_type(@volume_type['id'], :name => 'test_volume_type_1').body['volume_type'] end tests('#get_volume_type').formats(@volume_type_format) do Fog::Volume[:openstack].get_volume_type_details(@volume_type['id']).body['volume_type'] end tests('#list_volume_type').formats([@volume_type_format]) do Fog::Volume[:openstack].list_volume_types.body['volume_types'] end succeeds do Fog::Volume[:openstack].delete_volume_type(@volume_type['id']) end end end fog-openstack-0.1.6/tests/openstack/requests/volume/availability_zone_tests.rb0000644000175600017570000000053212730051546027111 0ustar pravipraviShindo.tests('Fog::Volume[:openstack] | availability zone requests', ['openstack']) do @flavor_format = { 'zoneName' => String, 'zoneState' => Hash, } tests('success') do tests('#list_zones').data_matches_schema({'availabilityZoneInfo' => [@flavor_format]}) do Fog::Volume[:openstack].list_zones.body end end end fog-openstack-0.1.6/tests/openstack/requests/volume/quota_tests.rb0000644000175600017570000000257412730051546024545 0ustar pravipraviShindo.tests('Fog::Volume[:openstack] | quota requests', ['openstack']) do @tenant_id = Fog::Compute[:openstack].list_tenants.body['tenants'].first['id'] @quota_set_format = { 'volumes' => Fog::Nullable::Integer, 'gigabytes' => Fog::Nullable::Integer, 'snapshots' => Fog::Nullable::Integer, 'id' => String } tests('success') do tests('#get_quota_defaults').formats({ 'quota_set' => @quota_set_format }) do Fog::Volume[:openstack].get_quota_defaults(@tenant_id).body end tests('#get_quota').formats(@quota_set_format) do @quota = Fog::Volume[:openstack].get_quota(@tenant_id).body['quota_set'] @quota end tests('#update_quota') do new_values = @quota.merge({ 'volumes' => @quota['volumes']/2, 'snapshots' => @quota['snapshots']/2 }) succeeds do Fog::Volume[:openstack].update_quota(@tenant_id, new_values.clone) end returns(new_values, 'returns new values') do Fog::Volume[:openstack].get_quota(@tenant_id).body['quota_set'] end # set quota back to old values succeeds do Fog::Volume[:openstack].update_quota(@tenant_id, @quota.clone) end # ensure old values are restored returns(@quota, 'old values restored') do Fog::Volume[:openstack].get_quota(@tenant_id).body['quota_set'] end end end end fog-openstack-0.1.6/tests/openstack/requests/compute/0000755000175600017570000000000012730051546022002 5ustar pravipravifog-openstack-0.1.6/tests/openstack/requests/compute/service_tests.rb0000644000175600017570000000205412730051546025212 0ustar pravipraviShindo.tests('Fog::Compute[:openstack] | service requests', ['openstack']) do @service_format = { "id" => Integer, "binary" => String, "host" => String, "state" => String, "status" => String, "updated_at" => String, "zone" => String, 'disabled_reason' => Fog::Nullable::String } tests('success') do tests('#list_services').data_matches_schema({'services' => [@service_format]}) do services = Fog::Compute[:openstack].list_services.body @service = services['services'].last services end tests('#disable_service').succeeds do Fog::Compute[:openstack].disable_service(@service['host'], @service['binary']) end tests('#disable_service_log_reason').succeeds do Fog::Compute[:openstack].disable_service_log_reason(@service['host'], @service['binary'], 'reason') end tests('#enable_service').succeeds do Fog::Compute[:openstack].enable_service(@service['host'], @service['binary']) end end end fog-openstack-0.1.6/tests/openstack/requests/compute/limit_tests.rb0000644000175600017570000000344612730051546024676 0ustar pravipraviShindo.tests('Fog::Compute[:openstack] | limits requests', ['openstack']) do @rate_limit_format = { 'regex' => String, 'uri' => String, 'limit' => Array } @rate_limit_usage_format = { 'next-available' => String, 'unit' => String, 'verb' => String, 'remaining' => Fixnum, 'value' => Fixnum } @absolute_limits_format = { 'maxServerMeta' => Fixnum, 'maxTotalInstances' => Fixnum, 'maxPersonality' => Fixnum, 'maxImageMeta' => Fixnum, 'maxPersonalitySize' => Fixnum, 'maxSecurityGroupRules' => Fixnum, 'maxTotalKeypairs' => Fixnum, 'maxSecurityGroups' => Fixnum, 'maxTotalCores' => Fixnum, 'maxTotalFloatingIps' => Fixnum, 'maxTotalRAMSize' => Fixnum, 'totalCoresUsed' => Fixnum, 'totalRAMUsed' => Fixnum, 'totalInstancesUsed' => Fixnum, 'totalSecurityGroupsUsed' => Fixnum, 'totalFloatingIpsUsed' => Fixnum } @limits_format = { 'rate' => Array, 'absolute' => Hash } tests('success') do tests('#get_limits') do tests('format').formats(@limits_format) do Fog::Compute[:openstack].get_limits.body['limits'] end tests('rate limit format').formats(@rate_limit_format) do Fog::Compute[:openstack].get_limits.body['limits']['rate'].first end tests('rate limit usage format').formats(@rate_limit_usage_format) do Fog::Compute[:openstack].get_limits.body['limits']['rate'].first['limit'].first end tests('absolute limits format').formats(@absolute_limits_format) do Fog::Compute[:openstack].get_limits.body['limits']['absolute'] end end end end fog-openstack-0.1.6/tests/openstack/requests/compute/keypair_tests.rb0000644000175600017570000000151612730051546025220 0ustar pravipraviShindo.tests('Fog::Compute[:openstack] | keypair requests', ['openstack']) do @keypair_format = { "public_key" => String, "private_key" => String, "user_id" => String, "name" => String, "fingerprint" => String } @keypair_list_format = { "public_key" => String, "name" => String, "fingerprint" => String } tests('success') do tests('#create_key_pair((key_name, public_key = nil))').formats({"keypair" => @keypair_format}) do Fog::Compute[:openstack].create_key_pair('from_shindo_test').body end tests('#list_key_pairs').formats({"keypairs" => [{"keypair" => @keypair_list_format}]}) do Fog::Compute[:openstack].list_key_pairs.body end tests('#delete_key_pair(key_name)').succeeds do Fog::Compute[:openstack].delete_key_pair('from_shindo_test') end end end fog-openstack-0.1.6/tests/openstack/requests/compute/volume_tests.rb0000644000175600017570000000243012730051546025057 0ustar pravipravirequire 'fog/openstack' Shindo.tests('Fog::Compute[:openstack] | volume requests', ['openstack']) do @volume_format = { 'id' => String, 'displayName' => String, 'size' => Integer, 'displayDescription' => String, 'status' => String, 'snapshotId' => Fog::Nullable::String, 'availabilityZone' => String, 'attachments' => Array, 'volumeType' => Fog::Nullable::String, 'createdAt' => String, 'metadata' => Hash } tests('success') do tests('#create_volume').data_matches_schema({'volume' => @volume_format}) do Fog::Compute[:openstack].create_volume('loud', 'this is a loud volume', 3).body end tests('#list_volumes').data_matches_schema({'volumes' => [@volume_format]}) do Fog::Compute[:openstack].list_volumes.body end tests('#get_volume_detail').data_matches_schema({'volume' => @volume_format}) do volume_id = Fog::Compute[:openstack].volumes.all.first.id Fog::Compute[:openstack].get_volume_details(volume_id).body end tests('#delete_volume').succeeds do volume_id = Fog::Compute[:openstack].volumes.all.first.id Fog::Compute[:openstack].delete_volume(volume_id) end end end fog-openstack-0.1.6/tests/openstack/requests/compute/image_tests.rb0000644000175600017570000000312512730051546024634 0ustar pravipravirequire 'fog/openstack' Shindo.tests('Fog::Compute[:openstack] | image requests', ['openstack']) do @image_format = { 'created' => Fog::Nullable::String, 'id' => String, 'name' => String, 'progress' => Fog::Nullable::Integer, 'status' => String, 'updated' => String, 'minRam' => Integer, 'minDisk' => Integer, 'server' => Fog::Nullable::Hash, 'metadata' => Hash, 'links' => Array } tests('success') do # Setup @image_id = Fog::Compute[:openstack].images[0].id unless Fog.mocking? Fog::Compute[:openstack].images.get(@image_id).wait_for { ready? } end tests("#get_image_details(#{@image_id})").formats(@image_format) do pending if Fog.mocking? Fog::Compute[:openstack].get_image_details(@image_id).body['image'] end tests('#list_images').formats({'images' => [OpenStack::Compute::Formats::SUMMARY]}) do Fog::Compute[:openstack].list_images.body end tests('#list_images_detail').formats({'images' => [@image_format]}) do Fog::Compute[:openstack].list_images_detail.body end # Teardown unless Fog.mocking? Fog::Compute[:openstack].images.get(@image_id).wait_for { ready? } end end tests('failure') do tests('#delete_image(0)').raises(Fog::Compute::OpenStack::NotFound) do pending if Fog.mocking? Fog::Compute[:openstack].delete_image(0) end tests('#get_image_details(0)').raises(Fog::Compute::OpenStack::NotFound) do pending if Fog.mocking? Fog::Compute[:openstack].get_image_details(0) end end end fog-openstack-0.1.6/tests/openstack/requests/compute/address_tests.rb0000644000175600017570000000306512730051546025202 0ustar pravipraviShindo.tests('Fog::Compute[:openstack] | address requests', ['openstack']) do compute = Fog::Compute[:openstack] @server_id = compute.create_server("shindo_test_server", get_image_ref, get_flavor_ref).body['server']['id'] @address_format = { "instance_id" => NilClass, "ip" => String, "fixed_ip" => NilClass, "id" => Integer, "pool" => String } @address_pools_format = { "name" => String } tests('success') do tests('#allocate_address').formats({"floating_ip" => @address_format}) do data = compute.allocate_address.body @address_id = data['floating_ip']['id'] @address_ip = data['floating_ip']['ip'] data end tests('#list_all_addresses').formats({"floating_ips" => [@address_format]}) do compute.list_all_addresses.body end tests('#get_address(address_id)').formats({"floating_ip" => @address_format}) do compute.get_address(@address_id).body end tests('#list_address_pools').formats({"floating_ip_pools" => [@address_pools_format]}) do compute.list_address_pools.body end compute.servers.get(@server_id).wait_for { ready? } tests('#associate_address(server_id, ip_address)').succeeds do compute.associate_address(@server_id, @address_ip).body end tests('#disassociate_address(server_id, ip_address)').succeeds do compute.disassociate_address(@server_id, @address_ip).body end tests('#release_address(ip_address)').succeeds do compute.release_address(@address_id) end end compute.delete_server(@server_id) end fog-openstack-0.1.6/tests/openstack/requests/compute/helper.rb0000644000175600017570000000167612730051546023620 0ustar pravipraviclass OpenStack module Compute module Formats SUMMARY = { 'id' => String, 'name' => String, 'links' => Array } end end end def compute Fog::Compute[:openstack] end def get_flavor_ref ENV['OPENSTACK_FLAVOR_REF'] || compute.list_flavors.body['flavors'].first['id'] end def get_image_ref ENV['OPENSTACK_IMAGE_REF'] || compute.list_images.body['images'].first['id'] end def get_volume_ref ENV['OPENSTACK_VOLUME_REF'] || compute.list_volumes.body['volumes'].first['id'] end def get_flavor_ref_resize # by default we simply add one to the default flavor ref ENV['OPENSTACK_FLAVOR_REF_RESIZE'] || (get_flavor_ref.to_i + 1).to_s end def set_password_enabled pw_enabled = ENV['OPENSTACK_SET_PASSWORD_ENABLED'] || "true" return pw_enabled == "true" end def get_security_group_ref ENV['OPENSTACK_SECURITY_GROUP_REF'] || compute.list_security_groups.body['security_groups'].first['name'] end fog-openstack-0.1.6/tests/openstack/requests/compute/server_tests.rb0000644000175600017570000002442012730051546025061 0ustar pravipraviShindo.tests('Fog::Compute[:openstack] | server requests', ['openstack']) do @base_server_format = { 'id' => String, 'addresses' => Hash, 'flavor' => Hash, 'hostId' => String, 'metadata' => Hash, 'name' => String, 'progress' => Integer, 'status' => String, 'accessIPv4' => Fog::Nullable::String, 'accessIPv6' => Fog::Nullable::String, 'links' => Array, 'created' => String, 'updated' => String, 'user_id' => String, 'config_drive' => String, } @server_from_image_format = @base_server_format.merge('image' => Hash) @create_format = { 'adminPass' => String, 'id' => String, 'links' => Array, 'security_groups' => Fog::Nullable::Array, } @reservation_format = { 'reservation_id' => String, } @image_format = { 'created' => Fog::Nullable::String, 'id' => String, 'name' => String, 'progress' => Fog::Nullable::Integer, 'status' => String, 'updated' => String, 'minRam' => Integer, 'minDisk' => Integer, 'server' => Hash, 'metadata' => Hash, 'links' => Array } tests('success') do @image_id = get_image_ref @snapshot_id = nil @flavor_id = get_flavor_ref @security_group_name = get_security_group_ref #CREATE_SERVER_WITH_BLOCK_DEVICE_MAPPING tests('#create_server("test", nil , #{@flavor_id}) with a block_device_mapping').formats(@create_format, false) do @volume1_id = compute.create_volume('test', 'this is a test volume', 1).body["volume"]["id"] volume_data = { :delete_on_termination => true, :device_name => "vda", :volume_id => @volume1_id, :volume_size => 1, } data = compute.create_server("test", nil, @flavor_id, "block_device_mapping" => volume_data).body['server'] @server_id = data['id'] data end tests("#get_server_details(#{@server_id})").formats(@base_server_format, false) do compute.get_server_details(@server_id).body['server'] end tests("#block_device_mapping").succeeds do compute.servers.get(@server_id).volumes.first.id == @volume1_id end #CREATE_SERVER_WITH_BLOCK_DEVICE_MAPPING_V2 tests('#create_server("test", nil , #{@flavor_id}) with multiple block_device_mapping_v2').formats(@create_format, false) do @volume2_id = compute.create_volume('test', 'this is a test volume', 1).body["volume"]["id"] volume_data = [{ :boot_index => 0, :uuid => @volume1_id, :device_name => "vda", :source_type => "volume", :destination_type => "volume", :delete_on_termination => true, :volume_size => 20 }, { :boot_index => 1, :uuid => @volume2_id, :device_name => "vdb", :source_type => "volume", :destination_type => "volume", :delete_on_termination => true, :volume_size => 10 }] data = compute.create_server("test", nil, @flavor_id, "block_device_mapping_v2" => volume_data).body['server'] @server_id = data['id'] data end tests("#get_server_details(#{@server_id})").formats(@base_server_format, false) do compute.get_server_details(@server_id).body['server'] end tests("#block_device_mapping_v2").succeeds do compute.servers.get(@server_id).volumes.collect(&:id).sort == [@volume1_id, @volume2_id].sort end #CREATE_SINGLE_FROM_IMAGE tests('#create_server("test", #{@image_id} , 19)').formats(@create_format, false) do data = Fog::Compute[:openstack].create_server("test", @image_id, @flavor_id).body['server'] @server_id = data['id'] data end Fog::Compute[:openstack].servers.get(@server_id).wait_for { ready? } tests("#get_server_details(#{@server_id})").formats(@server_from_image_format, false) do Fog::Compute[:openstack].get_server_details(@server_id).body['server'] end #MULTI_CREATE_FROM_IMAGE tests('#create_server("test", #{@image_id} , 19, {"min_count" => 2, "return_reservation_id" => "True"})').formats(@reservation_format, false) do data = Fog::Compute[:openstack].create_server("test", @image_id, @flavor_id, {"min_count" => 2, "return_reservation_id" => "True"}).body @reservation_id = data['reservation_id'] data end tests('#validate_multi_create') do passed = false @multi_create_servers = [] if Fog.mocking? @multi_create_servers = [Fog::Mock.random_numbers(6).to_s, Fog::Mock.random_numbers(6).to_s] else @multi_create_servers = Fog::Compute[:openstack].list_servers_detail({'reservation_id' => @reservation_id}).body['servers'].map{|server| server['id']} end if (@multi_create_servers.size == 2) passed = true end end unless Fog.mocking? @multi_create_servers.each {|server| Fog::Compute[:openstack].servers.get(server).destroy } end #LIST #NOTE: we can remove strict=false if we remove uuid from GET /servers tests('#list_servers').formats({'servers' => [OpenStack::Compute::Formats::SUMMARY]}, false) do Fog::Compute[:openstack].list_servers.body end #DETAILS tests('#list_servers_detail').formats({'servers' => [@server_from_image_format]}, false) do Fog::Compute[:openstack].list_servers_detail.body end #CHANGE PASSWORD if set_password_enabled tests("#change_server_password(#{@server_id}, 'fogupdatedserver')").succeeds do Fog::Compute[:openstack].change_server_password(@server_id, 'foggy') end Fog::Compute[:openstack].servers.get(@server_id).wait_for { ready? } end #UPDATE SERVER NAME tests("#update_server(#{@server_id}, :name => 'fogupdatedserver')").succeeds do Fog::Compute[:openstack].update_server(@server_id, :name => 'fogupdatedserver') end Fog::Compute[:openstack].servers.get(@server_id).wait_for { ready? } #ADD SECURITY GROUP tests("#add_security_group(#{@server_id}, #{@security_group_name})").succeeds do Fog::Compute[:openstack].add_security_group(@server_id, @security_group_name) end #REMOVE SECURITY GROUP tests("#remove_security_group(#{@server_id}, #{@security_group_name})").succeeds do Fog::Compute[:openstack].remove_security_group(@server_id, @security_group_name) end #CREATE IMAGE WITH METADATA tests("#create_image(#{@server_id}, 'fog')").formats('image' => @image_format) do data = Fog::Compute[:openstack].create_image(@server_id, 'fog', {"foo" => "bar"}).body @snapshot_id = data['image']['id'] data end Fog::Compute[:openstack].images.get(@snapshot_id).wait_for { ready? } #REBUILD tests("#rebuild_server(#{@server_id}, #{@snapshot_id}, 'fog')").formats({'server' => @server_from_image_format}, false) do Fog::Compute[:openstack].rebuild_server(@server_id, @snapshot_id, 'fog', 'newpass', {"foo" => "bar"}).body end Fog::Compute[:openstack].servers.get(@server_id).wait_for { ready? } if not Fog.mocking? #RESIZE tests("#resize_server(#{@server_id}, #{get_flavor_ref_resize})").succeeds do Fog::Compute[:openstack].resize_server(@server_id, get_flavor_ref_resize) end Fog::Compute[:openstack].servers.get(@server_id).wait_for { self.state == 'VERIFY_RESIZE' } if not Fog.mocking? #RESIZE CONFIRM tests("#resize_confirm(#{@server_id}, #{get_flavor_ref_resize})").succeeds do Fog::Compute[:openstack].confirm_resize_server(@server_id) end Fog::Compute[:openstack].servers.get(@server_id).wait_for { ready? } if not Fog.mocking? #REBOOT - HARD tests("#reboot_server(#{@server_id}, 'HARD')").succeeds do Fog::Compute[:openstack].reboot_server(@server_id, 'HARD') end Fog::Compute[:openstack].servers.get(@server_id).wait_for { ready? } if not Fog.mocking? #REBOOT - SOFT tests("#reboot_server(#{@server_id}, 'SOFT')").succeeds do Fog::Compute[:openstack].reboot_server(@server_id, 'SOFT') end Fog::Compute[:openstack].servers.get(@server_id).wait_for { ready? } if not Fog.mocking? #STOP tests("#stop_server(#{@server_id})").succeeds do Fog::Compute[:openstack].stop_server(@server_id) end #START tests("#start_server(#{@server_id})").succeeds do Fog::Compute[:openstack].start_server(@server_id) end Fog::Compute[:openstack].servers.get(@server_id).wait_for { ready? } if not Fog.mocking? tests("#shelve_server(#{@server_id})").succeeds do Fog::Compute[:openstack].shelve_server(@server_id) end Fog::Compute[:openstack].servers.get(@server_id).wait_for { ready? } if not Fog.mocking? tests("#unshelve_server(#{@server_id})").succeeds do Fog::Compute[:openstack].unshelve_server(@server_id) end Fog::Compute[:openstack].servers.get(@server_id).wait_for { ready? } if not Fog.mocking? #DELETE tests("#delete_server(#{@server_id})").succeeds do Fog::Compute[:openstack].delete_server(@server_id) end #DELETE IMAGE tests("#delete_image(#{@snapshot_id})").succeeds do Fog::Compute[:openstack].delete_image(@snapshot_id) end end tests('failure') do tests('#delete_server(0)').raises(Fog::Compute::OpenStack::NotFound) do Fog::Compute[:openstack].delete_server(0) end tests('#get_server_details(0)').raises(Fog::Compute::OpenStack::NotFound) do Fog::Compute[:openstack].get_server_details(0) end tests("#update_server(0, :name => 'fogupdatedserver', :adminPass => 'fogupdatedserver')").raises(Fog::Compute::OpenStack::NotFound) do Fog::Compute[:openstack].update_server(0, :name => 'fogupdatedserver', :adminPass => 'fogupdatedserver') end tests('#reboot_server(0)').raises(Fog::Compute::OpenStack::NotFound) do pending if Fog.mocking? Fog::Compute[:openstack].reboot_server(0) end tests('#start_server(0)').raises(Fog::Compute::OpenStack::NotFound) do pending if Fog.mocking? Fog::Compute[:openstack].start_server(0) end tests('#stop_server(0)').raises(Fog::Compute::OpenStack::NotFound) do pending if Fog.mocking? Fog::Compute[:openstack].stop_server(0) end end end fog-openstack-0.1.6/tests/openstack/requests/compute/flavor_tests.rb0000644000175600017570000000725512730051546025053 0ustar pravipraviShindo.tests('Fog::Compute[:openstack] | flavor requests', ['openstack']) do @flavor_format = { 'id' => String, 'name' => String, 'disk' => Integer, 'ram' => Integer, 'links' => Array, 'swap' => Fog::Nullable::String, 'rxtx_factor' => Fog::Nullable::Float, 'OS-FLV-EXT-DATA:ephemeral' => Integer, 'os-flavor-access:is_public' => Fog::Nullable::Boolean, 'OS-FLV-DISABLED:disabled' => Fog::Nullable::Boolean, 'vcpus' => Integer } tests('success') do tests('#get_flavor_details(1)').data_matches_schema(@flavor_format) do Fog::Compute[:openstack].get_flavor_details("1").body['flavor'] end tests('#list_flavors').data_matches_schema({'flavors' => [OpenStack::Compute::Formats::SUMMARY]}) do Fog::Compute[:openstack].list_flavors.body end tests('#list_flavors_detail').data_matches_schema({'flavors' => [@flavor_format]}) do Fog::Compute[:openstack].list_flavors_detail.body end tests('#create_flavor(attributes)').data_matches_schema({'flavor' => @flavor_format}) do attributes = {:flavor_id => '100', :name => 'shindo test flavor', :disk => 10, :ram => 10, :vcpus => 10, :swap => "0", :rxtx_factor => 2.4, :ephemeral => 0, :is_public => false} Fog::Compute[:openstack].create_flavor(attributes).body end tests('add_flavor_access(flavor_ref, tenant_id)').data_matches_schema({'flavor_access' => [{'tenant_id' => String, 'flavor_id' => String}]}) do Fog::Compute[:openstack].add_flavor_access(100, 1).body end tests('remove_flavor_access(flavor_ref, tenant_id)').data_matches_schema({'flavor_access' => []}) do Fog::Compute[:openstack].remove_flavor_access(100, 1).body end tests('list_tenants_with_flavor_access(flavor_ref)').data_matches_schema({'flavor_access' => [{'tenant_id' => String, 'flavor_id' => String}]}) do Fog::Compute[:openstack].list_tenants_with_flavor_access(100).body end tests('delete_flavor(flavor_id)').succeeds do Fog::Compute[:openstack].delete_flavor('100') end tests('#get_flavor_metadata(flavor_ref)').data_matches_schema('extra_specs' => {'cpu_arch' => String}) do Fog::Compute[:openstack].get_flavor_metadata("1").body end tests('#create_flavor_metadata(flavor_ref, metadata)').data_matches_schema('extra_specs' => {'cpu_arch' => String}) do metadata = {:cpu_arch => 'x86_64'} Fog::Compute[:openstack].create_flavor_metadata("1", metadata).body end end tests('failure') do tests('#get_flavor_details(0)').raises(Fog::Compute::OpenStack::NotFound) do Fog::Compute[:openstack].get_flavor_details("0") end tests('add_flavor_access(1234, 1)').raises(Fog::Compute::OpenStack::NotFound) do pending if Fog.mocking? Fog::Compute[:openstack].add_flavor_access(1234, 1).body end tests('remove_flavor_access(1234, 1)').raises(Fog::Compute::OpenStack::NotFound) do pending if Fog.mocking? Fog::Compute[:openstack].remove_flavor_access(1234, 1).body end tests('list_tenants_with_flavor_access(1234)').raises(Fog::Compute::OpenStack::NotFound) do pending if Fog.mocking? Fog::Compute[:openstack].list_tenants_with_flavor_access(1234) end tests('get_flavor_metadata(flavor_ref)').raises(Fog::Compute::OpenStack::NotFound) do pending if Fog.mocking? Fog::Compute[:openstack].get_flavor_metadata("1234").body end tests('create_flavor_metadata(flavor_ref)').raises(Fog::Compute::OpenStack::NotFound) do pending if Fog.mocking? metadata = {:cpu_arch => 'x86_64'} Fog::Compute[:openstack].create_flavor_metadata("1234", metadata).body end end end fog-openstack-0.1.6/tests/openstack/requests/compute/availability_zone_tests.rb0000644000175600017570000000106212730051546027255 0ustar pravipraviShindo.tests('Fog::Compute[:openstack] | availability zone requests', ['openstack']) do @flavor_format = { 'zoneName' => String, 'hosts' => Fog::Nullable::Hash, 'zoneState' => Hash, } tests('success') do tests('#list_zones').data_matches_schema({'availabilityZoneInfo' => [@flavor_format]}) do Fog::Compute[:openstack].list_zones.body end tests('#list_zones_detailed').data_matches_schema({'availabilityZoneInfo' => [@flavor_format]}) do Fog::Compute[:openstack].list_zones_detailed.body end end end fog-openstack-0.1.6/tests/openstack/requests/compute/security_group_tests.rb0000644000175600017570000000504012730051546026633 0ustar pravipraviShindo.tests('Fog::Compute[:openstack] | security group requests', ['openstack']) do @security_group = Hash.new @security_group_rule = Hash.new @security_group_format = { "id" => Integer, "rules" => Array, "tenant_id" => String, "name" => String, "description" => String } @security_group_rule_format = { "id" => Integer, "from_port" => Integer, "to_port" => Integer, "ip_protocol" => String, "group" => Hash, "ip_range" => Hash, "parent_group_id" => Integer } tests('success') do tests('#create_security_group(name, description)').formats({"security_group" => @security_group_format}) do security_group = Fog::Compute[:openstack].create_security_group('from_shindo_test', 'this is from the shindo test').body @security_group_id = security_group['security_group']['id'] security_group end tests('#create_security_group_rule(parent_group_id, ip_protocol, from_port, to_port, cidr, group_id=nil)').formats({"security_group_rule" => @security_group_rule_format}) do security_group_rule = Fog::Compute[:openstack].create_security_group_rule(@security_group_id, "tcp", 2222, 3333, "20.20.20.20/24").body @security_group_rule_id = security_group_rule['security_group_rule']['id'] security_group_rule end tests('#list_security_groups').formats({"security_groups" => [@security_group_format]}) do Fog::Compute[:openstack].list_security_groups.body end tests('#get_security_group(security_group_id)').formats({"security_group" => @security_group_format}) do Fog::Compute[:openstack].get_security_group(@security_group_id).body end tests('#get_security_group_rule').formats({"security_group_rule" => @security_group_rule_format}) do Fog::Compute[:openstack].create_security_group_rule(@security_group_id, "tcp", 2222, 3333, "20.20.20.20/24").body Fog::Compute[:openstack].get_security_group_rule(@security_group_rule_id).body end tests('#delete_security_group_rule(security_group_rule_id)').succeeds do Fog::Compute[:openstack].delete_security_group_rule(@security_group_rule_id) end tests('#delete_security_group(security_group_id)').succeeds do Fog::Compute[:openstack].delete_security_group(@security_group_id) returns(false) { groups = Fog::Compute[:openstack].list_security_groups.body['security_groups'] groups.any? { |group| group['id'] == @security_group_id } } end end # tests('success') end fog-openstack-0.1.6/tests/openstack/requests/compute/quota_tests.rb0000644000175600017570000000331512730051546024704 0ustar pravipraviShindo.tests('Fog::Compute[:openstack] | quota requests', ['openstack']) do @tenant_id = Fog::Compute[:openstack].list_tenants.body['tenants'].first['id'] @quota_set_format = { 'key_pairs' => Fixnum, 'metadata_items' => Fixnum, 'injected_file_content_bytes' => Fixnum, 'injected_file_path_bytes' => Fixnum, 'injected_files' => Fixnum, 'ram' => Fixnum, 'floating_ips' => Fixnum, 'instances' => Fixnum, 'cores' => Fixnum, 'security_groups' => Fog::Nullable::Integer, 'security_group_rules' => Fog::Nullable::Integer, 'volumes' => Fog::Nullable::Integer, 'gigabytes' => Fog::Nullable::Integer, 'id' => String } tests('success') do tests('#get_quota_defaults').formats({ 'quota_set' => @quota_set_format }) do Fog::Compute[:openstack].get_quota_defaults(@tenant_id).body end tests('#get_quota').formats(@quota_set_format) do @quota = Fog::Compute[:openstack].get_quota(@tenant_id).body['quota_set'] @quota end tests('#update_quota') do new_values = @quota.merge({ 'floating_ips' => @quota['floating_ips']/2, 'cores' => @quota['cores']/2 }) succeeds do Fog::Compute[:openstack].update_quota(@tenant_id, new_values.clone) end returns(new_values, 'returns new values') do Fog::Compute[:openstack].get_quota(@tenant_id).body['quota_set'] end # set quota back to old values succeeds do Fog::Compute[:openstack].update_quota(@tenant_id, @quota.clone) end # ensure old values are restored returns(@quota, 'old values restored') do Fog::Compute[:openstack].get_quota(@tenant_id).body['quota_set'] end end end end fog-openstack-0.1.6/tests/openstack/requests/compute/tenant_tests.rb0000644000175600017570000000100712730051546025040 0ustar pravipraviShindo.tests('Fog::Compute[:openstack] | tenant requests', ['openstack']) do @tenant_format = { 'id' => String, 'name' => String, 'enabled' => Fog::Boolean, 'description' => Fog::Nullable::String } tests('success') do tests('#list_tenants').formats({'tenants_links' => Array, 'tenants' => [@tenant_format]}) do Fog::Compute[:openstack].list_tenants.body end tests('#set_tenant("admin")').succeeds do Fog::Compute[:openstack].set_tenant("admin") end end end fog-openstack-0.1.6/tests/openstack/requests/compute/aggregate_tests.rb0000644000175600017570000000421012730051546025474 0ustar pravipraviShindo.tests('Fog::Compute[:openstack] | Compute aggregate requests', ['openstack']) do openstack = Fog::Identity[:openstack] @aggregate_format = { "availability_zone" => Fog::Nullable::String, "created_at" => String, "deleted" => Fog::Boolean, "deleted_at" => Fog::Nullable::String, "id" => Integer, "name" => String, "updated_at" => Fog::Nullable::String } @detailed_aggregate_format = @aggregate_format.merge({ 'hosts' => Array, }) @metadata_aggregate_format = @aggregate_format.merge({ "metadata" => Hash, }) tests('success') do tests('#create_aggregate').data_matches_schema({'aggregate' => @aggregate_format}) do aggregate_body = Fog::Compute[:openstack].create_aggregate('test_aggregate').body @aggregate = aggregate_body['aggregate'] aggregate_body end tests('#list_aggregates').data_matches_schema({'aggregates' => [@metadata_aggregate_format]}) do Fog::Compute[:openstack].list_aggregates.body end tests('#update_aggregate').data_matches_schema({'aggregate' => @aggregate_format}) do aggregate_attributes = {'name' => 'test_aggregate2'} Fog::Compute[:openstack].update_aggregate(@aggregate['id'], aggregate_attributes).body end tests('#get_aggregate').data_matches_schema({'aggregate' => @detailed_aggregate_format}) do Fog::Compute[:openstack].get_aggregate(@aggregate['id']).body end tests('#add_aggregate_host').succeeds do @host_name = Fog::Compute[:openstack].hosts.select{ |x| x.service_name == 'compute' }.first.host_name Fog::Compute[:openstack].add_aggregate_host(@aggregate['id'], @host_name) end tests('#remove_aggregate_host').succeeds do Fog::Compute[:openstack].remove_aggregate_host(@aggregate['id'], @host_name) end tests('#update_aggregate_metadata').succeeds do Fog::Compute[:openstack].update_aggregate_metadata(@aggregate['id'], {'test' => 'test', 'test2' => 'test2'}) end tests('#delete_aggregate').succeeds do Fog::Compute[:openstack].delete_aggregate(@aggregate['id']) end end end fog-openstack-0.1.6/tests/openstack/requests/identity/0000755000175600017570000000000012730051546022157 5ustar pravipravifog-openstack-0.1.6/tests/openstack/requests/identity/helper.rb0000644000175600017570000000113712730051546023765 0ustar pravipraviclass OpenStack module Identity def self.get_tenant_id_old identity = Fog::Identity::OpenStack.new(:openstack_auth_url => 'http://openstack:35357/v2.0/tokens') ENV['OPENSTACK_TENANT_NAME'] || identity.list_tenants.body['tenants'].first['id'] end def self.get_user_id_old identity = Fog::Identity::OpenStack.new(:openstack_auth_url => 'http://openstack:35357/v2.0/tokens') ENV['OPENSTACK_USER_ID'] || identity.list_users.body['users'].first['id'] end def self.get_tenant_id 'tenant_id' end def self.get_user_id 'user_id' end end end fog-openstack-0.1.6/tests/openstack/requests/identity/user_tests.rb0000644000175600017570000000247612730051546024715 0ustar pravipraviShindo.tests('Fog::Identity[:openstack] | user requests', ['openstack']) do @user_format = { 'id' => String, 'name' => String, 'enabled' => Fog::Boolean, 'email' => String, 'tenantId' => Fog::Nullable::String } @identity = Fog::Identity[:openstack] tests('success') do @user_name = Fog::Mock.random_hex(64) @user_name_update = Fog::Mock.random_hex(64) tests("#create_user('#{@user_name}', 'mypassword', 'morph@example.com', 't3n4nt1d', true)").formats(@user_format, false) do @user = @identity.create_user( @user_name, "mypassword", "morph@example.com", OpenStack::Identity.get_tenant_id ).body['user'] end tests('#list_users').formats({'users' => [@user_format]}) do @identity.list_users.body end tests('#get_user_by_id').formats(@user_format) do @identity.get_user_by_id(@user['id']).body['user'] end tests('#get_user_by_name').formats(@user_format) do @identity.get_user_by_name(@user['name']).body['user'] end tests("#update_user(#{@user['id']}, :name => 'fogupdateduser')").succeeds do @identity.update_user(@user['id'], :name => @user_name_update, :email => 'fog@test.com') end tests("#delete_user(#{@user['id']})").succeeds do @identity.delete_user(@user['id']) end end end fog-openstack-0.1.6/tests/openstack/requests/identity/tenant_tests.rb0000644000175600017570000000324312730051546025221 0ustar pravipraviShindo.tests('Fog::Identity[:openstack] | tenant requests', ['openstack']) do @tenant_format = { 'id' => String, 'name' => String, 'enabled' => Fog::Nullable::Boolean, 'description' => Fog::Nullable::String } @role_format = { 'id' => String, 'name' => String } @tenant_name = Fog::Mock.random_hex(64) @tenant_name_update = Fog::Mock.random_hex(64) @tenant_name_update2 = Fog::Mock.random_hex(64) @identity = Fog::Identity[:openstack] tests('success') do tests('#list_tenants').formats({'tenants' => [@tenant_format], 'tenants_links' => []}) do @identity.list_tenants.body end tests('#list_roles_for_user_on_tenant(0,1)'). formats({'roles' => [@role_format]}) do @identity.list_roles_for_user_on_tenant( @identity.current_tenant['id'], OpenStack::Identity.get_user_id).body end tests('#create_tenant').formats({'tenant' => @tenant_format}) do @tenant = @identity.create_tenant('name' => @tenant_name).body end tests('#get_tenant').formats({'tenant' => @tenant_format}) do @identity.get_tenant(@tenant['tenant']['id']).body end tests('#update_tenant check format').formats({'tenant' => @tenant_format}) do @tenant = @identity.update_tenant( @tenant['tenant']['id'], 'name' => @tenant_name_update).body end tests('#update_tenant update name').succeeds do @tenant = @identity.update_tenant( @tenant['tenant']['id'], 'name' => @tenant_name_update2).body @tenant['tenant']['name'] == @tenant_name_update2 end tests('#delete_tenant').succeeds do @identity.delete_tenant(@tenant['tenant']['id']) end end end fog-openstack-0.1.6/tests/openstack/requests/identity/role_tests.rb0000644000175600017570000000321112730051546024664 0ustar pravipraviShindo.tests('Fog::Identity[:openstack] | role requests', ['openstack']) do @role_format = { 'id' => String, 'name' => String } @identity = Fog::Identity::OpenStack.new(:openstack_auth_url => 'http://openstack:35357/v2.0/tokens') @user = @identity.list_users.body['users'].first @tenant = @identity.list_tenants.body['tenants'].first tests('success') do tests('#create_role("Role Name")').formats(@role_format, false) do @role = @identity.create_role("Role Name").body['role'] end tests('#list_roles').formats({'roles' => [@role_format]}) do @identity.list_roles.body end tests("#get_role('#{@role['id']}')").formats(@role_format) do @identity.get_role(@role['id']).body['role'] end tests('#create_user_role(@tenant["id"], @user["id"], @role["id"])').formats(@role_format) do @identity.create_user_role(@tenant['id'], @user['id'], @role['id']).body['role'] end tests("#list_roles_for_user_on_tenant('#{@tenant['id']}','#{@user['id']}')").formats([@role_format]) do @identity.list_roles_for_user_on_tenant(@tenant['id'], @user['id']).body['roles'] end tests("#delete_user_role with tenant").returns("") do @identity.delete_user_role(@tenant['id'], @user['id'], @role['id']).body end tests("#delete_user_role with tenant").formats(@role_format) do # FIXME - Response (under mocks) is empty String which does not match schema pending @identity.delete_user_role(@tenant['id'], @user['id'], @role['id']).body end tests("#delete_role('#{@role['id']}')").succeeds do @identity.delete_role(@role['id']).body end end end fog-openstack-0.1.6/tests/openstack/requests/identity/ec2_credentials_tests.rb0000644000175600017570000000221612730051546026755 0ustar pravipraviShindo.tests('Fog::Identity[:openstack] | EC2 credential requests', ['openstack']) do @credential_format = { 'access' => String, 'tenant_id' => String, 'secret' => String, 'user_id' => String, } @identity = Fog::Identity::OpenStack.new(:openstack_auth_url => "http://openstack:35357/v2.0/tokens") @user_id = OpenStack::Identity.get_user_id @tenant_id = OpenStack::Identity.get_tenant_id tests('success') do tests('#create_ec2_credential'). formats({'credential' => @credential_format}) do response = @identity.create_ec2_credential(@user_id, @tenant_id) @ec2_credential = response.body['credential'] response.body end tests('#get_ec2_credential'). formats({'credential' => @credential_format}) do @identity.get_ec2_credential(@user_id, @ec2_credential['access']).body end tests('#list_ec2_credentials'). formats({'credentials' => [@credential_format]}) do @identity.list_ec2_credentials(@user_id).body end tests('#delete_ec2_credential').succeeds do @identity.delete_ec2_credential(@user_id, @ec2_credential['access']) end end end fog-openstack-0.1.6/tests/openstack/requests/metering/0000755000175600017570000000000012730051546022140 5ustar pravipravifog-openstack-0.1.6/tests/openstack/requests/metering/meter_tests.rb0000644000175600017570000000265712730051546025035 0ustar pravipraviShindo.tests('Fog::Metering[:openstack] | meter requests', ['openstack']) do @sample_format = { 'counter_name' => String, 'user_id' => String, 'resource_id' => String, 'timestamp' => String, 'resource_metadata' => Hash, 'source' => String, 'counter_unit' => String, 'counter_volume' => Float, 'project_id' => String, 'message_id' => String, 'counter_type' => String } @meter_format = { 'user_id' => String, 'name' => String, 'resource_id' => String, 'project_id' => String, 'type' => String, 'unit' => String } @statistics_format = { 'count' => Integer, 'duration_start' => String, 'min' => Float, 'max' => Float, 'duration_end' => String, 'period' => Integer, 'period_end' => String, 'duration' => Float, 'period_start' => String, 'avg' => Float, 'sum' => Float } tests('success') do tests('#list_meters').formats([@meter_format]) do Fog::Metering[:openstack].list_meters.body end tests('#get_samples').formats([@sample_format]) do Fog::Metering[:openstack].get_samples('test').body end tests('#get_statistics').formats([@statistics_format]) do Fog::Metering[:openstack].get_statistics('test').body end end end fog-openstack-0.1.6/tests/openstack/requests/metering/resource_tests.rb0000644000175600017570000000076112730051546025542 0ustar pravipraviShindo.tests('Fog::Metering[:openstack] | resource requests', ['openstack']) do @resource_format = { 'resource_id' => String, 'project_id' => String, 'user_id' => String, 'metadata' => Hash, } tests('success') do tests('#list_resource').formats([@resource_format]) do Fog::Metering[:openstack].list_resources.body end tests('#get_resource').formats(@resource_format) do Fog::Metering[:openstack].get_resource('test').body end end end fog-openstack-0.1.6/tests/openstack/requests/metering/event_tests.rb0000644000175600017570000000064012730051546025030 0ustar pravipraviShindo.tests('Fog::Metering[:openstack] | event requests', ['openstack']) do @event_format = { 'message_id' => String, 'event_type' => String, } tests('success') do tests('#list_events').formats([@event_format]) do Fog::Metering[:openstack].list_events.body end tests('#get_event').formats(@event_format) do Fog::Metering[:openstack].get_event('test').body end end end fog-openstack-0.1.6/tests/openstack/requests/planning/0000755000175600017570000000000012730051546022134 5ustar pravipravifog-openstack-0.1.6/tests/openstack/requests/planning/.gitkeep0000644000175600017570000000000012730051546023553 0ustar pravipravifog-openstack-0.1.6/tests/openstack/requests/planning/plan_tests.rb0000644000175600017570000000425112730051546024637 0ustar pravipraviShindo.tests('Fog::Openstack[:planning] | Planning plan requests', ['openstack']) do openstack = Fog::Identity[:openstack] @plan_format = { "created_at" => Fog::Nullable::String, "description" => Fog::Nullable::String, "name" => String, "parameters" => Fog::Nullable::Array, "roles" => Fog::Nullable::Array, "updated_at" => Fog::Nullable::String, "uuid" => String, "version" => Fog::Nullable::Integer, } @plan_templates_format = Hash tests('success') do tests('#list_plans').data_matches_schema([@plan_format]) do plans = Fog::Openstack[:planning].list_plans.body @instance = plans.first plans end tests('#get_plan').data_matches_schema(@plan_format) do Fog::Openstack[:planning].get_plan(@instance['uuid']).body end tests('#delete_plan').succeeds do Fog::Openstack[:planning].delete_plan(@instance['uuid']) end tests('#create_plan').data_matches_schema(@plan_format) do plan_attributes = { :name => 'test-plan-name', :description => 'test-plan-desc', } @instance = Fog::Openstack[:planning].create_plan(plan_attributes).body end tests('#add_role_to_plan').data_matches_schema(@plan_format) do @role_instance = Fog::Openstack[:planning].list_roles.body.first Fog::Openstack[:planning].add_role_to_plan(@instance['uuid'], @role_instance['uuid']).body end tests('#patch_plan').data_matches_schema(@plan_format) do parameters = Fog::Openstack[:planning].get_plan(@instance['uuid']).body['parameters'][0..1] plan_parameters = parameters.map do |parameter| { "name" => parameter['name'], "value" => "test-#{parameter['name']}-value", } end Fog::Openstack[:planning].patch_plan(@instance['uuid'], plan_parameters).body end tests('#get_plan_templates').data_matches_schema(@plan_templates_format) do Fog::Openstack[:planning].get_plan_templates(@instance['uuid']).body end tests('#remove_role_from_plan').data_matches_schema(@plan_format) do Fog::Openstack[:planning].remove_role_from_plan(@instance['uuid'], @role_instance['uuid']).body end end end fog-openstack-0.1.6/tests/openstack/requests/planning/role_tests.rb0000644000175600017570000000070112730051546024642 0ustar pravipraviShindo.tests('Fog::Openstack[:planning] | Planning role requests', ['openstack']) do openstack = Fog::Identity[:openstack] @role_format = { 'description' => Fog::Nullable::String, 'name' => Fog::Nullable::String, 'uuid' => String, 'version' => Integer, } tests('success') do tests('#list_roles').data_matches_schema([@role_format]) do Fog::Openstack[:planning].list_roles.body end end end fog-openstack-0.1.6/tests/openstack/requests/orchestration/0000755000175600017570000000000012730051546023212 5ustar pravipravifog-openstack-0.1.6/tests/openstack/requests/orchestration/stack_tests.rb0000644000175600017570000000422412730051546026070 0ustar pravipraviShindo.tests('Fog::Orchestration[:openstack] | stack requests', ['openstack']) do @stack_format = { 'links' => Array, 'id' => String, 'stack_name' => String, 'description' => Fog::Nullable::String, 'stack_status' => String, 'stack_status_reason' => String, 'creation_time' => Time, 'updated_time' => Time } @stack_detailed_format = { "parent" => Fog::Nullable::String, "disable_rollback" => Fog::Boolean, "description" => String, "links" => Array, "stack_status_reason" => String, "stack_name" => String, "stack_user_project_id" => String, "stack_owner" => String, "creation_time" => Fog::Nullable::String, "capabilities" => Array, "notification_topics" => Array, "updated_time" => Fog::Nullable::String, "timeout_mins" => Fog::Nullable::String, "stack_status" => String, "parameters" => Hash, "id" => String, "outputs" => Array, "template_description" => String } @create_format = { 'id' => String, 'links' => Array, } tests('success') do tests('#create_stack("teststack")').formats(@create_format) do @stack = Fog::Orchestration[:openstack].create_stack("teststack").body end tests('#list_stack_data').formats({'stacks' => [@stack_format]}) do Fog::Orchestration[:openstack].list_stack_data.body end tests('#list_stack_data_Detailed').formats({'stacks' => [@stack_detailed_format]}) do Fog::Orchestration[:openstack].list_stack_data_detailed.body end tests('#update_stack("teststack")').formats({}) do Fog::Orchestration[:openstack].update_stack("teststack").body end tests('#patch_stack("teststack")').formats({}) do Fog::Orchestration[:openstack].patch_stack(@stack).body end tests('#delete_stack("teststack", "id")').formats({}) do Fog::Orchestration[:openstack].delete_stack("teststack", "id").body end end end fog-openstack-0.1.6/tests/openstack/requests/introspection/0000755000175600017570000000000012730051546023226 5ustar pravipravifog-openstack-0.1.6/tests/openstack/requests/introspection/introspection_tests.rb0000644000175600017570000003143012730051546027676 0ustar pravipraviShindo.tests('Fog::Introspection::OpenStack | Introspection requests', ['openstack']) do @inspector = Fog::Introspection::OpenStack.new @node_uuid = Fog::UUID.uuid @introspection_finished = { "error" => "null", "finished" => "true" } @introspection_data = { "cpu_arch" => String, "macs" => Array, "root_disk" => { "rotational" => Fog::Boolean, "vendor" => String, "name" => String, "wwn_vendor_extension" => Fog::Nullable::String, "wwn_with_extension" => Fog::Nullable::String, "model" => Fog::Nullable::String, "wwn" => Fog::Nullable::String, "serial" => Fog::Nullable::String, "size" => Integer, }, "extra" => { "network" => { "eth0" => { "vlan-challenged" => String, "tx-udp_tnl-segmentation" => String, "ipv4-network" => String, "rx-vlan-stag-filter" => String, "highdma" => String, "tx-nocache-copy" => String, "tx-gso-robust" => String, "fcoe-mtu" => String, "netns-local" => String, "udp-fragmentation-offload" => String, "serial" => String, "latency" => Integer, "tx-checksumming/tx-checksum-ipv6" => String, "tx-checksumming/tx-checksum-ipv4" => String, "ipv4-netmask" => String, "tcp-segmentation-offload/tx-tcp-segmentation" => String, "tx-ipip-segmentation" => String, "rx-vlan-offload" => String, "tx-gre-segmentation" => String, "tx-checksumming/tx-checksum-ip-generic" => String, "tcp-segmentation-offload/tx-tcp-ecn-segmentation" => String, "tx-checksumming/tx-checksum-fcoe-crc" => String, "ipv4" => String, "businfo" => String, "rx-vlan-stag-hw-parse" => String, "tx-vlan-offload" => String, "product" => String, "vendor" => String, "tx-checksumming/tx-checksum-sctp" => String, "driver" => String, "tx-sit-segmentation" => String, "busy-poll" => String, "tx-vlan-stag-hw-insert" => String, "scatter-gather/tx-scatter-gather" => String, "link" => String, "ntuple-filters" => String, "rx-all" => String, "tcp-segmentation-offload" => String, "tcp-segmentation-offload/tx-tcp6-segmentation" => String, "rx-checksumming" => String, "rx-fcs" => String, "tx-lockless" => String, "generic-segmentation-offload" => String, "tx-fcoe-segmentation" => String, "tx-checksumming" => String, "ipv4-cidr" => Integer, "large-receive-offload" => String, "rx-vlan-filter" => String, "receive-hashing" => String, "scatter-gather/tx-scatter-gather-fraglist" => String, "generic-receive-offload" => String, "loopback" => String, "scatter-gather" => String, "tx-mpls-segmentation" => String }, "eth1" => { "vlan-challenged" => String, "tx-udp_tnl-segmentation" => String, "tx-vlan-stag-hw-insert" => String, "rx-vlan-stag-filter" => String, "highdma" => String, "tx-nocache-copy" => String, "tx-gso-robust" => String, "fcoe-mtu" => String, "netns-local" => String, "udp-fragmentation-offload" => String, "serial" => String, "latency" => Integer, "tx-checksumming/tx-checksum-ipv6" => String, "tx-checksumming/tx-checksum-ipv4" => String, "tx-fcoe-segmentation" => String, "tcp-segmentation-offload/tx-tcp-segmentation" => String, "tx-ipip-segmentation" => String, "rx-vlan-offload" => String, "tx-gre-segmentation" => String, "tx-checksumming/tx-checksum-ip-generic" => String, "tcp-segmentation-offload/tx-tcp-ecn-segmentation" => String, "tx-checksumming/tx-checksum-fcoe-crc" => String, "rx-vlan-stag-hw-parse" => String, "businfo" => String, "tx-vlan-offload" => String, "product" => String, "vendor" => String, "tx-checksumming/tx-checksum-sctp" => String, "driver" => String, "tx-sit-segmentation" => String, "busy-poll" => String, "scatter-gather/tx-scatter-gather" => String, "link" => String, "ntuple-filters" => String, "rx-all" => String, "tcp-segmentation-offload" => String, "tcp-segmentation-offload/tx-tcp6-segmentation" => String, "rx-checksumming" => String, "tx-lockless" => String, "generic-segmentation-offload" => String, "loopback" => String, "tx-checksumming" => String, "large-receive-offload" => String, "rx-vlan-filter" => String, "receive-hashing" => String, "scatter-gather/tx-scatter-gather-fraglist" => String, "generic-receive-offload" => String, "rx-fcs" => String, "scatter-gather" => String, "tx-mpls-segmentation" => String } }, "firmware" => { "bios" => { "date" => String, "version" => String, "vendor" => String } }, "system" => { "kernel" => { "cmdline" => String, "version" => String, "arch" => String }, "product" => { "version" => String, "vendor" => String, "name" => String, "uuid" => String }, "os" => { "version" => String, "vendor" => String } }, "memory" => { "total" => { "size" => Integer } }, "disk" => { "vda" => { "optimal_io_size" => Integer, "physical_block_size" => Integer, "rotational" => Integer, "vendor" => String, "size" => Integer }, "logical" => {"count" => Integer} }, "cpu" => { "logical" => {"number" => Integer}, "physical_0" => { "physid" => Integer, "product" => String, "frequency" => Integer, "vendor" => String, "flags" => String }, "physical_1" => { "physid" => Integer, "product" => String, "frequency" => Integer, "vendor" => String, "flags" => String }, "physical_2" => { "physid" => Integer, "product" => String, "frequency" => Integer, "vendor" => String, "flags" => String }, "physical_3" => { "physid" => Integer, "product" => String, "frequency" => Integer, "vendor" => String, "flags" => String }, "physical" => {"number" => Integer} } }, "interfaces" => { "eth0" => { "ip" => String, "mac" => String } }, "cpus" => 4, "boot_interface" => String, "memory_mb" => Integer, "ipmi_address" => String, "inventory" => { "bmc_address" => String, "interfaces" => [ { "ipv4_address" => Fog::Nullable::String, "switch_port_descr" => Fog::Nullable::String, "switch_chassis_descr" => Fog::Nullable::String, "name" => String, "mac_address" => String }, { "ipv4_address" => Fog::Nullable::String, "switch_port_descr" => Fog::Nullable::String, "switch_chassis_descr" => Fog::Nullable::String, "name" => String, "mac_address" => String } ], "disks" => [ { "rotational" => Fog::Boolean, "vendor" => String, "name" => String, "wwn_vendor_extension" => Fog::Nullable::String, "wwn_with_extension" => Fog::Nullable::String, "model" => Fog::Nullable::String, "wwn" => Fog::Nullable::String, "serial" => Fog::Nullable::String, "size" => Integer } ], "system_vendor" => { "serial_number" => String, "product_name" => String, "manufacturer" => String }, "memory" => { "physical_mb" => Integer, "total" => Integer }, "cpu" => { "count" => Integer, "frequency" => String, "model_name" => String, "architecture" => String } }, "error" => Fog::Nullable::String, "local_gb" => Integer, "all_interfaces" => { "eth0" => { "ip" => Fog::Nullable::String, "mac" => String }, "eth1" => { "ip" => Fog::Nullable::String, "mac" => String } }, "logs" => String } tests('success') do tests('#create_introspection').succeeds do @inspector.create_introspection(@node_uuid).body end tests('#abort_introspection').succeeds do @inspector.abort_introspection(@node_uuid).body end tests('#get_introspection').data_matches_schema(@introspection_finished) do @inspector.get_introspection(@node_uuid).body end tests('#get_introspection_details').data_matches_schema('data' => @introspection_data) do @inspector.get_introspection_details(@node_uuid).body end end end fog-openstack-0.1.6/tests/openstack/requests/introspection/rules_tests.rb0000644000175600017570000000240112730051546026124 0ustar pravipraviShindo.tests('@inspector | Introspection rules requests', ['openstack']) do @inspector = Fog::Introspection::OpenStack.new @rules_id = Fog::UUID.uuid @rules = { 'description' => Fog::Nullable::String, 'actions' => Array, 'conditions' => Array, 'uuid' => Fog::Nullable::String, } tests('success') do tests('#list_rules').data_matches_schema('rules' => @rules) do @inspector.list_rules.body end tests('#create_rules').data_matches_schema('rules' => @rules) do attributes = { "actions" => { "action" => "set-attribute", "path" => "/driver_info/ipmi_address", "value" => "{data[inventory][bmc_address]}" }, "conditions" => { "field" => "node://property.path", "op" => "eq", "value" => "val", }, "description" => "", "uuid" => "" } @inspector.create_rules(attributes).body end tests('#get_rules').data_matches_schema('rules' => @rules) do @inspector.get_rules(@rules_id).body end tests('#delete_rules').succeeds do @inspector.delete_rules(@rules_id) end tests('#delete_rules_all').succeeds do @inspector.delete_rules_all end end end fog-openstack-0.1.6/tests/openstack/requests/nfv/0000755000175600017570000000000012730051546021117 5ustar pravipravifog-openstack-0.1.6/tests/openstack/requests/nfv/vnf_tests.rb0000644000175600017570000000614612730051546023466 0ustar pravipraviShindo.tests('@vnf | NFV vnfs requests', ['openstack']) do @nfv = Fog::NFV::OpenStack.new @vnfs_create = { "status" => String, "description" => String, "tenant_id" => String, "name" => String, "instance_id" => String, "mgmt_url" => Fog::Nullable::String, "attributes" => Hash, "id" => String, "vnfd_id" => String, } @vnfs = { "status" => String, "description" => String, "tenant_id" => String, "name" => String, "instance_id" => String, "mgmt_url" => Fog::Nullable::String, "attributes" => Hash, "id" => String, } tests('success') do tests('#create_vnfs').data_matches_schema('vnf' => @vnfs_create) do vnfd_data = {:attributes => {:vnfd => "template_name: sample-vnfd\ndescription: demo-example\n\nservice_prop"\ "erties:\n Id: sample-vnfd\n vendor: tacker\n version: 1\n\nvdus:\n"\ " vdu1:\n id: vdu1\n vm_image: cirros\n instance_type: m1.ti"\ "ny\n\n network_interfaces:\n management:\n network: ne"\ "t_mgmt\n management: true\n pkt_in:\n network: net"\ "0\n pkt_out:\n network: net1\n\n placement_policy:\n "\ " availability_zone: nova\n\n auto-scaling: noop\n\n config:"\ "\n param0: key0\n param1: key1\n"}, :service_types => [{:service_type => "vnfd"}], :mgmt_driver => "noop", :infra_driver => "heat"} auth = {"tenantName" => "admin", "passwordCredentials" => {"username" => "admin", "password" => "password"}} @vnfd_body = @nfv.create_vnfd(:vnfd => vnfd_data, :auth => auth).body vnf_data = {:vnfd_id => @vnfd_body["vnfd"]["id"], :name => 'Test'} auth = {"tenantName" => "admin", "passwordCredentials" => {"username" => "admin", "password" => "password"}} @vnf_body = @nfv.create_vnf(:vnf => vnf_data, :auth => auth).body end Fog::NFV[:openstack].vnfs.get(@vnf_body["vnf"]["id"]).wait_for { ready? } tests('#list_vnfs').data_matches_schema('vnfs' => [@vnfs]) do @nfv.list_vnfs.body end tests('#get_vnfs').data_matches_schema('vnf' => @vnfs) do @nfv.get_vnf(@vnf_body["vnf"]["id"]).body end tests('#update_vnfs').data_matches_schema('vnf' => @vnfs) do vnf_data = {:attributes => {:config => "vdus:\n vdu1: \n\n"}} auth = {"tenantName" => "admin", "passwordCredentials" => {"username" => "admin", "password" => "password"}} @nfv.update_vnf(@vnf_body["vnf"]["id"], :vnf => vnf_data, :auth => auth).body end tests('#delete_vnfs').succeeds do sleep(10) unless Fog.mocking? @nfv.delete_vnf(@vnf_body["vnf"]["id"]) @nfv.delete_vnfd(@vnfd_body["vnfd"]["id"]) end end end fog-openstack-0.1.6/tests/openstack/requests/nfv/vnfd_tests.rb0000644000175600017570000000405112730051546023623 0ustar pravipraviShindo.tests('@vnfd | NFV vnfds requests', ['openstack']) do @nfv = Fog::NFV::OpenStack.new @vnfds = { "service_types" => Array, "description" => String, "tenant_id" => String, "mgmt_driver" => String, "infra_driver" => String, "attributes" => Hash, "id" => String, "name" => String } tests('success') do tests('#create_vnfds').data_matches_schema('vnfd' => @vnfds) do vnfd_data = {:attributes => {:vnfd => "template_name: sample-vnfd\ndescription: demo-example\n\nservice_prop"\ "erties:\n Id: sample-vnfd\n vendor: tacker\n version: 1\n\nvdus:\n"\ " vdu1:\n id: vdu1\n vm_image: cirros\n instance_type: m1.ti"\ "ny\n\n network_interfaces:\n management:\n network: ne"\ "t_mgmt\n management: true\n pkt_in:\n network: net"\ "0\n pkt_out:\n network: net1\n\n placement_policy:\n "\ " availability_zone: nova\n\n auto-scaling: noop\n\n config:"\ "\n param0: key0\n param1: key1\n"}, :service_types => [{:service_type => "vnfd"}], :mgmt_driver => "noop", :infra_driver => "heat"} auth = {"tenantName" => "admin", "passwordCredentials" => {"username" => "admin", "password" => "password"}} @vnfd_body = @nfv.create_vnfd(:vnfd => vnfd_data, :auth => auth).body end tests('#list_vnfds').data_matches_schema('vnfds' => [@vnfds]) do @nfv.list_vnfds.body end tests('#get_vnfds').data_matches_schema('vnfd' => @vnfds) do @nfv.get_vnfd(@vnfd_body["vnfd"]["id"]).body end tests('#delete_vnfds').succeeds do @nfv.delete_vnfd(@vnfd_body["vnfd"]["id"]) end end end fog-openstack-0.1.6/tests/openstack/requests/network/0000755000175600017570000000000012730051546022017 5ustar pravipravifog-openstack-0.1.6/tests/openstack/requests/network/lb_member_tests.rb0000644000175600017570000000403512730051546025514 0ustar pravipraviShindo.tests('Fog::Network[:openstack] | lb_member requests', ['openstack']) do @lb_member_format = { 'id' => String, 'pool_id' => String, 'address' => String, 'protocol_port' => Integer, 'weight' => Integer, 'status' => String, 'admin_state_up' => Fog::Boolean, 'tenant_id' => String, } tests('success') do tests('#create_lb_member').formats({'member' => @lb_member_format}) do pool_id = 'pool_id' address = '10.0.0.1' protocol_port = 80 weight = 100 attributes = {:admin_state_up => true, :tenant_id => 'tenant_id'} Fog::Network[:openstack].create_lb_member(pool_id, address, protocol_port, weight, attributes).body end tests('#list_lb_members').formats({'members' => [@lb_member_format]}) do Fog::Network[:openstack].list_lb_members.body end tests('#get_lb_member').formats({'member' => @lb_member_format}) do lb_member_id = Fog::Network[:openstack].lb_members.all.first.id Fog::Network[:openstack].get_lb_member(lb_member_id).body end tests('#update_lb_member').formats({'member' => @lb_member_format}) do lb_member_id = Fog::Network[:openstack].lb_members.all.first.id attributes = {:pool_id => 'new_pool_id', :weight => 50, :admin_state_up => false} Fog::Network[:openstack].update_lb_member(lb_member_id, attributes).body end tests('#delete_lb_member').succeeds do lb_member_id = Fog::Network[:openstack].lb_members.all.first.id Fog::Network[:openstack].delete_lb_member(lb_member_id) end end tests('failure') do tests('#get_lb_member').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].get_lb_member(0) end tests('#update_lb_member').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].update_lb_member(0, {}) end tests('#delete_lb_member').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].delete_lb_member(0) end end end fog-openstack-0.1.6/tests/openstack/requests/network/lb_pool_tests.rb0000644000175600017570000000553012730051546025217 0ustar pravipraviShindo.tests('Fog::Network[:openstack] | lb_pool requests', ['openstack']) do @lb_pool_format = { 'id' => String, 'subnet_id' => String, 'protocol' => String, 'lb_method' => String, 'name' => String, 'description' => String, 'health_monitors' => Array, 'members' => Array, 'status' => String, 'admin_state_up' => Fog::Boolean, 'vip_id' => Fog::Nullable::String, 'tenant_id' => String, 'active_connections' => Fog::Nullable::Integer, 'bytes_in' => Fog::Nullable::Integer, 'bytes_out' => Fog::Nullable::Integer, 'total_connections' => Fog::Nullable::Integer } @lb_pool_stats_format = { 'active_connections' => Integer, 'bytes_in' => Integer, 'bytes_out' => Integer, 'total_connections' => Integer } tests('success') do tests('#create_lb_pool').formats({'pool' => @lb_pool_format}) do subnet_id = 'subnet_id' protocol = 'HTTP' lb_method = 'ROUND_ROBIN' attributes = {:name => 'test-pool', :description => 'Test Pool', :admin_state_up => true, :tenant_id => 'tenant_id'} Fog::Network[:openstack].create_lb_pool(subnet_id, protocol, lb_method, attributes).body end tests('#list_lb_pools').formats({'pools' => [@lb_pool_format]}) do Fog::Network[:openstack].list_lb_pools.body end tests('#get_lb_pool').formats({'pool' => @lb_pool_format}) do lb_pool_id = Fog::Network[:openstack].lb_pools.all.first.id Fog::Network[:openstack].get_lb_pool(lb_pool_id).body end tests('#get_lb_pool_stats').formats({'stats' => @lb_pool_stats_format}) do lb_pool_id = Fog::Network[:openstack].lb_pools.all.first.id Fog::Network[:openstack].get_lb_pool_stats(lb_pool_id).body end tests('#update_lb_pool').formats({'pool' => @lb_pool_format}) do lb_pool_id = Fog::Network[:openstack].lb_pools.all.first.id attributes = {:name => 'new-test-pool', :description => 'New Test Pool', :lb_method => 'LEAST_CONNECTIONS', :admin_state_up => false} Fog::Network[:openstack].update_lb_pool(lb_pool_id, attributes).body end tests('#delete_lb_pool').succeeds do lb_pool_id = Fog::Network[:openstack].lb_pools.all.first.id Fog::Network[:openstack].delete_lb_pool(lb_pool_id) end end tests('failure') do tests('#get_lb_pool').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].get_lb_pool(0) end tests('#update_lb_pool').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].update_lb_pool(0, {}) end tests('#delete_lb_pool').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].delete_lb_pool(0) end end end fog-openstack-0.1.6/tests/openstack/requests/network/subnet_tests.rb0000644000175600017570000000444012730051546025070 0ustar pravipraviShindo.tests('Fog::Network[:openstack] | subnet requests', ['openstack']) do @subnet_format = { 'id' => String, 'name' => String, 'network_id' => String, 'cidr' => String, 'ip_version' => Integer, 'gateway_ip' => String, 'allocation_pools' => Array, 'dns_nameservers' => Array, 'host_routes' => Array, 'enable_dhcp' => Fog::Boolean, 'tenant_id' => String, } tests('success') do tests('#create_subnet').formats({'subnet' => @subnet_format}) do network_id = 'net_id' cidr = '10.2.2.0/24' ip_version = 4 attributes = {:name => 'subnet_name', :gateway_ip => '10.2.2.1', :allocation_pools => [], :dns_nameservers => [], :host_routes => [], :enable_dhcp => true, :tenant_id => 'tenant_id'} Fog::Network[:openstack].create_subnet(network_id, cidr, ip_version, attributes).body end tests('#list_subnet').formats({'subnets' => [@subnet_format]}) do Fog::Network[:openstack].list_subnets.body end tests('#get_subnet').formats({'subnet' => @subnet_format}) do subnet_id = Fog::Network[:openstack].subnets.all.first.id Fog::Network[:openstack].get_subnet(subnet_id).body end tests('#update_subnet').formats({'subnet' => @subnet_format}) do subnet_id = Fog::Network[:openstack].subnets.all.first.id attributes = {:name => 'subnet_name', :gateway_ip => '10.2.2.1', :allocation_pools => [], :dns_nameservers => [], :host_routes => [], :enable_dhcp => true} Fog::Network[:openstack].update_subnet(subnet_id, attributes).body end tests('#delete_subnet').succeeds do subnet_id = Fog::Network[:openstack].subnets.all.first.id Fog::Network[:openstack].delete_subnet(subnet_id) end end tests('failure') do tests('#get_subnet').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].get_subnet(0) end tests('#update_subnet').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].update_subnet(0, {}) end tests('#delete_subnet').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].delete_subnet(0) end end end fog-openstack-0.1.6/tests/openstack/requests/network/port_tests.rb0000644000175600017570000000450212730051546024553 0ustar pravipraviShindo.tests('Fog::Network[:openstack] | port requests', ['openstack']) do @port_format = { 'id' => String, 'name' => String, 'network_id' => String, 'fixed_ips' => Array, 'mac_address' => String, 'status' => String, 'admin_state_up' => Fog::Boolean, 'device_owner' => String, 'device_id' => String, 'tenant_id' => String, 'security_groups' => Array, 'allowed_address_pairs' => Array } tests('success') do tests('#create_port').formats({'port' => @port_format}) do network_id = 'net_id' attributes = {:name => 'port_name', :fixed_ips => [], :mac_address => 'fa:16:3e:62:91:7f', :admin_state_up => true, :device_owner => 'device_owner', :device_id => 'device_id', :tenant_id => 'tenant_id' ,:security_groups => [], :allowed_address_pairs => [] } Fog::Network[:openstack].create_port(network_id, attributes).body end tests('#list_port').formats({'ports' => [@port_format]}) do Fog::Network[:openstack].list_ports.body end tests('#get_port').formats({'port' => @port_format}) do port_id = Fog::Network[:openstack].ports.all.first.id Fog::Network[:openstack].get_port(port_id).body end tests('#update_port').formats({'port' => @port_format}) do port_id = Fog::Network[:openstack].ports.all.first.id attributes = {:name => 'port_name', :fixed_ips => [], :admin_state_up => true, :device_owner => 'device_owner', :device_id => 'device_id'} Fog::Network[:openstack].update_port(port_id, attributes).body end tests('#delete_port').succeeds do port_id = Fog::Network[:openstack].ports.all.first.id Fog::Network[:openstack].delete_port(port_id) end end tests('failure') do tests('#get_port').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].get_port(0) end tests('#update_port').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].update_port(0, {}) end tests('#delete_port').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].delete_port(0) end end end fog-openstack-0.1.6/tests/openstack/requests/network/ipsec_policy_tests.rb0000644000175600017570000000540212730051546026251 0ustar pravipraviShindo.tests('Fog::Network[:openstack] | ipsec_policy requests', ['openstack']) do @ipsec_policy_format = { 'id' => String, 'name' => String, 'description' => String, 'tenant_id' => String, 'lifetime' => Hash, 'pfs' => String, 'transform_protocol' => String, 'auth_algorithm' => String, 'encapsulation_mode' => String, 'encryption_algorithm' => String } tests('success') do tests('#create_ipsec_policy').formats('ipsecpolicy' => @ipsec_policy_format) do attributes = {:name => 'test-ipsec-policy', :description => 'Test VPN ipsec Policy', :tenant_id => 'tenant_id', :auth_algorithm => 'sha1', :encryption_algorithm => 'aes-128', :pfs => 'group5', :transform_protocol => 'esp', :lifetime => {'units' => 'seconds', 'value' => 3600}, :encapsulation_mode => 'tunnel' } Fog::Network[:openstack].create_ipsec_policy(attributes).body end tests('#list_ipsec_policies').formats('ipsecpolicies' => [@ipsec_policy_format]) do Fog::Network[:openstack].list_ipsec_policies.body end tests('#get_ipsec_policy').formats('ipsecpolicy' => @ipsec_policy_format) do ipsec_policy_id = Fog::Network[:openstack].ipsec_policies.all.first.id Fog::Network[:openstack].get_ipsec_policy(ipsec_policy_id).body end tests('#update_ipsec_policy').formats('ipsecpolicy' => @ipsec_policy_format) do ipsec_policy_id = Fog::Network[:openstack].ipsec_policies.all.first.id attributes = {:name => 'rename-test-ipsec-policy', :description => 'Test VPN ipsec Policy', :tenant_id => 'tenant_id', :auth_algorithm => 'sha1', :encryption_algorithm => 'aes-128', :pfs => 'group5', :transform_protocol => 'esp', :lifetime => {'units' => 'seconds', 'value' => 3600}, :encapsulation_mode => 'tunnel' } Fog::Network[:openstack].update_ipsec_policy(ipsec_policy_id, attributes).body end tests('#delete_ipsec_policy').succeeds do ipsec_policy_id = Fog::Network[:openstack].ipsec_policies.all.first.id Fog::Network[:openstack].delete_ipsec_policy(ipsec_policy_id) end end tests('failure') do tests('#get_ipsec_policy').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].get_ipsec_policy(0) end tests('#update_ipsec_policy').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].update_ipsec_policy(0, {}) end tests('#delete_ipsec_policy').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].delete_ipsec_policy(0) end end end fog-openstack-0.1.6/tests/openstack/requests/network/network_tests.rb0000644000175600017570000000667712730051546025277 0ustar pravipraviShindo.tests('Fog::Network[:openstack] | network requests', ['openstack']) do @network_format = { 'id' => String, 'name' => String, 'subnets' => Array, 'shared' => Fog::Boolean, 'status' => String, 'admin_state_up' => Fog::Boolean, 'tenant_id' => String, } @network_format_extensions = { 'router:external' => Fog::Boolean, 'provider:network_type' => String, 'provider:physical_network' => Fog::Nullable::String, 'provider:segmentation_id' => Integer } tests('success') do tests('#create_network').formats({'network' => @network_format}) do attributes = { :name => 'net_name', :shared => false, :admin_state_up => true, :tenant_id => 'tenant_id' } Fog::Network[:openstack].create_network(attributes).body end tests('#create_network+provider extensions').formats( {'network' => @network_format.merge(@network_format_extensions)} ) do attributes = { :name => 'net_name', :shared => false, :admin_state_up => true, :tenant_id => 'tenant_id', :router_external => true, # local, gre, vlan. Depends on the provider. # May rise an exception if the network_type isn't valid: # QuantumError: "Invalid input for operation: provider:physical_network" :provider_network_type => 'gre', :provider_segmentation_id => 22, } Fog::Network[:openstack].create_network(attributes).body end tests('#list_networks').formats({'networks' => [@network_format]}) do Fog::Network[:openstack].list_networks.body end tests('#get_network').formats({'network' => @network_format}) do network_id = Fog::Network[:openstack].networks.all.first.id Fog::Network[:openstack].get_network(network_id).body end tests('#update_network').formats({'network' => @network_format}) do network_id = Fog::Network[:openstack].networks.all.first.id attributes = {:name => 'net_name', :shared => false, :admin_state_up => true} Fog::Network[:openstack].update_network(network_id, attributes).body end tests('#delete_network').succeeds do network_id = Fog::Network[:openstack].networks.all.first.id Fog::Network[:openstack].delete_network(network_id) end end tests('failure') do tests('#create_network+provider extensions').raises( Excon::Errors::BadRequest ) do pending if Fog.mocking? attributes = { :name => 'net_name', :shared => false, :admin_state_up => true, :tenant_id => 'tenant_id', :router_external => true, # QuantumError: "Invalid input for operation: provider:physical_network" :provider_network_type => 'foobar', :provider_segmentation_id => 22, } Fog::Network[:openstack].create_network(attributes) end tests('#get_network').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].get_network(0) end tests('#update_network').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].update_network(0, {}) end tests('#delete_network').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].delete_network(0) end end # Cleaning up the mess Fog::Network[:openstack].networks.each do |n| Fog::Network[:openstack].delete_network(n.id) end end fog-openstack-0.1.6/tests/openstack/requests/network/lb_health_monitor_tests.rb0000644000175600017570000000725612730051546027271 0ustar pravipraviShindo.tests('Fog::Network[:openstack] | lb_health_monitor requests', ['openstack']) do @lb_health_monitor_format = { 'id' => String, 'type' => String, 'delay' => Integer, 'timeout' => Integer, 'max_retries' => Integer, 'http_method' => String, 'url_path' => String, 'expected_codes' => String, 'status' => String, 'admin_state_up' => Fog::Boolean, 'tenant_id' => String, } tests('success') do before do @lb_pool = Fog::Network[:openstack].lb_pools.create(:subnet_id => 'subnet_id', :protocol => 'HTTP', :lb_method => 'ROUND_ROBIN') end after do @lb_pool.destroy end tests('#create_lb_health_monitor').formats({'health_monitor' => @lb_health_monitor_format}) do type = 'PING' delay = 1 timeout = 5 max_retries = 10 attributes = {:http_method => 'GET', :url_path => '/', :expected_codes => '200, 201', :admin_state_up => true, :tenant_id => 'tenant_id'} Fog::Network[:openstack].create_lb_health_monitor(type, delay, timeout, max_retries, attributes).body end tests('#list_lb_health_monitors').formats({'health_monitors' => [@lb_health_monitor_format]}) do Fog::Network[:openstack].list_lb_health_monitors.body end tests('#get_lb_health_monitor').formats({'health_monitor' => @lb_health_monitor_format}) do lb_health_monitor_id = Fog::Network[:openstack].lb_health_monitors.all.first.id Fog::Network[:openstack].get_lb_health_monitor(lb_health_monitor_id).body end tests('#update_lb_health_monitor').formats({'health_monitor' => @lb_health_monitor_format}) do lb_health_monitor_id = Fog::Network[:openstack].lb_health_monitors.all.first.id attributes = {:delay => 5, :timeout => 10, :max_retries => 20, :http_method => 'POST', :url_path => '/varz', :expected_codes => '200', :admin_state_up => false} Fog::Network[:openstack].update_lb_health_monitor(lb_health_monitor_id, attributes).body end tests('#associate_lb_health_monitor').succeeds do lb_health_monitor_id = Fog::Network[:openstack].lb_health_monitors.all.first.id Fog::Network[:openstack].associate_lb_health_monitor(@lb_pool.id, lb_health_monitor_id) end tests('#disassociate_lb_health_monitor').succeeds do lb_health_monitor_id = Fog::Network[:openstack].lb_health_monitors.all.first.id Fog::Network[:openstack].disassociate_lb_health_monitor(@lb_pool.id, lb_health_monitor_id) end tests('#delete_lb_health_monitor').succeeds do lb_health_monitor_id = Fog::Network[:openstack].lb_health_monitors.all.first.id Fog::Network[:openstack].delete_lb_health_monitor(lb_health_monitor_id) end end tests('failure') do tests('#get_lb_health_monitor').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].get_lb_health_monitor(0) end tests('#update_lb_health_monitor').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].update_lb_health_monitor(0, {}) end tests('#associate_lb_health_monitor').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].associate_lb_health_monitor(0, 0) end tests('#disassociate_lb_health_monitor').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].disassociate_lb_health_monitor(0, 0) end tests('#delete_lb_health_monitor').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].delete_lb_health_monitor(0) end end end fog-openstack-0.1.6/tests/openstack/requests/network/vpn_service_tests.rb0000644000175600017570000000447112730051546026117 0ustar pravipraviShindo.tests('Fog::Network[:openstack] | vpn_service requests', ['openstack']) do @vpn_service_format = { 'id' => String, 'subnet_id' => String, 'router_id' => String, 'name' => String, 'description' => String, 'status' => String, 'admin_state_up' => Fog::Boolean, 'tenant_id' => String, 'external_v4_ip' => String, 'external_v6_ip' => String } tests('success') do tests('#create_vpn_service').formats('vpnservice' => @vpn_service_format) do subnet_id = 'subnet_id' router_id = 'router_id' attributes = {:name => 'test-vpn-service', :description => 'Test VPN Service', :admin_state_up => true, :tenant_id => 'tenant_id'} Fog::Network[:openstack].create_vpn_service(subnet_id, router_id, attributes).body end tests('#list_vpn_services').formats('vpnservices' => [@vpn_service_format]) do Fog::Network[:openstack].list_vpn_services.body end tests('#get_vpn_service').formats('vpnservice' => @vpn_service_format) do vpn_service_id = Fog::Network[:openstack].vpn_services.all.first.id Fog::Network[:openstack].get_vpn_service(vpn_service_id).body end tests('#update_vpn_service').formats('vpnservice' => @vpn_service_format) do vpn_service_id = Fog::Network[:openstack].vpn_services.all.first.id attributes = {:name => 'renamed-test-vpn-service', :description => 'Test VPN Service', :admin_state_up => true, :tenant_id => 'tenant_id', :subnet_id => 'subnet_id', :router_id => 'router_id'} Fog::Network[:openstack].update_vpn_service(vpn_service_id, attributes).body end tests('#delete_vpn_service').succeeds do vpn_servcice_id = Fog::Network[:openstack].vpn_services.all.first.id Fog::Network[:openstack].delete_vpn_service(vpn_servcice_id) end end tests('failure') do tests('#get_vpn_service').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].get_vpn_service(0) end tests('#update_lb_pool').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].update_lb_pool(0, {}) end tests('#delete_vpn_service').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].delete_vpn_service(0) end end end fog-openstack-0.1.6/tests/openstack/requests/network/security_group_tests.rb0000644000175600017570000000277112730051546026660 0ustar pravipraviShindo.tests('Fog::Network[:openstack] | security_group requests', ['openstack']) do @security_group_format = { "id" => String, "name" => String, "description" => String, "tenant_id" => String, "security_group_rules" => [Hash] } tests('success') do @sec_group_id = nil tests("#create_security_group('fog_security_group', 'tests group')").formats(@security_group_format) do attributes = {:name => "fog_security_group", :description => "tests group"} data = Fog::Network[:openstack].create_security_group(attributes).body["security_group"] @sec_group_id = data["id"] data end tests("#get_security_group('#{@sec_group_id}')").formats(@security_group_format) do Fog::Network[:openstack].get_security_group(@sec_group_id).body["security_group"] end tests("#list_security_groups").formats('security_groups' => [@security_group_format]) do Fog::Network[:openstack].list_security_groups.body end tests("#delete_security_group('#{@sec_group_id}')").succeeds do Fog::Network[:openstack].delete_security_group(@sec_group_id) end end tests('failure') do tests("#get_security_group(0)").raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].get_security_group(0) end tests("#delete_security_group(0)").raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].delete_security_group(0) end end end fog-openstack-0.1.6/tests/openstack/requests/network/lb_vip_tests.rb0000644000175600017570000000512512730051546025044 0ustar pravipraviShindo.tests('Fog::Network[:openstack] | lb_vip requests', ['openstack']) do @lb_vip_format = { 'id' => String, 'subnet_id' => String, 'pool_id' => String, 'protocol' => String, 'protocol_port' => Integer, 'name' => String, 'description' => String, 'address' => String, 'port_id' => String, 'session_persistence' => Hash, 'connection_limit' => Integer, 'status' => String, 'admin_state_up' => Fog::Boolean, 'tenant_id' => String, } tests('success') do tests('#create_lb_vip').formats({'vip' => @lb_vip_format}) do subnet_id = 'subnet_id' pool_id = 'pool_id' protocol = 'HTTP' protocol_port = 80 attributes = {:name => 'test-vip', :description => 'Test VIP', :address => '10.0.0.1', :connection_limit => 10, :session_persistence => { "cookie_name" => "COOKIE_NAME", "type" => "APP_COOKIE" }, :admin_state_up => true, :tenant_id => 'tenant_id'} Fog::Network[:openstack].create_lb_vip(subnet_id, pool_id, protocol, protocol_port, attributes).body end tests('#list_lb_vips').formats({'vips' => [@lb_vip_format]}) do Fog::Network[:openstack].list_lb_vips.body end tests('#get_lb_vip').formats({'vip' => @lb_vip_format}) do lb_vip_id = Fog::Network[:openstack].lb_vips.all.first.id Fog::Network[:openstack].get_lb_vip(lb_vip_id).body end tests('#update_lb_vip').formats({'vip' => @lb_vip_format}) do lb_vip_id = Fog::Network[:openstack].lb_vips.all.first.id attributes = {:pool_id => 'new_pool_id', :name => 'new-test-vip', :description => 'New Test VIP', :connection_limit => 5, :session_persistence => { "type" => "HTTP_COOKIE" }, :admin_state_up => false} Fog::Network[:openstack].update_lb_vip(lb_vip_id, attributes).body end tests('#delete_lb_vip').succeeds do lb_vip_id = Fog::Network[:openstack].lb_vips.all.first.id Fog::Network[:openstack].delete_lb_vip(lb_vip_id) end end tests('failure') do tests('#get_lb_vip').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].get_lb_vip(0) end tests('#update_lb_vip').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].update_lb_vip(0, {}) end tests('#delete_lb_vip').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].delete_lb_vip(0) end end end fog-openstack-0.1.6/tests/openstack/requests/network/quota_tests.rb0000644000175600017570000000343312730051546024722 0ustar pravipraviShindo.tests('Fog::Network[:openstack] | quota requests', ['openstack']) do @tenant_id = Fog::Compute[:openstack].list_tenants.body['tenants'].first['id'] @quota_format = { 'subnet' => Fog::Nullable::Integer, 'router' => Fog::Nullable::Integer, 'port' => Fog::Nullable::Integer, 'network' => Fog::Nullable::Integer, 'floatingip' => Fog::Nullable::Integer } @quotas_format = [{ 'subnet' => Fog::Nullable::Integer, 'router' => Fog::Nullable::Integer, 'port' => Fog::Nullable::Integer, 'network' => Fog::Nullable::Integer, 'floatingip' => Fog::Nullable::Integer, 'tenant_id' => Fog::Nullable::String }] tests('success') do tests('#get_quotas').formats({ 'quotas' => @quotas_format }) do Fog::Network[:openstack].get_quotas.body end tests('#get_quota').formats(@quota_format) do @quota = Fog::Network[:openstack].get_quota(@tenant_id).body['quota'] end tests('#update_quota') do new_values = @quota.merge({ 'volumes' => @quota['subnet']/2, 'snapshots' => @quota['router']/2 }) succeeds do Fog::Network[:openstack].update_quota(@tenant_id, new_values.clone) end returns(new_values, 'returns new values') do Fog::Network[:openstack].get_quota(@tenant_id).body['quota'] end # set quota back to old values succeeds do Fog::Network[:openstack].update_quota(@tenant_id, @quota.clone) end # ensure old values are restored returns(@quota, 'old values restored') do Fog::Network[:openstack].get_quota(@tenant_id).body['quota'] end end tests('#delete_quota') do succeeds do Fog::Network[:openstack].delete_quota(@tenant_id) end end end end fog-openstack-0.1.6/tests/openstack/requests/network/router_tests.rb0000644000175600017570000000451312730051546025111 0ustar pravipraviShindo.tests('Fog::Network[:openstack] | router requests', ['openstack']) do @router_format = { :id => String, :name => String, :status => String, :admin_state_up => Fog::Boolean, :tenant_id => String, :external_gateway_info => Fog::Nullable::Hash, } tests('success') do tests('#create_router').formats({'router' => @router_format}) do attributes = { :admin_state_up => true, :tenant_id => 'tenant_id' } Fog::Network[:openstack].create_router('router_name', attributes).body end tests('#list_routers').formats({'routers' => [@router_format]}) do Fog::Network[:openstack].list_routers.body end tests('#get_router').formats({'router' => @router_format}) do router_id = Fog::Network[:openstack].routers.all.first.id Fog::Network[:openstack].get_router(router_id).body end tests('#update_router').formats({'router' => @router_format}) do router_id = Fog::Network[:openstack].routers.all.first.id attributes = { :name => 'net_name', :external_gateway_info => { :network_id => 'net_id' }, :status => 'ACTIVE', :admin_state_up => true } Fog::Network[:openstack].update_router(router_id, attributes).body end tests('#update_router_with_network').formats({'router' => @router_format}) do router_id = Fog::Network[:openstack].routers.all.first.id net = Fog::Network[:openstack].networks.first attributes = { :name => 'net_name', :external_gateway_info => net, :status => 'ACTIVE', :admin_state_up => true } Fog::Network[:openstack].update_router(router_id, attributes).body end tests('#delete_router').succeeds do router_id = Fog::Network[:openstack].routers.all.last.id Fog::Network[:openstack].delete_router(router_id) end end tests('failure') do tests('#get_router').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].get_router(0) end tests('#update_router').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].update_router(0, {}) end tests('#delete_router').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].delete_router(0) end end end fog-openstack-0.1.6/tests/openstack/requests/network/security_group_rule_tests.rb0000644000175600017570000000444112730051546027703 0ustar pravipraviShindo.tests('Fog::Network[:openstack] | security_grouprule requests', ['openstack']) do @security_group_rule_format = { "id" => String, "remote_group_id" => Fog::Nullable::String, "direction" => String, "remote_ip_prefix" => Fog::Nullable::String, "protocol" => Fog::Nullable::String, "ethertype" => String, "port_range_max" => Fog::Nullable::Integer, "port_range_min" => Fog::Nullable::Integer, "security_group_id" => String, "tenant_id" => String } tests('success') do attributes = {:name => "my_security_group", :description => "tests group"} data = Fog::Network[:openstack].create_security_group(attributes).body["security_group"] @sec_group_id = data["id"] @sec_group_rule_id = nil tests("#create_security_group_rule(#{@sec_group_id}, 'ingress', attributes)").formats(@security_group_rule_format) do attributes = { :remote_ip_prefix => "0.0.0.0/0", :protocol => "tcp", :port_range_min => 22, :port_range_max => 22 } data = Fog::Network[:openstack].create_security_group_rule(@sec_group_id, 'ingress', attributes).body["security_group_rule"] @sec_group_rule_id = data["id"] data end tests("#get_security_group_rule('#{@sec_group_rule_id}')").formats(@security_group_rule_format) do Fog::Network[:openstack].get_security_group_rule(@sec_group_rule_id).body["security_group_rule"] end tests("#list_security_group_rules").formats("security_group_rules" => [@security_group_rule_format]) do Fog::Network[:openstack].list_security_group_rules.body end tests("#delete_security_group_rule('#{@sec_group_rule_id}')").succeeds do Fog::Network[:openstack].delete_security_group_rule(@sec_group_rule_id) end end tests('failure') do tests('#get_security_group_rule(0)').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].get_security_group_rule(0) end tests('#delete_security_group_rule(0)').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].delete_security_group_rule(0) end end Fog::Network[:openstack].delete_security_group(@sec_group_id) end fog-openstack-0.1.6/tests/openstack/requests/network/ike_policy_tests.rb0000644000175600017570000000531012730051546025714 0ustar pravipraviShindo.tests('Fog::Network[:openstack] | ike_policy requests', ['openstack']) do @ike_policy_format = { 'id' => String, 'name' => String, 'description' => String, 'tenant_id' => String, 'auth_algorithm' => String, 'encryption_algorithm' => String, 'pfs' => String, 'phase1_negotiation_mode' => String, 'lifetime' => Hash, 'ike_version' => String } tests('success') do tests('#create_ike_policy').formats('ikepolicy' => @ike_policy_format) do attributes = {:name => 'test-ike-policy', :description => 'Test VPN IKE Policy', :tenant_id => 'tenant_id', :auth_algorithm => 'sha1', :encryption_algorithm => 'aes-256', :pfs => 'group5', :phase1_negotiation_mode => 'main', :lifetime => {'units' => 'seconds', 'value' => 3600}, :ike_version => 'v1' } Fog::Network[:openstack].create_ike_policy(attributes).body end tests('#list_ike_policies').formats('ikepolicies' => [@ike_policy_format]) do Fog::Network[:openstack].list_ike_policies.body end tests('#get_ike_policy').formats('ikepolicy' => @ike_policy_format) do ike_policy_id = Fog::Network[:openstack].ike_policies.all.first.id Fog::Network[:openstack].get_ike_policy(ike_policy_id).body end tests('#update_ike_policy').formats('ikepolicy' => @ike_policy_format) do ike_policy_id = Fog::Network[:openstack].ike_policies.all.first.id attributes = {:name => 'rename-test-ike-policy', :description => 'Test VPN IKE Policy', :tenant_id => 'tenant_id', :auth_algorithm => 'sha1', :encryption_algorithm => 'aes-256', :pfs => 'group5', :phase1_negotiation_mode => 'main', :lifetime => {'units' => 'seconds', 'value' => 3600}, :ike_version => 'v1' } Fog::Network[:openstack].update_ike_policy(ike_policy_id, attributes).body end tests('#delete_ike_policy').succeeds do ike_policy_id = Fog::Network[:openstack].ike_policies.all.first.id Fog::Network[:openstack].delete_ike_policy(ike_policy_id) end end tests('failure') do tests('#get_ike_policy').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].get_ike_policy(0) end tests('#update_ike_policy').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].update_ike_policy(0, {}) end tests('#delete_ike_policy').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].delete_ike_policy(0) end end end fog-openstack-0.1.6/tests/openstack/requests/network/ipsec_site_connection_tests.rb0000644000175600017570000000742512730051546030144 0ustar pravipraviShindo.tests('Fog::Network[:openstack] | ipsec_site_connection requests', ['openstack']) do @ipsec_site_connection_format = { 'id' => String, 'name' => String, 'description' => String, 'status' => String, 'tenant_id' => String, 'admin_state_up' => Fog::Boolean, 'psk' => String, 'initiator' => String, 'auth_mode' => String, 'peer_cidrs' => Array, 'mtu' => Integer, 'peer_ep_group_id' => String, 'ikepolicy_id' => String, 'vpnservice_id' => String, 'dpd' => Hash, 'route_mode' => String, 'ipsecpolicy_id' => String, 'local_ep_group_id' => String, 'peer_address' => String, 'peer_id' => String } tests('success') do tests('#create_ipsec_site_connection').formats('ipsec_site_connection' => @ipsec_site_connection_format) do vpnservice_id = "vpn" ikepolicy_id = "ike" ipsecpolicy_id = "ipsec" attributes = {:name => 'test-ipsec-site-connection', :description => 'Test VPN IPSec Site Connection', :tenant_id => 'tenant_id', :peer_address => "172.24.4.226", :peer_id => "172.24.4.226", :peer_cidrs => [], :psk => "secret", :mtu => 1500, :dpd => {"action" => "hold", "interval" => 30, "timeout" => 120}, :initiator => "bi-directional", :admin_state_up => true } Fog::Network[:openstack].create_ipsec_site_connection(vpnservice_id, ikepolicy_id, ipsecpolicy_id, attributes).body end tests('#list_ipsec_site_connections').formats('ipsec_site_connections' => [@ipsec_site_connection_format]) do Fog::Network[:openstack].list_ipsec_site_connections.body end tests('#get_ipsec_site_connection').formats('ipsec_site_connection' => @ipsec_site_connection_format) do ipsec_site_connection_id = Fog::Network[:openstack].ipsec_site_connections.all.first.id Fog::Network[:openstack].get_ipsec_site_connection(ipsec_site_connection_id).body end tests('#update_ipsec_site_connection').formats('ipsec_site_connection' => @ipsec_site_connection_format) do ipsec_site_connection_id = Fog::Network[:openstack].ipsec_site_connections.all.first.id attributes = {:name => 'rename-test-ipsec-site-connection', :description => 'Test VPN IPSec Site Connection', :tenant_id => 'tenant_id', :peer_address => "172.24.4.226", :peer_id => "172.24.4.226", :peer_cidrs => [], :psk => "secret", :mtu => 1500, :dpd => {"action" => "hold", "interval" => 30, "timeout" => 120}, :initiator => "bi-directional", :admin_state_up => true} Fog::Network[:openstack].update_ipsec_site_connection(ipsec_site_connection_id, attributes).body end tests('#delete_ipsec_site_connection').succeeds do ipsec_site_connection_id = Fog::Network[:openstack].ipsec_site_connections.all.first.id Fog::Network[:openstack].delete_ipsec_site_connection(ipsec_site_connection_id) end end tests('failure') do tests('#get_ipsec_site_connection').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].get_ipsec_site_connection(0) end tests('#update_ipsec_site_connection').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].update_ipsec_site_connection(0, {}) end tests('#delete_ipsec_site_connection').raises(Fog::Network::OpenStack::NotFound) do Fog::Network[:openstack].delete_ipsec_site_connection(0) end end end fog-openstack-0.1.6/tests/openstack/requests/baremetal/0000755000175600017570000000000012730051546022262 5ustar pravipravifog-openstack-0.1.6/tests/openstack/requests/baremetal/chassis_tests.rb0000644000175600017570000000307412730051546025472 0ustar pravipraviShindo.tests('Fog::Baremetal[:openstack] | Baremetal chassis requests', ['openstack']) do openstack = Fog::Identity[:openstack] @chassis_format = { 'description' => String, 'uuid' => String, 'links' => Array } @detailed_chassis_format = { 'description' => String, 'uuid' => String, 'created_at' => String, 'updated_at' => Fog::Nullable::String, 'extra' => Hash, 'nodes' => Array, 'links' => Array } tests('success') do tests('#list_chassis').data_matches_schema({'chassis' => [@chassis_format]}) do Fog::Baremetal[:openstack].list_chassis.body end tests('#list_chassis_detailed').data_matches_schema({'chassis' => [@detailed_chassis_format]}) do Fog::Baremetal[:openstack].list_chassis_detailed.body end tests('#create_chassis').data_matches_schema(@detailed_chassis_format) do chassis_attributes = {:description => 'description'} @instance = Fog::Baremetal[:openstack].create_chassis(chassis_attributes).body end tests('#get_chassis').data_matches_schema(@detailed_chassis_format) do Fog::Baremetal[:openstack].get_chassis(@instance['uuid']).body end tests('#patch_chassis').data_matches_schema(@detailed_chassis_format) do Fog::Baremetal[:openstack].patch_chassis( @instance['uuid'], [{'op' => 'replace', 'path' => '/description', 'value' => 'new description'}]).body end tests('#delete_chassis').succeeds do Fog::Baremetal[:openstack].delete_chassis(@instance['uuid']) end end end fog-openstack-0.1.6/tests/openstack/requests/baremetal/node_tests.rb0000644000175600017570000000606412730051546024764 0ustar pravipraviShindo.tests('Fog::Baremetal[:openstack] | Baremetal node requests', ['openstack']) do openstack = Fog::Identity[:openstack] @node_format = { 'instance_uuid' => Fog::Nullable::String, 'maintenance' => Fog::Boolean, 'power_state' => Fog::Nullable::String, 'provision_state' => Fog::Nullable::String, 'uuid' => String, 'links' => Array } @detailed_node_format = { 'instance_uuid' => Fog::Nullable::String, 'maintenance' => Fog::Boolean, 'power_state' => Fog::Nullable::String, 'provision_state' => Fog::Nullable::String, 'uuid' => String, 'created_at' => String, 'updated_at' => Fog::Nullable::String, 'chassis_uuid' => Fog::Nullable::String, 'console_enabled' => Fog::Boolean, 'driver' => String, 'driver_info' => Hash, 'extra' => Hash, 'instance_info' => Hash, 'last_error' => Fog::Nullable::String, 'maintenance_reason' => Fog::Nullable::String, 'properties' => Hash, 'provision_updated_at' => Fog::Nullable::String, 'reservation' => Fog::Nullable::String, 'target_power_state' => Fog::Nullable::String, 'target_provision_state' => Fog::Nullable::String, 'links' => Array } tests('success') do tests('#list_nodes').data_matches_schema({'nodes' => [@node_format]}) do Fog::Baremetal[:openstack].list_nodes.body end tests('#list_nodes_detailed').data_matches_schema({'nodes' => [@detailed_node_format]}) do Fog::Baremetal[:openstack].list_nodes_detailed.body end tests('#create_node').data_matches_schema(@detailed_node_format) do node_attributes = {:driver => 'pxe_ipmitool'} @instance = Fog::Baremetal[:openstack].create_node(node_attributes).body end tests('#get_node').data_matches_schema(@detailed_node_format) do Fog::Baremetal[:openstack].get_node(@instance['uuid']).body end tests('#patch_node').data_matches_schema(@detailed_node_format) do Fog::Baremetal[:openstack].patch_node( @instance['uuid'], [{'op' => 'replace', 'path' => '/driver', 'value' => 'pxe_ssh'}]).body end tests('#set_node_power_state').data_matches_schema(@detailed_node_format) do Fog::Baremetal[:openstack].set_node_power_state( @instance['uuid'], 'power off').body end tests('#set_node_provision_state').data_matches_schema(@detailed_node_format) do Fog::Baremetal[:openstack].set_node_provision_state( @instance['uuid'], 'manage').body end tests('#set_node_maintenance').succeeds do Fog::Baremetal[:openstack].set_node_maintenance(@instance['uuid']) end tests('#unset_node_maintenance').succeeds do Fog::Baremetal[:openstack].unset_node_maintenance(@instance['uuid']) end tests('#delete_node').succeeds do Fog::Baremetal[:openstack].delete_node(@instance['uuid']) end end end fog-openstack-0.1.6/tests/openstack/requests/baremetal/port_tests.rb0000644000175600017570000000433412730051546025021 0ustar pravipraviShindo.tests('Fog::Baremetal[:openstack] | Baremetal port requests', ['openstack']) do openstack = Fog::Identity[:openstack] @port_format = { 'address' => String, 'uuid' => String } # {"node_uuid"=>"ebf4e459-ddd6-4ce9-bef5-5181987cb62c", "uuid"=>"82a26de6-6af5-4cd3-a076-a5af1a75d457", "links"=>[{"href"=>"http://192.0.2.1:6385/v1/ports/82a26de6-6af5-4cd3-a076-a5af1a75d457", "rel"=>"self"}, {"href"=>"http://192.0.2.1:6385/ports/82a26de6-6af5-4cd3-a076-a5af1a75d457", "rel"=>"bookmark"}], "extra"=>{}, "created_at"=>"2015-01-15T09:22:23.673409+00:00", "updated_at"=>nil, "address"=>"00:c2:08:85:de:ca"} does not match {"address"=>String, "uuid"=>String, "created_at"=>String, "updated_at"=>String, "extra"=>Hash, "node_uuid"=>String} @detailed_port_format = { 'address' => String, 'uuid' => String, 'created_at' => String, 'updated_at' => Fog::Nullable::String, 'extra' => Hash, 'node_uuid' => String, 'links' => Array } tests('success') do tests('#list_ports').data_matches_schema({'ports' => [@port_format]}) do Fog::Baremetal[:openstack].list_ports.body end tests('#list_ports_detailed').data_matches_schema({'ports' => [@detailed_port_format]}) do Fog::Baremetal[:openstack].list_ports_detailed.body end tests('#create_port').data_matches_schema(@detailed_port_format) do node_attributes = {:driver => 'pxe_ipmitool'} @instance = Fog::Baremetal[:openstack].create_node(node_attributes).body port_attributes = {:address => '00:c2:08:85:de:ca', :node_uuid => @instance['uuid']} @port = Fog::Baremetal[:openstack].create_port(port_attributes).body end tests('#get_port').data_matches_schema(@detailed_port_format) do Fog::Baremetal[:openstack].get_port(@port['uuid']).body end tests('#patch_port').data_matches_schema(@detailed_port_format) do Fog::Baremetal[:openstack].patch_port( @port['uuid'], [{'op' => 'add', 'path' => '/extra/name', 'value' => 'eth1'}]).body end tests('#delete_port').succeeds do Fog::Baremetal[:openstack].delete_port(@port['uuid']) Fog::Baremetal[:openstack].delete_node(@instance['uuid']) end end end fog-openstack-0.1.6/tests/openstack/requests/baremetal/driver_tests.rb0000644000175600017570000000246012730051546025326 0ustar pravipraviShindo.tests('Fog::Baremetal[:openstack] | Baremetal driver requests', ['openstack']) do openstack = Fog::Identity[:openstack] @driver_format = { 'hosts' => Array, 'name' => String } @driver_properties_format = { "pxe_deploy_ramdisk" => String, "ipmi_transit_address" => String, "ipmi_terminal_port" => String, "ipmi_target_channel" => String, "ipmi_transit_channel" => String, "ipmi_local_address" => String, "ipmi_username" => String, "ipmi_address" => String, "ipmi_target_address" => String, "ipmi_password" => String, "pxe_deploy_kernel" => String, "ipmi_priv_level" => String, "ipmi_bridging" => String } tests('success') do tests('#list_drivers').data_matches_schema({'drivers' => [@driver_format]}) do instances = Fog::Baremetal[:openstack].list_drivers.body @instance = instances['drivers'].last instances end tests('#get_driver').data_matches_schema(@driver_format) do Fog::Baremetal[:openstack].get_driver(@instance['name']).body end tests('#get_driver_properties').data_matches_schema(@driver_properties_format) do Fog::Baremetal[:openstack].get_driver_properties(@instance['name']).body end end end fog-openstack-0.1.6/tests/openstack/requests/storage/0000755000175600017570000000000012730051546021772 5ustar pravipravifog-openstack-0.1.6/tests/openstack/requests/storage/container_tests.rb0000644000175600017570000000346512730051546025533 0ustar pravipraviShindo.tests('Fog::Storage[:openstack] | container requests', ["openstack"]) do @container_format = [String] @containers_format = [{ 'bytes' => Integer, 'count' => Integer, 'name' => String }] tests('success') do tests("#put_container('fogcontainertests')").succeeds do pending if Fog.mocking? Fog::Storage[:openstack].put_container('fogcontainertests') end tests("#get_container('fogcontainertests')").formats(@container_format) do pending if Fog.mocking? Fog::Storage[:openstack].get_container('fogcontainertests').body end tests("#get_containers").formats(@containers_format) do pending if Fog.mocking? Fog::Storage[:openstack].get_containers.body end tests("#head_container('fogcontainertests')").succeeds do pending if Fog.mocking? Fog::Storage[:openstack].head_container('fogcontainertests') end tests("#head_containers").succeeds do pending if Fog.mocking? Fog::Storage[:openstack].head_containers end tests("#delete_container('fogcontainertests')").succeeds do pending if Fog.mocking? Fog::Storage[:openstack].delete_container('fogcontainertests') end end tests('failure') do tests("#get_container('fognoncontainer')").raises(Fog::Storage::OpenStack::NotFound) do pending if Fog.mocking? Fog::Storage[:openstack].get_container('fognoncontainer') end tests("#head_container('fognoncontainer')").raises(Fog::Storage::OpenStack::NotFound) do pending if Fog.mocking? Fog::Storage[:openstack].head_container('fognoncontainer') end tests("#delete_container('fognoncontainer')").raises(Fog::Storage::OpenStack::NotFound) do pending if Fog.mocking? Fog::Storage[:openstack].delete_container('fognoncontainer') end end end fog-openstack-0.1.6/tests/openstack/requests/storage/large_object_tests.rb0000644000175600017570000003413612730051546026170 0ustar pravipraviShindo.tests('Fog::Storage[:openstack] | large object requests', ['openstack']) do unless Fog.mocking? @directory = Fog::Storage[:openstack].directories.create(:key => 'foglargeobjecttests') @directory2 = Fog::Storage[:openstack].directories.create(:key => 'foglargeobjecttests2') @segments = { :a => { :container => @directory.identity, :name => 'fog_large_object/a', :data => 'a' * (1024**2 + 10), :size => 1024**2 + 10, :etag => 'c2e97007d59f0c19b850debdcb80cca5' }, :b => { :container => @directory.identity, :name => 'fog_large_object/b', :data => 'b' * (1024**2 + 20), :size => 1024**2 + 20, :etag => 'd35f50622a1259daad75ff7d5512c7ef' }, :c => { :container => @directory.identity, :name => 'fog_large_object2/a', :data => 'c' * (1024**2 + 30), :size => 1024**2 + 30, :etag => '901d3531a87d188041d4d5b43cb464c1' }, :d => { :container => @directory2.identity, :name => 'fog_large_object2/b', :data => 'd' * (1024**2 + 40), :size => 1024**2 + 40, :etag => '350c0e00525198813920a157df185c8d' } } end tests('success') do tests('upload test segments').succeeds do pending if Fog.mocking? @segments.each_value do |segment| Fog::Storage[:openstack].put_object(segment[:container], segment[:name], segment[:data]) end end tests('dynamic large object requests') do pending if Fog.mocking? tests('#put_object_manifest alias').succeeds do Fog::Storage[:openstack].put_object_manifest(@directory.identity, 'fog_large_object') end tests('using default X-Object-Manifest header') do tests('#put_dynamic_obj_manifest').succeeds do Fog::Storage[:openstack].put_dynamic_obj_manifest(@directory.identity, 'fog_large_object') end tests('#get_object streams all segments matching the default prefix').succeeds do expected = @segments[:a][:data] + @segments[:b][:data] + @segments[:c][:data] Fog::Storage[:openstack].get_object(@directory.identity, 'fog_large_object').body == expected end # When the manifest object name is equal to the segment prefix, OpenStack treats it as if it's the first segment. # So you must prepend the manifest object's Etag - Digest::MD5.hexdigest('') tests('#head_object returns Etag that includes manifest object in calculation').succeeds do etags = ['d41d8cd98f00b204e9800998ecf8427e', @segments[:a][:etag], @segments[:b][:etag], @segments[:c][:etag]] expected = "\"#{ Digest::MD5.hexdigest(etags.join) }\"" # returned in quotes "\"2577f38428e895c50de6ea78ccc7da2a"\" Fog::Storage[:openstack].head_object(@directory.identity, 'fog_large_object').headers['Etag'] == expected end end tests('specifying X-Object-Manifest segment prefix') do tests('#put_dynamic_obj_manifest').succeeds do options = { 'X-Object-Manifest' => "#{ @directory.identity }/fog_large_object/" } Fog::Storage[:openstack].put_dynamic_obj_manifest(@directory.identity, 'fog_large_object', options) end tests('#get_object streams segments only matching the specified prefix').succeeds do expected = @segments[:a][:data] + @segments[:b][:data] Fog::Storage[:openstack].get_object(@directory.identity, 'fog_large_object').body == expected end tests('#head_object returns Etag that does not include manifest object in calculation').succeeds do etags = [@segments[:a][:etag], @segments[:b][:etag]] expected = "\"#{ Digest::MD5.hexdigest(etags.join) }\"" # returned in quotes "\"0f035ed3cc38aa0ef46dda3478fad44d"\" Fog::Storage[:openstack].head_object(@directory.identity, 'fog_large_object').headers['Etag'] == expected end end tests('storing manifest in a different container than the segments') do tests('#put_dynamic_obj_manifest').succeeds do options = { 'X-Object-Manifest' => "#{ @directory.identity }/fog_large_object/" } Fog::Storage[:openstack].put_dynamic_obj_manifest(@directory2.identity, 'fog_large_object', options) end tests('#get_object').succeeds do expected = @segments[:a][:data] + @segments[:b][:data] Fog::Storage[:openstack].get_object(@directory2.identity, 'fog_large_object').body == expected end end end tests('static large object requests') do pending if Fog.mocking? tests('single container') do tests('#put_static_obj_manifest').succeeds do segments = [ { :path => "#{ @segments[:a][:container] }/#{ @segments[:a][:name] }", :etag => @segments[:a][:etag], :size_bytes => @segments[:a][:size] }, { :path => "#{ @segments[:c][:container] }/#{ @segments[:c][:name] }", :etag => @segments[:c][:etag], :size_bytes => @segments[:c][:size] } ] Fog::Storage[:openstack].put_static_obj_manifest(@directory.identity, 'fog_large_object', segments) end tests('#head_object') do etags = [@segments[:a][:etag], @segments[:c][:etag]] etag = "\"#{ Digest::MD5.hexdigest(etags.join) }\"" # "\"ad7e633a12e8a4915b45e6dd1d4b0b4b\"" content_length = (@segments[:a][:size] + @segments[:c][:size]).to_s response = Fog::Storage[:openstack].head_object(@directory.identity, 'fog_large_object') returns(etag, 'returns ETag computed from segments') { response.headers['Etag'] } returns(content_length , 'returns Content-Length for all segments') { response.headers['Content-Length'] } returns('True', 'returns X-Static-Large-Object header') { response.headers['X-Static-Large-Object'] } end tests('#get_object').succeeds do expected = @segments[:a][:data] + @segments[:c][:data] Fog::Storage[:openstack].get_object(@directory.identity, 'fog_large_object').body == expected end tests('#delete_static_large_object') do expected = { 'Number Not Found' => 0, 'Response Status' => '200 OK', 'Errors' => [], 'Number Deleted' => 3, 'Response Body' => '' } returns(expected, 'deletes manifest and segments') do Fog::Storage[:openstack].delete_static_large_object(@directory.identity, 'fog_large_object').body end end end tests('multiple containers') do tests('#put_static_obj_manifest').succeeds do segments = [ { :path => "#{ @segments[:b][:container] }/#{ @segments[:b][:name] }", :etag => @segments[:b][:etag], :size_bytes => @segments[:b][:size] }, { :path => "#{ @segments[:d][:container] }/#{ @segments[:d][:name] }", :etag => @segments[:d][:etag], :size_bytes => @segments[:d][:size] } ] Fog::Storage[:openstack].put_static_obj_manifest(@directory2.identity, 'fog_large_object', segments) end tests('#head_object') do etags = [@segments[:b][:etag], @segments[:d][:etag]] etag = "\"#{ Digest::MD5.hexdigest(etags.join) }\"" # "\"9801a4cc4472896a1e975d03f0d2c3f8\"" content_length = (@segments[:b][:size] + @segments[:d][:size]).to_s response = Fog::Storage[:openstack].head_object(@directory2.identity, 'fog_large_object') returns(etag, 'returns ETag computed from segments') { response.headers['Etag'] } returns(content_length , 'returns Content-Length for all segments') { response.headers['Content-Length'] } returns('True', 'returns X-Static-Large-Object header') { response.headers['X-Static-Large-Object'] } end tests('#get_object').succeeds do expected = @segments[:b][:data] + @segments[:d][:data] Fog::Storage[:openstack].get_object(@directory2.identity, 'fog_large_object').body == expected end tests('#delete_static_large_object') do expected = { 'Number Not Found' => 0, 'Response Status' => '200 OK', 'Errors' => [], 'Number Deleted' => 3, 'Response Body' => '' } returns(expected, 'deletes manifest and segments') do Fog::Storage[:openstack].delete_static_large_object(@directory2.identity, 'fog_large_object').body end end end end end tests('failure') do tests('dynamic large object requests') do pending if Fog.mocking? tests('#put_dynamic_obj_manifest with missing container').raises(Fog::Storage::OpenStack::NotFound) do Fog::Storage[:openstack].put_dynamic_obj_manifest('fognoncontainer', 'fog_large_object') end end tests('static large object requests') do pending if Fog.mocking? tests('upload test segments').succeeds do Fog::Storage[:openstack].put_object(@segments[:a][:container], @segments[:a][:name], @segments[:a][:data]) Fog::Storage[:openstack].put_object(@segments[:b][:container], @segments[:b][:name], @segments[:b][:data]) end tests('#put_static_obj_manifest with missing container').raises(Fog::Storage::OpenStack::NotFound) do Fog::Storage[:openstack].put_static_obj_manifest('fognoncontainer', 'fog_large_object', []) end tests('#put_static_obj_manifest with missing object') do segments = [ { :path => "#{ @segments[:c][:container] }/#{ @segments[:c][:name] }", :etag => @segments[:c][:etag], :size_bytes => @segments[:c][:size] } ] expected = { 'Errors' => [[segments[0][:path], '404 Not Found']] } error = nil begin Fog::Storage[:openstack].put_static_obj_manifest(@directory.identity, 'fog_large_object', segments) rescue => err error = err end raises(Excon::Errors::BadRequest) do raise error if error end returns(expected, 'returns error information') do Fog::JSON.decode(error.response.body) end end tests('#put_static_obj_manifest with invalid etag') do segments = [ { :path => "#{ @segments[:a][:container] }/#{ @segments[:a][:name] }", :etag => @segments[:b][:etag], :size_bytes => @segments[:a][:size] } ] expected = { 'Errors' => [[segments[0][:path], 'Etag Mismatch']] } error = nil begin Fog::Storage[:openstack].put_static_obj_manifest(@directory.identity, 'fog_large_object', segments) rescue => err error = err end raises(Excon::Errors::BadRequest) do raise error if error end returns(expected, 'returns error information') do Fog::JSON.decode(error.response.body) end end tests('#put_static_obj_manifest with invalid byte_size') do segments = [ { :path => "#{ @segments[:a][:container] }/#{ @segments[:a][:name] }", :etag => @segments[:a][:etag], :size_bytes => @segments[:b][:size] } ] expected = { 'Errors' => [[segments[0][:path], 'Size Mismatch']] } error = nil begin Fog::Storage[:openstack].put_static_obj_manifest(@directory.identity, 'fog_large_object', segments) rescue => err error = err end raises(Excon::Errors::BadRequest) do raise error if error end returns(expected, 'returns error information') do Fog::JSON.decode(error.response.body) end end tests('#delete_static_large_object with missing container') do expected = { 'Number Not Found' => 1, 'Response Status' => '200 OK', 'Errors' => [], 'Number Deleted' => 0, 'Response Body' => '' } returns(expected, 'reports missing object') do Fog::Storage[:openstack].delete_static_large_object('fognoncontainer', 'fog_large_object').body end end tests('#delete_static_large_object with missing manifest') do expected = { 'Number Not Found' => 1, 'Response Status' => '200 OK', 'Errors' => [], 'Number Deleted' => 0, 'Response Body' => '' } returns(expected, 'reports missing manifest') do Fog::Storage[:openstack].delete_static_large_object(@directory.identity, 'fog_non_object').body end end tests('#delete_static_large_object with missing segment') do tests('#put_static_obj_manifest for segments :a and :b').succeeds do segments = [ { :path => "#{ @segments[:a][:container] }/#{ @segments[:a][:name] }", :etag => @segments[:a][:etag], :size_bytes => @segments[:a][:size] }, { :path => "#{ @segments[:b][:container] }/#{ @segments[:b][:name] }", :etag => @segments[:b][:etag], :size_bytes => @segments[:b][:size] } ] Fog::Storage[:openstack].put_static_obj_manifest(@directory.identity, 'fog_large_object', segments) end tests('#delete_object segment :b').succeeds do Fog::Storage[:openstack].delete_object(@segments[:b][:container], @segments[:b][:name]) end tests('#delete_static_large_object') do expected = { 'Number Not Found' => 1, 'Response Status' => '200 OK', 'Errors' => [], 'Number Deleted' => 2, 'Response Body' => '' } returns(expected, 'deletes manifest and segment :a, and reports missing segment :b') do Fog::Storage[:openstack].delete_static_large_object(@directory.identity, 'fog_large_object').body end end end end end unless Fog.mocking? @directory.destroy @directory2.destroy end end fog-openstack-0.1.6/tests/openstack/requests/storage/object_tests.rb0000644000175600017570000001653512730051546025021 0ustar pravipraviShindo.tests('Fog::Storage[:openstack] | object requests', ["openstack"]) do unless Fog.mocking? @directory = Fog::Storage[:openstack].directories.create(:key => 'fogobjecttests') end module OpenStackStorageHelpers def override_path(path) @path = path end end tests('success') do tests("#put_object('fogobjecttests', 'fog_object')").succeeds do pending if Fog.mocking? Fog::Storage[:openstack].put_object('fogobjecttests', 'fog_object', lorem_file) end tests("#get_object('fogobjectests', 'fog_object')").succeeds do pending if Fog.mocking? Fog::Storage[:openstack].get_object('fogobjecttests', 'fog_object').body == lorem_file.read end tests("#get_object('fogobjecttests', 'fog_object', &block)").succeeds do pending if Fog.mocking? data = '' Fog::Storage[:openstack].get_object('fogobjecttests', 'fog_object') do |chunk, remaining_bytes, total_bytes| data << chunk end data == lorem_file.read end tests("#public_url('fogobjectests', 'fog_object')").succeeds do pending if Fog.mocking? Fog::Storage[:openstack].directories.first.files.first.public_url end tests("#public_url('fogobjectests')").succeeds do pending if Fog.mocking? Fog::Storage[:openstack].directories.first.public_url end tests("#head_object('fogobjectests', 'fog_object')").succeeds do pending if Fog.mocking? Fog::Storage[:openstack].head_object('fogobjecttests', 'fog_object') end tests("#delete_object('fogobjecttests', 'fog_object')").succeeds do pending if Fog.mocking? Fog::Storage[:openstack].delete_object('fogobjecttests', 'fog_object') end def test_temp_url(url_s, time, desired_scheme) object_url = URI.parse(url_s) query_params = URI.decode_www_form(object_url.query) tests("the link is #{desired_scheme}").returns(desired_scheme) { object_url.scheme } tests('the container and object are present in the path').returns(true) do (object_url.path =~ /\/#{@directory.identity}\/fog_object/) != nil end tests('a temp_url_sig is present').returns(true) do query_params.any? { |p| p[0] == 'temp_url_sig' } end tests('temp_url_expires matches the expiration').returns(true) do query_params.any? { |p| p == ['temp_url_expires', time.to_i.to_s] } end end tests("#get_object_http_url('directory.identity', 'fog_object', expiration timestamp)").succeeds do pending if Fog.mocking? ts = Time.at(1395343213) url_s = Fog::Storage[:openstack].get_object_http_url(@directory.identity, 'fog_object', ts) test_temp_url(url_s, ts, 'http') end tests("#get_object_https_url('directory.identity', 'fog_object', expiration timestamp)").succeeds do pending if Fog.mocking? ts = Time.at(1395343215) url_s = Fog::Storage[:openstack].get_object_https_url(@directory.identity, 'fog_object', ts) test_temp_url(url_s, ts, 'https') end tests("put_object with block") do pending if Fog.mocking? tests("#put_object('fogobjecttests', 'fog_object', &block)").succeeds do begin file = lorem_file buffer_size = file.stat.size / 2 # chop it up into two buffers Fog::Storage[:openstack].put_object('fogobjecttests', 'fog_block_object', nil) do file.read(buffer_size).to_s end ensure file.close end end tests('#get_object').succeeds do Fog::Storage[:openstack].get_object('fogobjecttests', 'fog_block_object').body == lorem_file.read end tests('#delete_object').succeeds do Fog::Storage[:openstack].delete_object('fogobjecttests', 'fog_block_object') end end tests('#delete_multiple_objects') do pending if Fog.mocking? Fog::Storage[:openstack].put_object('fogobjecttests', 'fog_object', lorem_file) Fog::Storage[:openstack].put_object('fogobjecttests', 'fog_object2', lorem_file) Fog::Storage[:openstack].directories.create(:key => 'fogobjecttests2') Fog::Storage[:openstack].put_object('fogobjecttests2', 'fog_object', lorem_file) expected = { "Number Not Found" => 0, "Response Status" => "200 OK", "Errors" => [], "Number Deleted" => 2, "Response Body" => "" } returns(expected, 'deletes multiple objects') do Fog::Storage[:openstack].delete_multiple_objects('fogobjecttests', ['fog_object', 'fog_object2']).body end returns(expected, 'deletes object and container') do Fog::Storage[:openstack].delete_multiple_objects(nil, ['fogobjecttests2/fog_object', 'fogobjecttests2']).body end end end tests('failure') do tests("#get_object('fogobjecttests', 'fog_non_object')").raises(Fog::Storage::OpenStack::NotFound) do pending if Fog.mocking? Fog::Storage[:openstack].get_object('fogobjecttests', 'fog_non_object') end tests("#get_object('fognoncontainer', 'fog_non_object')").raises(Fog::Storage::OpenStack::NotFound) do pending if Fog.mocking? Fog::Storage[:openstack].get_object('fognoncontainer', 'fog_non_object') end tests("#head_object('fogobjecttests', 'fog_non_object')").raises(Fog::Storage::OpenStack::NotFound) do pending if Fog.mocking? Fog::Storage[:openstack].head_object('fogobjecttests', 'fog_non_object') end tests("#head_object('fognoncontainer', 'fog_non_object')").raises(Fog::Storage::OpenStack::NotFound) do pending if Fog.mocking? Fog::Storage[:openstack].head_object('fognoncontainer', 'fog_non_object') end tests("#delete_object('fogobjecttests', 'fog_non_object')").raises(Fog::Storage::OpenStack::NotFound) do pending if Fog.mocking? Fog::Storage[:openstack].delete_object('fogobjecttests', 'fog_non_object') end tests("#delete_object('fognoncontainer', 'fog_non_object')").raises(Fog::Storage::OpenStack::NotFound) do pending if Fog.mocking? Fog::Storage[:openstack].delete_object('fognoncontainer', 'fog_non_object') end tests('#delete_multiple_objects') do pending if Fog.mocking? expected = { "Number Not Found" => 2, "Response Status" => "200 OK", "Errors" => [], "Number Deleted" => 0, "Response Body" => "" } returns(expected, 'reports missing objects') do Fog::Storage[:openstack].delete_multiple_objects('fogobjecttests', ['fog_non_object', 'fog_non_object2']).body end returns(expected, 'reports missing container') do Fog::Storage[:openstack].delete_multiple_objects('fognoncontainer', ['fog_non_object', 'fog_non_object2']).body end tests('deleting non-empty container') do Fog::Storage[:openstack].put_object('fogobjecttests', 'fog_object', lorem_file) expected = { "Number Not Found" => 0, "Response Status" => "400 Bad Request", "Errors" => [['fogobjecttests', '409 Conflict']], "Number Deleted" => 1, "Response Body" => "" } returns(expected, 'deletes object but not container') do Fog::Storage[:openstack].delete_multiple_objects(nil, ['fogobjecttests', 'fogobjecttests/fog_object']).body end end end end unless Fog.mocking? @directory.destroy end end fog-openstack-0.1.6/tests/openstack/requests/image/0000755000175600017570000000000012730051546021410 5ustar pravipravifog-openstack-0.1.6/tests/openstack/requests/image/image_tests.rb0000644000175600017570000001046612730051546024250 0ustar pravipraviShindo.tests('Fog::Image[:openstack] | image requests', ['openstack']) do openstack = Fog::Identity[:openstack] @image_attributes = { :name => 'new image', :owner => openstack.current_tenant['id'], :is_public => true, :copy_from => 'http://website.com/image.iso', :disk_format => 'iso', :properties => {:user_id => openstack.current_user['id'], :owner_id => openstack.current_tenant['id']}, :container_format => 'bare' } @image_format = { 'name' => String, 'container_format' => String, 'disk_format' => String, 'checksum' => String, 'id' => String, 'size' => Integer } @detailed_image_format = { 'id' => String, 'name' => String, 'size' => Integer, 'disk_format' => String, 'container_format' => String, 'checksum' => String, 'min_disk' => Integer, 'created_at' => String, 'deleted_at' => Fog::Nullable::String, 'updated_at' => String, 'deleted' => Fog::Boolean, 'protected' => Fog::Boolean, 'is_public' => Fog::Boolean, 'status' => String, 'min_ram' => Integer, 'owner' => Fog::Nullable::String, 'properties' => Hash } @image_meta_format ={ 'X-Image-Meta-Is_public'=>String, 'X-Image-Meta-Min_disk'=>Fog::Nullable::String, 'X-Image-Meta-Property-Ramdisk_id'=>Fog::Nullable::String, 'X-Image-Meta-Disk_format'=>Fog::Nullable::String, 'X-Image-Meta-Created_at'=>String, 'X-Image-Meta-Container_format'=>Fog::Nullable::String, 'Etag'=>String, 'Location'=>String, 'X-Image-Meta-Protected'=>String, 'Date'=>String, 'X-Image-Meta-Name'=>String, 'X-Image-Meta-Min_ram'=>String, 'Content-Type'=>String, 'X-Image-Meta-Updated_at'=>String, 'X-Image-Meta-Property-Kernel_id'=>Fog::Nullable::String, 'X-Image-Meta-Size'=>String, 'X-Image-Meta-Checksum'=>Fog::Nullable::String, 'X-Image-Meta-Deleted'=>String, 'Content-Length'=>String, 'X-Image-Meta-Status'=>String, 'X-Image-Meta-Owner'=>String, 'X-Image-Meta-Id'=>String } @image_members_format =[ {'can_share'=>Fog::Nullable::Boolean, 'member_id'=>String } ] tests('success') do tests('#list_public_images').data_matches_schema({'images' => [@image_format]}) do Fog::Image[:openstack].list_public_images.body end tests('#list_public_images_detailed').data_matches_schema({'images' => [@detailed_image_format]}) do Fog::Image[:openstack].list_public_images_detailed.body end tests('#create_image').data_matches_schema({'image' => @detailed_image_format}) do begin if Fog.mocking? image_attributes = @image_attributes else require 'tempfile' image_attributes = @image_attributes.dup image_attributes.delete(:copy_from) test_iso = Tempfile.new(['fog_test_iso', '.iso']) test_iso.write Fog::Mock.random_hex(32) test_iso.close image_attributes[:location] = test_iso.path end @instance = Fog::Image[:openstack].create_image(image_attributes).body ensure test_iso.delete if test_iso end end tests('#get_image').data_matches_schema(@image_meta_format) do Fog::Image[:openstack].get_image(@instance['image']['id']).headers end tests('#update_image').data_matches_schema(@detailed_image_format) do Fog::Image[:openstack].update_image({:id => @instance['image']['id'], :name => 'edit image'}).body['image'] end tests('#add_member_to_image').succeeds do Fog::Image[:openstack].add_member_to_image( @instance['image']['id'], @instance['image']['owner']) end tests('#get_image_members').succeeds do Fog::Image[:openstack].get_image_members(@instance['image']['id']) end tests('#get_shared_images').succeeds do Fog::Image[:openstack].get_shared_images(@instance['image']['owner']) end tests('#remove_member_from_image').succeeds do Fog::Image[:openstack].remove_member_from_image( @instance['image']['id'], @instance['image']['owner']) end tests('#delete_image').succeeds do Fog::Image[:openstack].delete_image(@instance['image']['id']) end end end fog-openstack-0.1.6/tests/openstack/models/0000755000175600017570000000000012730051546017736 5ustar pravipravifog-openstack-0.1.6/tests/openstack/models/compute/0000755000175600017570000000000012730051546021412 5ustar pravipravifog-openstack-0.1.6/tests/openstack/models/compute/images_tests.rb0000644000175600017570000000040212730051546024422 0ustar pravipraviShindo.tests("Fog::Compute[:openstack] | images collection", ['openstack']) do tests('success') do tests('#all').succeeds do fog = Fog::Compute[:openstack] test 'not nil' do fog.images.all.is_a? Array end end end end fog-openstack-0.1.6/tests/openstack/models/compute/service_tests.rb0000644000175600017570000000075312730051546024626 0ustar pravipraviShindo.tests("Fog::Compute[:openstack] | services", ['openstack']) do tests('success') do tests('#all').succeeds do services = Fog::Compute[:openstack].services.all @service = services.first end tests('#get').succeeds do service = Fog::Compute[:openstack].services.get(@service.id) %w(id binary host).all? do |attr| attr1 = service.send(attr.to_sym) attr2 = @service.send(attr.to_sym) attr1 == attr2 end end end end fog-openstack-0.1.6/tests/openstack/models/compute/server_tests.rb0000644000175600017570000001451512730051546024475 0ustar pravipraviShindo.tests("Fog::Compute[:openstack] | server", ['openstack']) do tests('success') do tests('#floating_ips').succeeds do fog = Fog::Compute[:openstack] net = Fog::Network[:openstack] flavor = fog.flavors.first.id image = fog.images.first.id server = fog.servers.new(:name => 'test server', :flavor_ref => flavor, :image_ref => image) server.save ip1 = net.floating_ips.create(:floating_network_id => 'f0000000-0000-0000-0000\ -000000000000', :fixed_ip_address => '192.168.11.3') server.associate_address(ip1.fixed_ip_address) server.reload returns( ["192.168.11.3"] ) { server.floating_ip_addresses } end tests('#security_groups').succeeds do fog = Fog::Compute[:openstack] begin my_group = fog.security_groups.create(:name => 'my_group', :description => 'my group') flavor = fog.flavors.first.id image = fog.images.first.id server = fog.servers.new(:name => 'test server', :flavor_ref => flavor, :image_ref => image) server.security_groups = my_group server.save found_groups = server.security_groups returns(1) { found_groups.length } group = found_groups.first returns('my_group') { group.name } returns(server.service) { group.service } ensure unless Fog.mocking? then server.destroy if server begin fog.servers.get(server.id).wait_for do false end rescue Fog::Errors::Error # ignore, server went away end end my_group.destroy if my_group end end tests('#failed') do fog = Fog::Compute[:openstack] flavor = fog.flavors.first.id image = fog.images.first.id tests('successful server').returns(false) do server = fog.servers.new( :name => 'test server', :flavor_ref => flavor, :image_ref => image, :state => 'success' ) server.failed? end tests('failed server').returns(true) do server = fog.servers.new( :name => 'test server', :flavor_ref => flavor, :image_ref => image, :state => 'ERROR' ) server.failed? end end tests('#metadata').succeeds do fog = Fog::Compute[:openstack] begin flavor = fog.flavors.first.id image = fog.images.first.id server = fog.servers.new(:name => 'test server', :metadata => {"foo" => "bar"}, :flavor_ref => flavor, :image_ref => image) server.save returns(1) { server.metadata.length } server.metadata.each do |datum| datum.value = 'foo' datum.save datum.destroy end ensure unless Fog.mocking? then server.destroy if server begin fog.servers.get(server.id).wait_for do false end rescue Fog::Errors::Error # ignore, server went away end end end end tests('#resize').succeeds do fog = Fog::Compute[:openstack] begin flavor = fog.flavors.first.id image = fog.images.first.id server = fog.servers.new(:name => 'test server', :flavor_ref => flavor, :image_ref => image) server.save flavor_resize = fog.flavors[1].id server.resize(flavor_resize) server.wait_for { server.state == "VERIFY_RESIZE" } unless Fog.mocking? server.revert_resize server.wait_for { server.state == "ACTIVE" } unless Fog.mocking? server.resize(flavor_resize) server.wait_for { server.state == "VERIFY_RESIZE" } unless Fog.mocking? server.confirm_resize ensure unless Fog.mocking? then server.destroy if server begin fog.servers.get(server.id).wait_for do false end rescue Fog::Errors::Error # ignore, server went away end end end end tests('#volumes').succeeds do fog = Fog::Compute[:openstack] begin volume = fog.volumes.new(:name => 'test volume', :description => 'test volume', :size => 1) volume.save volume.wait_for { volume.status == 'available' } unless Fog.mocking? flavor = fog.flavors.first.id image = fog.images.first.id server = fog.servers.new(:name => 'test server', :flavor_ref => flavor, :image_ref => image) server.save server.wait_for { server.state == "ACTIVE" } unless Fog.mocking? server.attach_volume(volume.id, '/dev/vdc') volume.wait_for { volume.status == 'in-use' } unless Fog.mocking? found_volumes = server.volumes returns(1) { found_volumes.length } volume = found_volumes.first returns('test volume') { volume.name } found_attachments = server.volume_attachments returns(1) { found_attachments.length } attachment = found_attachments.first returns('/dev/vdc') { attachment['device'] } server.detach_volume(volume.id) volume.wait_for { volume.status == 'available' } unless Fog.mocking? found_volumes = server.volumes returns(0) { found_volumes.length } found_attachments = server.volume_attachments returns(0) { found_attachments.length } ensure unless Fog.mocking? then server.destroy if server volume.destroy if volume begin fog.servers.get(server.id).wait_for do false end fog.volumes.get(volume.id).wait_for do false end rescue Fog::Errors::Error # ignore, server went away end end end end end end fog-openstack-0.1.6/tests/openstack/models/compute/security_group_tests.rb0000644000175600017570000000401612730051546026245 0ustar pravipraviShindo.tests("Fog::Compute[:openstack] | security_group", ['openstack']) do tests('success') do begin fog = Fog::Compute[:openstack] security_group = fog.security_groups.create( :name => 'my_group', :description => 'my group' ) tests('#create').succeeds do security_group = fog.security_groups.create( :name => 'my_group', :description => 'my group' ) returns('my_group') { security_group.name } returns('my group') { security_group.description } returns([]) { security_group.security_group_rules } returns(true, "Tenant Id is not nil") { security_group.tenant_id != nil } end tests('#rules').succeeds do tests("#create").succeeds do rules_count = security_group.security_group_rules.count rule = security_group.security_group_rules.create( :parent_group_id => security_group.id, :ip_protocol => 'tcp', :from_port => 1234, :to_port => 1234, :ip_range => { "cidr" => "0.0.0.0/0" } ) returns(true, "added security group rule") { security_group.security_group_rules.count == (rules_count + 1) } security_group_rule = security_group.security_group_rules.find { |r| r.id == rule.id } returns(true, "security group rule has rule attributes") { security_group_rule.attributes == rule.attributes } end tests("#destroy").succeeds do rule = security_group.security_group_rules.create( :parent_group_id => security_group.id, :ip_protocol => 'tcp', :from_port => 1234, :to_port => 1234, :ip_range => { "cidr" => "0.0.0.0/0" } ) rule.destroy returns(true, "successfully destroyed rule") { rule.reload == nil } end end ensure security_group.destroy if security_group end end end fog-openstack-0.1.6/tests/openstack/models/identity/0000755000175600017570000000000012730051546021567 5ustar pravipravifog-openstack-0.1.6/tests/openstack/models/identity/roles_tests.rb0000644000175600017570000000131012730051546024455 0ustar pravipraviShindo.tests("Fog::Identity[:openstack] | roles", ['openstack']) do @identity = Fog::Identity::OpenStack.new(:openstack_auth_url => 'http://openstack:35357/v2.0/tokens') @tenant = @identity.tenants.create(:name => 'test_user') @user = @identity.users.create(:name => 'test_user', :tenant_id => @tenant.id, :password => 'spoof') @role = @identity.roles(:user => @user, :tenant => @tenant).create(:name => 'test_role') @roles = @identity.roles(:user => @user, :tenant => @tenant) tests('success') do tests('#all').succeeds do @roles.all end tests('#get').succeeds do @roles.get @roles.first.id end end @role.destroy @user.destroy @tenant.destroy end fog-openstack-0.1.6/tests/openstack/models/identity/users_tests.rb0000644000175600017570000000307412730051546024503 0ustar pravipraviShindo.tests("Fog::Identity[:openstack] | users", ['openstack']) do openstack = Fog::Identity::OpenStack.new(:openstack_auth_url => 'http://openstack:35357/v2.0/tokens') tenant_id = openstack.list_tenants.body['tenants'].first['id'] @instance = openstack.users.create( :name => 'foobar', :email => 'foo@bar.com', :tenant_id => tenant_id, :password => 'spoof', :enabled => true ) tests('success') do tests('#find_by_id').succeeds do openstack = Fog::Identity::OpenStack.new(:openstack_auth_url => 'http://openstack:35357/v2.0/tokens') user = openstack.users.find_by_id(@instance.id) user.id == @instance.id end tests('#find_by_name').succeeds do openstack = Fog::Identity::OpenStack.new(:openstack_auth_url => 'http://openstack:35357/v2.0/tokens') user = openstack.users.find_by_name(@instance.name) user.name == @instance.name end tests('#destroy').succeeds do openstack = Fog::Identity::OpenStack.new(:openstack_auth_url => 'http://openstack:35357/v2.0/tokens') openstack.users.destroy(@instance.id) end end tests('fails') do pending if Fog.mocking? tests('#find_by_id').raises(Fog::Identity::OpenStack::NotFound) do Fog::Identity[:openstack].users.find_by_id('fake') end tests('#find_by_name').raises(Fog::Identity::OpenStack::NotFound) do Fog::Identity[:openstack].users.find_by_name('fake') end tests('#destroy').raises(Fog::Identity::OpenStack::NotFound) do Fog::Identity[:openstack].users.destroy('fake') end end end fog-openstack-0.1.6/tests/openstack/models/identity/ec2_credential_tests.rb0000644000175600017570000000175612730051546026212 0ustar pravipraviShindo.tests("Fog::Identity[:openstack] | ec2_credential", ['openstack']) do before do openstack = Fog::Identity::OpenStack.new(:openstack_auth_url => 'http://openstack:35357/v2.0/tokens') tenant_id = openstack.list_tenants.body['tenants'].first['id'] @user = openstack.users.find { |user| user.name == 'foobar' } @user ||= openstack.users.create({ :name => 'foobar', :email => 'foo@bar.com', :tenant_id => tenant_id, :password => 'spoof', :enabled => true }) @ec2_credential = openstack.ec2_credentials.create({ :user_id => @user.id, :tenant_id => tenant_id, }) end after do @user.ec2_credentials.each do |ec2_credential| ec2_credential.destroy end @user.destroy end tests('success') do tests('#destroy').returns(true) do @ec2_credential.destroy end end tests('failure') do tests('#save').raises(Fog::Errors::Error) do @ec2_credential.save end end end fog-openstack-0.1.6/tests/openstack/models/identity/user_tests.rb0000644000175600017570000000222112730051546024311 0ustar pravipraviShindo.tests("Fog::Identity[:openstack] | user", ['openstack']) do openstack = Fog::Identity::OpenStack.new(:openstack_auth_url => 'http://openstack:35357/v2.0/tokens') tenant_id = openstack.list_tenants.body['tenants'].first['id'] @instance = openstack.users.new( :name => 'User Name', :email => 'test@fog.com', :tenant_id => tenant_id, :password => 'spoof', :enabled => true ) tests('success') do tests('#save').returns(true) do @instance.save end tests('#roles').succeeds do @instance.roles end tests('#update').returns(true) do @instance.update({:name => 'updatename', :email => 'new@email.com'}) end tests('#update_password').returns(true) do @instance.update_password('swordfish') end tests('#update_tenant').returns(true) do @instance.update_tenant(tenant_id) end tests('#update_enabled').returns(true) do @instance.update_enabled(true) end tests('#destroy').returns(true) do @instance.destroy end end tests('failure') do tests('#save').raises(Fog::Errors::Error) do @instance.save end end end fog-openstack-0.1.6/tests/openstack/models/identity/tenants_tests.rb0000644000175600017570000000227512730051546025020 0ustar pravipraviShindo.tests("Fog::Compute[:openstack] | tenants", ['openstack']) do openstack = Fog::Identity::OpenStack.new(:openstack_auth_url => 'http://openstack:35357/v2.0/tokens') @instance = openstack.tenants.create(:name => 'test') tests('success') do tests('#find_by_id').succeeds do openstack = Fog::Identity::OpenStack.new(:openstack_auth_url => 'http://openstack:35357/v2.0/tokens') tenant = openstack.tenants.find_by_id(@instance.id) tenant.id == @instance.id end tests('#destroy').succeeds do openstack = Fog::Identity::OpenStack.new(:openstack_auth_url => 'http://openstack:35357/v2.0/tokens') openstack.tenants.destroy(@instance.id) end end tests('fails') do pending if Fog.mocking? tests('#find_by_id').raises(Fog::Identity::OpenStack::NotFound) do openstack = Fog::Identity::OpenStack.new(:openstack_auth_url => 'http://openstack:35357/v2.0/tokens') openstack.tenants.find_by_id('fake') end tests('#destroy').raises(Fog::Identity::OpenStack::NotFound) do openstack = Fog::Identity::OpenStack.new(:openstack_auth_url => 'http://openstack:35357/v2.0/tokens') openstack.tenants.destroy('fake') end end end fog-openstack-0.1.6/tests/openstack/models/identity/tenant_tests.rb0000644000175600017570000000162112730051546024627 0ustar pravipraviShindo.tests("Fog::Identity[:openstack] | tenant", ['openstack']) do tests('success') do @openstack = Fog::Identity::OpenStack.new(:openstack_auth_url => 'http://openstack:35357/v2.0/tokens') tests('#roles_for(0)').succeeds do instance = @openstack.tenants.first instance.roles_for(0) end tests('#users').succeeds do instance = @openstack.tenants.first openstack = Fog::Identity::OpenStack.new(:openstack_auth_url => 'http://openstack:35357/v2.0/tokens') instance.users.count != openstack.users.count end end tests('CRUD') do tests('#create').succeeds do @instance = @openstack.tenants.create(:name => 'test') !@instance.id.nil? end tests('#update').succeeds do @instance.update(:name => 'test2') @instance.name == 'test2' end tests('#destroy').succeeds do @instance.destroy == true end end end fog-openstack-0.1.6/tests/openstack/models/identity/role_tests.rb0000644000175600017570000000160712730051546024303 0ustar pravipraviShindo.tests("Fog::Identity[:openstack] | role", ['openstack']) do @identity = Fog::Identity::OpenStack.new(:openstack_auth_url => 'http://openstack:35357/v2.0/tokens') @instance = @identity.roles.new( :name => 'Role Name', :user_id => 1, :role_id => 1 ) @tenant = @identity.tenants.create(:name => 'test_user') @user = @identity.users.create(:name => 'test_user', :tenant_id => @tenant.id, :password => 'spoof') tests('success') do tests('#save').returns(true) do @instance.save end tests('#add_to_user(@user.id, @tenant.id)').returns(true) do @instance.add_to_user(@user.id, @tenant.id) end tests('#remove_to_user(@user.id, @tenant.id)').returns(true) do @instance.remove_to_user(@user.id, @tenant.id) end tests('#destroy').returns(true) do @instance.destroy end end @user.destroy @tenant.destroy end fog-openstack-0.1.6/tests/openstack/models/identity/ec2_credentials_tests.rb0000644000175600017570000000276012730051546026371 0ustar pravipraviShindo.tests("Fog::Identity[:openstack] | ec2_credentials", ['openstack']) do before do openstack = Fog::Identity::OpenStack.new(:openstack_auth_url => 'http://openstack:35357/v2.0/tokens') tenant_id = openstack.list_tenants.body['tenants'].first['id'] @user = openstack.users.find { |user| user.name == 'foobar' } @user ||= openstack.users.create({ :name => 'foobar', :email => 'foo@bar.com', :tenant_id => tenant_id, :password => 'spoof', :enabled => true }) @ec2_credential = openstack.ec2_credentials.create({ :user_id => @user.id, :tenant_id => tenant_id, }) end after do @user.ec2_credentials.each do |ec2_credential| ec2_credential.destroy end @user.destroy end tests('success') do tests('#find_by_access_key').succeeds do ec2_credential = @user.ec2_credentials.find_by_access_key(@ec2_credential.access) ec2_credential.access == @ec2_credential.access end tests('#create').succeeds do @user.ec2_credentials.create end tests('#destroy').succeeds do @user.ec2_credentials.destroy(@ec2_credential.access) end end tests('fails') do pending if Fog.mocking? tests('#find_by_access_key').raises(Fog::Identity::OpenStack::NotFound) do @user.ec2_credentials.find_by_access_key('fake') end tests('#destroy').raises(Fog::Identity::OpenStack::NotFound) do @user.ec2_credentials.destroy('fake') end end end fog-openstack-0.1.6/tests/openstack/models/planning/0000755000175600017570000000000012730051546021544 5ustar pravipravifog-openstack-0.1.6/tests/openstack/models/planning/plans_tests.rb0000644000175600017570000000072512730051546024434 0ustar pravipraviShindo.tests("Fog::Openstack[:planning] | plans", ['openstack']) do tests('success') do tests('#all').succeeds do plans = Fog::Openstack[:planning].plans.all @instance = plans.first end tests('#get').succeeds do Fog::Openstack[:planning].plans.get(@instance.uuid) end tests('#find_by_*').succeeds do plan = Fog::Openstack[:planning].plans.find_by_name(@instance.name) plan.name == @instance.name end end end fog-openstack-0.1.6/tests/openstack/models/planning/.gitkeep0000644000175600017570000000000012730051546023163 0ustar pravipravifog-openstack-0.1.6/tests/openstack/models/planning/plan_tests.rb0000644000175600017570000000221212730051546024242 0ustar pravipraviShindo.tests("Fog::Openstack[:planning] | plan", ['openstack']) do @instance = Fog::Openstack[:planning].plans.first tests('success') do tests('#add_role').succeeds do @role = Fog::Openstack[:planning].list_roles.body.first @instance.add_role(@role['uuid']) end tests('#templates').succeeds do @instance.templates end tests('#master_template').succeeds do @instance.master_template end tests('#environment').succeeds do @instance.environment end tests('#provider_resource_templates').succeeds do @instance.provider_resource_templates end tests('#patch').succeeds do parameter = @instance.parameters.first @instance.patch(:parameters => [{"name" => parameter['name'], "value" => 'new_value'}]) end tests('#remove_role').succeeds do @instance.remove_role(@role['uuid']) end tests('#save').succeeds do @instance.save end tests('#update').succeeds do @instance.update end tests('#destroy').succeeds do @instance.destroy end tests('#create').succeeds do @instance.create end end end fog-openstack-0.1.6/tests/openstack/models/planning/role_tests.rb0000644000175600017570000000061312730051546024254 0ustar pravipraviShindo.tests("Fog::Openstack[:planning] | plan", ['openstack']) do @instance = Fog::Openstack[:planning].roles.first tests('success') do tests('#add_role').succeeds do @plan = Fog::Openstack[:planning].list_plans.body.first @instance.add_to_plan(@plan['uuid']) end tests('#remove_role').succeeds do @instance.remove_from_plan(@plan['uuid']) end end end fog-openstack-0.1.6/tests/openstack/models/nfv/0000755000175600017570000000000012730051546020527 5ustar pravipravifog-openstack-0.1.6/tests/openstack/models/nfv/vnfs_tests.rb0000644000175600017570000000364412730051546023261 0ustar pravipraviShindo.tests("Fog::NFV[:openstack] | vnfs", ['openstack']) do vnfd_data = {:attributes => {:vnfd => "template_name: sample-vnfd\ndescription: demo-example\n\nservice_prop"\ "erties:\n Id: sample-vnfd\n vendor: tacker\n version: 1\n\nvdus:\n"\ " vdu1:\n id: vdu1\n vm_image: cirros\n instance_type: m1.ti"\ "ny\n\n network_interfaces:\n management:\n network: ne"\ "t_mgmt\n management: true\n pkt_in:\n network: net"\ "0\n pkt_out:\n network: net1\n\n placement_policy:\n "\ " availability_zone: nova\n\n auto-scaling: noop\n\n config:"\ "\n param0: key0\n param1: key1\n"}, :service_types => [{:service_type => "vnfd"}], :mgmt_driver => "noop", :infra_driver => "heat"} auth = {"tenantName" => "admin", "passwordCredentials" => {"username" => "admin", "password" => "password"}} @vnfd = Fog::NFV[:openstack].vnfds.create(:vnfd => vnfd_data, :auth => auth) vnf_data = {:vnfd_id => @vnfd.id, :name => 'Test'} @vnf = Fog::NFV[:openstack].vnfs.create(:vnf => vnf_data, :auth => auth) Fog::NFV[:openstack].vnfs.get(@vnf.id).wait_for { ready? } tests('success') do tests('#find_by_id').succeeds do vnf = Fog::NFV[:openstack].vnfs.find_by_id(@vnf.id) vnf.id == @vnf.id end tests('#get').succeeds do vnf = Fog::NFV[:openstack].vnfs.get(@vnf.id) vnf.id == @vnf.id end tests('#destroy').succeeds do sleep(10) unless Fog.mocking? Fog::NFV[:openstack].vnfs.destroy(@vnf.id) Fog::NFV[:openstack].vnfds.destroy(@vnfd.id) end end end fog-openstack-0.1.6/tests/openstack/models/nfv/vnfds_tests.rb0000644000175600017570000000322012730051546023413 0ustar pravipraviShindo.tests("Fog::NFV[:openstack] | vnfs", ['openstack']) do vnfd_data = {:attributes => {:vnfd => "template_name: sample-vnfd\ndescription: demo-example\n\nservice_prop"\ "erties:\n Id: sample-vnfd\n vendor: tacker\n version: 1\n\nvdus:\n"\ " vdu1:\n id: vdu1\n vm_image: cirros\n instance_type: m1.ti"\ "ny\n\n network_interfaces:\n management:\n network: ne"\ "t_mgmt\n management: true\n pkt_in:\n network: net"\ "0\n pkt_out:\n network: net1\n\n placement_policy:\n "\ " availability_zone: nova\n\n auto-scaling: noop\n\n config:"\ "\n param0: key0\n param1: key1\n"}, :service_types => [{:service_type => "vnfd"}], :mgmt_driver => "noop", :infra_driver => "heat"} auth = {"tenantName" => "admin", "passwordCredentials" => {"username" => "admin", "password" => "password"}} @vnfd = Fog::NFV[:openstack].vnfds.create(:vnfd => vnfd_data, :auth => auth) tests('success') do tests('#find_by_id').succeeds do vnf = Fog::NFV[:openstack].vnfds.find_by_id(@vnfd.id) vnf.id == @vnfd.id end tests('#get').succeeds do vnf = Fog::NFV[:openstack].vnfds.get(@vnfd.id) vnf.id == @vnfd.id end tests('#destroy').succeeds do Fog::NFV[:openstack].vnfds.destroy(@vnfd.id) end end end fog-openstack-0.1.6/tests/openstack/models/nfv/vnf_tests.rb0000644000175600017570000000355712730051546023101 0ustar pravipraviShindo.tests("Fog::NFV[:openstack] | vnf", ['openstack']) do tests('success') do tests('#create').succeeds do vnfd_data = {:attributes => {:vnfd => "template_name: sample-vnfd\ndescription: demo-example\n\nservice_prop"\ "erties:\n Id: sample-vnfd\n vendor: tacker\n version: 1\n\nvdus:\n"\ " vdu1:\n id: vdu1\n vm_image: cirros\n instance_type: m1.ti"\ "ny\n\n network_interfaces:\n management:\n network: ne"\ "t_mgmt\n management: true\n pkt_in:\n network: net"\ "0\n pkt_out:\n network: net1\n\n placement_policy:\n "\ " availability_zone: nova\n\n auto-scaling: noop\n\n config:"\ "\n param0: key0\n param1: key1\n"}, :service_types => [{:service_type => "vnfd"}], :mgmt_driver => "noop", :infra_driver => "heat"} auth = {"tenantName" => "admin", "passwordCredentials" => {"username" => "admin", "password" => "password"}} @vnfd = Fog::NFV[:openstack].vnfds.create(:vnfd => vnfd_data, :auth => auth) vnf_data = {:vnfd_id => @vnfd.id, :name => 'Test'} @vnf = Fog::NFV[:openstack].vnfs.create(:vnf => vnf_data, :auth => auth) end Fog::NFV[:openstack].vnfs.get(@vnf.id).wait_for { ready? } tests('#update').succeeds do @vnf.vnf = {:attributes => {:config => "vdus:\n vdu1: \n\n"}} @vnf.update end tests('#destroy').succeeds do sleep(10) unless Fog.mocking? @vnf.destroy @vnfd.destroy end end end fog-openstack-0.1.6/tests/openstack/models/nfv/vnfd_tests.rb0000644000175600017570000000273112730051546023236 0ustar pravipraviShindo.tests("Fog::NFV[:openstack] | vnf", ['openstack']) do tests('success') do tests('#create').succeeds do vnfd_data = {:attributes => {:vnfd => "template_name: sample-vnfd\ndescription: demo-example\n\nservice_prop"\ "erties:\n Id: sample-vnfd\n vendor: tacker\n version: 1\n\nvdus:\n"\ " vdu1:\n id: vdu1\n vm_image: cirros\n instance_type: m1.ti"\ "ny\n\n network_interfaces:\n management:\n network: ne"\ "t_mgmt\n management: true\n pkt_in:\n network: net"\ "0\n pkt_out:\n network: net1\n\n placement_policy:\n "\ " availability_zone: nova\n\n auto-scaling: noop\n\n config:"\ "\n param0: key0\n param1: key1\n"}, :service_types => [{:service_type => "vnfd"}], :mgmt_driver => "noop", :infra_driver => "heat"} auth = {"tenantName" => "admin", "passwordCredentials" => {"username" => "admin", "password" => "password"}} @vnfd = Fog::NFV[:openstack].vnfds.create(:vnfd => vnfd_data, :auth => auth) end tests('#destroy').succeeds do @vnfd.destroy == true end end end fog-openstack-0.1.6/tests/openstack/models/network/0000755000175600017570000000000012730051546021427 5ustar pravipravifog-openstack-0.1.6/tests/openstack/models/network/lb_member_tests.rb0000644000175600017570000000163512730051546025127 0ustar pravipraviShindo.tests("Fog::Network[:openstack] | lb_member", ['openstack']) do tests('success') do tests('#create').succeeds do @instance = Fog::Network[:openstack].lb_members.create(:pool_id => 'pool_id', :address => '10.0.0.1', :protocol_port => '80', :weight => 100, :admin_state_up => true, :tenant_id => 'tenant_id') !@instance.id.nil? end tests('#update').succeeds do @instance.pool_id = 'new_pool_id' @instance.weight = 50 @instance.admin_state_up = false @instance.update end tests('#destroy').succeeds do @instance.destroy == true end end end fog-openstack-0.1.6/tests/openstack/models/network/lb_pool_tests.rb0000644000175600017570000000354412730051546024632 0ustar pravipraviShindo.tests("Fog::Network[:openstack] | lb_pool", ['openstack']) do tests('success') do before do @lb_health_monitor = Fog::Network[:openstack].lb_health_monitors.create(:type => 'PING', :delay => 1, :timeout => 5, :max_retries => 10) end after do @lb_health_monitor.destroy end tests('#create').succeeds do @instance = Fog::Network[:openstack].lb_pools.create(:subnet_id => 'subnet_id', :protocol => 'HTTP', :lb_method => 'ROUND_ROBIN', :name => 'test-pool', :description => 'Test Pool', :admin_state_up => true, :tenant_id => 'tenant_id') !@instance.id.nil? end tests('#update').succeeds do @instance.name = 'new-test-pool' @instance.description = 'New Test Pool' @instance.lb_method = 'LEAST_CONNECTIONS' @instance.admin_state_up = false @instance.update end tests('#stats').succeeds do @instance.stats !@instance.active_connections.nil? end tests('#associate_health_monitor').succeeds do @instance.associate_health_monitor(@lb_health_monitor.id) end tests('#disassociate_health_monitor').succeeds do @instance.disassociate_health_monitor(@lb_health_monitor.id) end tests('#destroy').succeeds do @instance.destroy == true end end end fog-openstack-0.1.6/tests/openstack/models/network/lb_pools_tests.rb0000644000175600017570000000103512730051546025006 0ustar pravipraviShindo.tests("Fog::Network[:openstack] | lb_pools", ['openstack']) do @lb_pool = Fog::Network[:openstack].lb_pools.create(:subnet_id => 'subnet_id', :protocol => 'HTTP', :lb_method => 'ROUND_ROBIN') @lb_pools = Fog::Network[:openstack].lb_pools tests('success') do tests('#all').succeeds do @lb_pools.all end tests('#get').succeeds do @lb_pools.get @lb_pool.id end end @lb_pool.destroy end fog-openstack-0.1.6/tests/openstack/models/network/subnet_tests.rb0000644000175600017570000000221712730051546024500 0ustar pravipraviShindo.tests("Fog::Network[:openstack] | subnet", ['openstack']) do tests('success') do tests('#create').succeeds do @instance = Fog::Network[:openstack].subnets.create(:name => 'subnet_name', :network_id => 'net_id', :cidr => '10.2.2.0/24', :ip_version => 4, :gateway_ip => '10.2.2.1', :allocation_pools => [], :dns_nameservers => [], :host_routes => [], :enable_dhcp => true, :tenant_id => 'tenant_id') !@instance.id.nil? end tests('#update').succeeds do @instance.name = 'new_subnet_name' @instance.update end tests('#destroy').succeeds do @instance.destroy == true end end end fog-openstack-0.1.6/tests/openstack/models/network/ports_tests.rb0000644000175600017570000000155712730051546024355 0ustar pravipraviShindo.tests("Fog::Network[:openstack] | ports", ['openstack']) do @port = Fog::Network[:openstack].ports.create(:name => 'port_name', :network_id => 'net_id', :fixed_ips => [], :mac_address => 'fa:16:3e:62:91:7f', :admin_state_up => true, :device_owner => 'device_owner', :device_id => 'device_id', :tenant_id => 'tenant_id') @ports = Fog::Network[:openstack].ports tests('success') do tests('#all').succeeds do @ports.all end tests('#get').succeeds do @ports.get @port.id end end @port.destroy end fog-openstack-0.1.6/tests/openstack/models/network/floating_ips_tests.rb0000644000175600017570000000071112730051546025653 0ustar pravipraviShindo.tests("Fog::Network[:openstack] | floating_ips", ['openstack']) do @floating_ip = Fog::Network[:openstack].floating_ips.create(:floating_network_id => 'f0000000-0000-0000-0000-000000000000') @floating_ips = Fog::Network[:openstack].floating_ips tests('success') do tests('#all').succeeds do @floating_ips.all end tests('#get').succeeds do @floating_ips.get @floating_ip.id end end @floating_ip.destroy end fog-openstack-0.1.6/tests/openstack/models/network/security_groups_tests.rb0000644000175600017570000000117212730051546026445 0ustar pravipraviShindo.tests('Fog::Network[:openstack] | security_groups collection', ['openstack']) do attributes = {:name => "my_secgroup", :description => "my sec group desc"} collection_tests(Fog::Network[:openstack].security_groups, attributes, true) tests('success') do attributes = {:name => "fogsecgroup", :description => "fog sec group desc"} @secgroup = Fog::Network[:openstack].security_groups.create(attributes) tests('#all(filter)').succeeds do secgroup = Fog::Network[:openstack].security_groups.all({:name => "fogsecgroup"}) secgroup.first.name == "fogsecgroup" end @secgroup.destroy end end fog-openstack-0.1.6/tests/openstack/models/network/routers_tests.rb0000644000175600017570000000063012730051546024700 0ustar pravipraviShindo.tests("Fog::Network[:openstack] | routers", ['openstack']) do @router = Fog::Network[:openstack].routers.create( :name => 'router_name', :admin_state_up => true ) @routers = Fog::Network[:openstack].routers tests('success') do tests('#all').succeeds do @routers.all end tests('#get').succeeds do @routers.get @router.id end end @router.destroy end fog-openstack-0.1.6/tests/openstack/models/network/port_tests.rb0000644000175600017570000000176112730051546024167 0ustar pravipraviShindo.tests("Fog::Network[:openstack] | port", ['openstack']) do tests('success') do tests('#create').succeeds do @instance = Fog::Network[:openstack].ports.create(:name => 'port_name', :network_id => 'net_id', :fixed_ips => [], :mac_address => 'fa:16:3e:62:91:7f', :admin_state_up => true, :device_owner => 'device_owner', :device_id => 'device_id', :tenant_id => 'tenant_id') !@instance.id.nil? end tests('#update').succeeds do @instance.name = 'new_port_name' @instance.update end tests('#destroy').succeeds do @instance.destroy == true end end end fog-openstack-0.1.6/tests/openstack/models/network/lb_vips_tests.rb0000644000175600017570000000112412730051546024632 0ustar pravipraviShindo.tests("Fog::Network[:openstack] | lb_vips", ['openstack']) do @lb_vip = Fog::Network[:openstack].lb_vips.create(:subnet_id => 'subnet_id', :pool_id => 'pool_id', :protocol => 'HTTP', :protocol_port => 80) @lb_vips = Fog::Network[:openstack].lb_vips tests('success') do tests('#all').succeeds do @lb_vips.all end tests('#get').succeeds do @lb_vips.get @lb_vip.id end end @lb_vip.destroy end fog-openstack-0.1.6/tests/openstack/models/network/floating_ip_tests.rb0000644000175600017570000000177712730051546025505 0ustar pravipraviShindo.tests("Fog::Network[:openstack] | floating_ip", ['openstack']) do tests('success') do tests('#create').succeeds do @instance = Fog::Network[:openstack].floating_ips.create(:floating_network_id => 'f0000000-0000-0000-0000-000000000000') !@instance.id.nil? end tests('#update').succeeds do @instance.port_id = 'p0000000-0000-0000-0000-000000000000' @instance.update end tests('#destroy').succeeds do @instance.destroy == true end tests('#associate').succeeds do port_id = 'p0000000-0000-0000-0000-000000000000' fixed_ip_address = '8.8.8.8' @instance.associate(port_id, fixed_ip_address) returns(port_id) { @instance.port_id } returns(fixed_ip_address) { @instance.fixed_ip_address } end tests('#disassociate').succeeds do fixed_ip_address = '8.8.8.8' @instance.disassociate(fixed_ip_address) returns(nil) { @instance.port_id } returns(nil) { @instance.fixed_ip_address } end end end fog-openstack-0.1.6/tests/openstack/models/network/ike_policies_tests.rb0000644000175600017570000000266112730051546025642 0ustar pravipraviShindo.tests("Fog::Network[:openstack] | ike_policies", ['openstack']) do @ike_policy = Fog::Network[:openstack].ike_policies.create(:name => 'test-ike-policy', :description => 'Test VPN IKE Policy', :tenant_id => 'tenant_id', :auth_algorithm => 'sha1', :encryption_algorithm => 'aes-256', :pfs => 'group5', :phase1_negotiation_mode => 'main', :lifetime => { 'units' => 'seconds', 'value' => 3600 }, :ike_version => 'v1') @ike_policies = Fog::Network[:openstack].ike_policies tests('success') do tests('#all').succeeds do @ike_policies.all end tests('#get').succeeds do @ike_policies.get(@ike_policy.id) end end @ike_policy.destroy end fog-openstack-0.1.6/tests/openstack/models/network/ipsec_policy_tests.rb0000644000175600017570000000365012730051546025664 0ustar pravipraviShindo.tests("Fog::Network[:openstack] | ipsec_policy", ['openstack']) do tests('success') do tests('#create').succeeds do @instance = Fog::Network[:openstack].ipsec_policies.create(:name => 'test-ipsec-policy', :description => 'Test VPN ipsec Policy', :tenant_id => 'tenant_id', :auth_algorithm => 'sha1', :encryption_algorithm => 'aes-128', :pfs => 'group5', :transform_protocol => 'esp', :lifetime => { 'units' => 'seconds', 'value' => 3600 }, :encapsulation_mode => 'tunnel') !@instance.id.nil? end tests('#update').succeeds do @instance.name = 'rename-test-ipsec-policy' @instance.description = 'Test VPN ipsec Policy' @instance.tenant_id = 'baz' @instance.auth_algorithm = 'sha27' @instance.encryption_algorithm = 'aes-18' @instance.pfs = 'group52' @instance.transform_protocol = 'espn' @instance.encapsulation_mode = 'tunnel' @instance.lifetime = {'units' => 'seconds', 'value' => 3600} @instance.update end tests('#destroy').succeeds do @instance.destroy == true end end end fog-openstack-0.1.6/tests/openstack/models/network/ipsec_site_connections_tests.rb0000644000175600017570000000220712730051546027730 0ustar pravipraviShindo.tests("Fog::Network[:openstack] | ipsec_site_connections", ['openstack']) do params = {:name => 'test-ipsec-site-connection', :vpnservice_id => 'vpn', :ikepolicy_id => 'ike', :ipsecpolicy_id => 'ipsec', :description => 'Test VPN IPSec Site Connection', :tenant_id => 'tenant_id', :peer_address => "172.24.4.226", :peer_id => "172.24.4.226", :peer_cidrs => [], :psk => "secret", :mtu => 1500, :dpd => {"action" => "hold", "interval" => 30, "timeout" => 120}, :initiator => "bi-directional", :admin_state_up => true} @ipsec_site_connection = Fog::Network[:openstack].ipsec_site_connections.create(params) @ipsec_site_connections = Fog::Network[:openstack].ipsec_site_connections tests('success') do tests('#all').succeeds do @ipsec_site_connections.all end tests('#get').succeeds do @ipsec_site_connections.get(@ipsec_site_connection.id) end end @ipsec_site_connection.destroy end fog-openstack-0.1.6/tests/openstack/models/network/network_tests.rb0000644000175600017570000000336312730051546024674 0ustar pravipraviShindo.tests("Fog::Network[:openstack] | network", ['openstack']) do tests('success') do tests('#create').succeeds do @instance = Fog::Network[:openstack].networks.create(:name => 'net_name', :shared => false, :admin_state_up => true, :tenant_id => 'tenant_id') !@instance.id.nil? end tests('#create+extensions').succeeds do net = Fog::Network[:openstack].networks.create( :name => 'net_name', :shared => false, :admin_state_up => true, :tenant_id => 'tenant_id', :router_external => true, # local, gre, vlan. Depends on the provider. # May rise an exception if the network_type isn't valid: # QuantumError: "Invalid input for operation: provider:physical_network" :provider_network_type => 'gre', :provider_segmentation_id => 22 ) net.destroy net.provider_network_type == 'gre' end tests('have attributes') do attributes = [ :name, :subnets, :shared, :status, :admin_state_up, :tenant_id, :provider_network_type, :provider_physical_network, :provider_segmentation_id, :router_external ] tests("The network model should respond to") do attributes.each do |attribute| test("#{attribute}") { @instance.respond_to? attribute } end end end tests('#update').succeeds do @instance.name = 'new_net_name' @instance.update end tests('#destroy').succeeds do @instance.destroy == true end end end fog-openstack-0.1.6/tests/openstack/models/network/lb_health_monitor_tests.rb0000644000175600017570000000355112730051546026673 0ustar pravipraviShindo.tests("Fog::Network[:openstack] | lb_health_monitor", ['openstack']) do tests('success') do before do @lb_pool = Fog::Network[:openstack].lb_pools.create(:subnet_id => 'subnet_id', :protocol => 'HTTP', :lb_method => 'ROUND_ROBIN') end after do @lb_pool.destroy end tests('#create').succeeds do @instance = Fog::Network[:openstack].lb_health_monitors.create(:type => 'PING', :delay => 1, :timeout => 5, :max_retries => 10, :http_method => 'GET', :url_path => '/', :expected_codes => '200, 201', :admin_state_up => true, :tenant_id => 'tenant_id') !@instance.id.nil? end tests('#update').succeeds do @instance.delay = 5 @instance.timeout = 10 @instance.max_retries = 20 @instance.http_method = 'POST' @instance.url_path = '/varz' @instance.expected_codes = '200' @instance.admin_state_up = false @instance.update end tests('#associate_to_pool').succeeds do @instance.associate_to_pool(@lb_pool.id) end tests('#disassociate_from_pool').succeeds do @instance.disassociate_from_pool(@lb_pool.id) end tests('#destroy').succeeds do @instance.destroy == true end end end fog-openstack-0.1.6/tests/openstack/models/network/vpn_service_tests.rb0000644000175600017570000000207612730051546025526 0ustar pravipraviShindo.tests("Fog::Network[:openstack] | vpn_service", ['openstack']) do tests('success') do tests('#create').succeeds do @instance = Fog::Network[:openstack].vpn_services.create(:subnet_id => 'foo', :router_id => 'bar', :name => 'test', :description => 'test', :admin_state_up => true, :tenant_id => 'tenant') !@instance.id.nil? end tests('#update').succeeds do @instance.subnet_id = 'new' @instance.router_id = 'new' @instance.name = 'rename' @instance.description = 'new' @instance.admin_state_up = false @instance.tenant_id = 'baz' @instance.update end tests('#destroy').succeeds do @instance.destroy == true end end end fog-openstack-0.1.6/tests/openstack/models/network/networks_tests.rb0000644000175600017570000000114112730051546025047 0ustar pravipraviShindo.tests("Fog::Network[:openstack] | networks", ['openstack']) do @network = Fog::Network[:openstack].networks.create(:name => 'net_name', :shared => false, :admin_state_up => true, :tenant_id => 'tenant_id') @networks = Fog::Network[:openstack].networks tests('success') do tests('#all').succeeds do @networks.all end tests('#get').succeeds do @networks.get @network.id end end @network.destroy end fog-openstack-0.1.6/tests/openstack/models/network/security_group_tests.rb0000644000175600017570000000105012730051546026255 0ustar pravipraviShindo.tests('Fog::Network[:openstack] | security_group model', ['openstack']) do model_tests(Fog::Network[:openstack].security_groups, {:name => "fogsecgroup"}, true) tests('success') do tests('#create').succeeds do attributes = {:name => "my_secgroup", :description => "my sec group desc"} @secgroup = Fog::Network[:openstack].security_groups.create(attributes) @secgroup.wait_for { ready? } unless Fog.mocking? !@secgroup.id.nil? end tests('#destroy').succeeds do @secgroup.destroy end end end fog-openstack-0.1.6/tests/openstack/models/network/lb_vip_tests.rb0000644000175600017570000000326712730051546024461 0ustar pravipraviShindo.tests("Fog::Network[:openstack] | lb_vip", ['openstack']) do tests('success') do tests('#create').succeeds do @instance = Fog::Network[:openstack].lb_vips.create(:subnet_id => 'subnet_id', :pool_id => 'pool_id', :protocol => 'HTTP', :protocol_port => 80, :name => 'test-vip', :description => 'Test VIP', :address => '10.0.0.1', :session_persistence => { "cookie_name" => "COOKIE_NAME", "type" => "APP_COOKIE" }, :connection_limit => 10, :admin_state_up => true, :tenant_id => 'tenant_id') !@instance.id.nil? end tests('#update').succeeds do @instance.pool_id = 'new_pool_id', @instance.name = 'new-test-vip' @instance.description = 'New Test VIP' @instance.session_persistence = { "type" => "HTTP_COOKIE" } @instance.connection_limit = 5 @instance.admin_state_up = false @instance.update end tests('#destroy').succeeds do @instance.destroy == true end end end fog-openstack-0.1.6/tests/openstack/models/network/router_tests.rb0000644000175600017570000000166112730051546024522 0ustar pravipraviShindo.tests("Fog::Network[:openstack] | router", ['openstack']) do tests('success') do tests('#create').succeeds do @instance = Fog::Network[:openstack].routers.create( :name => 'router_name', :admin_state_up => true ) !@instance.id.nil? end tests('#update') do test('router name') do @instance.name = 'new_name' @instance.update @instance.name == 'new_name' end # Needs code from issue #1598 #test 'external_gateway_info' do # net = Fog::Network[:openstack].networks.create( # :name => 'net_name', # :shared => false, # :admin_state_up => true, # :tenant_id => 'tenant_id', # :router_external => true, # ) # @instance.external_gateway_info = net # @instance.update #end end tests('#destroy').succeeds do @instance.destroy == true end end end fog-openstack-0.1.6/tests/openstack/models/network/ipsec_policies_tests.rb0000644000175600017570000000157612730051546026201 0ustar pravipraviShindo.tests("Fog::Network[:openstack] | ipsec_policies", ['openstack']) do params = {:name => 'test-ipsec-policy', :description => 'Test VPN ipsec Policy', :tenant_id => 'tenant_id', :auth_algorithm => 'sha1', :encryption_algorithm => 'aes-128', :pfs => 'group5', :transform_protocol => 'esp', :lifetime => {'units' => 'seconds', 'value' => 3600}, :encapsulation_mode => 'tunnel'} @ipsec_policy = Fog::Network[:openstack].ipsec_policies.create(params) @ipsec_policies = Fog::Network[:openstack].ipsec_policies tests('success') do tests('#all').succeeds do @ipsec_policies.all end tests('#get').succeeds do @ipsec_policies.get(@ipsec_policy.id) end end @ipsec_policy.destroy end fog-openstack-0.1.6/tests/openstack/models/network/security_group_rule_tests.rb0000644000175600017570000000165712730051546027321 0ustar pravipraviShindo.tests('Fog::Network[:openstack] | security_group_rule model', ['openstack']) do @secgroup = Fog::Network[:openstack].security_groups.create({:name => "fogsecgroup"}) attributes = {:security_group_id => @secgroup.id, :direction => "ingress"} model_tests(Fog::Network[:openstack].security_group_rules, attributes, true) tests('success') do tests('#create').succeeds do attributes = { :security_group_id => @secgroup.id, :direction => "ingress", :protocol => "tcp", :port_range_min => 22, :port_range_max => 22, :remote_ip_prefix => "0.0.0.0/0" } @secgrouprule = Fog::Network[:openstack].security_group_rules.create(attributes) @secgrouprule.wait_for { ready? } unless Fog.mocking? !@secgrouprule.id.nil? end tests('#destroy').succeeds do @secgrouprule.destroy end end @secgroup.destroy end fog-openstack-0.1.6/tests/openstack/models/network/ike_policy_tests.rb0000644000175600017570000000363312730051546025332 0ustar pravipraviShindo.tests("Fog::Network[:openstack] | ike_policy", ['openstack']) do tests('success') do tests('#create').succeeds do @instance = Fog::Network[:openstack].ike_policies.create(:name => 'test-ike-policy', :description => 'Test VPN IKE Policy', :tenant_id => 'tenant_id', :auth_algorithm => 'sha1', :encryption_algorithm => 'aes-256', :pfs => 'group5', :phase1_negotiation_mode => 'main', :lifetime => { 'units' => 'seconds', 'value' => 3600 }, :ike_version => 'v1') !@instance.id.nil? end tests('#update').succeeds do @instance.name = 'rename-test-ike-policy' @instance.description = 'Test VPN IKE Policy' @instance.tenant_id = 'baz' @instance.auth_algorithm = 'sha512' @instance.encryption_algorithm = 'aes-512' @pfs = 'group1' @phase1_negotiation_mode = 'main' @ike_version = 'v1' @lifetime = {'units' => 'seconds', 'value' => 3600} @instance.update end tests('#destroy').succeeds do @instance.destroy == true end end end fog-openstack-0.1.6/tests/openstack/models/network/security_group_rules_tests.rb0000644000175600017570000000167212730051546027501 0ustar pravipraviShindo.tests('Fog::Network[:openstack] | security_group_rules collection', ['openstack']) do @secgroup = Fog::Network[:openstack].security_groups.create({:name => "my_secgroup"}) attributes = {:security_group_id => @secgroup.id, :direction => "ingress"} collection_tests(Fog::Network[:openstack].security_group_rules, attributes, true) tests('success') do attributes = { :security_group_id => @secgroup.id, :direction => "ingress", :protocol => "tcp", :port_range_min => 22, :port_range_max => 22, :remote_ip_prefix => "0.0.0.0/0" } @secgrouprule = Fog::Network[:openstack].security_group_rules.create(attributes) tests('#all(filter)').succeeds do secgrouprule = Fog::Network[:openstack].security_group_rules.all({:direction => "ingress"}) secgrouprule.first.direction == "ingress" end @secgrouprule.destroy end @secgroup.destroy end fog-openstack-0.1.6/tests/openstack/models/network/lb_health_monitors_tests.rb0000644000175600017570000000133512730051546027054 0ustar pravipraviShindo.tests("Fog::Network[:openstack] | lb_health_monitors", ['openstack']) do @lb_health_monitor = Fog::Network[:openstack].lb_health_monitors.create(:type => 'PING', :delay => 1, :timeout => 5, :max_retries => 10) @lb_health_monitors = Fog::Network[:openstack].lb_health_monitors tests('success') do tests('#all').succeeds do @lb_health_monitors.all end tests('#get').succeeds do @lb_health_monitors.get @lb_health_monitor.id end end @lb_health_monitor.destroy end fog-openstack-0.1.6/tests/openstack/models/network/subnets_tests.rb0000644000175600017570000000203312730051546024657 0ustar pravipraviShindo.tests("Fog::Network[:openstack] | subnets", ['openstack']) do @subnet = Fog::Network[:openstack].subnets.create(:name => 'subnet_name', :network_id => 'net_id', :cidr => '10.2.2.0/24', :ip_version => 4, :gateway_ip => '10.2.2.1', :allocation_pools => [], :dns_nameservers => [], :host_routes => [], :enable_dhcp => true, :tenant_id => 'tenant_id') @subnets = Fog::Network[:openstack].subnets tests('success') do tests('#all').succeeds do @subnets.all end tests('#get').succeeds do @subnets.get @subnet.id end end @subnet.destroy end fog-openstack-0.1.6/tests/openstack/models/network/ipsec_site_connection_tests.rb0000644000175600017570000000341312730051546027545 0ustar pravipraviShindo.tests("Fog::Network[:openstack] | ipsec_site_connection", ['openstack']) do tests('success') do tests('#create').succeeds do params = {:name => 'test-ipsec-site-connection', :vpnservice_id => 'vpn', :ikepolicy_id => 'ike', :ipsecpolicy_id => 'ipsec', :description => 'Test VPN IPSec Site Connection', :tenant_id => 'tenant_id', :peer_address => "172.24.4.226", :peer_id => "172.24.4.226", :peer_cidrs => [], :psk => "secret", :mtu => 1500, :dpd => { "action" => "hold", "interval" => 30, "timeout" => 120 }, :initiator => "bi-directional", :admin_state_up => true} @instance = Fog::Network[:openstack].ipsec_site_connections.create(params) !@instance.id.nil? end tests('#update').succeeds do @instance.name = 'rename-test-ipsec-site-connection' @instance.description = 'Test VPN IPSec Site Connection' @instance.tenant_id = 'baz' @instance.peer_address = "172.24.4.227" @instance.peer_id = "172.24.4.227" @instance.peer_cidrs = [] @instance.psk = "secrets" @instance.mtu = 1600 @instance.initiator = "bi-directional" @instance.admin_state_up = false @instance.dpd = { "action" => "hold", "interval" => 50, "timeout" => 120 } @instance.update end tests('#destroy').succeeds do @instance.destroy == true end end end fog-openstack-0.1.6/tests/openstack/models/network/lb_members_tests.rb0000644000175600017570000000117312730051546025307 0ustar pravipraviShindo.tests("Fog::Network[:openstack] | lb_members", ['openstack']) do @lb_member = Fog::Network[:openstack].lb_members.create(:pool_id => 'pool_id', :address => '10.0.0.1', :protocol_port => '80', :weight => 100) @lb_members = Fog::Network[:openstack].lb_members tests('success') do tests('#all').succeeds do @lb_members.all end tests('#get').succeeds do @lb_members.get @lb_member.id end end @lb_member.destroy end fog-openstack-0.1.6/tests/openstack/models/network/vpn_services_tests.rb0000644000175600017570000000153512730051546025710 0ustar pravipraviShindo.tests("Fog::Network[:openstack] | vpn_services", ['openstack']) do @vpn_service = Fog::Network[:openstack].vpn_services.create(:subnet_id => 'foo', :router_id => 'bar', :name => 'test', :description => 'test', :admin_state_up => true, :tenant_id => 'tenant') @vpn_services = Fog::Network[:openstack].vpn_services tests('success') do tests('#all').succeeds do @vpn_services.all end tests('#get').succeeds do @vpn_services.get @vpn_service.id end end @vpn_service.destroy end fog-openstack-0.1.6/tests/openstack/models/storage/0000755000175600017570000000000012730051546021402 5ustar pravipravifog-openstack-0.1.6/tests/openstack/models/storage/file_tests.rb0000644000175600017570000001520712730051546024075 0ustar pravipraviShindo.tests('Fog::OpenStack::Storage | file', ['openstack']) do pending if Fog.mocking? def object_attributes(file=@instance) @instance.service.head_object(@directory.key, file.key).headers end def object_meta_attributes @instance.service.head_object(@directory.key, @instance.key).headers.reject {|k, v| !(k =~ /X-Object-Meta-/)} end def clear_metadata @instance.metadata.tap do |metadata| metadata.each_pair {|k, v| metadata[k] = nil } end end file_attributes = { :key => 'fog_file_tests', :body => lorem_file } directory_attributes = { # Add a random suffix to prevent collision :key => "fogfilestests-#{rand(65536)}" } @directory = Fog::Storage[:openstack]. directories. create(directory_attributes) model_tests(@directory.files, file_attributes.merge(:etag => 'foo'), Fog.mocking?) do tests('#save should not blow up with etag') do @instance.save end end model_tests(@directory.files, file_attributes, Fog.mocking?) do tests("#metadata should load empty metadata").returns({}) do @instance.metadata end tests('#save') do tests('#metadata') do before do @instance.metadata[:foo] = 'bar' @instance.save end after do clear_metadata @instance.save end tests("should update metadata").returns('bar') do object_meta_attributes['X-Object-Meta-Foo'] end tests('should cache metadata').returns('bar') do @instance.metadata[:foo] end tests('should remove empty metadata').returns({}) do @instance.metadata[:foo] = nil @instance.save object_meta_attributes end end tests('#content_disposition') do before do @instance = @directory.files.create :key => 'meta-test', :body => lorem_file, :content_disposition => 'ho-ho-ho' end after do clear_metadata @instance.save end tests("sets Content-Disposition on create").returns("ho-ho-ho") do object_attributes(@instance)["Content-Disposition"] end end tests('#metadata keys') do after do clear_metadata @instance.save end @instance.metadata[:foo_bar] = 'baz' tests("should support compound key names").returns('baz') do @instance.save object_meta_attributes['X-Object-Meta-Foo-Bar'] end @instance.metadata['foo'] = 'bar' tests("should support string keys").returns('bar') do @instance.save object_meta_attributes['X-Object-Meta-Foo'] end @instance.metadata['foo_bar'] = 'baz' tests("should support compound string key names").returns('baz') do @instance.save object_meta_attributes['X-Object-Meta-Foo-Bar'] end @instance.metadata['foo-bar'] = 'baz' tests("should support hyphenated keys").returns('baz') do @instance.save object_meta_attributes['X-Object-Meta-Foo-Bar'] end @instance.metadata['foo-bar'] = 'baz' @instance.metadata[:'foo_bar'] = 'bref' tests("should only support one value per metadata key").returns('bref') do @instance.save object_meta_attributes['X-Object-Meta-Foo-Bar'] end end end tests("#access_control_allow_origin") do tests("#access_control_allow_origin should default to nil").returns(nil) do @instance.access_control_allow_origin end @instance.access_control_allow_origin = 'http://example.com' @instance.save tests("#access_control_allow_origin should return access control attribute").returns('http://example.com') do @instance.access_control_allow_origin end @instance.access_control_allow_origin = 'foo' @instance.save tests("#access_control_allow_origin= should update access_control_allow_origin").returns('bar') do @instance.access_control_allow_origin = 'bar' @instance.save @instance.access_control_allow_origin end tests("#access_control_allow_origin= should not blow up on nil") do @instance.access_control_allow_origin = nil @instance.save end end tests("#delete_at") do @delete_at_time = (Time.now + 300).to_i tests("#delete_at should default to nil").returns(nil) do @instance.delete_at end @instance.delete_at = @delete_at_time @instance.save tests("#delete_at should return delete_at attribute").returns(@delete_at_time) do @instance.delete_at end @instance.delete_at = @delete_at_time @instance.save tests("#delete_at= should update delete_at").returns(@delete_at_time + 100) do @instance.delete_at = @delete_at_time + 100 @instance.save @instance.delete_at end tests("#delete_at= should not blow up on nil") do @instance.delete_at = nil @instance.save end end end model_tests(@directory.files, file_attributes, Fog.mocking?) do tests("#origin") do tests("#origin should default to nil").returns(nil) do @instance.save @instance.origin end @instance.origin = 'http://example.com' @instance.save tests("#origin should return access control attributes").returns('http://example.com') do @instance.origin end @instance.attributes.delete('Origin') @instance.origin = 'foo' @instance.save tests("#origin= should update origin").returns('bar') do @instance.origin = 'bar' @instance.save @instance.origin end tests("#origin= should not blow up on nil") do @instance.origin = nil @instance.save end end tests("#content_encoding") do tests("#content_encoding should default to nil").returns(nil) do @instance.save @instance.content_encoding end @instance.content_encoding = 'gzip' @instance.save tests("#content_encoding should return the content encoding").returns('gzip') do @instance.content_encoding end @instance.attributes.delete('content_encoding') @instance.content_encoding = 'foo' @instance.save tests("#content_encoding= should update content_encoding").returns('bar') do @instance.content_encoding = 'bar' @instance.save @instance.content_encoding end tests("#content_encoding= should not blow up on nil") do @instance.content_encoding = nil @instance.save end end end @directory.destroy end fog-openstack-0.1.6/tests/openstack/models/image/0000755000175600017570000000000012730051546021020 5ustar pravipravifog-openstack-0.1.6/tests/openstack/models/image/images_tests.rb0000644000175600017570000000115712730051546024040 0ustar pravipraviShindo.tests("Fog::Image[:openstack] | images", ['openstack']) do @instance = Fog::Image[:openstack].create_image({:name => "model test image"}).body tests('success') do tests('#find_by_id').succeeds do image = Fog::Image[:openstack].images.find_by_id(@instance['image']['id']) image.id == @instance['image']['id'] end tests('#get').succeeds do image = Fog::Image[:openstack].images.get(@instance['image']['id']) image.id == @instance['image']['id'] end tests('#destroy').succeeds do Fog::Image[:openstack].images.destroy(@instance['image']['id']) end end end fog-openstack-0.1.6/tests/openstack/models/image/image_tests.rb0000644000175600017570000000144312730051546023653 0ustar pravipraviShindo.tests("Fog::Image[:openstack] | image", ['openstack']) do tests('success') do tests('#create').succeeds do @instance = Fog::Image[:openstack].images.create(:name => 'test image') !@instance.id.nil? end tests('#update').succeeds do @instance.name = 'edit test image' @instance.update @instance.name == 'edit test image' end tests('#get image metadata').succeeds do @instance.metadata end tests('#add member').succeeds do @instance.add_member(@instance.owner) end tests('#show members').succeeds do @instance.members end tests('#remove member').succeeds do @instance.remove_member(@instance.owner) end tests('#destroy').succeeds do @instance.destroy == true end end end fog-openstack-0.1.6/tests/helpers/0000755000175600017570000000000012730051546016126 5ustar pravipravifog-openstack-0.1.6/tests/helpers/compute/0000755000175600017570000000000012730051546017602 5ustar pravipravifog-openstack-0.1.6/tests/helpers/compute/server_helper.rb0000644000175600017570000000124612730051546022777 0ustar pravipravidef server_tests(connection, params = {}, mocks_implemented = true) model_tests(connection.servers, params, mocks_implemented) do tests('#reload').returns(true) do pending if Fog.mocking? && !mocks_implemented @instance.wait_for { ready? } identity = @instance.identity !identity.nil? && identity == @instance.reload.identity end responds_to([:ready?, :state]) yield if block_given? tests('#reboot').succeeds do pending if Fog.mocking? && !mocks_implemented @instance.wait_for { ready? } @instance.reboot end if !Fog.mocking? || mocks_implemented @instance.wait_for { ready? } end end end fog-openstack-0.1.6/tests/helpers/compute/flavors_helper.rb0000644000175600017570000000146312730051546023146 0ustar pravipravidef flavors_tests(connection, params = {}, mocks_implemented = true) tests('success') do tests("#all").succeeds do pending if Fog.mocking? && !mocks_implemented connection.flavors.all end if !Fog.mocking? || mocks_implemented @identity = connection.flavors.first.identity end tests("#get('#{@identity}')").succeeds do pending if Fog.mocking? && !mocks_implemented connection.flavors.get(@identity) end end tests('failure') do if !Fog.mocking? || mocks_implemented invalid_flavor_identity = connection.flavors.first.identity.to_s.gsub(/\w/, '0') end tests("#get('#{invalid_flavor_identity}')").returns(nil) do pending if Fog.mocking? && !mocks_implemented connection.flavors.get(invalid_flavor_identity) end end end fog-openstack-0.1.6/tests/helpers/compute/servers_helper.rb0000644000175600017570000000041012730051546023152 0ustar pravipravidef servers_tests(connection, params = {}, mocks_implemented = true) collection_tests(connection.servers, params, mocks_implemented) do if !Fog.mocking? || mocks_implemented @instance.wait_for { ready? } yield if block_given? end end end fog-openstack-0.1.6/tests/helpers/model_helper.rb0000644000175600017570000000141412730051546021112 0ustar pravipravidef model_tests(collection, params = {}, mocks_implemented = true) tests('success') do @instance = collection.new(params) tests("#save").succeeds do pending if Fog.mocking? && !mocks_implemented @instance.save end if block_given? yield(@instance) end tests("#destroy").succeeds do pending if Fog.mocking? && !mocks_implemented @instance.destroy end end end # Generates a unique identifier with a random differentiator. # Useful when rapidly re-running tests, so we don't have to wait # serveral minutes for deleted objects to disappear from the API # E.g. 'fog-test-1234' def uniq_id(base_name = 'fog-test') # random_differentiator suffix = rand(65536).to_s(16).rjust(4, '0') [base_name, suffix] * '-' end fog-openstack-0.1.6/tests/helpers/schema_validator_tests.rb0000644000175600017570000000723112730051546023205 0ustar pravipraviShindo.tests('Fog::Schema::DataValidator', 'meta') do validator = Fog::Schema::DataValidator.new tests('#validate') do tests('returns true') do returns(true, 'when value matches schema expectation') do validator.validate({"key" => "Value"}, {"key" => String}) end returns(true, 'when values within an array all match schema expectation') do validator.validate({"key" => [1, 2]}, {"key" => [Integer]}) end returns(true, 'when nested values match schema expectation') do validator.validate({"key" => {:nested_key => "Value"}}, {"key" => {:nested_key => String}}) end returns(true, 'when collection of values all match schema expectation') do validator.validate([{"key" => "Value"}, {"key" => "Value"}], [{"key" => String}]) end returns(true, 'when collection is empty although schema covers optional members') do validator.validate([], [{"key" => String}]) end returns(true, 'when additional keys are passed and not strict') do validator.validate({"key" => "Value", :extra => "Bonus"}, {"key" => String}, {:allow_extra_keys => true}) end returns(true, 'when value is nil and schema expects NilClass') do validator.validate({"key" => nil}, {"key" => NilClass}) end returns(true, 'when value and schema match as hashes') do validator.validate({}, {}) end returns(true, 'when value and schema match as arrays') do validator.validate([], []) end returns(true, 'when value is a Time') do validator.validate({"time" => Time.now}, {"time" => Time}) end returns(true, 'when key is missing but value should be NilClass (#1477)') do validator.validate({}, {"key" => NilClass}, {:allow_optional_rules => true}) end returns(true, 'when key is missing but value is nullable (#1477)') do validator.validate({}, {"key" => Fog::Nullable::String}, {:allow_optional_rules => true}) end end tests('returns false') do returns(false, 'when value does not match schema expectation') do validator.validate({"key" => nil}, {"key" => String}) end returns(false, 'when key formats do not match') do validator.validate({"key" => "Value"}, {:key => String}) end returns(false, 'when additional keys are passed and strict') do validator.validate({"key" => "Missing"}, {}) end returns(false, 'when some keys do not appear') do validator.validate({}, {"key" => String}) end returns(false, 'when collection contains a member that does not match schema') do validator.validate([{"key" => "Value"}, {"key" => 5}], [{"key" => String}]) end returns(false, 'when collection has multiple schema patterns') do validator.validate([{"key" => "Value"}], [{"key" => Integer}, {"key" => String}]) end returns(false, 'when hash and array are compared') do validator.validate({}, []) end returns(false, 'when array and hash are compared') do validator.validate([], {}) end returns(false, 'when a hash is expected but another data type is found') do validator.validate({"key" => {:nested_key => []}}, {"key" => {:nested_key => {}}}) end returns(false, 'when key is missing but value should be NilClass (#1477)') do validator.validate({}, {"key" => NilClass}, {:allow_optional_rules => false}) end returns(false, 'when key is missing but value is nullable (#1477)') do validator.validate({}, {"key" => Fog::Nullable::String}, {:allow_optional_rules => false}) end end end end fog-openstack-0.1.6/tests/helpers/collection_helper.rb0000644000175600017570000000502712730051546022151 0ustar pravipravidef collection_tests(collection, params = {}, mocks_implemented = true) tests('success') do tests("#new(#{params.inspect})").succeeds do pending if Fog.mocking? && !mocks_implemented collection.new(params) end tests("#create(#{params.inspect})").succeeds do pending if Fog.mocking? && !mocks_implemented @instance = collection.create(params) end # FIXME: work around for timing issue on AWS describe_instances mocks if Fog.mocking? && @instance.respond_to?(:ready?) @instance.wait_for { ready? } end tests("#all").succeeds do pending if Fog.mocking? && !mocks_implemented collection.all end if !Fog.mocking? || mocks_implemented @identity = @instance.identity end tests("#get(#{@identity})").succeeds do pending if Fog.mocking? && !mocks_implemented collection.get(@identity) end tests('Enumerable') do pending if Fog.mocking? && !mocks_implemented methods = [ 'all?', 'any?', 'find', 'detect', 'collect', 'map', 'find_index', 'flat_map', 'collect_concat', 'group_by', 'none?', 'one?' ] # JRuby 1.7.5+ issue causes a SystemStackError: stack level too deep # https://github.com/jruby/jruby/issues/1265 if RUBY_PLATFORM == "java" and JRUBY_VERSION =~ /1\.7\.[5-8]/ methods.delete('all?') end methods.each do |enum_method| if collection.respond_to?(enum_method) tests("##{enum_method}").succeeds do block_called = false collection.send(enum_method) {|x| block_called = true } block_called end end end [ 'max_by','min_by' ].each do |enum_method| if collection.respond_to?(enum_method) tests("##{enum_method}").succeeds do block_called = false collection.send(enum_method) {|x| block_called = true; 0 } block_called end end end end if block_given? yield(@instance) end if !Fog.mocking? || mocks_implemented @instance.destroy end end tests('failure') do if !Fog.mocking? || mocks_implemented @identity = @identity.to_s @identity = @identity.gsub(/[a-zA-Z]/) { Fog::Mock.random_letters(1) } @identity = @identity.gsub(/\d/) { Fog::Mock.random_numbers(1) } @identity end tests("#get('#{@identity}')").returns(nil) do pending if Fog.mocking? && !mocks_implemented collection.get(@identity) end end end fog-openstack-0.1.6/tests/helpers/formats_helper_tests.rb0000644000175600017570000000702012730051546022706 0ustar pravipraviShindo.tests('test_helper', 'meta') do tests('comparing welcome data against schema') do data = {:welcome => "Hello" } data_matches_schema(:welcome => String) { data } end tests('#data_matches_schema') do tests('when value matches schema expectation') do data_matches_schema({"key" => String}) { {"key" => "Value"} } end tests('when values within an array all match schema expectation') do data_matches_schema({"key" => [Integer]}) { {"key" => [1, 2]} } end tests('when nested values match schema expectation') do data_matches_schema({"key" => {:nested_key => String}}) { {"key" => {:nested_key => "Value"}} } end tests('when collection of values all match schema expectation') do data_matches_schema([{"key" => String}]) { [{"key" => "Value"}, {"key" => "Value"}] } end tests('when collection is empty although schema covers optional members') do data_matches_schema([{"key" => String}], {:allow_optional_rules => true}) { [] } end tests('when additional keys are passed and not strict') do data_matches_schema({"key" => String}, {:allow_extra_keys => true}) { {"key" => "Value", :extra => "Bonus"} } end tests('when value is nil and schema expects NilClass') do data_matches_schema({"key" => NilClass}) { {"key" => nil} } end tests('when value and schema match as hashes') do data_matches_schema({}) { {} } end tests('when value and schema match as arrays') do data_matches_schema([]) { [] } end tests('when value is a Time') do data_matches_schema({"time" => Time}) { {"time" => Time.now} } end tests('when key is missing but value should be NilClass (#1477)') do data_matches_schema({"key" => NilClass}, {:allow_optional_rules => true}) { {} } end tests('when key is missing but value is nullable (#1477)') do data_matches_schema({"key" => Fog::Nullable::String}, {:allow_optional_rules => true}) { {} } end end tests('#formats backwards compatible changes') do tests('when value matches schema expectation') do formats({"key" => String}) { {"key" => "Value"} } end tests('when values within an array all match schema expectation') do formats({"key" => [Integer]}) { {"key" => [1, 2]} } end tests('when nested values match schema expectation') do formats({"key" => {:nested_key => String}}) { {"key" => {:nested_key => "Value"}} } end tests('when collection of values all match schema expectation') do formats([{"key" => String}]) { [{"key" => "Value"}, {"key" => "Value"}] } end tests('when collection is empty although schema covers optional members') do formats([{"key" => String}]) { [] } end tests('when additional keys are passed and not strict') do formats({"key" => String}, false) { {"key" => "Value", :extra => "Bonus"} } end tests('when value is nil and schema expects NilClass') do formats({"key" => NilClass}) { {"key" => nil} } end tests('when value and schema match as hashes') do formats({}) { {} } end tests('when value and schema match as arrays') do formats([]) { [] } end tests('when value is a Time') do formats({"time" => Time}) { {"time" => Time.now} } end tests('when key is missing but value should be NilClass (#1477)') do formats({"key" => NilClass}) { {} } end tests('when key is missing but value is nullable (#1477)') do formats({"key" => Fog::Nullable::String}) { {} } end end end fog-openstack-0.1.6/tests/helpers/mock_helper.rb0000644000175600017570000000070712730051546020747 0ustar pravipravi# Use so you can run in mock mode from the command line # # FOG_MOCK=true fog if ENV["FOG_MOCK"] == "true" Fog.mock! end # if in mocked mode, fill in some fake credentials for us if Fog.mock? Fog.credentials = { :openstack_api_key => 'openstack_api_key', :openstack_username => 'openstack_username', :openstack_tenant => 'openstack_tenant', :openstack_auth_url => 'http://openstack:35357/v2.0/tokens', }.merge(Fog.credentials) end fog-openstack-0.1.6/tests/helpers/responds_to_helper.rb0000644000175600017570000000037412730051546022355 0ustar pravipravimodule Shindo class Tests def responds_to(method_names) for method_name in [*method_names] tests("#respond_to?(:#{method_name})").returns(true) do @instance.respond_to?(method_name) end end end end end fog-openstack-0.1.6/tests/helpers/formats_helper.rb0000644000175600017570000000705612730051546021475 0ustar pravipravirequire "fog/schema/data_validator" # format related hackery # allows both true.is_a?(Fog::Boolean) and false.is_a?(Fog::Boolean) # allows both nil.is_a?(Fog::Nullable::String) and ''.is_a?(Fog::Nullable::String) module Fog module Boolean; end module Nullable module Boolean; end module Integer; end module String; end module Time; end module Float; end module Hash; end module Array; end end end [FalseClass, TrueClass].each {|klass| klass.send(:include, Fog::Boolean)} [FalseClass, TrueClass, NilClass, Fog::Boolean].each {|klass| klass.send(:include, Fog::Nullable::Boolean)} [NilClass, String].each {|klass| klass.send(:include, Fog::Nullable::String)} [NilClass, Time].each {|klass| klass.send(:include, Fog::Nullable::Time)} [Integer, NilClass].each {|klass| klass.send(:include, Fog::Nullable::Integer)} [Float, NilClass].each {|klass| klass.send(:include, Fog::Nullable::Float)} [Hash, NilClass].each {|klass| klass.send(:include, Fog::Nullable::Hash)} [Array, NilClass].each {|klass| klass.send(:include, Fog::Nullable::Array)} module Shindo class Tests # Generates a Shindo test that compares a hash schema to the result # of the passed in block returning true if they match. # # The schema that is passed in is a Hash or Array of hashes that # have Classes in place of values. When checking the schema the # value should match the Class. # # Strict mode will fail if the data has additional keys. Setting # +strict+ to +false+ will allow additional keys to appear. # # @param [Hash] schema A Hash schema # @param [Hash] options Options to change validation rules # @option options [Boolean] :allow_extra_keys # If +true+ does not fail when keys are in the data that are # not specified in the schema. This allows new values to # appear in API output without breaking the check. # @option options [Boolean] :allow_optional_rules # If +true+ does not fail if extra keys are in the schema # that do not match the data. Not recommended! # @yield Data to check with schema # # @example Using in a test # Shindo.tests("comparing welcome data against schema") do # data = {:welcome => "Hello" } # data_matches_schema(:welcome => String) { data } # end # # comparing welcome data against schema # + data matches schema # # @example Example schema # { # "id" => String, # "ram" => Integer, # "disks" => [ # { # "size" => Float # } # ], # "dns_name" => Fog::Nullable::String, # "active" => Fog::Boolean, # "created" => DateTime # } # # @return [Boolean] def data_matches_schema(schema, options = {}) test('data matches schema') do validator = Fog::Schema::DataValidator.new valid = validator.validate(yield, schema, options) @message = validator.message unless valid valid end end # @deprecated #formats is deprecated. Use #data_matches_schema instead def formats(format, strict = true) test('has proper format') do if strict options = {:allow_extra_keys => false, :allow_optional_rules => true} else options = {:allow_extra_keys => true, :allow_optional_rules => true} end validator = Fog::Schema::DataValidator.new valid = validator.validate(yield, format, options) @message = validator.message unless valid valid end end end end fog-openstack-0.1.6/tests/helpers/succeeds_helper.rb0000644000175600017570000000020612730051546021606 0ustar pravipravimodule Shindo class Tests def succeeds test('succeeds') do !!instance_eval(&Proc.new) end end end end fog-openstack-0.1.6/tests/helper.rb0000644000175600017570000000123612730051546016272 0ustar pravipravirequire 'coveralls' Coveralls.wear! require File.expand_path('../../lib/fog/openstack', __FILE__) Bundler.require(:test) Excon.defaults.merge!(:debug_request => true, :debug_response => true) require File.expand_path(File.join(File.dirname(__FILE__), 'helpers', 'mock_helper')) # This overrides the default 600 seconds timeout during live test runs unless Fog.mocking? Fog.timeout = ENV['FOG_TEST_TIMEOUT'] || 2_000 Fog::Logger.warning "Setting default fog timeout to #{Fog.timeout} seconds" end def lorem_file File.open(File.dirname(__FILE__) + '/lorem.txt', 'r') end def array_differences(array_a, array_b) (array_a - array_b) | (array_b - array_a) end fog-openstack-0.1.6/README.md0000644000175600017570000004046412730051546014611 0ustar pravipravi# Fog::Openstack [![Gem Version](https://badge.fury.io/rb/fog-openstack.svg)](http://badge.fury.io/rb/fog-openstack) [![Build Status](https://travis-ci.org/fog/fog-openstack.svg?branch=master)](https://travis-ci.org/fog/fog-openstack) [![Dependency Status](https://gemnasium.com/fog/fog-openstack.svg)](https://gemnasium.com/fog/fog-openstack) [![Coverage Status](https://coveralls.io/repos/github/fog/fog-openstack/badge.svg?branch=master)](https://coveralls.io/github/fog/fog-openstack?branch=master) [![Code Climate](https://codeclimate.com/github/fog/fog-openstack.png)](https://codeclimate.com/github/fog/fog-openstack) [![Join the chat at https://gitter.im/fog/fog-openstack](https://badges.gitter.im/fog/fog-openstack.svg)](https://gitter.im/fog/fog-openstack?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) This is the plugin Gem to talk to [OpenStack](http://openstack.org) clouds via fog. The main maintainers for the OpenStack sections are @dhague, @Ladas, @seanhandley, @mdarby and @jjasghar. Please send CC them on pull requests. ## Supported OpenStack APIs See the list of [supported OpenStack projects](supported.md). ## Installation Add this line to your application's Gemfile: ```ruby gem 'fog-openstack' ``` And then execute: $ bundle Or install it yourself as: $ gem install fog-openstack ## Usage ### Initial Setup Require the gem: ```ruby require "fog/openstack" ``` Checklist: * Before you can do anything with an OpenStack cloud, you need to authenticate yourself with the identity service, "Keystone". * All following examples assume that `@connection_params` is a hash of valid connection information for an OpenStack cloud. * The `:openstack_username` and `:openstack_api_key` keys must map to a valid user/password combination in Keystone. * If you don't know what domain your user belongs to, chances are it's the `default` domain. By default, all users are a member of the `default` domain unless otherwise specified. Connection parameters: ```ruby @connection_params = { openstack_auth_url: "http://devstack.test:5000/v3/auth/tokens", openstack_username: "admin", openstack_api_key: "password", openstack_project_name: "admin", openstack_domain_id: "default" } ``` If you're using Keystone V2, you don't need to supply domain details but ensure the `openstack_auth_url` parameter references the correct endpoint. ```ruby @connection_params = { openstack_auth_url: "http://devstack.test:5000/v2.0/tokens" openstack_username: "admin", openstack_api_key: "password", openstack_project_name: "admin" } ``` If you're not sure whether your OpenStack cloud uses Keystone V2 or V3 then you can find out by logging into the dashboard (Horizon) and navigating to "Access & Security" under the "Project" section. Select "API Access" and find the line for the Identity Service. If the endpoint has "v3" in it, you're on Keystone V3, if it has "v2" then (surprise) you're on Keystone V2. If you need a version of OpenStack to test against, get youself a copy of [DevStack](http://docs.openstack.org/developer/devstack/). ### Networking Gotcha Note that tenants (aka projects) in OpenStack usually require that you create a default gateway router in order to allow external access to your instances. The exception is if you're using Nova (and not Neutron) for your instance networking. If you're using Neutron, you'll want to [set up your default gateway](https://github.com/fog/fog-openstack/blob/usage_doc/README.md#networking-neutron) before you try to give instances public addresses (aka floating IPs). ### Compute (Nova) Initialise a connection to the compute service: ```ruby compute = Fog::Compute::OpenStack.new(@connection_params) ``` Get a list of available images for use with booting new instances: ```ruby p compute.images # => # ] # > ``` List available flavors so we can decide how powerful to make this instance: ```ruby p compute.flavors # => , # , # ... ``` Now we know the `id` numbers of a valid image and a valid flavor, we can instantiate an instance: ```ruby flavor = compute.flavors[0] image = compute.images[0] instance = compute.servers.create name: 'test', image_ref: image.id, flavor_ref: flavor.id # Optionally, wait for the instance to provision before continuing instance.wait_for { ready? } # => {:duration=>17.359134} p instance # => [{"OS-EXT-IPS-MAC:mac_addr"=>"fa:16:3e:f4:75:ab", "version"=>4, "addr"=>"1.2.3.4", "OS-EXT-IPS:type"=>"fixed"}]}, # flavor={"id"=>"2"}, # host_id="f5ea01262720d02e886508bc4fa994782c516557d232c72aeb79638e", # image={"id"=>"57a67f8a-7bae-4578-b684-b9b4dcd48d7f"}, # name="test", # personality=nil, # progress=0, # accessIPv4="", # accessIPv6="", # availability_zone="nova", # user_data_encoded=nil, # state="ACTIVE", # created=2016-03-07 08:07:36 UTC, # updated=2016-03-07 08:07:52 UTC, # tenant_id="06a9a90c60074cdeae5f7fdd0048d9ac" # ... # > ``` And destroy it when we're done: ```ruby instance.destroy # => true ``` You'll probably need your instances to be accessible via SSH. [Learn more about SSH keypairs](https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/). Allow TCP traffic through port 22: ```ruby security_group = compute.security_groups.create name: "Test SSH", description: "Allow access to port 22" # => , # tenant_id="06a9a90c60074cdeae5f7fdd0048d9ac" # > compute.security_group_rules.create parent_group_id: security_group.id, ip_protocol: "tcp", from_port: 22, to_port: 22 key_pair = compute.key_pairs.create name: "My Public Key", public_key: "/full/path/to/ssh.pub" # => ``` Now create a new server using the security group and keypair we created: ```ruby instance = compute.servers.create name: "Test 2", image_ref: image.id, flavor_ref: flavor.id, key_name: key_pair.name, security_groups: security_group # => # (some data omitted for brevity) ``` Finally, assign a floating IP address to make this instance sit under a world-visible public IP address: ```ruby pool_name = compute.addresses.get_address_pools[0]['name'] floating_ip_address = compute.addresses.create pool: pool_name instance.associate_address floating_ip_address.ip p floating_ip_address # => ``` Now you can SSH into the instance: ``` $ ssh cirros@1.2.3.4 The authenticity of host '1.2.3.4 (1.2.3.4)' can't be established. RSA key fingerprint is SHA256:cB0L/owUtcHsMhFhsuSZXxK4oRg/uqP/6IriUomQnQQ. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '1.2.3.4' (RSA) to the list of known hosts. $ pwd /home/cirros ``` ### Volume (Cinder) Create and attach a volume to a running instance: ```ruby compute = Fog::Compute::OpenStack.new(@connection_params) volume = compute.volumes.create name: "Test", description: "Testing", size: 1 # => flavor = compute.flavors[3] image = compute.images[0] instance = compute.servers.create name: "test", image_ref: image.id, flavor_ref: flavor.id instance.wait_for { ready? } volume.reload instance.attach_volume(volume.id, "/dev/vdb") ``` Detach volume and create a snapshot: ```ruby instance.detach_volume(volume.id) volume.reload compute.snapshots.create volume_id: volume.id, name: "test", description: "test" # => ``` Destroy a volume: ```ruby volume.destroy # => true ``` ### Image (Glance) Create Glance image from URL: ```ruby image = Fog::Image::OpenStack.new(@connection_params) cirros_location = "http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img" image.images.create name: "cirros", disk_format: "qcow2", container_format: "bare", location: cirros_location # => ``` Create Glance image from file: ```ruby cirros_location = "http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img" image_out = File.open("/tmp/cirros-image-#{SecureRandom.hex}", 'wb') streamer = lambda do |chunk, _, _| image_out.write chunk end Excon.get cirros_location, response_block: streamer image_out.close image.images.create name: "cirros", disk_format: "qcow2", container_format: "bare", location: image_out.path ``` Destroy image: ```ruby cirros = image.images.get("4beedb46-e32f-4ef3-a87b-7f1234294dc1") cirros.destroy ``` ### Identity (Keystone) List domains (Keystone V3 only): ```ruby identity = Fog::Identity::OpenStack.new(@connection_params) identity.domains # => # ] # > ``` List projects (aka tenants): ```ruby identity.projects # => , # ... # ] # On Keystone V2 identity.tenants # => user.destroy # => true ``` Create/destroy new tenant: ```ruby project = identity.projects.create name: "test", description: "test" # => project.destroy # => true ``` Grant user role on tenant and revoke it: ```ruby role = identity.roles.select{|role| role.name == "_member_"}[0] # => project.grant_role_to_user(role.id, user.id) project.revoke_role_from_user(role.id, user.id) ``` ### Networking (Neutron) Set up a project's public gateway (needed for external access): ```ruby identity = Fog::Identity::OpenStack.new(@connection_params) tenants = identity.projects.select do |project| project.name == @connection_params[:openstack_project_name] end tenant_id = tenants[0].id neutron = Fog::Network::OpenStack.new(@connection_params) network = neutron.networks.create name: "default", tenant_id: tenant_id subnet = network.subnets.create name: "default", cidr: "192.168.0.0/24", network_id: network.id, ip_version: 4, dns_nameservers: ["8.8.8.8", "8.8.4.4"], tenant_id: tenant_id external_network = neutron.networks.select(&:router_external)[0] router = neutron.routers.create name: 'default', tenant_id: tenant_id, external_gateway_info: external_network.id neutron.add_router_interface router.id, subnet.id ``` ### Further Reading * See [the documentation directory](https://github.com/fog/fog-openstack/tree/master/lib/fog/openstack/docs) for more examples. * Read the [OpenStack API documentation](http://developer.openstack.org/api-ref.html). * Also, remember that reading the code itself is the best way to educate yourself on how best to interact with this gem. ## Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/fog-openstack. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. ## License The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). fog-openstack-0.1.6/CODE_OF_CONDUCT.md0000644000175600017570000000453112730051546016124 0ustar pravipravi# Contributor Code of Conduct As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality. Examples of unacceptable behavior by participants include: * The use of sexualized language or imagery * Personal attacks * Trolling or insulting/derogatory comments * Public or private harassment * Publishing other's private information, such as physical or electronic addresses, without explicit permission * Other unethical or unprofessional conduct Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team. This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting a project maintainer at matt.darby@rackspace.com. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. Maintainers are obligated to maintain confidentiality with regard to the reporter of an incident. This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.3.0, available at [http://contributor-covenant.org/version/1/3/0/][version] [homepage]: http://contributor-covenant.org [version]: http://contributor-covenant.org/version/1/3/0/ fog-openstack-0.1.6/CHANGELOG.md0000644000175600017570000000251312730051546015134 0ustar pravipravi# 1.10.1 2013/04/04 ## Storage * Added storage (Swift) example to set account quotas: https://github.com/fog/fog/blob/master/lib/fog/openstack/examples/storage/set-account-quota.rb * Added account impersonation to the storage service Now it's possible to use an admin account with a reseller role to impersonate other accounts and set account metadata headers. See the account quotas example included in this release ## Network * create_network request updated Implements provider extensions when creating networks. See http://docs.openstack.org/trunk/openstack-network/admin/content/provider_attributes.html * Network Router support (Quantum) Added router model/collection and related requests. * New network service example See https://github.com/fog/fog/blob/master/lib/fog/openstack/examples/network/network_subnets_routers.rb * :openstack_endpoint_type parameter was added to the network service ## Image * Added basic image service example (Glance) Download CirrOS 0.3.0 image from launchpad (~6.5MB) to /tmp and upload it to Glance. See https://github.com/fog/fog/blob/master/lib/fog/openstack/examples/image/upload-test-image.rb * Check for glance version (fog only supports v1) ## Compute * create_server and the Server model where updated to allow booting a VM with NICs (net_id, port_id, fixed_ip). fog-openstack-0.1.6/Gemfile0000644000175600017570000000020312730051546014610 0ustar pravipravisource 'https://rubygems.org' gem "coveralls", require: false # Specify your gem's dependencies in fog-openstack.gemspec gemspec fog-openstack-0.1.6/.ruby-version0000644000175600017570000000000612730051546015763 0ustar pravipravi2.1.2 fog-openstack-0.1.6/.ruby-gemset0000644000175600017570000000001612730051546015563 0ustar pravipravifog-openstack fog-openstack-0.1.6/supported.md0000644000175600017570000000402612730051546015673 0ustar pravipravi# Supported OpenStack Projects ## Supported | Project | Fog Type | API Version(s) | Compliance | Notes | |------------------|---------------|----------------|------------|-------| | Ceilometer | Metering | v2 | TBD | | | Cinder | Volume | v1, v2 | TBD | | | Glance | Image | v1, v2 | TBD | | | Heat | Orchestration | v1 | TBD | | | Keystone | Identity | v2, v3 | TBD | | | Neutron | Network | v2 | TBD | | | Nova | Compute | v2.0 | TBD | | | Ironic | Bare Metal | v1 | TBD | | | Ironic Inspector | Introspection | v1 | TBD | | | Swift | Storage | v2 | TBD | | | Tacker | NFV | v1 | TBD | | ## Wish List Feel free to submit pull requests to add support for these. * [barbican](https://wiki.openstack.org/wiki/Barbican) (Key Management) * [congress](https://wiki.openstack.org/wiki/Congress) (Policy As a Service) * [designate](https://wiki.openstack.org/wiki/Designate) (DNSaaS) * [magnum](https://wiki.openstack.org/wiki/Magnum) (Containers) * [manila](https://wiki.openstack.org/wiki/Manila) (File Storage) * [monasca](https://wiki.openstack.org/wiki/Monasca) (Monitoring) * [trove](https://wiki.openstack.org/wiki/Trove) (DBaaS) ## Unsupported * aodh (Telemetry Alarms) * astara (Network) * cloudkitty (Telemetry) * cue (Messaging) * dragonflow (Network) * ec2-api (Compatibility Layer) * freezer (Disaster Recovery) * fuel (Orchestration) * gnocchi (TSDB) * horizon (Web Frontend) * kolla (Containers) * kuryr (Containers) * mistral (Workflow) * murano (Catalog Service) * rally (Benchmarking) * sahara (Map-Reduce) * searchlight (Searching) * senlin (Clustering) * solum (Lifecycle) * tripleo (Orchestration) * zaqar (Messaging) fog-openstack-0.1.6/lib/0000755000175600017570000000000012730051546014070 5ustar pravipravifog-openstack-0.1.6/lib/fog/0000755000175600017570000000000012730051546014643 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack.rb0000644000175600017570000005167512730051546017175 0ustar pravipravirequire 'fog/openstack/version' require 'fog/core' require 'fog/json' require 'fog/openstack/core' require 'fog/openstack/common' require 'fog/openstack/errors' require 'fog/openstack/compute' require 'fog/openstack/identity_v2' require 'fog/openstack/identity_v3' require 'fog/openstack/image_v1' require 'fog/openstack/image_v2' require 'fog/openstack/storage' require 'fog/openstack/volume_v1' require 'fog/openstack/volume_v2' require 'fog/openstack/planning' module Fog module Compute autoload :OpenStack, File.expand_path('../openstack/compute', __FILE__) end module Identity autoload :OpenStack, File.expand_path('../openstack/identity', __FILE__) end module Image autoload :OpenStack, File.expand_path('../openstack/image', __FILE__) end module Metering autoload :OpenStack, File.expand_path('../openstack/metering', __FILE__) end module Network autoload :OpenStack, File.expand_path('../openstack/network', __FILE__) end module Orchestration autoload :OpenStack, File.expand_path('../openstack/orchestration', __FILE__) end module NFV autoload :OpenStack, File.expand_path('../openstack/nfv', __FILE__) end module Volume autoload :OpenStack, File.expand_path('../openstack/volume', __FILE__) end module Baremetal autoload :OpenStack, File.expand_path('../openstack/baremetal', __FILE__) end module Introspection autoload :OpenStack, File.expand_path('../openstack/introspection', __FILE__) end module OpenStack extend Fog::Provider service(:compute, 'Compute') service(:image, 'Image') service(:identity, 'Identity') service(:network, 'Network') service(:storage, 'Storage') service(:volume, 'Volume') service(:metering, 'Metering') service(:orchestration, 'Orchestration') service(:nfv, 'NFV') service(:baremetal, 'Baremetal') service(:planning, 'Planning') service(:introspection, 'Introspection') @@token_cache = {} def self.clear_token_cache @@token_cache.clear end def self.authenticate(options, connection_options = {}) case options[:openstack_auth_uri].path when /v1(\.\d+)?/ authenticate_v1(options, connection_options) when /v2(\.\d+)?/ authenticate_v2(options, connection_options) when /v3(\.\d+)?/ authenticate_v3(options, connection_options) else authenticate_v2(options, connection_options) end end # legacy v1.0 style auth def self.authenticate_v1(options, connection_options = {}) uri = options[:openstack_auth_uri] connection = Fog::Core::Connection.new(uri.to_s, false, connection_options) @openstack_api_key = options[:openstack_api_key] @openstack_username = options[:openstack_username] response = connection.request({ :expects => [200, 204], :headers => { 'X-Auth-Key' => @openstack_api_key, 'X-Auth-User' => @openstack_username }, :method => 'GET', :path => (uri.path and not uri.path.empty?) ? uri.path : 'v1.0' }) return { :token => response.headers['X-Auth-Token'], :server_management_url => response.headers['X-Server-Management-Url'] || response.headers['X-Storage-Url'], :identity_public_endpoint => response.headers['X-Keystone'] } end # Keystone Style Auth def self.authenticate_v2(options, connection_options = {}) uri = options[:openstack_auth_uri] tenant_name = options[:openstack_tenant] service_type = options[:openstack_service_type] service_name = options[:openstack_service_name] identity_service_type = options[:openstack_identity_service_type] endpoint_type = (options[:openstack_endpoint_type] || 'publicURL').to_s openstack_region = options[:openstack_region] body = retrieve_tokens_v2(options, connection_options) service = get_service(body, service_type, service_name) options[:unscoped_token] = body['access']['token']['id'] unless service unless tenant_name response = Fog::Core::Connection.new( "#{uri.scheme}://#{uri.host}:#{uri.port}/v2.0/tenants", false, connection_options).request({ :expects => [200, 204], :headers => {'Content-Type' => 'application/json', 'Accept' => 'application/json', 'X-Auth-Token' => body['access']['token']['id']}, :method => 'GET' }) body = Fog::JSON.decode(response.body) if body['tenants'].empty? raise Fog::Errors::NotFound.new('No Tenant Found') else options[:openstack_tenant] = body['tenants'].first['name'] end end body = retrieve_tokens_v2(options, connection_options) service = get_service(body, service_type, service_name) end unless service available = body['access']['serviceCatalog'].map { |endpoint| endpoint['type'] }.sort.join ', ' missing = service_type.join ', ' message = "Could not find service #{missing}. Have #{available}" raise Fog::Errors::NotFound, message end service['endpoints'] = service['endpoints'].select do |endpoint| endpoint['region'] == openstack_region end if openstack_region if service['endpoints'].empty? raise Fog::Errors::NotFound.new("No endpoints available for region '#{openstack_region}'") end if openstack_region regions = service["endpoints"].map{ |e| e['region'] }.uniq if regions.count > 1 raise Fog::Errors::NotFound.new("Multiple regions available choose one of these '#{regions.join(',')}'") end identity_service = get_service(body, identity_service_type) if identity_service_type tenant = body['access']['token']['tenant'] user = body['access']['user'] management_url = service['endpoints'].find{|s| s[endpoint_type]}[endpoint_type] identity_url = identity_service['endpoints'].find{|s| s['publicURL']}['publicURL'] if identity_service { :user => user, :tenant => tenant, :identity_public_endpoint => identity_url, :server_management_url => management_url, :token => body['access']['token']['id'], :expires => body['access']['token']['expires'], :current_user_id => body['access']['user']['id'], :unscoped_token => options[:unscoped_token] } end # Keystone Style Auth def self.authenticate_v3(options, connection_options = {}) uri = options[:openstack_auth_uri] project_name = options[:openstack_project_name] service_type = options[:openstack_service_type] service_name = options[:openstack_service_name] identity_service_type = options[:openstack_identity_service_type] endpoint_type = map_endpoint_type(options[:openstack_endpoint_type] || 'publicURL') openstack_region = options[:openstack_region] token, body = retrieve_tokens_v3 options, connection_options service = get_service_v3(body, service_type, service_name, openstack_region, options) options[:unscoped_token] = token unless service unless project_name request_body = { :expects => [200], :headers => {'Content-Type' => 'application/json', 'Accept' => 'application/json', 'X-Auth-Token' => token}, :method => 'GET' } user_id = body['token']['user']['id'] project_uri = uri.clone project_uri.path = uri.path.sub('/auth/tokens', "/users/#{user_id}/projects") project_uri_param = "#{project_uri.scheme}://#{project_uri.host}:#{project_uri.port}#{project_uri.path}" response = Fog::Core::Connection.new(project_uri_param, false, connection_options).request(request_body) projects_body = Fog::JSON.decode(response.body) if projects_body['projects'].empty? options[:openstack_domain_id] = body['token']['user']['domain']['id'] else options[:openstack_project_id] = projects_body['projects'].first['id'] options[:openstack_project_name] = projects_body['projects'].first['name'] options[:openstack_domain_id] = projects_body['projects'].first['domain_id'] end end token, body = retrieve_tokens_v3(options, connection_options) service = get_service_v3(body, service_type, service_name, openstack_region, options) end unless service available_services = body['token']['catalog'].map { |service| service['type'] }.sort.join ', ' available_regions = body['token']['catalog'].map { |service| service['endpoints'].map { |endpoint| endpoint['region'] }.uniq }.uniq.sort.join ', ' missing = service_type.join ', ' message = "Could not find service #{missing}#{(' in region '+openstack_region) if openstack_region}."+ " Have #{available_services}#{(' in regions '+available_regions) if openstack_region}" raise Fog::Errors::NotFound, message end service['endpoints'] = service['endpoints'].select do |endpoint| endpoint['region'] == openstack_region && endpoint['interface'] == endpoint_type end if openstack_region if service['endpoints'].empty? raise Fog::Errors::NotFound.new("No endpoints available for region '#{openstack_region}'") end if openstack_region regions = service["endpoints"].map { |e| e['region'] }.uniq if regions.count > 1 raise Fog::Errors::NotFound.new("Multiple regions available choose one of these '#{regions.join(',')}'") end identity_service = get_service_v3(body, identity_service_type, nil, nil, :openstack_endpoint_path_matches => /\/v3/) if identity_service_type management_url = service['endpoints'].find { |e| e['interface']==endpoint_type }['url'] identity_url = identity_service['endpoints'].find { |e| e['interface']=='public' }['url'] if identity_service if body['token']['project'] tenant = body['token']['project'] elsif body['token']['user']['project'] tenant = body['token']['user']['project'] end return { :user => body['token']['user']['name'], :tenant => tenant, :identity_public_endpoint => identity_url, :server_management_url => management_url, :token => token, :expires => body['token']['expires_at'], :current_user_id => body['token']['user']['id'], :unscoped_token => options[:unscoped_token] } end def self.get_service(body, service_type=[], service_name=nil) if not body['access'].nil? body['access']['serviceCatalog'].find do |s| if service_name.nil? or service_name.empty? service_type.include?(s['type']) else service_type.include?(s['type']) and s['name'] == service_name end end elsif not body['token']['catalog'].nil? body['token']['catalog'].find do |s| if service_name.nil? or service_name.empty? service_type.include?(s['type']) else service_type.include?(s['type']) and s['name'] == service_name end end end end def self.retrieve_tokens_v2(options, connection_options = {}) api_key = options[:openstack_api_key].to_s username = options[:openstack_username].to_s tenant_name = options[:openstack_tenant].to_s auth_token = options[:openstack_auth_token] || options[:unscoped_token] uri = options[:openstack_auth_uri] omit_default_port = options[:openstack_auth_omit_default_port] identity_v2_connection = Fog::Core::Connection.new(uri.to_s, false, connection_options) request_body = {:auth => Hash.new} if auth_token request_body[:auth][:token] = { :id => auth_token } else request_body[:auth][:passwordCredentials] = { :username => username, :password => api_key } end request_body[:auth][:tenantName] = tenant_name if tenant_name request = { :expects => [200, 204], :headers => {'Content-Type' => 'application/json'}, :body => Fog::JSON.encode(request_body), :method => 'POST', :path => (uri.path and not uri.path.empty?) ? uri.path : 'v2.0' } request[:omit_default_port] = omit_default_port unless omit_default_port.nil? response = identity_v2_connection.request(request) Fog::JSON.decode(response.body) end def self.retrieve_tokens_v3(options, connection_options = {}) api_key = options[:openstack_api_key].to_s username = options[:openstack_username].to_s userid = options[:openstack_userid] domain_id = options[:openstack_domain_id] domain_name = options[:openstack_domain_name] project_domain = options[:openstack_project_domain] project_domain_id = options[:openstack_project_domain_id] user_domain = options[:openstack_user_domain] user_domain_id = options[:openstack_user_domain_id] project_name = options[:openstack_project_name] project_id = options[:openstack_project_id] auth_token = options[:openstack_auth_token] || options[:unscoped_token] uri = options[:openstack_auth_uri] omit_default_port = options[:openstack_auth_omit_default_port] cache_ttl = options[:openstack_cache_ttl] || 0 connection = Fog::Core::Connection.new(uri.to_s, false, connection_options) request_body = {:auth => {}} scope = {} if project_name || project_id scope[:project] = if project_id.nil? then if project_domain || project_domain_id {:name => project_name, :domain => project_domain_id.nil? ? {:name => project_domain} : {:id => project_domain_id}} else {:name => project_name, :domain => domain_id.nil? ? {:name => domain_name} : {:id => domain_id}} end else {:id => project_id} end elsif domain_name || domain_id scope[:domain] = domain_id.nil? ? {:name => domain_name} : {:id => domain_id} else # unscoped token end if auth_token request_body[:auth][:identity] = { :methods => %w{token}, :token => { :id => auth_token } } else request_body[:auth][:identity] = { :methods => %w{password}, :password => { :user => { :password => api_key } } } if userid request_body[:auth][:identity][:password][:user][:id] = userid else if user_domain || user_domain_id request_body[:auth][:identity][:password][:user].merge! :domain => user_domain_id.nil? ? {:name => user_domain} : {:id => user_domain_id} elsif domain_name || domain_id request_body[:auth][:identity][:password][:user].merge! :domain => domain_id.nil? ? {:name => domain_name} : {:id => domain_id} end request_body[:auth][:identity][:password][:user][:name] = username end end request_body[:auth][:scope] = scope unless scope.empty? path = (uri.path and not uri.path.empty?) ? uri.path : 'v3' response, expires = @@token_cache[{:body => request_body, :path => path}] if cache_ttl > 0 unless response && expires > Time.now request = { :expects => [201], :headers => {'Content-Type' => 'application/json'}, :body => Fog::JSON.encode(request_body), :method => 'POST', :path => path } request[:omit_default_port] = omit_default_port unless omit_default_port.nil? response = connection.request(request) @@token_cache[{:body => request_body, :path => path}] = response, Time.now + cache_ttl if cache_ttl > 0 end [response.headers["X-Subject-Token"], Fog::JSON.decode(response.body)] end def self.get_service_v3(hash, service_type=[], service_name=nil, region=nil, options={}) # Find all services matching any of the types in service_type, filtered by service_name if it's non-nil services = hash['token']['catalog'].find_all do |s| if service_name.nil? or service_name.empty? service_type.include?(s['type']) else service_type.include?(s['type']) and s['name'] == service_name end end if hash['token']['catalog'] # Filter the found services by region (if specified) and whether the endpoint path matches the given regex (e.g. /\/v3/) services.find do |s| s['endpoints'].any? { |ep| endpoint_region?(ep, region) && endpoint_path_match?(ep, options[:openstack_endpoint_path_matches])} end if services end def self.endpoint_region?(endpoint, region) region.nil? || endpoint['region'] == region end def self.endpoint_path_match?(endpoint, match_regex) match_regex.nil? || URI(endpoint['url']).path =~ match_regex end def self.get_supported_version(supported_versions, uri, auth_token, connection_options = {}) connection = Fog::Core::Connection.new("#{uri.scheme}://#{uri.host}:#{uri.port}", false, connection_options) response = connection.request({ :expects => [200, 204, 300], :headers => {'Content-Type' => 'application/json', 'Accept' => 'application/json', 'X-Auth-Token' => auth_token}, :method => 'GET' }) body = Fog::JSON.decode(response.body) version = nil unless body['versions'].empty? supported_version = body['versions'].find do |x| x["id"].match(supported_versions) && (x["status"] == "CURRENT" || x["status"] == "SUPPORTED") end version = supported_version["id"] if supported_version end if version.nil? raise Fog::OpenStack::Errors::ServiceUnavailable.new( "OpenStack service only supports API versions #{supported_versions.inspect}") end version end def self.get_supported_version_path(supported_versions, uri, auth_token, connection_options = {}) # Find a version in the path (e.g. the v1 in /xyz/v1/tenantid/abc) and get the path up until that version (e.g. /xyz)) path_components = uri.path.split '/' version_component_index = path_components.index{|comp| comp.match(/v[0-9].?[0-9]?/) } versionless_path = (path_components.take(version_component_index).join '/' if version_component_index) || uri.path connection = Fog::Core::Connection.new("#{uri.scheme}://#{uri.host}:#{uri.port}#{versionless_path}", false, connection_options) response = connection.request({ :expects => [200, 204, 300], :headers => {'Content-Type' => 'application/json', 'Accept' => 'application/json', 'X-Auth-Token' => auth_token}, :method => 'GET' }) body = Fog::JSON.decode(response.body) path = nil unless body['versions'].empty? supported_version = body['versions'].find do |x| x["id"].match(supported_versions) && (x["status"] == "CURRENT" || x["status"] == "SUPPORTED") end path = URI.parse(supported_version['links'].first['href']).path if supported_version end if path.nil? raise Fog::OpenStack::Errors::ServiceUnavailable.new( "OpenStack service only supports API versions #{supported_versions.inspect}") end path.chomp '/' end # CGI.escape, but without special treatment on spaces def self.escape(str, extra_exclude_chars = '') str.gsub(/([^a-zA-Z0-9_.-#{extra_exclude_chars}]+)/) do '%' + $1.unpack('H2' * $1.bytesize).join('%').upcase end end def self.map_endpoint_type type case type when "publicURL" "public" when "internalURL" "internal" when "adminURL" "admin" end end end end fog-openstack-0.1.6/lib/fog/openstack/0000755000175600017570000000000012730051546016632 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/network.rb0000644000175600017570000002670412730051546020661 0ustar pravipravi module Fog module Network class OpenStack < Fog::Service SUPPORTED_VERSIONS = /v2(\.0)*/ requires :openstack_auth_url recognizes :openstack_auth_token, :openstack_management_url, :persistent, :openstack_service_type, :openstack_service_name, :openstack_tenant, :openstack_tenant_id, :openstack_api_key, :openstack_username, :openstack_identity_endpoint, :current_user, :current_tenant, :openstack_region, :openstack_endpoint_type, :openstack_cache_ttl, :openstack_project_name, :openstack_project_id, :openstack_project_domain, :openstack_user_domain, :openstack_domain_name, :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id, :openstack_identity_prefix ## MODELS # model_path 'fog/openstack/models/network' model :network collection :networks model :port collection :ports model :subnet collection :subnets model :floating_ip collection :floating_ips model :router collection :routers model :lb_pool collection :lb_pools model :lb_member collection :lb_members model :lb_health_monitor collection :lb_health_monitors model :lb_vip collection :lb_vips model :vpn_service collection :vpn_services model :ike_policy collection :ike_policies model :ipsec_policy collection :ipsec_policies model :ipsec_site_connection collection :ipsec_site_connections model :rbac_policy collection :rbac_policies model :security_group collection :security_groups model :security_group_rule collection :security_group_rules ## REQUESTS # request_path 'fog/openstack/requests/network' # Network CRUD request :list_networks request :create_network request :delete_network request :get_network request :update_network # Port CRUD request :list_ports request :create_port request :delete_port request :get_port request :update_port # Subnet CRUD request :list_subnets request :create_subnet request :delete_subnet request :get_subnet request :update_subnet # FloatingIp CRUD request :list_floating_ips request :create_floating_ip request :delete_floating_ip request :get_floating_ip request :associate_floating_ip request :disassociate_floating_ip # Router CRUD request :list_routers request :create_router request :delete_router request :get_router request :update_router request :add_router_interface request :remove_router_interface # LBaaS Pool CRUD request :list_lb_pools request :create_lb_pool request :delete_lb_pool request :get_lb_pool request :get_lb_pool_stats request :update_lb_pool # LBaaS Member CRUD request :list_lb_members request :create_lb_member request :delete_lb_member request :get_lb_member request :update_lb_member # LBaaS Health Monitor CRUD request :list_lb_health_monitors request :create_lb_health_monitor request :delete_lb_health_monitor request :get_lb_health_monitor request :update_lb_health_monitor request :associate_lb_health_monitor request :disassociate_lb_health_monitor # LBaaS VIP CRUD request :list_lb_vips request :create_lb_vip request :delete_lb_vip request :get_lb_vip request :update_lb_vip # VPNaaS VPN Service CRUD request :list_vpn_services request :create_vpn_service request :delete_vpn_service request :get_vpn_service request :update_vpn_service # VPNaaS VPN IKE Policy CRUD request :list_ike_policies request :create_ike_policy request :delete_ike_policy request :get_ike_policy request :update_ike_policy # VPNaaS VPN IPSec Policy CRUD request :list_ipsec_policies request :create_ipsec_policy request :delete_ipsec_policy request :get_ipsec_policy request :update_ipsec_policy # VPNaaS VPN IPSec Site Connection CRUD request :list_ipsec_site_connections request :create_ipsec_site_connection request :delete_ipsec_site_connection request :get_ipsec_site_connection request :update_ipsec_site_connection # RBAC Policy CRUD request :list_rbac_policies request :create_rbac_policy request :delete_rbac_policy request :get_rbac_policy request :update_rbac_policy # Security Group request :create_security_group request :delete_security_group request :get_security_group request :list_security_groups # Security Group Rules request :create_security_group_rule request :delete_security_group_rule request :get_security_group_rule request :list_security_group_rules # Tenant request :set_tenant # Quota request :get_quotas request :get_quota request :update_quota request :delete_quota class Mock def self.data @data ||= Hash.new do |hash, key| network_id = Fog::UUID.uuid subnet_id = Fog::UUID.uuid tenant_id = Fog::Mock.random_hex(8) hash[key] = { :networks => { network_id => { 'id' => network_id, 'name' => 'Public', 'subnets' => [subnet_id], 'shared' => true, 'status' => 'ACTIVE', 'tenant_id' => tenant_id, 'provider_network_type' => 'vlan', 'router:external' => false, 'admin_state_up' => true, }, 'e624a36d-762b-481f-9b50-4154ceb78bbb' => { 'id' => 'e624a36d-762b-481f-9b50-4154ceb78bbb', 'name' => 'network_1', 'subnets' => ['2e4ec6a4-0150-47f5-8523-e899ac03026e'], 'shared' => false, 'status' => 'ACTIVE', 'admin_state_up' => true, 'tenant_id' => 'f8b26a6032bc47718a7702233ac708b9', } }, :ports => {}, :subnets => { subnet_id => { 'id' => subnet_id, 'name' => "Public", 'network_id' => network_id, 'cidr' => "192.168.0.0/22", 'ip_version' => 4, 'gateway_ip' => Fog::Mock.random_ip, 'allocation_pools' => [], 'dns_nameservers' => [Fog::Mock.random_ip, Fog::Mock.random_ip], 'host_routes' => [Fog::Mock.random_ip], 'enable_dhcp' => true, 'tenant_id' => tenant_id, } }, :floating_ips => {}, :routers => {}, :lb_pools => {}, :lb_members => {}, :lb_health_monitors => {}, :lb_vips => {}, :vpn_services => {}, :ike_policies => {}, :ipsec_policies => {}, :ipsec_site_connections => {}, :rbac_policies => {}, :quota => { "subnet" => 10, "router" => 10, "port" => 50, "network" => 10, "floatingip" => 50 }, :quotas => [ { "subnet" => 10, "network" => 10, "floatingip" => 50, "tenant_id" => tenant_id, "router" => 10, "port" => 30 } ], :security_groups => {}, :security_group_rules => {}, } end end def self.reset @data = nil end include Fog::OpenStack::Core def initialize(options = {}) @auth_token = Fog::Mock.random_base64(64) @auth_token_expiration = (Time.now.utc + 86400).iso8601 initialize_identity options end def data self.class.data["#{@openstack_username}-#{@openstack_tenant}"] end def reset_data self.class.data.delete("#{@openstack_username}-#{@openstack_tenant}") end end class Real include Fog::OpenStack::Core def initialize(options = {}) initialize_identity options @openstack_service_type = options[:openstack_service_type] || ['network'] @openstack_service_name = options[:openstack_service_name] @connection_options = options[:connection_options] || {} authenticate set_api_path @persistent = options[:persistent] || false @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end def request(params) begin response = @connection.request(params.merge( :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'X-Auth-Token' => @auth_token }.merge!(params[:headers] || {}), :path => "#{@path}/#{params[:path]}" # , )) rescue Excon::Errors::Unauthorized => error if error.response.body != 'Bad username or password' # token expiration @openstack_must_reauthenticate = true authenticate set_api_path retry else # bad credentials raise error end rescue Excon::Errors::HTTPStatusError => error raise case error when Excon::Errors::NotFound Fog::Network::OpenStack::NotFound.slurp(error) else error end end unless response.body.empty? response.body = Fog::JSON.decode(response.body) end response end def set_api_path @path.sub!(%r{\/$}, '') unless @path.match(SUPPORTED_VERSIONS) @path = Fog::OpenStack.get_supported_version_path(SUPPORTED_VERSIONS, @openstack_management_uri, @auth_token, @connection_options) end end end end end end fog-openstack-0.1.6/lib/fog/openstack/errors.rb0000644000175600017570000000225712730051546020501 0ustar pravipravimodule Fog module OpenStack module Errors class ServiceError < Fog::Errors::Error attr_reader :response_data def self.slurp(error) if error.response.body.empty? data = nil message = nil else data = Fog::JSON.decode(error.response.body) message = data['message'] if message.nil? and !data.values.first.nil? message = data.values.first['message'] end end new_error = super(error, message) new_error.instance_variable_set(:@response_data, data) new_error end end class ServiceUnavailable < ServiceError; end class BadRequest < ServiceError attr_reader :validation_errors def self.slurp(error) new_error = super(error) unless new_error.response_data.nil? or new_error.response_data['badRequest'].nil? new_error.instance_variable_set(:@validation_errors, new_error.response_data['badRequest']['validationErrors']) end new_error end end class InterfaceNotImplemented < Fog::Errors::Error; end end end end fog-openstack-0.1.6/lib/fog/openstack/identity.rb0000644000175600017570000000735612730051546021023 0ustar pravipravi module Fog module Identity class OpenStack < Fog::Service requires :openstack_auth_url recognizes :openstack_auth_token, :openstack_management_url, :persistent, :openstack_service_type, :openstack_service_name, :openstack_tenant, :openstack_endpoint_type, :openstack_region, :openstack_domain_id, :openstack_project_name, :openstack_domain_name, :openstack_user_domain, :openstack_project_domain, :openstack_user_domain_id, :openstack_project_domain_id, :openstack_api_key, :openstack_current_user_id, :openstack_userid, :openstack_username, :current_user, :current_user_id, :current_tenant, :openstack_cache_ttl, :provider, :openstack_identity_prefix, :openstack_endpoint_path_matches # Fog::Identity::OpenStack.new() will return a Fog::Identity::OpenStack::V3 by default def self.new(args = {}) version = '3' url = Fog.credentials[:openstack_auth_url] || args[:openstack_auth_url] if url uri = URI(url) version = '2.0' if uri.path =~ /v2\.0/ end service = case version when '2.0' Fog::Identity::OpenStack::V2.new(args) else Fog::Identity::OpenStack::V3.new(args) end service end class Mock attr_reader :config def initialize(options = {}) @openstack_auth_uri = URI.parse(options[:openstack_auth_url]) @config = options end end class Real DEFAULT_SERVICE_TYPE_V3 = %w(identity_v3 identityv3 identity).collect(&:freeze).freeze DEFAULT_SERVICE_TYPE = %w(identity).collect(&:freeze).freeze def self.not_found_class Fog::Identity::OpenStack::NotFound end include Fog::OpenStack::Common def initialize(options = {}) if options.respond_to?(:config_service?) && options.config_service? configure(options) return end initialize_identity(options) @openstack_service_type = options[:openstack_service_type] || default_service_type(options) @openstack_service_name = options[:openstack_service_name] @connection_options = options[:connection_options] || {} @openstack_endpoint_type = options[:openstack_endpoint_type] || 'adminURL' initialize_endpoint_path_matches(options) authenticate if options[:openstack_identity_prefix] @path = "/#{options[:openstack_identity_prefix]}/#{@path}" end @persistent = options[:persistent] || false @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end def config_service? true end def config self end private def default_service_type(options) unless options[:openstack_identity_prefix] if @openstack_auth_uri.path =~ %r{/v3} || (options[:openstack_endpoint_path_matches] && options[:openstack_endpoint_path_matches] =~ '/v3') return DEFAULT_SERVICE_TYPE_V3 end end DEFAULT_SERVICE_TYPE end def initialize_endpoint_path_matches(options) if options[:openstack_endpoint_path_matches] @openstack_endpoint_path_matches = options[:openstack_endpoint_path_matches] end end def configure(source) source.instance_variables.each do |v| instance_variable_set(v, source.instance_variable_get(v)) end end end end end end fog-openstack-0.1.6/lib/fog/openstack/volume_v1.rb0000644000175600017570000001217112730051546021076 0ustar pravipravirequire 'fog/openstack/core' require 'fog/openstack/common' require 'fog/openstack/volume' module Fog module Volume class OpenStack class V1 < Fog::Volume::OpenStack SUPPORTED_VERSIONS = /v1(\.(0-9))*/ requires :openstack_auth_url recognizes *@@recognizes model_path 'fog/openstack/models/volume_v1' model :volume collection :volumes model :availability_zone collection :availability_zones model :volume_type collection :volume_types model :snapshot collection :snapshots model :transfer collection :transfers request_path 'fog/openstack/requests/volume_v1' # Volume request :list_volumes request :list_volumes_detailed request :create_volume request :update_volume request :get_volume_details request :extend_volume request :delete_volume request :list_zones request :list_volume_types request :create_volume_type request :delete_volume_type request :get_volume_type_details request :create_snapshot request :update_snapshot request :list_snapshots request :list_snapshots_detailed request :get_snapshot_details request :delete_snapshot request :update_snapshot_metadata request :delete_snapshot_metadata request :list_transfers request :list_transfers_detailed request :create_transfer request :get_transfer_details request :accept_transfer request :delete_transfer request :update_quota request :get_quota request :get_quota_defaults request :get_quota_usage request :update_metadata request :replace_metadata request :delete_metadata request :set_tenant request :action class Mock def self.data @data ||= Hash.new do |hash, key| hash[key] = { :users => {}, :tenants => {}, :quota => { 'gigabytes' => 1000, 'volumes' => 10, 'snapshots' => 10 } } end end def self.reset @data = nil end def initialize(options = {}) @openstack_username = options[:openstack_username] @openstack_tenant = options[:openstack_tenant] @openstack_auth_uri = URI.parse(options[:openstack_auth_url]) @auth_token = Fog::Mock.random_base64(64) @auth_token_expiration = (Time.now.utc + 86400).iso8601 management_url = URI.parse(options[:openstack_auth_url]) management_url.port = 8776 management_url.path = '/v1' @openstack_management_url = management_url.to_s @data ||= {:users => {}} unless @data[:users].find { |u| u['name'] == options[:openstack_username] } id = Fog::Mock.random_numbers(6).to_s @data[:users][id] = { 'id' => id, 'name' => options[:openstack_username], 'email' => "#{options[:openstack_username]}@mock.com", 'tenantId' => Fog::Mock.random_numbers(6).to_s, 'enabled' => true } end end def data self.class.data[@openstack_username] end def reset_data self.class.data.delete(@openstack_username) end def credentials {:provider => 'openstack', :openstack_auth_url => @openstack_auth_uri.to_s, :openstack_auth_token => @auth_token, :openstack_management_url => @openstack_management_url} end end class Real include Fog::OpenStack::Core def self.not_found_class Fog::Volume::OpenStack::NotFound end include Fog::OpenStack::Common def initialize(options = {}) initialize_identity options @openstack_service_type = options[:openstack_service_type] || ['volume'] @openstack_service_name = options[:openstack_service_name] @openstack_endpoint_type = options[:openstack_endpoint_type] || 'adminURL' @connection_options = options[:connection_options] || {} authenticate unless @path.match(SUPPORTED_VERSIONS) @path = Fog::OpenStack.get_supported_version_path(SUPPORTED_VERSIONS, @openstack_management_uri, @auth_token, @connection_options) end @persistent = options[:persistent] || false @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end end end end end end fog-openstack-0.1.6/lib/fog/openstack/volume.rb0000644000175600017570000000264312730051546020473 0ustar pravipravi module Fog module Volume class OpenStack < Fog::Service @@recognizes = [:openstack_auth_token, :openstack_management_url, :persistent, :openstack_service_type, :openstack_service_name, :openstack_tenant, :openstack_tenant_id, :openstack_api_key, :openstack_username, :openstack_identity_endpoint, :current_user, :current_tenant, :openstack_region, :openstack_endpoint_type, :openstack_cache_ttl, :openstack_project_name, :openstack_project_id, :openstack_project_domain, :openstack_user_domain, :openstack_domain_name, :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id, :openstack_identity_prefix] # Fog::Image::OpenStack.new() will return a Fog::Volume::OpenStack::V2 or a Fog::Volume::OpenStack::V1, # choosing the V2 by default, as V1 is deprecated since OpenStack Juno def self.new(args = {}) @openstack_auth_uri = URI.parse(args[:openstack_auth_url]) if args[:openstack_auth_url] if self.inspect == 'Fog::Volume::OpenStack' service = Fog::Volume::OpenStack::V2.new(args) || Fog::Volume::OpenStack::V1.new(args) else service = super end service end end end end fog-openstack-0.1.6/lib/fog/openstack/version.rb0000644000175600017570000000007612730051546020647 0ustar pravipravimodule Fog module Openstack VERSION = "0.1.6" end end fog-openstack-0.1.6/lib/fog/openstack/identity_v3.rb0000644000175600017570000001310612730051546021421 0ustar pravipravi require 'fog/openstack/common' require 'fog/openstack/identity' module Fog module Identity class OpenStack class V3 < Fog::Service requires :openstack_auth_url recognizes :openstack_auth_token, :openstack_management_url, :persistent, :openstack_service_type, :openstack_service_name, :openstack_tenant, :openstack_endpoint_type, :openstack_region, :openstack_domain_id, :openstack_project_name, :openstack_domain_name, :openstack_user_domain, :openstack_project_domain, :openstack_user_domain_id, :openstack_project_domain_id, :openstack_api_key, :openstack_current_user_id, :openstack_userid, :openstack_username, :current_user, :current_user_id, :current_tenant, :provider, :openstack_identity_prefix, :openstack_endpoint_path_matches, :openstack_cache_ttl model_path 'fog/openstack/models/identity_v3' model :domain collection :domains model :endpoint collection :endpoints model :project collection :projects model :service collection :services model :token collection :tokens model :user collection :users model :group collection :groups model :role collection :roles model :role_assignment collection :role_assignments model :os_credential collection :os_credentials model :policy collection :policies request_path 'fog/openstack/requests/identity_v3' request :list_users request :get_user request :create_user request :update_user request :delete_user request :list_user_groups request :list_user_projects request :list_groups request :get_group request :create_group request :update_group request :delete_group request :add_user_to_group request :remove_user_from_group request :group_user_check request :list_group_users request :list_roles request :list_role_assignments request :get_role request :create_role request :update_role request :delete_role request :auth_domains request :auth_projects request :list_domains request :get_domain request :create_domain request :update_domain request :delete_domain request :list_domain_user_roles request :grant_domain_user_role request :check_domain_user_role request :revoke_domain_user_role request :list_domain_group_roles request :grant_domain_group_role request :check_domain_group_role request :revoke_domain_group_role request :list_endpoints request :get_endpoint request :create_endpoint request :update_endpoint request :delete_endpoint request :list_projects request :get_project request :create_project request :update_project request :delete_project request :list_project_user_roles request :grant_project_user_role request :check_project_user_role request :revoke_project_user_role request :list_project_group_roles request :grant_project_group_role request :check_project_group_role request :revoke_project_group_role request :list_services request :get_service request :create_service request :update_service request :delete_service request :token_authenticate request :token_validate request :token_check request :token_revoke request :list_os_credentials request :get_os_credential request :create_os_credential request :update_os_credential request :delete_os_credential request :list_policies request :get_policy request :create_policy request :update_policy request :delete_policy class Mock include Fog::OpenStack::Core def initialize(options={}) end end def self.get_api_version uri, connection_options={} connection = Fog::Core::Connection.new(uri, false, connection_options) response = connection.request({ :expects => [200], :headers => {'Content-Type' => 'application/json', 'Accept' => 'application/json'}, :method => 'GET' }) body = Fog::JSON.decode(response.body) version = nil unless body['version'].empty? version = body['version']['id'] end if version.nil? raise Fog::OpenStack::Errors::ServiceUnavailable.new( "No version available at #{uri}") end version end class Real < Fog::Identity::OpenStack::Real private def default_service_type(_) DEFAULT_SERVICE_TYPE_V3 end def initialize_endpoint_path_matches(options) if options[:openstack_endpoint_path_matches] @openstack_endpoint_path_matches = options[:openstack_endpoint_path_matches] else @openstack_endpoint_path_matches = %r{/v3} unless options[:openstack_identity_prefix] end end end end end end end fog-openstack-0.1.6/lib/fog/openstack/image.rb0000644000175600017570000000117212730051546020242 0ustar pravipravi module Fog module Image class OpenStack < Fog::Service # Fog::Image::OpenStack.new() will return a Fog::Image::OpenStack::V2 or a Fog::Image::OpenStack::V1, # choosing the latest available def self.new(args = {}) @openstack_auth_uri = URI.parse(args[:openstack_auth_url]) if args[:openstack_auth_url] if self.inspect == 'Fog::Image::OpenStack' service = Fog::Image::OpenStack::V2.new(args) unless args.empty? service ||= Fog::Image::OpenStack::V1.new(args) else service = Fog::Service.new(args) end service end end end end fog-openstack-0.1.6/lib/fog/openstack/planning.rb0000644000175600017570000001320112730051546020762 0ustar pravipravi module Fog module Openstack class Planning < Fog::Service SUPPORTED_VERSIONS = /v2/ requires :openstack_auth_url recognizes :openstack_auth_token, :openstack_management_url, :persistent, :openstack_service_type, :openstack_service_name, :openstack_tenant, :openstack_tenant_id, :openstack_api_key, :openstack_username, :openstack_identity_endpoint, :current_user, :current_tenant, :openstack_region, :openstack_endpoint_type, :openstack_cache_ttl, :openstack_project_name, :openstack_project_id, :openstack_project_domain, :openstack_user_domain, :openstack_domain_name, :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id, :openstack_identity_prefix ## MODELS # model_path 'fog/openstack/models/planning' model :role collection :roles model :plan collection :plans ## REQUESTS # request_path 'fog/openstack/requests/planning' # Role requests request :list_roles # Plan requests request :list_plans request :get_plan_templates request :get_plan request :patch_plan request :create_plan request :delete_plan request :add_role_to_plan request :remove_role_from_plan class Mock def self.data @data ||= Hash.new end def self.reset @data = nil end def initialize(options={}) @openstack_username = options[:openstack_username] @openstack_tenant = options[:openstack_tenant] @openstack_auth_uri = URI.parse(options[:openstack_auth_url]) @auth_token = Fog::Mock.random_base64(64) @auth_token_expiration = (Time.now.utc + 86400).iso8601 management_url = URI.parse(options[:openstack_auth_url]) management_url.port = 9292 management_url.path = '/v1' @openstack_management_url = management_url.to_s @data ||= { :users => {} } unless @data[:users].find {|u| u['name'] == options[:openstack_username]} id = Fog::Mock.random_numbers(6).to_s @data[:users][id] = { 'id' => id, 'name' => options[:openstack_username], 'email' => "#{options[:openstack_username]}@mock.com", 'tenantId' => Fog::Mock.random_numbers(6).to_s, 'enabled' => true } end end def data self.class.data[@openstack_username] end def reset_data self.class.data.delete(@openstack_username) end def credentials { :provider => 'openstack', :openstack_auth_url => @openstack_auth_uri.to_s, :openstack_auth_token => @auth_token, :openstack_region => @openstack_region, :openstack_management_url => @openstack_management_url } end end class Real include Fog::OpenStack::Core def initialize(options={}) initialize_identity options @openstack_service_type = options[:openstack_service_type] || ['management'] # currently Tuskar is configured as 'management' service in Keystone @openstack_service_name = options[:openstack_service_name] @openstack_endpoint_type = options[:openstack_endpoint_type] || 'adminURL' @connection_options = options[:connection_options] || {} authenticate unless @path.match(SUPPORTED_VERSIONS) @path = "/v2" end @persistent = options[:persistent] || false @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end def request(params) begin response = @connection.request(params.merge({ :headers => { 'Content-Type' => 'application/json', 'X-Auth-Token' => @auth_token }.merge!(params[:headers] || {}), :path => "#{@path}/#{params[:path]}"#, })) rescue Excon::Errors::Unauthorized => error if error.response.body != 'Bad username or password' # token expiration @openstack_must_reauthenticate = true authenticate retry else # bad credentials raise error end rescue Excon::Errors::HTTPStatusError => error raise case error when Excon::Errors::NotFound Fog::Compute::OpenStack::NotFound.slurp(error) else error end end unless response.body.empty? response.body = Fog::JSON.decode(response.body) end response end private end end def self.[](service) new(:service => service) end def self.new(attributes) attributes = attributes.dup # Prevent delete from having side effects service = attributes.delete(:service).to_s.downcase.to_sym if services.include?(service) require "fog/openstack/#{service}" return Fog::Openstack.const_get(service.to_s.capitalize).new(attributes) end raise ArgumentError, "Openstack has no #{service} service" end def self.services # Ruby 1.8.7 compatibility for select returning Array of Arrays (pairs) Hash[Fog.services.select{|service, providers| providers.include?(:openstack)}].keys end end end fog-openstack-0.1.6/lib/fog/openstack/compute.rb0000644000175600017570000003124512730051546020640 0ustar pravipravi module Fog module Compute class OpenStack < Fog::Service requires :openstack_auth_url recognizes :openstack_auth_token, :openstack_management_url, :persistent, :openstack_service_type, :openstack_service_name, :openstack_tenant, :openstack_tenant_id, :openstack_api_key, :openstack_username, :openstack_identity_endpoint, :current_user, :current_tenant, :openstack_region, :openstack_endpoint_type, :openstack_cache_ttl, :openstack_project_name, :openstack_project_id, :openstack_project_domain, :openstack_user_domain, :openstack_domain_name, :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id, :openstack_identity_prefix ## MODELS # model_path 'fog/openstack/models/compute' model :aggregate collection :aggregates model :availability_zone collection :availability_zones model :server collection :servers model :service collection :services model :image collection :images model :flavor collection :flavors model :metadatum collection :metadata model :address collection :addresses model :security_group collection :security_groups model :security_group_rule collection :security_group_rules model :key_pair collection :key_pairs model :tenant collection :tenants model :volume collection :volumes model :volume_attachment collection :volume_attachments model :network collection :networks model :snapshot collection :snapshots model :host collection :hosts ## REQUESTS # request_path 'fog/openstack/requests/compute' # Aggregate CRUD request :list_aggregates request :create_aggregate request :update_aggregate request :get_aggregate request :update_aggregate request :update_aggregate_metadata request :add_aggregate_host request :remove_aggregate_host request :delete_aggregate # Server CRUD request :list_servers request :list_servers_detail request :create_server request :get_server_details request :get_server_password request :update_server request :delete_server # Server Actions request :server_actions request :server_action request :reboot_server request :rebuild_server request :resize_server request :confirm_resize_server request :revert_resize_server request :pause_server request :unpause_server request :suspend_server request :resume_server request :start_server request :stop_server request :rescue_server request :change_server_password request :add_fixed_ip request :remove_fixed_ip request :server_diagnostics request :boot_from_snapshot request :reset_server_state request :add_security_group request :remove_security_group request :shelve_server request :unshelve_server request :shelve_offload_server # Server Extenstions request :get_console_output request :get_vnc_console request :live_migrate_server request :migrate_server request :evacuate_server # Service CRUD request :list_services request :enable_service request :disable_service request :disable_service_log_reason request :delete_service # Image CRUD request :list_images request :list_images_detail request :create_image request :get_image_details request :delete_image # Flavor CRUD request :list_flavors request :list_flavors_detail request :get_flavor_details request :create_flavor request :delete_flavor # Flavor Actions request :get_flavor_metadata request :create_flavor_metadata request :update_flavor_metadata request :delete_flavor_metadata # Flavor Access request :add_flavor_access request :remove_flavor_access request :list_tenants_with_flavor_access # Hypervisor request :get_hypervisor_statistics # Metadata request :list_metadata request :get_metadata request :set_metadata request :update_metadata request :delete_metadata # Metadatam request :delete_meta request :update_meta # Address request :list_addresses request :list_address_pools request :list_all_addresses request :list_private_addresses request :list_public_addresses request :get_address request :allocate_address request :associate_address request :release_address request :disassociate_address # Security Group request :list_security_groups request :get_security_group request :create_security_group request :create_security_group_rule request :delete_security_group request :delete_security_group_rule request :get_security_group_rule # Key Pair request :list_key_pairs request :get_key_pair request :create_key_pair request :delete_key_pair # Tenant request :list_tenants request :set_tenant request :get_limits # Volume request :list_volumes request :list_volumes_detail request :create_volume request :get_volume_details request :delete_volume request :attach_volume request :detach_volume request :get_server_volumes request :list_volume_attachments # Snapshot request :create_snapshot request :list_snapshots request :list_snapshots_detail request :get_snapshot_details request :delete_snapshot # Usage request :list_usages request :get_usage # Quota request :get_quota request :get_quota_defaults request :update_quota # Hosts request :list_hosts request :get_host_details # Zones request :list_zones request :list_zones_detailed request :list_availability_zones class Mock attr_reader :auth_token attr_reader :auth_token_expiration attr_reader :current_user attr_reader :current_tenant def self.data @data ||= Hash.new do |hash, key| hash[key] = { :last_modified => { :images => {}, :servers => {}, :key_pairs => {}, :security_groups => {}, :addresses => {} }, :aggregates => [{ "availability_zone" => "nova", "created_at" => "2012-11-16T06:22:23.032493", "deleted" => false, "deleted_at" => nil, "id" => 1, "name" => "name", "updated_at" => nil }], :images => { "0e09fbd6-43c5-448a-83e9-0d3d05f9747e" => { "id" => "0e09fbd6-43c5-448a-83e9-0d3d05f9747e", "name" => "cirros-0.3.0-x86_64-blank", 'progress' => 100, 'status' => "ACTIVE", 'updated' => "", 'minRam' => 0, 'minDisk' => 0, 'metadata' => {}, 'links' => [{"href" => "http://nova1:8774/v1.1/admin/images/1", "rel" => "self"}, {"href" => "http://nova1:8774/admin/images/2", "rel" => "bookmark"}] } }, :servers => {}, :key_pairs => {}, :security_groups => { '0' => { "id" => 0, "tenant_id" => Fog::Mock.random_hex(8), "name" => "default", "description" => "default", "rules" => [ {"id" => 0, "parent_group_id" => 0, "from_port" => 68, "to_port" => 68, "ip_protocol" => "udp", "ip_range" => {"cidr" => "0.0.0.0/0"}, "group" => {}, }, ], }, }, :server_security_group_map => {}, :addresses => {}, :quota => { 'security_group_rules' => 20, 'security_groups' => 10, 'injected_file_content_bytes' => 10240, 'injected_file_path_bytes' => 256, 'injected_files' => 5, 'metadata_items' => 128, 'floating_ips' => 10, 'instances' => 10, 'key_pairs' => 10, 'gigabytes' => 5000, 'volumes' => 10, 'cores' => 20, 'ram' => 51200 }, :volumes => {}, :snapshots => {} } end end def self.reset @data = nil end include Fog::OpenStack::Core def initialize(options = {}) @auth_token = Fog::Mock.random_base64(64) @auth_token_expiration = (Time.now.utc + 86400).iso8601 initialize_identity options management_url = URI.parse(options[:openstack_auth_url]) management_url.port = 8774 management_url.path = '/v1.1/1' @openstack_management_url = management_url.to_s identity_public_endpoint = URI.parse(options[:openstack_auth_url]) identity_public_endpoint.port = 5000 @openstack_identity_public_endpoint = identity_public_endpoint.to_s end def data self.class.data["#{@openstack_username}-#{@current_tenant}"] end def reset_data self.class.data.delete("#{@openstack_username}-#{@current_tenant}") end end class Real include Fog::OpenStack::Core def initialize(options = {}) initialize_identity options @openstack_identity_service_type = options[:openstack_identity_service_type] || 'identity' @openstack_service_type = options[:openstack_service_type] || %w(nova compute) @openstack_service_name = options[:openstack_service_name] @connection_options = options[:connection_options] || {} authenticate unless @path =~ /1\.1|v2/ raise Fog::OpenStack::Errors::ServiceUnavailable, "OpenStack compute binding only supports version 2 (a.k.a. 1.1)" end @persistent = options[:persistent] || false @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end def request(params) begin response = @connection.request(params.merge(:headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'X-Auth-Token' => @auth_token }.merge!(params[:headers] || {}), :path => "#{@path}/#{params[:path]}", :query => params[:query])) rescue Excon::Errors::Unauthorized => error if error.response.body != 'Bad username or password' # token expiration @openstack_must_reauthenticate = true authenticate retry else # Bad Credentials raise error end rescue Excon::Errors::HTTPStatusError => error raise case error when Excon::Errors::NotFound Fog::Compute::OpenStack::NotFound.slurp(error) else error end end if !response.body.empty? && response.get_header('Content-Type') == 'application/json' response.body = Fog::JSON.decode(response.body) end response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/0000755000175600017570000000000012730051546020505 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/requests/volume/0000755000175600017570000000000012730051546022014 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/requests/volume/create_volume_type.rb0000644000175600017570000000200612730051546026232 0ustar pravipravimodule Fog module Volume class OpenStack module Real def create_volume_type(options = {}) data = { 'volume_type' => {} } vanilla_options = [:name, :extra_specs] vanilla_options.select { |o| options[o] }.each do |key| data['volume_type'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => [200, 202], :method => 'POST', :path => "types" ) end end module Mock def create_volume_type(options = {}) response = Excon::Response.new response.status = 202 response.body = { "volume_type"=> { "id"=> "6685584b-1eac-4da6-b5c3-555430cf68ff", "name"=> "vol-type-001", "extra_specs"=> { "capabilities"=> "gpu" } } } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/create_snapshot.rb0000644000175600017570000000052412730051546025524 0ustar pravipravimodule Fog module Volume class OpenStack module Real private def _create_snapshot(data) request( :body => Fog::JSON.encode(data), :expects => [200, 202], :method => 'POST', :path => "snapshots" ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/get_transfer_details.rb0000644000175600017570000000054112730051546026531 0ustar pravipravimodule Fog module Volume class OpenStack # no Mock needed, test coverage in RSpec module Real def get_transfer_details(transfer_id) request( :expects => 200, :method => 'GET', :path => "os-volume-transfer/#{transfer_id}" ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/list_transfers_detailed.rb0000644000175600017570000000057712730051546027247 0ustar pravipravimodule Fog module Volume class OpenStack # no Mock needed, test coverage in RSpec module Real def list_transfers_detailed(options = {}) request( :expects => 200, :method => 'GET', :path => 'os-volume-transfer/detail', :query => options ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/update_volume_type.rb0000644000175600017570000000206712730051546026260 0ustar pravipravimodule Fog module Volume class OpenStack module Real def update_volume_type(volume_type_id, options = {}) data = { 'volume_type' => {} } vanilla_options = [:name, :extra_specs] vanilla_options.select { |o| options[o] }.each do |key| data['volume_type'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => [200, 202], :method => 'PUT', :path => "types/#{volume_type_id}" ) end end module Mock def update_volume_type(volume_type_id, options = {}) response = Excon::Response.new response.status = 202 response.body = { "volume_type"=> { "id"=> "6685584b-1eac-4da6-b5c3-555430cf68ff", "name"=> "vol-type-001", "extra_specs"=> { "capabilities"=> "gpu" } } } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/update_metadata.rb0000644000175600017570000000065012730051546025464 0ustar pravipravimodule Fog module Volume class OpenStack module Real def update_metadata(volume_id, metadata = {}) data = { 'metadata' => metadata } request( :body => Fog::JSON.encode(data), :expects => [200], :method => 'POST', :path => "volumes/#{volume_id}/metadata" ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/get_quota_defaults.rb0000644000175600017570000000112612730051546026220 0ustar pravipravimodule Fog module Volume class OpenStack module Real def get_quota_defaults(tenant_id) request( :expects => 200, :method => 'GET', :path => "/os-quota-sets/#{tenant_id}/defaults" ) end end module Mock def get_quota_defaults(tenant_id) response = Excon::Response.new response.status = 200 response.body = { 'quota_set' => self.data[:quota].merge({'id' => tenant_id}) } response end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/volume/get_volume_type_details.rb0000644000175600017570000000135012730051546027254 0ustar pravipravimodule Fog module Volume class OpenStack module Real def get_volume_type_details(volume_type_id) request( :expects => 200, :method => 'GET', :path => "types/#{volume_type_id}" ) end end module Mock def get_volume_type_details(volume_type_id) response = Excon::Response.new response.status = 200 response.body = { "volume_type" => { "id" => "1", "name" => "type 1", "extra_specs" => { "volume_backend_name" => "type 1 backend name" } } } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/list_zones.rb0000644000175600017570000000127212730051546024534 0ustar pravipravimodule Fog module Volume class OpenStack module Real def list_zones(options = {}) request( :expects => 200, :method => 'GET', :path => 'os-availability-zone.json', :query => options ) end end module Mock def list_zones(options = {}) Excon::Response.new( :body => { "availabilityZoneInfo" => [ { "zoneState" => { "available" => true }, "zoneName" => "nova" } ] }, :status => 200 ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/list_volumes.rb0000644000175600017570000000170012730051546025064 0ustar pravipravimodule Fog module Volume class OpenStack module Real def list_volumes(options = true, options_deprecated = {}) if options.is_a?(Hash) path = 'volumes' query = options else # Backwards compatibility layer, when 'detailed' boolean was sent as first param if options Fog::Logger.deprecation('Calling OpenStack[:volume].list_volumes(true) is deprecated, use .list_volumes_detailed instead') else Fog::Logger.deprecation('Calling OpenStack[:volume].list_volumes(false) is deprecated, use .list_volumes({}) instead') end path = options ? 'volumes/detail' : 'volumes' query = options_deprecated end request( :expects => 200, :method => 'GET', :path => path, :query => query ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/create_transfer.rb0000644000175600017570000000107512730051546025513 0ustar pravipravimodule Fog module Volume class OpenStack module Real def create_transfer(volume_id, options={}) data = { 'transfer' => { 'volume_id' => volume_id } } if options[:name] data['transfer']['name'] = options[:name] end request( :body => Fog::JSON.encode(data), :expects => [200, 202], :method => 'POST', :path => 'os-volume-transfer' ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/action.rb0000644000175600017570000000051012730051546023612 0ustar pravipravimodule Fog module Volume class OpenStack module Real def action(id, data) request( :body => Fog::JSON.encode(data), :expects => [200, 202], :method => 'POST', :path => "volumes/#{id}/action" ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/list_volumes_detailed.rb0000644000175600017570000000050212730051546026716 0ustar pravipravimodule Fog module Volume class OpenStack module Real def list_volumes_detailed(options = {}) request( :expects => 200, :method => 'GET', :path => 'volumes/detail', :query => options ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/delete_volume.rb0000644000175600017570000000071012730051546025170 0ustar pravipravimodule Fog module Volume class OpenStack module Real def delete_volume(volume_id) request( :expects => 202, :method => 'DELETE', :path => "volumes/#{volume_id}" ) end end module Mock def delete_volume(volume_id) response = Excon::Response.new response.status = 204 response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/list_snapshots.rb0000644000175600017570000000237212730051546025422 0ustar pravipravimodule Fog module Volume class OpenStack module Real def list_snapshots(options = true, options_deprecated = {}) if options.is_a?(Hash) path = 'snapshots' query = options else # Backwards compatibility layer, when 'detailed' boolean was sent as first param if options Fog::Logger.deprecation('Calling OpenStack[:volume].list_snapshots(true) is deprecated, use .list_snapshots_detailed instead') else Fog::Logger.deprecation('Calling OpenStack[:volume].list_snapshots(false) is deprecated, use .list_snapshots({}) instead') end path = options ? 'snapshots/detail' : 'snapshots' query = options_deprecated end request( :expects => 200, :method => 'GET', :path => path, :query => query ) end end module Mock def list_snapshots(detailed=true, options={}) response = Excon::Response.new response.status = 200 response.body = { 'snapshots' => [get_snapshot_details.body["snapshot"]] } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/update_snapshot.rb0000644000175600017570000000250612730051546025545 0ustar pravipravimodule Fog module Volume class OpenStack module Real def update_snapshot(snapshot_id, data = {}) request( :body => Fog::JSON.encode('snapshot' => data), :expects => 200, :method => 'PUT', :path => "snapshots/#{snapshot_id}" ) end end module Mock def update_snapshot(snapshot_id, options = {}) unless snapshot_id raise ArgumentError, 'snapshot_id is required' end response = Excon::Response.new if snapshot = data[:snapshots][snapshot_id] response.status = 200 snapshot['display_name'] = options['display_name'] if options['display_name'] snapshot['display_description'] = options['display_description'] if options['display_description'] snapshot['name'] = options['name'] if options['name'] snapshot['description'] = options['description'] if options['description'] snapshot['metadata'] = options['metadata'] if options['metadata'] response.body = {'snapshot' => snapshot} response else raise Fog::HP::BlockStorageV2::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/update_volume.rb0000644000175600017570000000114312730051546025211 0ustar pravipravimodule Fog module Volume class OpenStack module Real def update_volume(volume_id, data = {}) request( :body => Fog::JSON.encode('volume' => data), :expects => 200, :method => 'PUT', :path => "volumes/#{volume_id}" ) end end module Mock def update_volume(volume_id, data = {}) response = Excon::Response.new response.status = 200 response.body = {'volume' => data.merge('id' => volume_id)} response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/get_quota_usage.rb0000644000175600017570000000201112730051546025507 0ustar pravipravimodule Fog module Volume class OpenStack module Real def get_quota_usage(tenant_id) request( :expects => 200, :method => 'GET', :path => "/os-quota-sets/#{tenant_id}?usage=True" ) end end module Mock def get_quota_usage(tenant_id) response = Excon::Response.new response.status = 200 response.body = { 'quota_set' => { 'gigabytes' => { 'reserved' => 0, 'limit' => -1, 'in_use' => 160 }, 'snapshots' => { 'reserved' => 0, 'limit' => 50, 'in_use' => 3 }, 'volumes' => { 'reserved' => 0, 'limit' => 50, 'in_use' => 5 }, 'id' => tenant_id } } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/set_tenant.rb0000644000175600017570000000057712730051546024516 0ustar pravipravimodule Fog module Volume class OpenStack module Real def set_tenant(tenant) @openstack_must_reauthenticate = true @openstack_tenant = tenant.to_s authenticate end end module Mock def set_tenant(tenant) true end end end # class OpenStack end # module Volume end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/volume/delete_volume_type.rb0000644000175600017570000000073712730051546026242 0ustar pravipravimodule Fog module Volume class OpenStack module Real def delete_volume_type(volume_type_id) request( :expects => 202, :method => 'DELETE', :path => "types/#{volume_type_id}" ) end end module Mock def delete_volume_type(volume_type_id) response = Excon::Response.new response.status = 204 response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/delete_snapshot.rb0000644000175600017570000000072212730051546025523 0ustar pravipravimodule Fog module Volume class OpenStack module Real def delete_snapshot(snapshot_id) request( :expects => 202, :method => 'DELETE', :path => "snapshots/#{snapshot_id}" ) end end module Mock def delete_snapshot(_snapshot_id) response = Excon::Response.new response.status = 202 response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/update_snapshot_metadata.rb0000644000175600017570000000066712730051546027413 0ustar pravipravimodule Fog module Volume class OpenStack module Real def update_snapshot_metadata(snapshot_id, metadata = {}) data = { 'metadata' => metadata } request( :body => Fog::JSON.encode(data), :expects => [200], :method => 'POST', :path => "snapshots/#{snapshot_id}/metadata" ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/extend_volume.rb0000644000175600017570000000110512730051546025214 0ustar pravipravimodule Fog module Volume class OpenStack module Real def extend_volume(volume_id, size) body = { 'os-extend' => { 'new_size' => size } } request( :expects => 202, :method => 'POST', :path => "volumes/#{volume_id}/action", :body => Fog::JSON.encode(body) ) end end module Mock def extend_volume(volume_id, size) response = Excon::Response.new response.status = 202 response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/list_snapshots_detailed.rb0000644000175600017570000000115012730051546027246 0ustar pravipravimodule Fog module Volume class OpenStack module Real def list_snapshots_detailed(options = {}) request( :expects => 200, :method => 'GET', :path => 'snapshots/detail', :query => options ) end end module Mock def list_snapshots_detailed(options = {}) response = Excon::Response.new response.status = 200 response.body = { 'snapshots' => [get_snapshot_details.body["snapshot"]] } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/get_quota.rb0000644000175600017570000000112312730051546024326 0ustar pravipravimodule Fog module Volume class OpenStack module Real def get_quota(tenant_id) request( :expects => 200, :method => 'GET', :path => "/os-quota-sets/#{tenant_id}" ) end end module Mock def get_quota(tenant_id) response = Excon::Response.new response.status = 200 response.body = { 'quota_set' => (self.data[:quota_updated] or self.data[:quota]).merge({'id' => tenant_id}) } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/list_volume_types.rb0000644000175600017570000000176312730051546026136 0ustar pravipravimodule Fog module Volume class OpenStack module Real def list_volume_types(options = {}) request( :expects => 200, :method => 'GET', :path => 'types', :query => options ) end end module Mock def list_volume_types(options = {}) response = Excon::Response.new response.status = 200 self.data[:volume_types] ||= [ { "id" => "1", "name" => "type 1", "extra_specs" => { "volume_backend_name" => "type 1 backend name" } }, { "id" => "2", "name" => "type 2", "extra_specs" => { "volume_backend_name" => "type 2 backend name" } } ] response.body = { 'volume_types' => self.data[:volume_types] } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/accept_transfer.rb0000644000175600017570000000075712730051546025515 0ustar pravipravimodule Fog module Volume class OpenStack module Real def accept_transfer(transfer_id, auth_key) data = { 'accept' => { 'auth_key' => auth_key } } request( :body => Fog::JSON.encode(data), :expects => [200, 202], :method => 'POST', :path => "os-volume-transfer/#{transfer_id}/accept" ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/replace_metadata.rb0000644000175600017570000000065012730051546025615 0ustar pravipravimodule Fog module Volume class OpenStack module Real def replace_metadata(volume_id, metadata = {}) data = { 'metadata' => metadata } request( :body => Fog::JSON.encode(data), :expects => [200], :method => 'PUT', :path => "volumes/#{volume_id}/metadata" ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/delete_snapshot_metadata.rb0000644000175600017570000000051512730051546027363 0ustar pravipravimodule Fog module Volume class OpenStack module Real def delete_snapshot_metadata(snapshot_id, key_name) request( :expects => [200], :method => 'DELETE', :path => "snapshots/#{snapshot_id}/metadata/#{key_name}" ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/get_volume_details.rb0000644000175600017570000000044112730051546026213 0ustar pravipravimodule Fog module Volume class OpenStack module Real def get_volume_details(volume_id) request( :expects => 200, :method => 'GET', :path => "volumes/#{volume_id}" ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/delete_transfer.rb0000644000175600017570000000045412730051546025512 0ustar pravipravimodule Fog module Volume class OpenStack module Real def delete_transfer(transfer_id) request( :expects => 202, :method => 'DELETE', :path => "os-volume-transfer/#{transfer_id}" ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/get_snapshot_details.rb0000644000175600017570000000045012730051546026543 0ustar pravipravimodule Fog module Volume class OpenStack module Real def get_snapshot_details(snapshot_id) request( :expects => 200, :method => 'GET', :path => "snapshots/#{snapshot_id}" ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/create_volume.rb0000644000175600017570000000116112730051546025172 0ustar pravipravimodule Fog module Volume class OpenStack module Real private def _create_volume(data, options={}) vanilla_options = [:snapshot_id, :imageRef, :volume_type, :source_volid, :availability_zone, :metadata] vanilla_options.select { |o| options[o] }.each do |key| data['volume'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => [200, 202], :method => 'POST', :path => "volumes" ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/update_quota.rb0000644000175600017570000000133312730051546025034 0ustar pravipravimodule Fog module Volume class OpenStack module Real def update_quota(tenant_id, options = {}) options['tenant_id'] = tenant_id request( :body => Fog::JSON.encode({ 'quota_set' => options }), :expects => 200, :method => 'PUT', :path => "/os-quota-sets/#{tenant_id}" ) end end module Mock def update_quota(tenant_id, options = {}) self.data[:quota_updated] = self.data[:quota].merge options response = Excon::Response.new response.status = 200 response.body = { 'quota_set' => self.data[:quota_updated] } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/list_transfers.rb0000644000175600017570000000055312730051546025406 0ustar pravipravimodule Fog module Volume class OpenStack # no Mock needed, test coverage in RSpec module Real def list_transfers(options = {}) request( :expects => 200, :method => 'GET', :path => 'os-volume-transfer', :query => options ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume/delete_metadata.rb0000644000175600017570000000047612730051546025452 0ustar pravipravimodule Fog module Volume class OpenStack module Real def delete_metadata(volume_id, key_name) request( :expects => [200], :method => 'DELETE', :path => "volumes/#{volume_id}/metadata/#{key_name}" ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/0000755000175600017570000000000012730051546022161 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/requests/compute/rescue_server.rb0000644000175600017570000000115412730051546025363 0ustar pravipravimodule Fog module Compute class OpenStack class Real # Rescue the server. # # === Parameters # * server_id <~String> - The ID of the server to be rescued. # === Returns # * success <~Boolean> def rescue_server(server_id) body = { 'rescue' => nil } server_action(server_id, body) == 202 end # def rescue_server end # class Real class Mock def rescue_server(server_id) true end # def rescue_server end # class Mock end # class OpenStack end # module Compute end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/list_servers_detail.rb0000644000175600017570000000220312730051546026551 0ustar pravipravimodule Fog module Compute class OpenStack class Real # Available filters: name, status, image, flavor, changes_since, reservation_id def list_servers_detail(options = {}) params = options.dup if params[:all_tenants] params['all_tenants'] = 'True' params.delete(:all_tenants) end request( :expects => [200, 203], :method => 'GET', :path => 'servers/detail.json', :query => params ) end end class Mock def list_servers_detail(filters = {}) response = Excon::Response.new servers = self.data[:servers].values for server in servers case server['status'] when 'BUILD' if Time.now - self.data[:last_modified][:servers][server['id']] > Fog::Mock.delay * 2 server['status'] = 'ACTIVE' end end end response.status = [200, 203][rand(1)] response.body = { 'servers' => servers } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/associate_address.rb0000644000175600017570000000160112730051546026164 0ustar pravipravimodule Fog module Compute class OpenStack class Real def associate_address(server_id, ip_address) body = { "addFloatingIp" => {"address" => ip_address}} server_action(server_id, body) end end class Mock def associate_address(server_id, ip_address) server = data[:servers][server_id] server["addresses"]['mocknet'] ||= [] ip_hash = {"OS-EXT-IPS-MAC:mac_addr"=>"fa:16:3e:85:47:40", "version"=>4, "addr"=>ip_address, "OS-EXT-IPS:type"=>"floating"} server["addresses"]['mocknet'] << ip_hash response = Excon::Response.new response.status = 202 response.headers = { "Content-Type" => "text/html, charset=UTF-8", "Content-Length" => "0", "Date"=> Date.new } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/add_flavor_access.rb0000644000175600017570000000142712730051546026134 0ustar pravipravimodule Fog module Compute class OpenStack class Real def add_flavor_access(flavor_ref, tenant_id) request( :body => Fog::JSON.encode({ "addTenantAccess" => { "tenant" => tenant_id } }), :expects => [200, 203], :method => 'POST', :path => "flavors/#{flavor_ref}/action.json" ) end end class Mock def add_flavor_access(flavor_ref, tenant_id) response = Excon::Response.new response.status = 200 response.body = { "flavor_access" => [{ "tenant_id" => tenant_id.to_s, "flavor_id" => flavor_ref.to_s }] } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/create_snapshot.rb0000644000175600017570000000275212730051546025676 0ustar pravipravimodule Fog module Compute class OpenStack class Real def create_snapshot(volume_id, name, description, force = false) data = { 'snapshot' => { 'volume_id' => volume_id, 'display_name' => name, 'display_description' => description, 'force' => force } } request( :body => Fog::JSON.encode(data), :expects => [200, 202], :method => 'POST', :path => "os-snapshots" ) end end class Mock def create_snapshot(volume_id, name, description, _force = false) volume_response = get_volume_details(volume_id) volume = volume_response.data[:body]['volume'] if volume.nil? raise Fog::Compute::OpenStack::NotFound else response = Excon::Response.new data = { "status" => "availble", "name" => name, "created_at" => Time.now, "description" => description, "volume_id" => volume_id, "id" => Fog::Mock.random_numbers(2), "size" => volume['size'] } self.data[:snapshots][data['id']] = data response.body = {"snapshot" => data} response.status = 202 response end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/shelve_offload_server.rb0000644000175600017570000000133212730051546027053 0ustar pravipravimodule Fog module Compute class OpenStack class Real # Shelve Off load the server. Data and resource associations are deleted. # # === Parameters # * server_id <~String> - The ID of the server to be shelve off loaded # === Returns # * success <~Boolean> def shelve_offload_server(server_id) body = { 'shelveOffload' => nil } server_action(server_id, body).status == 202 end # def shelve_off_load_server end # class Real class Mock def shelve_offload_server(server_id) true end # def shelve_off_load_server end # class Mock end # class OpenStack end # module Compute end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/delete_service.rb0000644000175600017570000000157712730051546025502 0ustar pravipravimodule Fog module Compute class OpenStack class Real def delete_service(uuid, optional_params = nil) # Encode all params optional_params = optional_params.each { |k, v| optional_params[k] = URI::encode(v) } if optional_params request( :expects => [202, 204], :method => 'DELETE', :path => "os-services/#{uuid}", :query => optional_params ) end end class Mock def delete_service(host, binary, optional_params = nil) response = Excon::Response.new response.status = 204 response.headers = { "Content-Type" => "text/html; charset=UTF-8", "Content-Length" => "0", "Date" => Date.new } response end end # mock end # openstack end # compute end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/create_security_group.rb0000644000175600017570000000316112730051546027115 0ustar pravipravimodule Fog module Compute class OpenStack class Real def create_security_group(name, description) data = { 'security_group' => { 'name' => name, 'description' => description } } request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'POST', :path => 'os-security-groups.json' ) end end class Mock def create_security_group(name, description) Fog::Identity::OpenStack.new(:openstack_auth_url => credentials[:openstack_auth_url]) tenant_id = Fog::Identity::OpenStack::V2::Mock.data[current_tenant][:tenants].keys.first security_group_id = Fog::Mock.random_numbers(2).to_i + 1 self.data[:security_groups][security_group_id.to_s] = { 'tenant_id' => tenant_id, 'rules' => [], 'id' => security_group_id, 'name' => name, 'description' => description } response = Excon::Response.new response.status = 200 response.headers = { 'X-Compute-Request-Id' => "req-#{Fog::Mock.random_hex(32)}", 'Content-Type' => 'application/json', 'Content-Length' => Fog::Mock.random_numbers(3).to_s, 'Date' => Date.new} response.body = { 'security_group' => self.data[:security_groups][security_group_id.to_s] } response end end # mock end # openstack end # compute end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/list_hosts.rb0000644000175600017570000000124212730051546024700 0ustar pravipravimodule Fog module Compute class OpenStack class Real def list_hosts(options = {}) request( :expects => [200, 203], :method => 'GET', :path => 'os-hosts.json', :query => options ) end end class Mock def list_hosts(options = {}) response = Excon::Response.new response.status = 200 response.body = { "hosts" => [ {"host_name" => "host.test.net", "service"=>"compute", "zone" => "az1"} ] } response end end # mock end # openstack end # compute end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/get_server_details.rb0000644000175600017570000000131412730051546026357 0ustar pravipravimodule Fog module Compute class OpenStack class Real def get_server_details(server_id) request( :expects => [200, 203], :method => 'GET', :path => "servers/#{server_id}.json" ) end end class Mock def get_server_details(server_id) response = Excon::Response.new if server = list_servers_detail.body['servers'].find {|_| _['id'] == server_id} response.status = [200, 203][rand(1)] response.body = { 'server' => server } response else raise Fog::Compute::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/get_aggregate.rb0000644000175600017570000000111312730051546025267 0ustar pravipravimodule Fog module Compute class OpenStack class Real def get_aggregate(uuid) request( :expects => [200], :method => 'GET', :path => "os-aggregates/#{uuid}" ) end end class Mock def get_aggregate(uuid) response = Excon::Response.new response.status = 2040 response.body = {'aggregate' => self.data[:aggregates].first.merge({ "hosts" => []})} response end end # mock end # openstack end # compute end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/list_public_addresses.rb0000644000175600017570000000136412730051546027060 0ustar pravipravimodule Fog module Compute class OpenStack class Real def list_public_addresses(server_id) request( :expects => [200, 203], :method => 'GET', :path => "servers/#{server_id}/ips/public.json" ) end end class Mock def list_public_addresses(server_id) response = Excon::Response.new if server = list_servers_detail.body['servers'].find {|_| _['id'] == server_id} response.status = [200, 203][rand(1)] response.body = { 'public' => server['addresses']['public'] } response else raise Fog::Compute::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/remove_flavor_access.rb0000644000175600017570000000134412730051546026677 0ustar pravipravimodule Fog module Compute class OpenStack class Real def remove_flavor_access(flavor_ref, tenant_id) request( :body => Fog::JSON.encode({ "removeTenantAccess" => { "tenant" => tenant_id.to_s } }), :expects => [200, 203], :method => 'POST', :path => "flavors/#{flavor_ref}/action.json" ) end end class Mock def remove_flavor_access(flavor_ref, tenant_id) response = Excon::Response.new response.status = 200 response.body = { "flavor_access" => [] } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/get_key_pair.rb0000644000175600017570000000502412730051546025151 0ustar pravipravimodule Fog module Compute class OpenStack class Real def get_key_pair(key_name) request( :expects => 200, :method => 'GET', :path => "os-keypairs/#{key_name}" ) end end class Mock def delete_key_pair(key_name) response = Excon::Response.new response.status = 200 response.headers = { "X-Compute-Request-Id" => "req-c373a42c-2825-4e60-8d34-99416ea850be", "Content-Type" => "application/json", "Content-Length" => "1289", "Date" => Date.new} response.body = { "keypair" => { "public_key" => "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDCdAZLjljntJbLVVkNHjWFSoKen2nZbk39ZfqhZJOMdeFdz"\ "02GWBS45rcuboeGg/gozKRwsLu4N6NLPlYtbK/NapJIvgO/djBp+FQG1QZNtLPsx7j4hVJac3yISGms+Xtu4c"\ "Ev6j5sFDzAgTQbWez0Z1+9qOq9ngdaoW+YClfQ== vagrant@nova\n", "private_key" => "-----BEGIN RSA PRIVATE KEY-----\nMIICXgIBAAKBgQDCdAZLjljn1tJbLVVkNHjWFSoKen2nZbk39Zfq"\ "hZJOMdeFdz02\nGWBS45rcuHboeGg/gozKRwsLu4N6NLPlYtbK/NapJIvgO/djBp+FQG1QZNtLPsx7\nj4hVJ"\ "ac3yISGms+Xtu4cEv6j5sFDzAgTQbWez0Z1+9qOq9ngdaoW+YClfQIDAQAB\nAoGBALBoT9m1vuQ82EONQf2R"\ "ONqHAsfUzi/SMhEZRgOlv9AemXZkcWyl4uPvxmtd\nEcreiTystAtCHjw7lhCExXthipevUjtIAAt+b3pMn6O"\ "yjad3IRvde6atMdjrje43\n/nftYtuXYyJTsvwEvLYqSioLQ0Nn/XDKhOpcM5tejDHOH35lAkEA+H4r7y9X52"\ "1u\nIABVAezBWaT/wvdMjx5cwfyYEQjnI1bxfRIqkgoY5gDDBdVbT75UTsHHbHLORQcw\nRjRvS2zgewJBAMh"\ "T6eyMonJvHHvC5RcchcY+dWkscIKoOzeyUKMb+7tERQa9/UN2\njYb+jdM0VyL0ruLFwYtl2m34gfmhcXgIvG"\ "cCQGzKMEnjHEUBr7jq7EyPbobkqeSd\niDMQQ+PZxmmO0EK0ib0L+v881HG926PuKK/cz+Q7Cif8iznFT+ksg"\ "50t6YkCQQC9\nwfcAskqieSuS9A9LcCIrojhXctf0e+T0Ij2N89DlF4sHEuqXf/IZ4IB5gsfTfdE3\nUDnAkK"\ "9yogaEbu/r0uKbAkEAy5kl71bIqvKTKsY2mES9ziVxfftl/9UIi5LI+QHb\nmC/c6cTrGVCM71fi2GMxGgBeE"\ "ea4+7xwoWTL4CxA00kmTg==\n-----END RSA PRIVATE KEY-----\n", "user_id" => "admin", "name" => key_name, "fingerprint" => "97:86:f4:15:68:0c:7b:a7:e5:8f:f0:bd:1f:27:65:ad" } } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/get_image_details.rb0000644000175600017570000000130012730051546026126 0ustar pravipravimodule Fog module Compute class OpenStack class Real def get_image_details(image_id) request( :expects => [200, 203], :method => 'GET', :path => "images/#{image_id}.json" ) end end class Mock def get_image_details(image_id) response = Excon::Response.new if image = list_images_detail.body['images'].find {|_| _['id'] == image_id} response.status = [200, 203][rand(1)] response.body = { 'image' => image } response else raise Fog::Compute::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/get_host_details.rb0000644000175600017570000000366012730051546026034 0ustar pravipravimodule Fog module Compute class OpenStack class Real def get_host_details(host) request( :expects => [200, 203], :method => 'GET', :path => "os-hosts/#{host}.json" ) end end class Mock def get_host_details(host) response = Excon::Response.new response.status = 200 response.body = { "host" => [ { "resource" => { "project" => "(total)", "memory_mb" => 64427, "host" => "cn28.la-1-3.morphcloud.net", "cpu" => 12, "disk_gb" => 1608 } }, { "resource" => { "project" => "(used_now)", "memory_mb" => 1753, "host" => "cn28.la-1-3.morphcloud.net", "cpu" => 3, "disk_gb" => 33 } }, { "resource" => { "project" => "(used_max)", "memory_mb" => 7168, "host" => "cn28.la-1-3.morphcloud.net", "cpu" => 3, "disk_gb" => 45 } }, { "resource" => { "project" => "bf8301f5164f4790889a1bc2bfb16d99", "memory_mb" => 5120, "host" => "cn28.la-1-3.morphcloud.net", "cpu" => 2, "disk_gb" => 35 } }, { "resource" => { "project" => "3bb4d0301c5f47d5b4d96a361fcf96f4", "memory_mb" => 2048, "host" => "cn28.la-1-3.morphcloud.net", "cpu" => 1, "disk_gb" => 10 } } ] } response end end # mock end # openstack end # compute end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/update_metadata.rb0000644000175600017570000000220112730051546025623 0ustar pravipravimodule Fog module Compute class OpenStack class Real def update_metadata(collection_name, parent_id, metadata = {}) request( :body => Fog::JSON.encode({ 'metadata' => metadata }), :expects => 200, :method => 'POST', :path => "#{collection_name}/#{parent_id}/metadata.json" ) end end class Mock def update_metadata(collection_name, parent_id, metadata = {}) if collection_name == "images" then if not list_images_detail.body['images'].find {|_| _['id'] == parent_id} raise Fog::Compute::OpenStack::NotFound end end if collection_name == "servers" then if not list_servers_detail.body['servers'].find {|_| _['id'] == parent_id} raise Fog::Compute::OpenStack::NotFound end end #FIXME join w/ existing metadata here response = Excon::Response.new response.body = { "metadata" => metadata } response.status = 200 response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/list_volumes_detail.rb0000644000175600017570000000104312730051546026553 0ustar pravipravimodule Fog module Compute class OpenStack class Real def list_volumes_detail(options = {}) request( :expects => 200, :method => 'GET', :path => 'os-volumes/detail', :query => options ) end end class Mock def list_volumes_detail(options = {}) Excon::Response.new( :body => { 'volumes' => self.data[:volumes].values }, :status => 200 ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/get_quota_defaults.rb0000644000175600017570000000111612730051546026364 0ustar pravipravimodule Fog module Compute class OpenStack class Real def get_quota_defaults(tenant_id) request( :expects => 200, :method => 'GET', :path => "/os-quota-sets/#{tenant_id}/defaults" ) end end class Mock def get_quota_defaults(tenant_id) response = Excon::Response.new response.status = 200 response.body = { 'quota_set' => self.data[:quota].merge({'id' => tenant_id}) } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/get_hypervisor_statistics.rb0000644000175600017570000000174712730051546030042 0ustar pravipravimodule Fog module Compute class OpenStack class Real def get_hypervisor_statistics(tenant_id) request( :expects => 200, :method => 'GET', :path => "os-hypervisors/statistics" ) end end class Mock def get_hypervisor_statistics(tenant_id) response = Excon::Response.new response.status = 200 response.body = { "hypervisor_statistics" => { "count" => 1, "current_workload" => 0, "disk_available_least" => 0, "free_disk_gb" => 1028, "free_ram_mb" => 7680, "local_gb" => 1028, "local_gb_used" => 0, "memory_mb" => 8192, "memory_mb_used" => 512, "running_vms" => 0, "vcpus" => 1, "vcpus_used" => 0 } } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/list_private_addresses.rb0000644000175600017570000000137112730051546027252 0ustar pravipravimodule Fog module Compute class OpenStack class Real def list_private_addresses(server_id) request( :expects => [200, 203], :method => 'GET', :path => "servers/#{server_id}/ips/private.json" ) end end class Mock def list_private_addresses(server_id) response = Excon::Response.new if server = list_servers_detail.body['servers'].find {|_| _['id'] == server_id} response.status = [200, 203][rand(1)] response.body = { 'private' => server['addresses']['private'] } response else raise Fog::Compute::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/list_services.rb0000644000175600017570000000361012730051546025364 0ustar pravipravimodule Fog module Compute class OpenStack class Real def list_services(parameters=nil) request( :expects => [200, 203], :method => 'GET', :path => 'os-services', :query => parameters ) end end class Mock def list_services(parameters=nil) response = Excon::Response.new response.status = 200 response.body = { "services" => [{ "id" => 1, "binary" => "nova-scheduler", "host" => "host1", "state" => "up", "status" => "disabled", "updated_at" => "2012-10-29T13:42:02.000000", "zone" => "internal", "disabled_reason" => "test2" }, { "id" => 2, "binary" => "nova-compute", "host" => "host1", "state" => "up", "status" => "disabled", "updated_at" => "2012-10-29T13:42:05.000000", "zone" => "nova", "disabled_reason" => "test2" }, { "id" => 3, "binary" => "nova-scheduler", "host" => "host2", "state" => "down", "status" => "enabled", "updated_at" => "2012-09-19T06:55:34.000000", "zone" => "internal", "disabled_reason" => "nil" }, { "id" => 4, "binary" => "nova-compute", "host" => "host2", "state" => "down", "status" => "disabled", "updated_at" => "2012-09-18T08:03:38.000000", "zone" => "nova", "disabled_reason" => "test2" }] } response end end # mock end # openstack end # compute end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/delete_key_pair.rb0000644000175600017570000000126512730051546025637 0ustar pravipravimodule Fog module Compute class OpenStack class Real def delete_key_pair(key_name) request( :expects => 202, :method => 'DELETE', :path => "os-keypairs/#{key_name}" ) end end class Mock def delete_key_pair(key_name) response = Excon::Response.new response.status = 202 response.headers = { "Content-Type" => "text/html; charset=UTF-8", "Content-Length" => "0", "Date" => Date.new } response.body = {} response end end # mock end # openstack end # compute end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/update_server.rb0000644000175600017570000000146612730051546025365 0ustar pravipravimodule Fog module Compute class OpenStack class Real def update_server(server_id, options = {}) request( :body => Fog::JSON.encode({ 'server' => options }), :expects => 200, :method => 'PUT', :path => "servers/#{server_id}.json" ) end end class Mock def update_server(server_id, options = {}) response = Excon::Response.new if server = list_servers_detail.body['servers'].find {|_| _['id'] == server_id} if options['name'] server['name'] = options['name'] end response.status = 200 response else raise Fog::Compute::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/create_security_group_rule.rb0000644000175600017570000000355212730051546030150 0ustar pravipravimodule Fog module Compute class OpenStack class Real def create_security_group_rule(parent_group_id, ip_protocol, from_port, to_port, cidr, group_id=nil) data = { 'security_group_rule' => { 'parent_group_id' => parent_group_id, 'ip_protocol' => ip_protocol, 'from_port' => from_port, 'to_port' => to_port, 'cidr' => cidr, 'group_id' => group_id } } request( :expects => 200, :method => 'POST', :body => Fog::JSON.encode(data), :path => 'os-security-group-rules.json' ) end end class Mock def create_security_group_rule(parent_group_id, ip_protocol, from_port, to_port, cidr, group_id=nil) parent_group_id = parent_group_id.to_i response = Excon::Response.new response.status = 200 response.headers = { 'X-Compute-Request-Id' => "req-#{Fog::Mock.random_hex(32)}", 'Content-Type' => 'application/json', 'Content-Length' => Fog::Mock.random_numbers(3).to_s, 'Date' => Date.new } rule = { 'id' => Fog::Mock.random_numbers(2).to_i, 'from_port' => from_port, 'group' => group_id || {}, 'ip_protocol' => ip_protocol, 'to_port' => to_port, 'parent_group_id' => parent_group_id, 'ip_range' => { 'cidr' => cidr } } self.data[:security_groups][parent_group_id.to_s]['rules'].push(rule) response.body = { 'security_group_rule' => rule } response end end # mock end # openstack end # compute end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/disable_service.rb0000644000175600017570000000177312730051546025641 0ustar pravipravimodule Fog module Compute class OpenStack class Real def disable_service(host, binary, optional_params = nil) data = {"host" => host, "binary" => binary} # Encode all params optional_params = optional_params.each { |k, v| optional_params[k] = URI::encode(v) } if optional_params request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'PUT', :path => "os-services/disable", :query => optional_params ) end end class Mock def disable_service(host, binary, optional_params = nil) response = Excon::Response.new response.status = 200 response.body = { "service" => { "host" => "host1", "binary" => "nova-compute", "status" => "disabled" } } response end end # mock end # openstack end # compute end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/list_zones.rb0000644000175600017570000000140012730051546024672 0ustar pravipravimodule Fog module Compute class OpenStack class Real def list_zones(options = {}) request( :expects => 200, :method => 'GET', :path => 'os-availability-zone.json', :query => options ) end end class Mock def list_zones(options = {}) Excon::Response.new( :body => { "availabilityZoneInfo" => [ { "zoneState" => { "available" => true }, "hosts" => nil, "zoneName" => "nova" } ] }, :status => 200 ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/list_volumes.rb0000644000175600017570000000217512730051546025240 0ustar pravipravimodule Fog module Compute class OpenStack class Real def list_volumes(options = true) if options.is_a?(Hash) path = 'os-volumes' query = options else # Backwards compatibility layer, when 'detailed' boolean was sent as first param if options Fog::Logger.deprecation('Calling OpenStack[:compute].list_volumes(true) is deprecated, use .list_volumes_detail instead') else Fog::Logger.deprecation('Calling OpenStack[:compute].list_volumes(false) is deprecated, use .list_volumes({}) instead') end path = options ? 'os-volumes/detail' : 'os-volumes' query = {} end request( :expects => 200, :method => 'GET', :path => path, :query => query ) end end class Mock def list_volumes(options = true) Excon::Response.new( :body => { 'volumes' => self.data[:volumes].values }, :status => 200 ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/delete_flavor_metadata.rb0000644000175600017570000000145412730051546027165 0ustar pravipravimodule Fog module Compute class OpenStack class Real def delete_flavor_metadata(flavor_ref, key) request( :expects => 200, :method => 'DELETE', :path => "flavors/#{flavor_ref}/os-extra_specs/#{key}" ) end end class Mock def delete_flavor_metadata(_flavor_ref, _key) response = Excon::Response.new response.status = 200 response.headers = { "X-Compute-Request-Id" => "req-fdc6f99e-55a2-4ab1-8904-0892753828cf", "Content-Type" => "application/json", "Content-Length" => "356", "Date" => Date.new } response.body = nil response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/delete_image.rb0000644000175600017570000000173012730051546025113 0ustar pravipravimodule Fog module Compute class OpenStack class Real def delete_image(image_id) request( :expects => 204, :method => 'DELETE', :path => "images/#{image_id}" ) end end class Mock def delete_image(image_id) response = Excon::Response.new if image = list_images_detail.body['images'].find {|_| _['id'] == image_id} if image['status'] == 'SAVING' response.status = 409 raise(Excon::Errors.status_error({:expects => 202}, response)) else self.data[:last_modified][:images].delete(image_id) self.data[:images].delete(image_id) response.status = 202 end response else response.status = 400 raise(Excon::Errors.status_error({:expects => 202}, response)) end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/remove_security_group.rb0000644000175600017570000000071612730051546027152 0ustar pravipravimodule Fog module Compute class OpenStack class Real def remove_security_group(server_id, group_name) body = {'removeSecurityGroup' => { "name" => group_name } } server_action(server_id, body) end end class Mock def remove_security_group(server_id, group_name) response = Excon::Response.new response.status = 200 response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/live_migrate_server.rb0000644000175600017570000000122512730051546026543 0ustar pravipravimodule Fog module Compute class OpenStack class Real def live_migrate_server(server_id, host, block_migration, disk_over_commit) body = { 'os-migrateLive' => { 'host' => host, 'block_migration' => block_migration, 'disk_over_commit' => disk_over_commit, } } server_action(server_id, body) end end class Mock def live_migrate_server(server_id, host, block_migration, disk_over_commit) response = Excon::Response.new response.status = 202 response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/reset_server_state.rb0000644000175600017570000000074312730051546026422 0ustar pravipravimodule Fog module Compute class OpenStack class Real def reset_server_state(server_id, status) body = { 'os-resetState' => { 'state' => status } } server_action(server_id, body, 202) end end class Mock def reset_server_state(server_id, status) response = get_server_details(server_id) response.body['server']['status'] = status.upcase response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/pause_server.rb0000644000175600017570000000115012730051546025206 0ustar pravipravimodule Fog module Compute class OpenStack class Real # Pause the server. # # === Parameters # * server_id <~String> - The ID of the server to pause. # === Returns # * success <~Boolean> def pause_server(server_id) body = { 'pause' => nil } server_action(server_id, body).status == 202 end # def pause_server end # class Real class Mock def pause_server(server_id) true end # def pause_server end # class Mock end # class OpenStack end # module Compute end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/delete_aggregate.rb0000644000175600017570000000123112730051546025753 0ustar pravipravimodule Fog module Compute class OpenStack class Real def delete_aggregate(uuid) request( :expects => [200, 202, 204], :method => 'DELETE', :path => "os-aggregates/#{uuid}" ) end end class Mock def delete_aggregate(uuid) response = Excon::Response.new response.status = 200 response.headers = { "Content-Type" => "text/html; charset=UTF-8", "Content-Length" => "0", "Date" => Date.new } response end end # mock end # openstack end # compute end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/get_flavor_metadata.rb0000644000175600017570000000117212730051546026477 0ustar pravipravimodule Fog module Compute class OpenStack class Real def get_flavor_metadata(flavor_ref) request( :expects => [200, 203], :method => 'GET', :path => "flavors/#{flavor_ref}/os-extra_specs" ) end end class Mock def get_flavor_metadata(flavor_ref) response = Excon::Response.new response.status = 200 response.body = { "extra_specs" => { "cpu_arch" => "x86_64" } } response end end # mock end # openstack end # compute end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/server_actions.rb0000644000175600017570000000227612730051546025543 0ustar pravipravimodule Fog module Compute class OpenStack class Real # Retrieve server actions. # # === Parameters # * server_id <~String> - The ID of the server to query for available actions. # === Returns # * actions <~Array> def server_actions(server_id) request( :expects => 200, :method => 'GET', :path => "servers/#{server_id}/os-instance-actions" ).body['instanceActions'] end # def server_actions end # class Real class Mock def server_actions(server_id) response = Excon::Response.new response.status = 200 response.body = [{ 'instance_uuid' => server_id, 'user_id' => '7067d67a2b23435ca2366588680b66c3', 'start_time' => Time.now.iso8601, 'request_id' => "req-#{server_id}", 'action' => 'stop', 'message' => nil, 'project_id' => '9d5d0b877cf449fdae078659cfa12e86' }] response end # def server_actions end # class Mock end # class OpenStack end # module Compute end # moduel Fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/list_volume_attachments.rb0000644000175600017570000000140312730051546027441 0ustar pravipravimodule Fog module Compute class OpenStack class Real def list_volume_attachments(server_id) request( expects: 200, method: 'GET', path: format('servers/%s/os-volume_attachments', server_id) ) end end class Mock def list_volume_attachments(server_id) Excon::Response.new( body: { volumeAttachments: [{ device: '/dev/vdd', serverId: server_id, id: '24011ca7-9937-41e4-b19b-141307d1b656', volumeId: '24011ca7-9937-41e4-b19b-141307d1b656' }] }, status: 200 ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/list_key_pairs.rb0000644000175600017570000000237312730051546025534 0ustar pravipravimodule Fog module Compute class OpenStack class Real def list_key_pairs(options = {}) request( :expects => [200, 203], :method => 'GET', :path => 'os-keypairs.json', :query => options ) end end class Mock def list_key_pairs(options = {}) response = Excon::Response.new response.status = 200 response.headers = { "X-Compute-Request-Id" => "req-c373a42c-2825-4e60-8d34-99416ea850be", "Content-Type" => "application/json", "Content-Length" => "360", "Date" => Date.new} response.body = { "keypairs" => [{ "keypair" => { "public_key" => "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDCdAZLjln1tJbLVVkNHjWFSoKen2nZbk39ZfqhZJOMdeFdz02GWBS4rcuHboeGg/gozKRwsLu4N6NLPlYtbK/NapJIvgO/djBp+FG1QZNtLPsx7j4hVJac3yISGms+Xtu4cEv6j5sFDzAgTQbWz0Z1+9qOq9ngdaoW+YClfQ== vagrant@nova\n", "name" => "test_key", "fingerprint" => "97:86:f4:15:68:0c:7b:a7:e5:8f:f0:bd:1f:27:65:ad" } }] } response end end # mock end # openstack end # compute end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/list_flavors.rb0000644000175600017570000000244512730051546025222 0ustar pravipravimodule Fog module Compute class OpenStack class Real def list_flavors(options = {}) request( :expects => [200, 203], :method => 'GET', :path => 'flavors.json', :query => options ) end end class Mock def list_flavors(options = {}) response = Excon::Response.new response.status = 200 response.body = { 'flavors' => [ { 'name' => '256 server', 'id' => '1', 'links' => ['https://itdoesntmatterwhatshere.heh'] }, { 'name' => '512 server', 'id' => '2', 'links' => ['https://itdoesntmatterwhatshere.heh'] }, { 'name' => '1GB server', 'id' => '3', 'links' => ['https://itdoesntmatterwhatshere.heh'] }, { 'name' => '2GB server', 'id' => '4', 'links' => ['https://itdoesntmatterwhatshere.heh'] }, { 'name' => '4GB server', 'id' => '5', 'links' => ['https://itdoesntmatterwhatshere.heh'] }, { 'name' => '8GB server', 'id' => '6', 'links' => ['https://itdoesntmatterwhatshere.heh'] }, { 'name' => '15.5GB server', 'id' => '7', 'links' => ['https://itdoesntmatterwhatshere.heh'] } ] } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/create_key_pair.rb0000644000175600017570000000456512730051546025646 0ustar pravipravimodule Fog module Compute class OpenStack class Real def create_key_pair(key_name, public_key = nil) data = { 'keypair' => { 'name' => key_name } } data['keypair']['public_key'] = public_key unless public_key.nil? request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'POST', :path => 'os-keypairs.json' ) end end class Mock def create_key_pair(key_name, public_key = nil) response = Excon::Response.new response.status = 200 response.headers = { "X-Compute-Request-Id" => "req-c373a42c-2825-4e60-8d34-99416ea850be", "Content-Type" => "application/json", "Content-Length" => "1289", "Date" => Date.new} response.body = { "keypair" => { "public_key" => "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDCdAZLjljntJbLVVkNHjWFSoKen2nZbk39ZfqhZJOMdeFdz02GWBS45rcuboeGg/gozKRwsLu4N6NLPlYtbK/NapJIvgO/djBp+FQG1QZNtLPsx7j4hVJac3yISGms+Xtu4cEv6j5sFDzAgTQbWez0Z1+9qOq9ngdaoW+YClfQ== vagrant@nova\n", "private_key" => "-----BEGIN RSA PRIVATE KEY-----\nMIICXgIBAAKBgQDCdAZLjljn1tJbLVVkNHjWFSoKen2nZbk39ZfqhZJOMdeFdz02\nGWBS45rcuHboeGg/gozKRwsLu4N6NLPlYtbK/NapJIvgO/djBp+FQG1QZNtLPsx7\nj4hVJac3yISGms+Xtu4cEv6j5sFDzAgTQbWez0Z1+9qOq9ngdaoW+YClfQIDAQAB\nAoGBALBoT9m1vuQ82EONQf2RONqHAsfUzi/SMhEZRgOlv9AemXZkcWyl4uPvxmtd\nEcreiTystAtCHjw7lhCExXthipevUjtIAAt+b3pMn6Oyjad3IRvde6atMdjrje43\n/nftYtuXYyJTsvwEvLYqSioLQ0Nn/XDKhOpcM5tejDHOH35lAkEA+H4r7y9X521u\nIABVAezBWaT/wvdMjx5cwfyYEQjnI1bxfRIqkgoY5gDDBdVbT75UTsHHbHLORQcw\nRjRvS2zgewJBAMhT6eyMonJvHHvC5RcchcY+dWkscIKoOzeyUKMb+7tERQa9/UN2\njYb+jdM0VyL0ruLFwYtl2m34gfmhcXgIvGcCQGzKMEnjHEUBr7jq7EyPbobkqeSd\niDMQQ+PZxmmO0EK0ib0L+v881HG926PuKK/cz+Q7Cif8iznFT+ksg50t6YkCQQC9\nwfcAskqieSuS9A9LcCIrojhXctf0e+T0Ij2N89DlF4sHEuqXf/IZ4IB5gsfTfdE3\nUDnAkK9yogaEbu/r0uKbAkEAy5kl71bIqvKTKsY2mES9ziVxfftl/9UIi5LI+QHb\nmC/c6cTrGVCM71fi2GMxGgBeEea4+7xwoWTL4CxA00kmTg==\n-----END RSA PRIVATE KEY-----\n", "user_id" => "admin", "name" => key_name, "fingerprint" => "97:86:f4:15:68:0c:7b:a7:e5:8f:f0:bd:1f:27:65:ad" } } response end end # mock end # openstack end # compute end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/add_fixed_ip.rb0000644000175600017570000000147312730051546025112 0ustar pravipravimodule Fog module Compute class OpenStack class Real # Add an IP address on a network. # # === Parameters # * server_id <~String> - The ID of the server in which to add an IP to. # * network_id <~String> - The ID of the network the IP should be on. # === Returns # * success <~Boolean> def add_fixed_ip(server_id, network_id) body = { 'addFixedIp' => { 'networkId' => network_id } } server_action(server_id, body).status == 202 end # def add_fixed_ip end # class Real class Mock def add_fixed_ip(server_id, network_id) true end # def add_fixed_ip end # class Mock end # class OpenStack end # module Compute end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/list_images.rb0000644000175600017570000000126712730051546025014 0ustar pravipravimodule Fog module Compute class OpenStack class Real def list_images request( :expects => [200, 203], :method => 'GET', :path => 'images.json' ) end end class Mock def list_images response = Excon::Response.new data = list_images_detail.body['images'] images = [] for image in data images << image.reject { |key, value| !['id', 'name', 'links'].include?(key) } end response.status = [200, 203][rand(1)] response.body = { 'images' => images } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/delete_volume.rb0000644000175600017570000000124212730051546025336 0ustar pravipravimodule Fog module Compute class OpenStack class Real def delete_volume(volume_id) request( :expects => 202, :method => 'DELETE', :path => "os-volumes/#{volume_id}" ) end end class Mock def delete_volume(volume_id) response = Excon::Response.new if list_volumes.body['volumes'].map { |v| v['id'] }.include? volume_id self.data[:volumes].delete(volume_id) response.status = 204 response else raise Fog::Compute::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/add_security_group.rb0000644000175600017570000000070512730051546026403 0ustar pravipravimodule Fog module Compute class OpenStack class Real def add_security_group(server_id, group_name) body = {'addSecurityGroup' => { "name" => group_name } } server_action(server_id, body) end end class Mock def add_security_group(server_id, group_name) response = Excon::Response.new response.status = 200 response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/list_metadata.rb0000644000175600017570000000104412730051546025320 0ustar pravipravimodule Fog module Compute class OpenStack class Real def list_metadata(collection_name, parent_id) request( :expects => [200, 203], :method => 'GET', :path => "/#{collection_name}/#{parent_id}/metadata.json" ) end end class Mock def list_metadata(collection_name, parent_id) response = Excon::Response.new response.status = 200 response.body = {} response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/get_console_output.rb0000644000175600017570000000077312730051546026436 0ustar pravipravimodule Fog module Compute class OpenStack class Real def get_console_output(server_id, log_length) body = { 'os-getConsoleOutput' => { 'length' => log_length } } server_action(server_id, body) end end class Mock def get_console_output(server_id, log_length) response = Excon::Response.new response.status = 200 response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/resume_server.rb0000644000175600017570000000116312730051546025375 0ustar pravipravimodule Fog module Compute class OpenStack class Real # Resume the server. # # === Parameters # * server_id <~String> - The ID of the server to be resumed. # === Returns # * success <~Boolean> def resume_server(server_id) body = { 'resume' => nil } server_action(server_id, body).status == 202 end # def resume_server end # class Real class Mock def resume_server(server_id) true end # def resume_server end # class Mock end # class OpenStack end # module Compute end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/remove_aggregate_host.rb0000644000175600017570000000143612730051546027052 0ustar pravipravimodule Fog module Compute class OpenStack class Real def remove_aggregate_host(uuid, host_uuid) data = {'remove_host' => {'host' => host_uuid}} request( :body => Fog::JSON.encode(data), :expects => [200], :method => 'POST', :path => "os-aggregates/#{uuid}/action" ) end end class Mock def remove_aggregate_host(uuid, host_uuid) response = Excon::Response.new response.status = 200 response.headers = { "Content-Type" => "text/html; charset=UTF-8", "Content-Length" => "0", "Date" => Date.new } response end end # mock end # openstack end # compute end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/delete_security_group_rule.rb0000644000175600017570000000175212730051546030147 0ustar pravipravimodule Fog module Compute class OpenStack class Real def delete_security_group_rule(security_group_rule_id) request( :expects => 202, :method => 'DELETE', :path => "os-security-group-rules/#{security_group_rule_id}" ) end end class Mock def delete_security_group_rule(security_group_rule_id) security_group = self.data[:security_groups].values.find{|sg| sg["rules"].find{ |sgr| sgr["id"].to_s == security_group_rule_id.to_s }} security_group["rules"].reject! { |sgr| sgr["id"] == security_group_rule_id } response = Excon::Response.new response.status = 202 response.headers = { "Content-Type" => "text/html; charset=UTF-8", "Content-Length" => "0", "Date" => Date.new } response.body = {} response end end # mock end # openstack end # compute end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/list_zones_detailed.rb0000644000175600017570000000343412730051546026536 0ustar pravipravimodule Fog module Compute class OpenStack class Real def list_zones_detailed(options = {}) request( :expects => 200, :method => 'GET', :path => 'os-availability-zone/detail.json', :query => options ) end end class Mock def list_zones_detailed(options = {}) Excon::Response.new( :body => { "availabilityZoneInfo" => [ { "zoneState" => { "available" => true}, "hosts" => { "instack.localdomain" => { "nova-conductor" => { "available" => true, "active" => true, "updated_at" => "2015-07-22T07:40:08.000000"}, "nova-scheduler" => { "available" => true, "active" => true, "updated_at" => "2015-07-22T07:40:04.000000"}, "nova-consoleauth" => { "available" => true, "active" => true, "updated_at" => "2015-07-22T07:40:09.000000"}}}, "zoneName" => "internal" }, { "zoneState" => { "available" => true}, "hosts" => { "instack.localdomain" => { "nova-compute" => { "available" => true, "active" => true, "updated_at" => "2015-07-22T07:40:04.000000"}}}, "zoneName" => "nova"}]}, :status => 200 ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/suspend_server.rb0000644000175600017570000000116612730051546025561 0ustar pravipravimodule Fog module Compute class OpenStack class Real # Suspend the server. # # === Parameters # * server_id <~String> - The ID of the server to suspend. # === Returns # * success <~Boolean> def suspend_server(server_id) body = { 'suspend' => nil } server_action(server_id, body).status == 202 end # def suspend_server end # class Real class Mock def suspend_server(server_id) true end # def suspend_server end # class Mock end # class OpenStack end # module Compute end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/create_image.rb0000644000175600017570000000272712730051546025123 0ustar pravipravimodule Fog module Compute class OpenStack class Real def create_image(server_id, name, metadata={}) body = { 'createImage' => { 'name' => name, 'metadata' => metadata }} data = server_action(server_id, body) image_id = data.headers["Location"].scan(/.*\/(.*)/).flatten[0] get_image_details(image_id) end end class Mock def create_image(server_id, name, metadata={}) response = Excon::Response.new response.status = 202 img_id=Fog::Mock.random_numbers(6).to_s data = { 'id' => img_id, 'server' => {"id"=>"3", "links"=>[{"href"=>"http://nova1:8774/admin/servers/#{server_id}", "rel"=>"bookmark"}]}, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/images/#{img_id}", "rel"=>"self"}, {"href"=>"http://nova1:8774/admin/images/#{img_id}", "rel"=>"bookmark"}], 'metadata' => metadata || {}, 'name' => name || "server_#{rand(999)}", 'progress' => 0, 'status' => 'SAVING', 'minDisk' => 0, 'minRam' => 0, 'updated' => "", 'created' => "" } self.data[:last_modified][:images][data['id']] = Time.now self.data[:images][data['id']] = data response.body = { 'image' => data } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/list_snapshots.rb0000644000175600017570000000231312730051546025562 0ustar pravipravimodule Fog module Compute class OpenStack class Real def list_snapshots(options = true) if options.is_a?(Hash) path = 'os-snapshots' query = options else # Backwards compatibility layer, when 'detailed' boolean was sent as first param if options Fog::Logger.deprecation('Calling OpenStack[:compute].list_snapshots(true) is deprecated, use .list_snapshots_detail instead') else Fog::Logger.deprecation('Calling OpenStack[:compute].list_snapshots(false) is deprecated, use .list_snapshots({}) instead') end path = options ? 'os-snapshots/detail' : 'os-snapshots' query = {} end request( :expects => 200, :method => 'GET', :path => path, :query => query ) end end class Mock def list_snapshots(options = true) response = Excon::Response.new response.status = 200 snapshots = self.data[:snapshots].values response.body = { 'snapshots' => snapshots } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/list_snapshots_detail.rb0000644000175600017570000000114512730051546027106 0ustar pravipravimodule Fog module Compute class OpenStack class Real def list_snapshots_detail(options = {}) request( :expects => 200, :method => 'GET', :path => 'os-snapshots/detail', :query => options ) end end class Mock def list_snapshots_detail(options = {}) response = Excon::Response.new response.status = 200 snapshots = self.data[:snapshots].values response.body = { 'snapshots' => snapshots } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/disable_service_log_reason.rb0000644000175600017570000000225512730051546030045 0ustar pravipravimodule Fog module Compute class OpenStack class Real def disable_service_log_reason(host, binary, disabled_reason, optional_params = nil) data = {"host" => host, "binary" => binary, "disabled_reason" => disabled_reason} # Encode all params optional_params = optional_params.each { |k, v| optional_params[k] = URI::encode(v) } if optional_params request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'PUT', :path => "os-services/disable-log-reason", :query => optional_params ) end end class Mock def disable_service_log_reason(host, binary, disabled_reason, optional_params = nil) response = Excon::Response.new response.status = 200 response.body = { "service" => { "host" => "host1", "binary" => "nova-compute", "status" => "disabled", "disabled_reason" => "test2" } } response end end # mock end # openstack end # compute end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/shelve_server.rb0000644000175600017570000000116212730051546025362 0ustar pravipravimodule Fog module Compute class OpenStack class Real # Shelve the server. # # === Parameters # * server_id <~String> - The ID of the server to be shelved # === Returns # * success <~Boolean> def shelve_server(server_id) body = { 'shelve' => nil } server_action(server_id, body).status == 202 end # def shelve_server end # class Real class Mock def shelve_server(server_id) true end # def shelve_server end # class Mock end # class OpenStack end # module Compute end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/list_aggregates.rb0000644000175600017570000000162212730051546025653 0ustar pravipravimodule Fog module Compute class OpenStack class Real def list_aggregates(options = {}) request( :expects => [200, 203], :method => 'GET', :path => 'os-aggregates', :query => options ) end end class Mock def list_aggregates(options = {}) response = Excon::Response.new response.status = 200 response.body = {'aggregates' => [{ "availability_zone" => "nova", "created_at" => "2012-11-16T06:22:23.032493", "deleted" => false, "deleted_at" => nil, "metadata" => { "availability_zone" => "nova" }, "id" => 1, "name" => "name", "updated_at" => nil }]} response end end # mock end # openstack end # compute end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/get_security_group_rule.rb0000644000175600017570000000240512730051546027460 0ustar pravipravimodule Fog module Compute class OpenStack class Real def get_security_group_rule(security_group_rule_id) request( :expects => [200], :method => 'GET', :path => "os-security-group-rules/#{security_group_rule_id}" ) end end class Mock def get_security_group_rule(security_group_rule_id) security_group_rule = nil self.data[:security_groups].find{|id, sg| security_group_rule = sg["rules"].find{ |sgr| sgr["id"].to_s == security_group_rule_id.to_s }} response = Excon::Response.new if security_group_rule response.status = 200 response.headers = { "X-Compute-Request-Id" => "req-63a90344-7c4d-42e2-936c-fd748bced1b3", "Content-Type" => "application/json", "Content-Length" => "167", "Date" => Date.new } response.body = { "security_group_rule" => security_group_rule } else raise Fog::Compute::OpenStack::NotFound, "Security group rule #{security_group_rule_id} does not exist" end response end end # mock end # openstack end #compute end #fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/detach_volume.rb0000644000175600017570000000142512730051546025327 0ustar pravipravimodule Fog module Compute class OpenStack class Real def detach_volume(server_id, attachment_id) request( :expects => 202, :method => 'DELETE', :path => "servers/%s/os-volume_attachments/%s" % [server_id, attachment_id] ) end end class Mock def detach_volume(server_id, attachment_id) response = Excon::Response.new if self.data[:volumes][attachment_id] && self.data[:volumes][attachment_id]['attachments'].reject! { |attachment| attachment['serverId'] == server_id } response.status = 202 response else raise Fog::Compute::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/delete_flavor.rb0000644000175600017570000000122312730051546025317 0ustar pravipravimodule Fog module Compute class OpenStack class Real def delete_flavor(flavor_id) request( :expects => 202, :method => 'DELETE', :path => "flavors/#{flavor_id}" ) end end class Mock def delete_flavor(flavor_id) response = Excon::Response.new response.status = 202 response.headers = { "Content-Type" => "text/html; charset=UTF-8", "Content-Length" => "0", "Date" => Date.new } response end end # mock end # openstack end # compute end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/get_vnc_console.rb0000644000175600017570000000230312730051546025653 0ustar pravipravimodule Fog module Compute class OpenStack class Real # Get a vnc console for an instance. # # === Parameters # * server_id <~String> - The ID of the server. # * console_type <~String> - Type of vnc console to get ('novnc' or 'xvpvnc'). # === Returns # * response <~Excon::Response>: # * body <~Hash>: # * url <~String> # * type <~String> def get_vnc_console(server_id, console_type) body = { 'os-getVNCConsole' => { 'type' => console_type } } server_action(server_id, body) end # def get_vnc_console end # class Real class Mock def get_vnc_console(server_id, console_type) response = Excon::Response.new response.status = 200 response.body = { "console" => { "url" => "http://192.168.27.100:6080/vnc_auto.html?token=c3606020-d1b7-445d-a88f-f7af48dd6a20", "type" => "novnc" } } response end # def get_vnc_console end # class Mock end # class OpenStack end # module Compute end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/list_tenants_with_flavor_access.rb0000644000175600017570000000123512730051546031143 0ustar pravipravimodule Fog module Compute class OpenStack class Real def list_tenants_with_flavor_access(flavor_ref) request( :expects => [200, 203], :method => 'GET', :path => "flavors/#{flavor_ref}/os-flavor-access.json" ) end end class Mock def list_tenants_with_flavor_access(flavor_ref) response = Excon::Response.new response.status = 200 response.body = { "flavor_access" => [{ "tenant_id" => Fog::Mock.random_hex(33), "flavor_id" => flavor_ref.to_s }] } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/rebuild_server.rb0000644000175600017570000000206212730051546025522 0ustar pravipravimodule Fog module Compute class OpenStack class Real def rebuild_server(server_id, image_ref, name, admin_pass=nil, metadata=nil, personality=nil) body = { 'rebuild' => { 'imageRef' => image_ref, 'name' => name }} body['rebuild']['adminPass'] = admin_pass if admin_pass body['rebuild']['metadata'] = metadata if metadata if personality body['rebuild']['personality'] = [] for file in personality body['rebuild']['personality'] << { 'contents' => Base64.encode64(file['contents']), 'path' => file['path'] } end end server_action(server_id, body, 202) end end class Mock def rebuild_server(server_id, image_ref, name, admin_pass=nil, metadata=nil, personality=nil) response = get_server_details(server_id) response.body['server']['status'] = "REBUILD" response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/delete_meta.rb0000644000175600017570000000167512730051546024767 0ustar pravipravimodule Fog module Compute class OpenStack class Real def delete_meta(collection_name, parent_id, key) request( :expects => 204, :method => 'DELETE', :path => "#{collection_name}/#{parent_id}/metadata/#{key}" ) end end class Mock def delete_meta(collection_name, parent_id, key) if collection_name == "images" then if not list_images_detail.body['images'].find {|_| _['id'] == parent_id} raise Fog::Compute::OpenStack::NotFound end end if collection_name == "servers" then if not list_servers_detail.body['servers'].find {|_| _['id'] == parent_id} raise Fog::Compute::OpenStack::NotFound end end response = Excon::Response.new response.status = 204 response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/remove_fixed_ip.rb0000644000175600017570000000145212730051546025654 0ustar pravipravimodule Fog module Compute class OpenStack class Real # Remove an IP address. # # === Parameters # * server_id <~String> - The ID of the server in which to remove an IP from. # * address <~String> - The IP address to be removed. # === Returns # * success <~Boolean> def remove_fixed_ip(server_id, address) body = { 'removeFixedIp' => { 'address' => address } } server_action(server_id, body).status == 202 end # def remove_fixed_ip end # class Real class Mock def remove_fixed_ip(server_id, address) true end # def remove_fixed_ip end # class Mock end # class OpenStack end # module Compute end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/list_images_detail.rb0000644000175600017570000000200512730051546026325 0ustar pravipravimodule Fog module Compute class OpenStack class Real def list_images_detail(filters = {}) request( :expects => [200, 203], :method => 'GET', :path => 'images/detail.json', :query => filters ) end end class Mock def list_images_detail(filters = {}) response = Excon::Response.new images = self.data[:images].values for image in images case image['status'] when 'SAVING' if Time.now - self.data[:last_modified][:images][image['id']] >= Fog::Mock.delay image['status'] = 'ACTIVE' end end end response.status = [200, 203][rand(1)] response.body = { 'images' => images.map {|image| image.reject {|key, value| !['id', 'name', 'links', 'minRam', 'minDisk', 'metadata', 'status', 'updated'].include?(key)}} } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/set_tenant.rb0000644000175600017570000000057712730051546024663 0ustar pravipravimodule Fog module Compute class OpenStack class Real def set_tenant(tenant) @openstack_must_reauthenticate = true @openstack_tenant = tenant.to_s authenticate end end class Mock def set_tenant(tenant) true end end end # class OpenStack end # module Compute end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/delete_snapshot.rb0000644000175600017570000000126612730051546025674 0ustar pravipravimodule Fog module Compute class OpenStack class Real def delete_snapshot(snapshot_id) request( :expects => 202, :method => 'DELETE', :path => "os-snapshots/#{snapshot_id}" ) end end class Mock def delete_snapshot(snapshot_id) response = Excon::Response.new response.status = 204 if list_snapshots_detail.body['snapshots'].find { |_| _['id'] == snapshot_id } self.data[:snapshots].delete(snapshot_id) else raise Fog::Compute::OpenStack::NotFound end response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/release_address.rb0000644000175600017570000000124512730051546025635 0ustar pravipravimodule Fog module Compute class OpenStack class Real def release_address(address_id) request( :expects => [200, 202], :method => 'DELETE', :path => "os-floating-ips/#{address_id}" ) end end class Mock def release_address(address_id) response = Excon::Response.new response.status = 202 response.headers = { "Content-Type" => "text/html; charset=UTF-8", "Content-Length" => "0", "Date" => Date.new } response.body = {} response end end # mock end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/create_flavor_metadata.rb0000644000175600017570000000176312730051546027171 0ustar pravipravimodule Fog module Compute class OpenStack class Real def create_flavor_metadata(flavor_ref, metadata) data = { 'extra_specs' => metadata } request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'POST', :path => "flavors/#{flavor_ref}/os-extra_specs" ) end end class Mock def create_flavor_metadata(flavor_ref, metadata) response = Excon::Response.new response.status = 200 response.headers = { "X-Compute-Request-Id" => "req-fdc6f99e-55a2-4ab1-8904-0892753828cf", "Content-Type" => "application/json", "Content-Length" => "356", "Date" => Date.new } response.body = { "extra_specs" => { "cpu_arch" => "x86_64" } } response end end # mock end # openstack end # compute end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/get_flavor_details.rb0000644000175600017570000000353112730051546026345 0ustar pravipravimodule Fog module Compute class OpenStack class Real def get_flavor_details(flavor_ref) request( :expects => [200, 203], :method => 'GET', :path => "flavors/#{flavor_ref}.json" ) end end class Mock def get_flavor_details(flavor_ref) response = Excon::Response.new flavor = { '1' => { 'id' => '1', 'name' => '256 server', 'ram' => 256, 'disk' => 10, 'swap' => '1', 'vcpus' => 1, 'OS-FLV-EXT-DATA:ephemeral' => 1, 'links' => [] }, '2' => { 'id' => '2', 'name' => '512 server', 'ram' => 512, 'disk' => 20, 'swap' => '1', 'vcpus' => 2, 'OS-FLV-EXT-DATA:ephemeral' => 1, 'links' => [] }, '3' => { 'id' => '3', 'name' => '1GB server', 'ram' => 1024, 'disk' => 40, 'swap' => '2', 'vcpus' => 2, 'OS-FLV-EXT-DATA:ephemeral' => 1, 'links' => [] }, '4' => { 'id' => '4', 'name' => '2GB server', 'ram' => 2048, 'disk' => 80, 'swap' => '4', 'vcpus' => 4, 'OS-FLV-EXT-DATA:ephemeral' => 1, 'links' => [] }, '5' => { 'id' => '5', 'name' => '4GB server', 'ram' => 4096, 'disk' => 160, 'swap' => '8', 'vcpus' => 8, 'OS-FLV-EXT-DATA:ephemeral' => 1, 'links' => [] }, '6' => { 'id' => '6', 'name' => '8GB server', 'ram' => 8192, 'disk' => 320, 'swap' => '16', 'vcpus' => 16, 'OS-FLV-EXT-DATA:ephemeral' => 1, 'links' => [] }, '7' => { 'id' => '7', 'name' => '15.5GB server', 'ram' => 15872, 'disk' => 620, 'swap' => '32', 'vcpus' => 32, 'OS-FLV-EXT-DATA:ephemeral' => 1, 'links' => [] } }[flavor_ref] if flavor response.status = 200 response.body = { 'flavor' => flavor } response else raise Fog::Compute::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/disassociate_address.rb0000644000175600017570000000116212730051546026666 0ustar pravipravimodule Fog module Compute class OpenStack class Real def disassociate_address(server_id, ip_address) body = { "removeFloatingIp" => {"address" => ip_address}} server_action(server_id, body) end end class Mock def disassociate_address(server_id, ip_address) response = Excon::Response.new response.status = 202 response.headers = { "Content-Type" => "text/html, charset=UTF-8", "Content-Length" => "0", "Date"=> Date.new } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/list_servers.rb0000644000175600017570000000163612730051546025240 0ustar pravipravimodule Fog module Compute class OpenStack class Real def list_servers(options = {}) params = options.dup if params[:all_tenants] params['all_tenants'] = 'True' params.delete(:all_tenants) end request( :expects => [200, 203], :method => 'GET', :path => 'servers.json', :query => params ) end end class Mock def list_servers(options = {}) response = Excon::Response.new data = list_servers_detail.body['servers'] servers = [] for server in data servers << server.reject { |key, value| !['id', 'name', 'links'].include?(key) } end response.status = [200, 203][rand(1)] response.body = { 'servers' => servers } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/evacuate_server.rb0000644000175600017570000000145212730051546025673 0ustar pravipravimodule Fog module Compute class OpenStack class Real def evacuate_server(server_id, host = nil, on_shared_storage = nil, admin_password = nil) evacuate = {} evacuate['host'] = host if host evacuate['onSharedStorage'] = on_shared_storage if on_shared_storage evacuate['adminPass'] = admin_password if admin_password body = { 'evacuate' => evacuate } server_action(server_id, body) end end class Mock def evacuate_server(_server_id, _host, _on_shared_storage, _admin_password = nil) response = Excon::Response.new response.status = 202 response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/get_address.rb0000644000175600017570000000173612730051546025001 0ustar pravipravimodule Fog module Compute class OpenStack class Real def get_address(address_id) request( :expects => [200], :method => 'GET', :path => "os-floating-ips/#{address_id}" ) end end class Mock def get_address(address_id) response = Excon::Response.new response.status = 200 response.headers = { "X-Compute-Request-Id" => "req-d4a21158-a86c-44a6-983a-e25645907f26", "Content-Type" => "application/json", "Content-Length" => "105", "Date"=> Date.new } response.body = { "floating_ip" => { "instance_id" => nil, "ip" => "192.168.27.129", "fixed_ip" => nil, "id" => 1, "pool" => "nova" } } response end end # mock end # openstack end # compute end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/delete_server.rb0000644000175600017570000000165012730051546025340 0ustar pravipravimodule Fog module Compute class OpenStack class Real def delete_server(server_id) request( :expects => 204, :method => 'DELETE', :path => "servers/#{server_id}" ) end end class Mock def delete_server(server_id) response = Excon::Response.new if server = list_servers_detail.body['servers'].find {|_| _['id'] == server_id} if server['status'] == 'BUILD' response.status = 409 raise(Excon::Errors.status_error({:expects => 204}, response)) else self.data[:last_modified][:servers].delete(server_id) self.data[:servers].delete(server_id) response.status = 204 end response else raise Fog::Compute::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/update_flavor_metadata.rb0000644000175600017570000000162212730051546027202 0ustar pravipravimodule Fog module Compute class OpenStack class Real def update_flavor_metadata(flavor_ref, key, value) data = {key => value} request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'PUT', :path => "flavors/#{flavor_ref}/os-extra_specs/#{key}" ) end end class Mock def update_flavor_metadata(_flavor_ref, key, value) response = Excon::Response.new response.status = 200 response.headers = { "X-Compute-Request-Id" => "req-fdc6f99e-55a2-4ab1-8904-0892753828cf", "Content-Type" => "application/json", "Content-Length" => "356", "Date" => Date.new } response.body = {key => value} response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/get_server_password.rb0000644000175600017570000000134712730051546026602 0ustar pravipravimodule Fog module Compute class OpenStack class Real def get_server_password(server_id) request( :expects => [200, 203], :method => 'GET', :path => "servers/#{server_id}/os-server-password.json" ) end end class Mock def get_server_password(server_id) response = Excon::Response.new if server = list_servers_detail.body['servers'].find {|_| _['id'] == server_id} response.status = [200, 203][rand(1)] response.body = { 'server' => server } response else raise Fog::Compute::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/start_server.rb0000644000175600017570000000115712730051546025235 0ustar pravipravimodule Fog module Compute class OpenStack class Real # Start the server. # # === Parameters # * server_id <~String> - The ID of the server to be started. # === Returns # * success <~Boolean> def start_server(server_id) body = { 'os-start' => nil } server_action(server_id, body).status == 202 end # def start_server end # class Real class Mock def start_server(server_id) true end # def start_server end # class Mock end # class OpenStack end # module Compute end # module Fogfog-openstack-0.1.6/lib/fog/openstack/requests/compute/unshelve_server.rb0000644000175600017570000000120012730051546025716 0ustar pravipravimodule Fog module Compute class OpenStack class Real # Unshelve the server. # # === Parameters # * server_id <~String> - The ID of the server to be unshelved # === Returns # * success <~Boolean> def unshelve_server(server_id) body = { 'unshelve' => nil } server_action(server_id, body).status == 202 end # def unshelve_server end # class Real class Mock def unshelve_server(server_id) true end # def unshelve_server end # class Mock end # class OpenStack end # module Compute end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/unpause_server.rb0000644000175600017570000000116612730051546025560 0ustar pravipravimodule Fog module Compute class OpenStack class Real # Unpause the server. # # === Parameters # * server_id <~String> - The ID of the server to unpause. # === Returns # * success <~Boolean> def unpause_server(server_id) body = { 'unpause' => nil } server_action(server_id, body).status == 202 end # def unpause_server end # class Real class Mock def unpause_server(server_id) true end # def unpause_server end # class Mock end # class OpenStack end # module Compute end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/list_addresses.rb0000644000175600017570000000133012730051546025513 0ustar pravipravimodule Fog module Compute class OpenStack class Real def list_addresses(server_id) request( :expects => [200, 203], :method => 'GET', :path => "servers/#{server_id}/ips.json" ) end end class Mock def list_addresses(server_id) response = Excon::Response.new if server = list_servers_detail.body['servers'].find {|_| _['id'] == server_id} response.status = [200, 203][rand(1)] response.body = { 'addresses' => server['addresses'] } response else raise Fog::Compute::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/reboot_server.rb0000644000175600017570000000066112730051546025371 0ustar pravipravimodule Fog module Compute class OpenStack class Real def reboot_server(server_id, type = 'SOFT') body = { 'reboot' => { 'type' => type }} server_action(server_id, body) end end class Mock def reboot_server(server_id, type = 'SOFT') response = Excon::Response.new response.status = 202 response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/get_quota.rb0000644000175600017570000000112212730051546024472 0ustar pravipravimodule Fog module Compute class OpenStack class Real def get_quota(tenant_id) request( :expects => 200, :method => 'GET', :path => "/os-quota-sets/#{tenant_id}" ) end end class Mock def get_quota(tenant_id) response = Excon::Response.new response.status = 200 response.body = { 'quota_set' => (self.data[:quota_updated] or self.data[:quota]).merge({'id' => tenant_id}) } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/create_flavor.rb0000644000175600017570000000566112730051546025332 0ustar pravipravimodule Fog module Compute class OpenStack class Real # PARAMETERS # # name = Name of flavor # ram = Memory in MB # vcpus = Number of VCPUs # disk = Size of local disk in GB # swap = Swap space in MB # rxtx_factor = RX/TX factor def create_flavor(attributes) # Get last flavor id flavor_ids = Array.new flavors = list_flavors_detail.body['flavors'] + list_flavors_detail(:is_public => false).body['flavors'] flavors.each do |flavor| flavor_ids << flavor['id'].to_i end # Set flavor id attributes[:flavor_id] = attributes[:flavor_id] || ((flavor_ids.length > 0) ? (flavor_ids.sort.last) + 1 : 1) data = { 'flavor' => { 'name' => attributes[:name], 'ram' => attributes[:ram], 'vcpus' => attributes[:vcpus], 'disk' => attributes[:disk], 'id' => attributes[:flavor_id], 'swap' => attributes[:swap], 'OS-FLV-EXT-DATA:ephemeral' => attributes[:ephemeral], 'os-flavor-access:is_public' => attributes[:is_public], 'rxtx_factor' => attributes[:rxtx_factor] } } request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'POST', :path => 'flavors' ) end end class Mock def create_flavor(attributes) response = Excon::Response.new response.status = 200 response.headers = { "X-Compute-Request-Id" => "req-fdc6f99e-55a2-4ab1-8904-0892753828cf", "Content-Type" => "application/json", "Content-Length" => "356", "Date" => Date.new } response.body = { "flavor" => { "vcpus" => attributes[:vcpus], "disk" => attributes[:disk], "name" => attributes[:name], "links" => [ { "href" => "http://192.168.27.100:8774/v1.1/6733e93c5f5c4eb1bcabc6902ba208d6/flavors/11", "rel" => "self" }, { "href" => "http://192.168.27.100:8774/6733e93c5f5c4eb1bcabc6902ba208d6/flavors/11", "rel" => "bookmark" } ], "rxtx_factor" => attributes[:rxtx_factor] || 1.0, "OS-FLV-EXT-DATA:ephemeral" => attributes[:ephemeral] || 0, "os-flavor-access:is_public" => attributes[:is_public] || false, "OS-FLV-DISABLED:disabled" => attributes[:disabled] || false, "ram" => attributes[:ram], "id" => "11", "swap" => attributes[:swap] || "" } } response end end # mock end # openstack end # compute end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/update_meta.rb0000644000175600017570000000217312730051546025001 0ustar pravipravimodule Fog module Compute class OpenStack class Real def update_meta(collection_name, parent_id, key, value) request( :body => Fog::JSON.encode({ 'meta' => {key => value}}), :expects => 200, :method => 'PUT', :path => "#{collection_name}/#{parent_id}/metadata/#{key}" ) end end class Mock def update_meta(collection_name, parent_id, key, value) if collection_name == "images" then if not list_images_detail.body['images'].find {|_| _['id'] == parent_id} raise Fog::Compute::OpenStack::NotFound end end if collection_name == "servers" then if not list_servers_detail.body['servers'].find {|_| _['id'] == parent_id} raise Fog::Compute::OpenStack::NotFound end end #FIXME join w/ existing metadata here response = Excon::Response.new response.body = { "metadata" => {key => value} } response.status = 200 response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/get_usage.rb0000644000175600017570000000373612730051546024462 0ustar pravipravimodule Fog module Compute class OpenStack class Real def get_usage(tenant_id, date_start, date_end) params = Hash.new params[:start] = date_start.utc.iso8601.chop! params[:end] = date_end.utc.iso8601.chop! request( :expects => [200, 203], :method => 'GET', :path => "os-simple-tenant-usage/#{tenant_id}", :query => params ) end end class Mock def get_usage(tenant_id, date_start, date_end) response = Excon::Response.new response.status = 200 response.body = {"tenant_usage"=> {"total_memory_mb_usage" => 0.0, "total_vcpus_usage" => 0.0, "total_hours" => 0.0, "tenant_id" => tenant_id, "stop" => date_start, "start" => date_end, "total_local_gb_usage" => 0.0, "server_usages" =>[{ "hours" => 0.0, "uptime" => 69180, "local_gb" => 0, "ended_at" => nil, "name" => "test server", "tenant_id" => tenant_id, "vcpus" => 1, "memory_mb" => 512, "state" => "active", "flavor" => "m1.tiny", "started_at" => "2012-03-05 09:11:44" } ] } } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/create_aggregate.rb0000644000175600017570000000207212730051546025760 0ustar pravipravimodule Fog module Compute class OpenStack class Real def create_aggregate(name, options = {}) data = { 'aggregate' => { 'name' => name } } vanilla_options = ["availability_zone"] vanilla_options.select{|o| options[o]}.each do |key| data['aggregate'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => [200], :method => 'POST', :path => "os-aggregates" ) end end class Mock def create_aggregate(name, options = {}) response = Excon::Response.new response.status = 200 response.headers = { "Content-Type" => "text/html; charset=UTF-8", "Content-Length" => "0", "Date" => Date.new } response.body = {'aggregate' => self.data[:aggregates].first} response end end # mock end # openstack end # compute end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/server_action.rb0000644000175600017570000000056612730051546025360 0ustar pravipravimodule Fog module Compute class OpenStack class Real def server_action(server_id, body, expects=[200,202]) request( :body => Fog::JSON.encode(body), :expects => expects, :method => 'POST', :path => "servers/#{server_id}/action.json" ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/update_aggregate_metadata.rb0000644000175600017570000000146212730051546027641 0ustar pravipravimodule Fog module Compute class OpenStack class Real def update_aggregate_metadata(uuid, metadata = {}) data = {'set_metadata' => {'metadata' => metadata}} request( :body => Fog::JSON.encode(data), :expects => [200], :method => 'POST', :path => "os-aggregates/#{uuid}/action" ) end end class Mock def update_aggregate_metadata(uuid, metadata = {}) response = Excon::Response.new response.status = 200 response.headers = { "Content-Type" => "text/html; charset=UTF-8", "Content-Length" => "0", "Date" => Date.new } response end end # mock end # openstack end # compute end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/get_server_volumes.rb0000644000175600017570000000135712730051546026433 0ustar pravipravimodule Fog module Compute class OpenStack class Real def get_server_volumes(server_id) request( :expects => 200, :method => 'GET', :path => "/servers/#{server_id}/os-volume_attachments" ) end end class Mock def get_server_volumes(server_id) response = Excon::Response.new response.status = 200 data = self.data[:volumes].values.select do |vol| vol['attachments'].find { |attachment| attachment["serverId"] == server_id } end response.body = { 'volumeAttachments' => data.map! { |vol| vol['attachments'] }.flatten(1) } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/get_volume_details.rb0000644000175600017570000000150112730051546026356 0ustar pravipravimodule Fog module Compute class OpenStack class Real def get_volume_details(volume_id) request( :expects => 200, :method => 'GET', :path => "os-volumes/#{volume_id}" ) end end class Mock def get_volume_details(volume_id) response = Excon::Response.new if data = self.data[:volumes][volume_id] if data['status'] == 'creating' \ && Time.now - Time.parse(data['createdAt']) >= Fog::Mock.delay data['status'] = 'available' end response.status = 200 response.body = { 'volume' => data } response else raise Fog::Compute::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/list_usages.rb0000644000175600017570000000305412730051546025032 0ustar pravipravimodule Fog module Compute class OpenStack class Real def list_usages(date_start = nil, date_end = nil, detailed=false) params = Hash.new params[:start] = date_start.iso8601.gsub(/\+.*/, '') if date_start params[:end] = date_end.iso8601.gsub(/\+.*/, '') if date_end params[:detailed] = (detailed ? '1' : '0') if detailed request( :expects => [200, 203], :method => 'GET', :path => 'os-simple-tenant-usage', :query => params ) end end class Mock def list_usages(date_start = nil, date_end = nil, detailed=false) params = Hash.new response = Excon::Response.new response.status = 200 response.body = {"tenant_usages"=>[{ "total_memory_mb_usage" => 0.00036124444444444445, "total_vcpus_usage" => 7.055555555555556e-07, "start" => "2012-03-06 05:05:56.349001", "tenant_id" => "b97c8abba0c44a0987c63b858a4823e5", "stop" => "2012-03-06 05:05:56.349255", "total_hours" => 7.055555555555556e-07, "total_local_gb_usage" => 0.0 } ] } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/update_aggregate.rb0000644000175600017570000000200012730051546025766 0ustar pravipravimodule Fog module Compute class OpenStack class Real def update_aggregate(uuid, options = {}) vanilla_options = ['name', 'availability_zone'] data = {'aggregate' => {}} vanilla_options.select{|o| options[o]}.each do |key| data['aggregate'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => [200], :method => 'PUT', :path => "os-aggregates/#{uuid}" ) end end class Mock def update_aggregate(uuid, options = {}) response = Excon::Response.new response.status = 200 response.headers = { "Content-Type" => "text/html; charset=UTF-8", "Content-Length" => "0", "Date" => Date.new } response.body = {'aggregate' => self.data[:aggregates].first} response end end # mock end # openstack end # compute end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/revert_resize_server.rb0000644000175600017570000000130312730051546026761 0ustar pravipravimodule Fog module Compute class OpenStack class Real def revert_resize_server(server_id) body = { 'revertResize' => nil } server_action(server_id, body) end end class Mock def revert_resize_server(server_id) response = Excon::Response.new response.status = 202 self.data[:servers][server_id]['flavorId'] = self.data[:servers][server_id]['old_flavorId'] self.data[:servers][server_id].delete('old_flavorId') self.data[:last_modified][:servers][server_id] = Time.now self.data[:servers][server_id]['status'] = 'ACTIVE' response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/list_address_pools.rb0000644000175600017570000000107512730051546026405 0ustar pravipravimodule Fog module Compute class OpenStack class Real def list_address_pools request( :expects => [200, 203], :method => 'GET', :path => "os-floating-ip-pools" ) end end class Mock def list_address_pools response = Excon::Response.new response.status = 200 response.body = { 'floating_ip_pools' => [ { 'name' => 'nova' } ] } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/stop_server.rb0000644000175600017570000000115112730051546025057 0ustar pravipravimodule Fog module Compute class OpenStack class Real # Stop the server. # # === Parameters # * server_id <~String> - The ID of the server to be stopped. # === Returns # * success <~Boolean> def stop_server(server_id) body = { 'os-stop' => nil } server_action(server_id, body).status == 202 end # def stop_server end # class Real class Mock def stop_server(server_id) true end # def stop_server end # class Mock end # class OpenStack end # module Compute end # module Fogfog-openstack-0.1.6/lib/fog/openstack/requests/compute/migrate_server.rb0000644000175600017570000000061012730051546025521 0ustar pravipravimodule Fog module Compute class OpenStack class Real def migrate_server(server_id) body = { 'migrate' => nil } server_action(server_id, body) end end class Mock def migrate_server(server_id) response = Excon::Response.new response.status = 202 response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/get_snapshot_details.rb0000644000175600017570000000133012730051546026706 0ustar pravipravimodule Fog module Compute class OpenStack class Real def get_snapshot_details(snapshot_id) request( :expects => 200, :method => 'GET', :path => "os-snapshots/#{snapshot_id}" ) end end class Mock def get_snapshot_details(snapshot_id) response = Excon::Response.new if snapshot = list_snapshots_detail.body['snapshots'].find{ |_| _['id'] == snapshot_id } response.status = 200 response.body = { 'snapshot' => snapshot } response else raise Fog::Compute::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/boot_from_snapshot.rb0000644000175600017570000000241312730051546026413 0ustar pravipravimodule Fog module Compute class OpenStack class Real def boot_from_snapshot(name, image_ref, flavor_ref, options={}) data = { 'server' => { 'flavorRef' => flavor_ref, 'imageRef' => image_ref, 'name' => name } } vanilla_options = ['metadata', 'accessIPv4', 'accessIPv6', 'availability_zone', 'user_data', 'block_device_mapping', 'key_name', 'security_groups'] vanilla_options.select{|o| options[o]}.each do |key| data['server'][key] = options[key] end if options['personality'] data['server']['personality'] = [] for file in options['personality'] data['server']['personality'] << { 'contents' => Base64.encode64(file['contents']), 'path' => file['path'] } end end request( :body => Fog::JSON.encode(data), :expects => [200, 202], :method => 'POST', :path => '/os-volumes_boot.json' ) end end end # class OpenStack end # module Compute end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/create_server.rb0000644000175600017570000001640412730051546025344 0ustar pravipravimodule Fog module Compute class OpenStack class Real def create_server(name, image_ref, flavor_ref, options = {}) data = { 'server' => { 'flavorRef' => flavor_ref, 'name' => name } } data['server']['imageRef'] = image_ref if image_ref vanilla_options = ['metadata', 'accessIPv4', 'accessIPv6', 'availability_zone', 'user_data', 'key_name', 'adminPass', 'config_drive', 'min_count', 'max_count', 'return_reservation_id' ] vanilla_options.select{|o| options[o]}.each do |key| data['server'][key] = options[key] end if options['security_groups'] # security names requires a hash with a name prefix data['server']['security_groups'] = Array(options['security_groups']).map do |sg| name = if sg.is_a?(Fog::Compute::OpenStack::SecurityGroup) then sg.name else sg end { :name => name } end end if options['personality'] data['server']['personality'] = [] for file in options['personality'] data['server']['personality'] << { 'contents' => Base64.encode64(file['contents'] || file[:contents]), 'path' => file['path'] || file[:path] } end end if options['nics'] data['server']['networks'] = Array(options['nics']).map do |nic| neti = { 'uuid' => (nic['net_id'] || nic[:net_id]) } neti['fixed_ip'] = (nic['v4_fixed_ip'] || nic[:v4_fixed_ip]) unless (nic['v4_fixed_ip'] || nic[:v4_fixed_ip]).nil? neti['port'] = (nic['port_id'] || nic[:port_id]) unless (nic['port_id'] || nic[:port_id]).nil? neti end end if options['os:scheduler_hints'] data['os:scheduler_hints'] = options['os:scheduler_hints'] end if (block_device_mapping = options['block_device_mapping_v2']) data['server']['block_device_mapping_v2'] = [block_device_mapping].flatten.collect do |mapping| entered_block_device_mapping = {} [:boot_index, :delete_on_termination, :destination_type, :device_name, :source_type, :uuid, :volume_size].each do |index| entered_block_device_mapping[index.to_s] = mapping[index] if mapping.key?(index) end entered_block_device_mapping end elsif (block_device_mapping = options['block_device_mapping']) data['server']['block_device_mapping'] = [block_device_mapping].flatten.collect do |mapping| { 'delete_on_termination' => mapping[:delete_on_termination], 'device_name' => mapping[:device_name], 'volume_id' => mapping[:volume_id], 'volume_size' => mapping[:volume_size], } end end path = options['block_device_mapping'] ? 'os-volumes_boot.json' : 'servers.json' request( :body => Fog::JSON.encode(data), :expects => [200, 202], :method => 'POST', :path => path ) end end class Mock def create_server(name, image_ref, flavor_ref, options = {}) response = Excon::Response.new response.status = 202 server_id = Fog::Mock.random_numbers(6).to_s identity = Fog::Identity::OpenStack.new :openstack_auth_url => credentials[:openstack_auth_url] user = identity.users.find { |u| u.name == @openstack_username } user_id = if user then user.id else response = identity.create_user(@openstack_username, 'password', "#{@openstack_username}@example.com") response.body["user"]["id"] end mock_data = { 'addresses' => {"Private" => [{"addr" => Fog::Mock.random_ip }]}, 'flavor' => {"id" => flavor_ref, "links"=>[{"href"=>"http://nova1:8774/admin/flavors/1", "rel"=>"bookmark"}]}, 'id' => server_id, 'image' => {"id" => image_ref, "links"=>[{"href"=>"http://nova1:8774/admin/images/#{image_ref}", "rel"=>"bookmark"}]}, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/servers/5", "rel"=>"self"}, {"href"=>"http://nova1:8774/admin/servers/5", "rel"=>"bookmark"}], 'hostId' => "123456789ABCDEF01234567890ABCDEF", 'metadata' => options['metadata'] || {}, 'name' => name || "server_#{rand(999)}", 'accessIPv4' => options['accessIPv4'] || "", 'accessIPv6' => options['accessIPv6'] || "", 'progress' => 0, 'status' => 'BUILD', 'created' => '2012-09-27T00:04:18Z', 'updated' => '2012-09-27T00:04:27Z', 'user_id' => @openstack_username, 'config_drive' => options['config_drive'] || '', } if nics = options['nics'] nics.each do |nic| mock_data["addresses"].merge!( "Public" => [{ 'addr' => Fog::Mock.random_ip }] ) end end response_data = {} if options['return_reservation_id'] == 'True' then response_data = { 'reservation_id' => "r-#{Fog::Mock.random_numbers(6).to_s}" } else response_data = { 'adminPass' => 'password', 'id' => server_id, 'links' => mock_data['links'], } end if block_devices = options["block_device_mapping_v2"] block_devices.each { |bd| compute.volumes.get(bd[:uuid]).attach(server_id, bd[:device_name]) } elsif block_device = options["block_device_mapping"] compute.volumes.get(block_device[:volume_id]).attach(server_id, block_device[:device_name]) end self.data[:last_modified][:servers][server_id] = Time.now self.data[:servers][server_id] = mock_data if security_groups = options['security_groups'] then groups = Array(options['security_groups']).map do |sg| if sg.is_a?(Fog::Compute::OpenStack::SecurityGroup) then sg.name else sg end end self.data[:server_security_group_map][server_id] = groups response_data['security_groups'] = groups end self.data[:last_modified][:servers][server_id] = Time.now self.data[:servers][server_id] = mock_data if options['return_reservation_id'] == 'True' then response.body = response_data else response.body = { 'server' => response_data } end response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/create_volume.rb0000644000175600017570000000327712730051546025351 0ustar pravipravi# module Fog module Compute class OpenStack # class Real def create_volume(name, description, size, options = {}) data = { 'volume' => { 'display_name' => name, 'display_description' => description, 'size' => size } } vanilla_options = [ :snapshot_id, :availability_zone, :volume_type, :metadata] vanilla_options.select { |o| options[o] }.each do |key| data['volume'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => [200, 202], :method => 'POST', :path => 'os-volumes' ) end end # class Mock def create_volume(name, description, size, options = {}) response = Excon::Response.new response.status = 202 data = {'id' => Fog::Mock.random_numbers(2), 'displayName' => name, 'displayDescription' => description, 'size' => size, 'status' => 'creating', 'snapshotId' => options[:snapshot_id], 'volumeType' => options[:volume_type] || 'None', 'availabilityZone' => options[:availability_zone] || 'nova', 'createdAt' => Time.now.strftime('%FT%T.%6N'), 'attachments' => [], 'metadata' => options[:metadata] || {} } self.data[:volumes][data['id']] = data response.body = {'volume' => data} response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/list_all_addresses.rb0000644000175600017570000000325112730051546026347 0ustar pravipravimodule Fog module Compute class OpenStack class Real def list_all_addresses(options = {}) request( :expects => [200, 203], :method => 'GET', :path => "os-floating-ips.json", :query => options ) end end class Mock def list_all_addresses(options = {}) response = Excon::Response.new response.status = 200 response.headers = { "X-Compute-Request-Id" => "req-d4a21158-a86c-44a6-983a-e25645907f26", "Content-Type" => "application/json", "Content-Length" => "378", "Date"=> Date.new } response.body = { "floating_ips" => [ { "instance_id" => nil, "ip" => "192.168.27.129", "fixed_ip" => nil, "id" => 1, "pool" => "nova" }, { "instance_id" => nil, "ip" => "192.168.27.130", "fixed_ip" => nil, "id" => 2, "pool" => "nova" }, { "instance_id" => nil, "ip" => "192.168.27.131", "fixed_ip" => nil, "id" => 3, "pool" => "nova" }, { "instance_id" => nil, "ip" => "192.168.27.132", "fixed_ip" => nil, "id" => 4, "pool" => "nova" } ] } response end end # mock end # openstack end # Compute end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/confirm_resize_server.rb0000644000175600017570000000064112730051546027113 0ustar pravipravimodule Fog module Compute class OpenStack class Real def confirm_resize_server(server_id) body = { 'confirmResize' => nil } server_action(server_id, body, 204) end end class Mock def confirm_resize_server(server_id) response = Excon::Response.new response.status = 204 response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/list_availability_zones.rb0000644000175600017570000000064612730051546027437 0ustar pravipravimodule Fog module Compute class OpenStack class Real def list_availability_zones(options = {}) params = options request( :expects => [200], :method => 'GET', :path => "os-availability-zone", :query => params ) end end class Mock def list_endpoints end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/update_quota.rb0000644000175600017570000000133212730051546025200 0ustar pravipravimodule Fog module Compute class OpenStack class Real def update_quota(tenant_id, options = {}) options['tenant_id'] = tenant_id request( :body => Fog::JSON.encode({ 'quota_set' => options }), :expects => 200, :method => 'PUT', :path => "/os-quota-sets/#{tenant_id}" ) end end class Mock def update_quota(tenant_id, options = {}) self.data[:quota_updated] = self.data[:quota].merge options response = Excon::Response.new response.status = 200 response.body = { 'quota_set' => self.data[:quota_updated] } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/change_server_password.rb0000644000175600017570000000073412730051546027247 0ustar pravipravimodule Fog module Compute class OpenStack class Real def change_server_password(server_id, admin_password) body = { 'changePassword' => { 'adminPass' => admin_password }} server_action(server_id, body) end end class Mock def change_server_password(server_id, admin_password) response = Excon::Response.new response.status = 202 response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/get_metadata.rb0000644000175600017570000000107312730051546025126 0ustar pravipravimodule Fog module Compute class OpenStack class Real def get_metadata(collection_name, parent_id, key) request( :expects => [200, 203], :method => 'GET', :path => "#{collection_name}/#{parent_id}/metadata/#{key}" ) end end class Mock def get_metadata(collection_name, parent_id, key) response = Excon::Response.new response.status = 200 response.body = { 'meta' => {} } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/enable_service.rb0000644000175600017570000000177012730051546025461 0ustar pravipravimodule Fog module Compute class OpenStack class Real def enable_service(host, binary, optional_params = nil) data = {"host" => host, "binary" => binary} # Encode all params optional_params = optional_params.each { |k, v| optional_params[k] = URI::encode(v) } if optional_params request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'PUT', :path => "os-services/enable", :query => optional_params ) end end class Mock def enable_service(host, binary, optional_params = nil) response = Excon::Response.new response.status = 200 response.body = { "service" => { "host" => "host1", "binary" => "nova-compute", "status" => "enabled" } } response end end # mock end # openstack end # compute end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/attach_volume.rb0000644000175600017570000000201112730051546025333 0ustar pravipravimodule Fog module Compute class OpenStack class Real def attach_volume(volume_id, server_id, device) data = { 'volumeAttachment' => { 'volumeId' => volume_id.to_s, 'device' => device } } request( :body => Fog::JSON.encode(data), :expects => [200, 202], :method => 'POST', :path => "servers/%s/os-volume_attachments" % [server_id] ) end end class Mock def attach_volume(volume_id, server_id, device) response = Excon::Response.new response.status = 200 data = { 'id' => volume_id, 'volumeId' => volume_id, 'serverId' => server_id, 'device' => device } self.data[:volumes][volume_id]['attachments'] << data response.body = { 'volumeAttachment' => data } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/list_tenants.rb0000644000175600017570000000252112730051546025215 0ustar pravipravimodule Fog module Compute class OpenStack class Real def list_tenants response = @identity_connection.request({ :expects => [200, 204], :headers => {'Content-Type' => 'application/json', 'Accept' => 'application/json', 'X-Auth-Token' => @auth_token}, :method => 'GET', :path => '/v2.0/tenants' }) response.body = Fog::JSON.decode(response.body) response end end class Mock def list_tenants response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = { 'tenants_links' => [], 'tenants' => [ {'id' => '1', 'description' => 'Has access to everything', 'enabled' => true, 'name' => 'admin'}, {'id' => '2', 'description' => 'Normal tenant', 'enabled' => true, 'name' => 'default'}, {'id' => '3', 'description' => 'Disabled tenant', 'enabled' => false, 'name' => 'disabled'} ] } response end end # class Mock end #class OpenStack end # module Compute end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/server_diagnostics.rb0000644000175600017570000000125112730051546026402 0ustar pravipravimodule Fog module Compute class OpenStack class Real # Retrieve server diagnostics. # # === Parameters # * server_id <~String> - The ID of the server to retrieve diagnostics. # === Returns # * actions <~Array> def server_diagnostics(server_id) request( :method => 'GET', :path => "servers/#{server_id}/diagnostics" ) end # def server_diagnostics end # class Real class Mock def server_diagnostics(server_id) end # def server_diagnostics end # class Real end # class OpenStack end # module Compute end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/allocate_address.rb0000644000175600017570000000203112730051546025773 0ustar pravipravimodule Fog module Compute class OpenStack class Real def allocate_address(pool = nil) request( :body => Fog::JSON.encode({'pool' => pool}), :expects => [200, 202], :method => 'POST', :path => 'os-floating-ips.json' ) end end class Mock def allocate_address(pool = nil) response = Excon::Response.new response.status = 200 response.headers = { "X-Compute-Request-Id" => "req-d4a21158-a86c-44a6-983a-e25645907f26", "Content-Type" => "application/json", "Content-Length" => "105", "Date"=> Date.new } response.body = { "floating_ip" => { "instance_id" => nil, "ip" => "192.168.27.132", "fixed_ip" => nil, "id" => 4, "pool"=>"nova" } } response end end # mock end # openstack end #compute end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/list_flavors_detail.rb0000644000175600017570000000330512730051546026540 0ustar pravipravimodule Fog module Compute class OpenStack class Real def list_flavors_detail(options = {}) request( :expects => [200, 203], :method => 'GET', :path => 'flavors/detail.json', :query => options ) end end class Mock def list_flavors_detail(options = {}) response = Excon::Response.new response.status = 200 response.body = { 'flavors' => [ { 'id' => '1', 'name' => '256 server', 'ram' => 256, 'disk' => 10, 'swap' => '1', 'vcpus' => 1, 'OS-FLV-EXT-DATA:ephemeral' => 1, 'links' => [] }, { 'id' => '2', 'name' => '512 server', 'ram' => 512, 'disk' => 20, 'swap' => '1', 'vcpus' => 2, 'OS-FLV-EXT-DATA:ephemeral' => 1, 'links' => [] }, { 'id' => '3', 'name' => '1GB server', 'ram' => 1024, 'disk' => 40, 'swap' => '2', 'vcpus' => 2, 'OS-FLV-EXT-DATA:ephemeral' => 1, 'links' => [] }, { 'id' => '4', 'name' => '2GB server', 'ram' => 2048, 'disk' => 80, 'swap' => '4', 'vcpus' => 4, 'OS-FLV-EXT-DATA:ephemeral' => 1, 'links' => [] }, { 'id' => '5', 'name' => '4GB server', 'ram' => 4096, 'disk' => 160, 'swap' => '8', 'vcpus' => 8, 'OS-FLV-EXT-DATA:ephemeral' => 1, 'links' => [] }, { 'id' => '6', 'name' => '8GB server', 'ram' => 8192, 'disk' => 320, 'swap' => '16', 'vcpus' => 16, 'OS-FLV-EXT-DATA:ephemeral' => 1, 'links' => [] }, { 'id' => '7', 'name' => '15.5GB server', 'ram' => 15872, 'disk' => 620, 'swap' => '32', 'vcpus' => 32, 'OS-FLV-EXT-DATA:ephemeral' => 1, 'links' => [] } ] } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/list_security_groups.rb0000644000175600017570000000404012730051546027005 0ustar pravipravimodule Fog module Compute class OpenStack class Real def list_security_groups(options = {}) path = "os-security-groups.json" if options.is_a?(Hash) server_id = options.delete(:server_id) query = options else # Backwards compatibility layer, only server_id was passed as first parameter previously Fog::Logger.deprecation('Calling OpenStack[:compute].list_security_groups(server_id) is deprecated, use .list_security_groups(:server_id => value) instead') server_id = options query = {} end if server_id path = "servers/#{server_id}/#{path}" end request( :expects => [200], :method => 'GET', :path => path, :query => query ) end end class Mock def list_security_groups(options = {}) if options.is_a?(Hash) server_id = options.delete(:server_id) query = options else server_id = options query = {} end security_groups = self.data[:security_groups].values groups = if server_id then server_group_names = Array(self.data[:server_security_group_map][server_id]) server_group_names.map do |name| security_groups.find do |sg| sg['name'] == name end end.compact else security_groups end Excon::Response.new( :body => { 'security_groups' => groups }, :headers => { "X-Compute-Request-Id" => "req-#{Fog::Mock.random_base64(36)}", "Content-Type" => "application/json", "Date" => Date.new }, :status => 200 ) end end # mock end # openstack end # compute end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/get_security_group.rb0000644000175600017570000000214612730051546026433 0ustar pravipravimodule Fog module Compute class OpenStack class Real def get_security_group(security_group_id) request( :expects => [200], :method => 'GET', :path => "os-security-groups/#{security_group_id}" ) end end class Mock def get_security_group(security_group_id) security_group = self.data[:security_groups][security_group_id.to_s] response = Excon::Response.new if security_group response.status = 200 response.headers = { "X-Compute-Request-Id" => "req-63a90344-7c4d-42e2-936c-fd748bced1b3", "Content-Type" => "application/json", "Content-Length" => "167", "Date" => Date.new } response.body = { "security_group" => security_group } else raise Fog::Compute::OpenStack::NotFound, "Security group #{security_group_id} does not exist" end response end end # mock end # openstack end #compute end #fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/delete_security_group.rb0000644000175600017570000000144712730051546027121 0ustar pravipravimodule Fog module Compute class OpenStack class Real def delete_security_group(security_group_id) request( :expects => 202, :method => 'DELETE', :path => "os-security-groups/#{security_group_id}" ) end end class Mock def delete_security_group(security_group_id) self.data[:security_groups].delete security_group_id.to_s response = Excon::Response.new response.status = 202 response.headers = { "Content-Type" => "text/html; charset=UTF-8", "Content-Length" => "0", "Date" => Date.new } response.body = {} response end end # mock end # openstack end # compute end #fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/add_aggregate_host.rb0000644000175600017570000000142512730051546026303 0ustar pravipravimodule Fog module Compute class OpenStack class Real def add_aggregate_host(uuid, host_uuid) data = {'add_host' => {'host' => host_uuid}} request( :body => Fog::JSON.encode(data), :expects => [200], :method => 'POST', :path => "os-aggregates/#{uuid}/action" ) end end class Mock def add_aggregate_host(uuid, host_uuid) response = Excon::Response.new response.status = 200 response.headers = { "Content-Type" => "text/html; charset=UTF-8", "Content-Length" => "0", "Date" => Date.new } response end end # mock end # openstack end # compute end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/compute/delete_metadata.rb0000644000175600017570000000102212730051546025603 0ustar pravipravimodule Fog module Compute class OpenStack class Real def delete_metadata(collection_name, parent_id, key) request( :expects => 204, :method => 'DELETE', :path => "#{collection_name}/#{parent_id}/metadata/#{key}" ) end end class Mock def delete_metadata(collection_name, parent_id, key) response = Excon::Response.new response.status = 204 response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/resize_server.rb0000644000175600017570000000066612730051546025405 0ustar pravipravimodule Fog module Compute class OpenStack class Real def resize_server(server_id, flavor_ref) body = { 'resize' => { 'flavorRef' => flavor_ref }} server_action(server_id, body) end end class Mock def resize_server(server_id, flavor_ref) response = Excon::Response.new response.status = 202 response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/set_metadata.rb0000644000175600017570000000210512730051546025137 0ustar pravipravimodule Fog module Compute class OpenStack class Real def set_metadata(collection_name, parent_id, metadata = {}) request( :body => Fog::JSON.encode({ 'metadata' => metadata }), :expects => 200, :method => 'PUT', :path => "#{collection_name}/#{parent_id}/metadata" ) end end class Mock def set_metadata(collection_name, parent_id, metadata = {}) if collection_name == "images" then if not list_images_detail.body['images'].find {|_| _['id'] == parent_id} raise Fog::Compute::OpenStack::NotFound end end if collection_name == "servers" then if not list_servers_detail.body['servers'].find {|_| _['id'] == parent_id} raise Fog::Compute::OpenStack::NotFound end end response = Excon::Response.new response.body = { "metadata" => metadata } response.status = 200 response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/compute/get_limits.rb0000644000175600017570000000571412730051546024655 0ustar pravipravimodule Fog module Compute class OpenStack # http://docs.openstack.org/api/openstack-compute/2/content/ProgramaticLimits.html # class Real def get_limits request( :expects => 200, :method => 'GET', :path => '/limits.json' ) end end class Mock def get_limits rate_limits = [ { 'regex' => '.*', 'limit' => [ { 'next-available' => '2012-11-22T16:13:44Z', 'unit' => 'MINUTE', 'verb' => 'POST', 'remaining' => 9, 'value' => 10 }, { 'next-available' => '2012-11-23T00:46:14Z', 'unit' => 'MINUTE', 'verb' => 'PUT', 'remaining' => 10, 'value' => 10 }, { 'next-available' => '2012-11-22T16:14:30Z', 'unit' => 'MINUTE', 'verb' => 'DELETE', 'remaining' => 99, 'value' => 100 } ], 'uri' => '*' }, { 'regex' => '^/servers', 'limit' => [ { 'next-available' => '2012-11-23T00:46:14Z', 'unit' => 'DAY', 'verb' => 'POST', 'remaining' => 50, 'value' => 50} ], 'uri'=>'*/servers' }, { 'regex' => '.*changes-since.*', 'limit' => [ { 'next-available' => '2012-11-23T00:46:14Z', 'unit' => 'MINUTE', 'verb' => 'GET', 'remaining' => 3, 'value' => 3 } ], 'uri' => '*changes-since*' } ] absolute_limits = { # Max 'maxServerMeta' => 128, 'maxTotalInstances' => 10, 'maxPersonality' => 5, 'maxImageMeta' => 128, 'maxPersonalitySize' => 10240, 'maxSecurityGroupRules' => 20, 'maxTotalKeypairs' => 100, 'maxSecurityGroups' => 10, 'maxTotalCores' => 20, 'maxTotalFloatingIps' => 10, 'maxTotalRAMSize' => 51200, # Used 'totalCoresUsed' => -1, 'totalRAMUsed' => -2048, 'totalInstancesUsed' => -1, 'totalSecurityGroupsUsed' => 0, 'totalFloatingIpsUsed' => 0 } Excon::Response.new( :status => 200, :body => { 'limits' => { 'rate' => rate_limits, 'absolute' => absolute_limits } } ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/image_v2/0000755000175600017570000000000012730051546022176 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/requests/image_v2/update_image.rb0000644000175600017570000000344312730051546025153 0ustar pravipravimodule Fog module Image class OpenStack class V2 class Real def update_image(id, json_patch) request( :headers => {'Content-Type' => 'application/openstack-images-v2.1-json-patch'}, :expects => [200], :method => 'PATCH', :path => "images/#{id}", :body => Fog::JSON.encode(json_patch) ) end end class Mock def update_image(attributes) response = Excon::Response.new response.status = 200 image = self.images.last response.body = { 'image' => { 'name' => attributes[:name] || image.name, 'size' => image.size, 'min_disk' => (attributes[:min_disk] || image.min_disk).to_i, 'disk_format' => attributes[:disk_format] || image.disk_format, 'created_at' => image.created_at, 'container_format' => attributes[:container_format] || image.container_format, 'deleted_at' => nil, 'updated_at' => Time.now.to_s, 'checksum' => image.checksum, 'id' => attributes[:id], 'deleted' => false, 'protected' => false, 'is_public' => attributes[:is_public] || image.is_public, 'status' => image.status, 'min_ram' => (attributes[:min_ram] || image.min_ram).to_i, 'owner' => attributes[:owner] || image.owner, 'properties' => attributes[:properties] || image.properties } } response end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/image_v2/update_image_member.rb0000644000175600017570000000211112730051546026471 0ustar pravipravimodule Fog module Image class OpenStack class V2 class Real def update_image_member(image_id, member) request( # 'status' is the only property we can update :body => Fog::JSON.encode(member.select {|key, value| key=='status'}), :expects => [200], :method => 'PUT', :path => "images/#{image_id}/members/#{member['member_id']}" ) end end # class Real class Mock def update_image_members(image_id, member) response = Excon::Response.new response.status = 204 response.body = { :status=> "accepted", :created_at=> "2013-11-26T07:21:21Z", :updated_at=> "2013-11-26T07:21:21Z", :image_id=> image_id, :member_id=> member['member_id'], :schema=> "/v2/schemas/member" } response end end # class Mock end # class OpenStack end end # module Identity end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/image_v2/delete_image.rb0000644000175600017570000000076712730051546025141 0ustar pravipravimodule Fog module Image class OpenStack class V2 class Real def delete_image(image_id) request( :expects => 204, :method => 'DELETE', :path => "images/#{image_id}" ) end end class Mock def delete_image(image_id) response = Excon::Response.new response.status = 204 response end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/image_v2/add_tag_to_image.rb0000644000175600017570000000116312730051546025753 0ustar pravipravimodule Fog module Image class OpenStack class V2 class Real def add_tag_to_image(image_id, tag) request( :expects => [204], :method => 'PUT', :path => "images/#{image_id}/tags/#{tag}" ) end end # class Real class Mock def add_tag_to_image(image_id, tag) response = Excon::Response.new response.status = 204 response end # def add_tag_to_image end # class Mock end # class OpenStack end end # module Image end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/image_v2/remove_member_from_image.rb0000644000175600017570000000125712730051546027541 0ustar pravipravimodule Fog module Image class OpenStack class V2 class Real def remove_member_from_image(image_id, member_id) request( :expects => [200, 204], :method => 'DELETE', :path => "images/#{image_id}/members/#{member_id}" ) end end # class Real class Mock def remove_member_from_image(image_id, member_id) response = Excon::Response.new response.status = [200, 204][rand(1)] response end # def list_tenants end # class Mock end # class OpenStack end end # module Identity end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/image_v2/reactivate_image.rb0000644000175600017570000000102012730051546026005 0ustar pravipravimodule Fog module Image class OpenStack class V2 class Real def reactivate_image(image_id) request( :expects => 204, :method => 'POST', :path => "images/#{image_id}/actions/reactivate" ) end end class Mock def reactivate_image(image_id) response = Excon::Response.new response.status = 204 response end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/image_v2/list_images.rb0000644000175600017570000000214712730051546025027 0ustar pravipravimodule Fog module Image class OpenStack class V2 class Real def list_images(options = {}) request( :expects => [200], :method => 'GET', :path => 'images', :query => options ) end end # class Real class Mock def list_images(options = {}) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = { "images" => [{ "name" => Fog::Mock.random_letters(10), "size" => Fog::Mock.random_numbers(8).to_i, "disk_format" => "iso", "container_format" => "bare", "id" => Fog::Mock.random_hex(36), "checksum" => Fog::Mock.random_hex(32)}] } response end # def list_tenants end # class Mock end # class OpenStack end end # module Identity end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/image_v2/create_image.rb0000644000175600017570000000317412730051546025135 0ustar pravipravimodule Fog module Image class OpenStack class V2 class Real def create_image(image) location = image.delete :location headers = {} headers["Location"] = location if location request( :headers => headers, :expects => [201], :method => 'POST', :path => "images", :body => Fog::JSON.encode(image) ) end end class Mock def create_image(attributes) response = Excon::Response.new response.status = 201 image_id = Fog::Mock.random_hex(32) image = self.data[:images][image_id] = { 'tags' => attributes[:tags] || [], 'name' => attributes[:name], 'size' => nil, 'min_disk' => attributes[:min_disk] || 0, 'disk_format' => attributes[:disk_format] || 'raw', 'created_at' => Time.now.strftime('%FT%T.%6N'), 'container_format' => attributes[:container_format] || 'bare', 'deleted_at' => nil, 'updated_at' => Time.now.strftime('%FT%T.%6N'), 'checksum' => nil, 'id' => image_id, 'visibility' => attributes[:visibility] || 'public', 'status' => 'queued', 'min_ram' => attributes[:min_ram] || 0, 'owner' => attributes[:owner] || Fog::Mock.random_hex(32) } response.body = image response end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/image_v2/upload_image.rb0000644000175600017570000000150512730051546025152 0ustar pravipravimodule Fog module Image class OpenStack class V2 class Real def upload_image(image_id, body, params={}) request_hash = { :headers => {'Content-Type' => 'application/octet-stream'}, :expects => 204, :method => 'PUT', :path => "images/#{image_id}/file" } request_hash[:request_block] = params[:request_block] if params[:request_block] request_hash[:body] = body if body request(request_hash).body ensure body.close if body.respond_to?(:close) end end class Mock def upload_image(image_id, body) response = Excon::Response.new response.status = 204 end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/image_v2/set_tenant.rb0000644000175600017570000000065612730051546024676 0ustar pravipravimodule Fog module Image class OpenStack class V2 class Real def set_tenant(tenant) @openstack_must_reauthenticate = true @openstack_tenant = tenant.to_s authenticate end end class Mock def set_tenant(tenant) true end end end # class OpenStack end end # module Compute end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/image_v2/get_image_members.rb0000644000175600017570000000151312730051546026156 0ustar pravipravimodule Fog module Image class OpenStack class V2 class Real def get_image_members(image_id) request( :expects => [200, 204], :method => 'GET', :path => "images/#{image_id}/members" ) end end # class Real class Mock def get_image_members(image_id) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = { "members" => [ {"member_id" => "ff528b20431645ebb5fa4b0a71ca002f", "can_share" => false} ] } response end # def list_tenants end # class Mock end # class OpenStack end end # module Identity end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/image_v2/deactivate_image.rb0000644000175600017570000000102012730051546025767 0ustar pravipravimodule Fog module Image class OpenStack class V2 class Real def deactivate_image(image_id) request( :expects => 204, :method => 'POST', :path => "images/#{image_id}/actions/deactivate" ) end end class Mock def deactivate_image(image_id) response = Excon::Response.new response.status = 204 response end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/image_v2/get_image.rb0000644000175600017570000000447012730051546024451 0ustar pravipravimodule Fog module Image class OpenStack class V2 class Real def get_image(image_id) request( :expects => [200, 204], :method => 'HEAD', :path => "images/#{image_id}" ) end end # class Real class Mock def get_image(image_id) response = Excon::Response.new response.status = [200, 204][rand(1)] response.headers= {"X-Image-Meta-Is_public" => "True", "X-Image-Meta-Min_disk" => "0", "X-Image-Meta-Property-Ramdisk_id" => "b45aa128-cd36-4ad9-a026-1a1c2bfd8fdc", "X-Image-Meta-Disk_format" => "ami", "X-Image-Meta-Created_at" => "2012-02-21T07:32:26", "X-Image-Meta-Container_format" => "ami", "Etag" => "2f81976cae15c16ef0010c51e3a6c163", "Location" => "http://192.168.27.100:9292/v1/images/0e09fbd6-43c5-448a-83e9-0d3d05f9747e", "X-Image-Meta-Protected" => "False", "Date" => "Fri, 24 Feb 2012 02:14:25 GMT", "X-Image-Meta-Name" => "cirros-0.3.0-x86_64-blank", "X-Image-Meta-Min_ram" => "0", "Content-Type" => "text/html; charset=UTF-8", "X-Image-Meta-Updated_at" => "2012-02-21T07:32:29", "X-Image-Meta-Property-Kernel_id" => "cd28951e-e1c2-4bc5-95d3-f0495abbcdc5", "X-Image-Meta-Size" => "25165824", "X-Image-Meta-Checksum" => "2f81976cae15c16ef0010c51e3a6c163", "X-Image-Meta-Deleted" => "False", "Content-Length" => "0", "X-Image-Meta-Owner" => "ff528b20431645ebb5fa4b0a71ca002f", "X-Image-Meta-Status" => "active", "X-Image-Meta-Id" => "0e09fbd6-43c5-448a-83e9-0d3d05f9747e"} response.body = "" response end # def list_tenants end # class Mock end # class OpenStack end end # module Identity end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/image_v2/add_member_to_image.rb0000644000175600017570000000130412730051546026444 0ustar pravipravimodule Fog module Image class OpenStack class V2 class Real def add_member_to_image(image_id, tenant_id) request( :expects => [200], :method => 'POST', :path => "images/#{image_id}/members", :body => Fog::JSON.encode({:member => tenant_id}) ) end end # class Real class Mock def add_member_to_image(image_id, tenant_id) response = Excon::Response.new response.status = 200 response end # def list_tenants end # class Mock end # class OpenStack end end # module Identity end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/image_v2/download_image.rb0000644000175600017570000000163212730051546025476 0ustar pravipravimodule Fog module Image class OpenStack class V2 class Real def download_image(image_id, content_range=nil, params) # TODO: implement content range handling request_hash = { :expects => [200, 204], :method => 'GET', :raw_body => true, :path => "images/#{image_id}/file", } request_hash[:response_block] = params[:response_block] if params[:response_block] request(request_hash).body end end # class Real class Mock def download_image(image_id, content_range=nil) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = "" response end # def list_tenants end # class Mock end # class OpenStack end end # module Identity end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/image_v2/get_shared_images.rb0000644000175600017570000000152212730051546026155 0ustar pravipravimodule Fog module Image class OpenStack class V2 class Real def get_shared_images(tenant_id) request( :expects => [200, 204], :method => 'GET', :path => "shared-images/#{tenant_id}" ) end end # class Real class Mock def get_shared_images(tenant_id) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = { "shared_images" => [ {"image_id" => "ff528b20431645ebb5fa4b0a71ca002f", "can_share" => false} ] } response end # def list_tenants end # class Mock end # class OpenStack end end # module Identity end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/image_v2/remove_tag_from_image.rb0000644000175600017570000000120512730051546027036 0ustar pravipravimodule Fog module Image class OpenStack class V2 class Real def remove_tag_from_image(image_id, tag) request( :expects => [204], :method => 'DELETE', :path => "images/#{image_id}/tags/#{tag}" ) end end # class Real class Mock def remove_tag_from_image(image_id, tag) response = Excon::Response.new response.status = 204 response end # def remove_tag_from_image end # class Mock end # class OpenStack end end # module Image end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/image_v2/get_image_by_id.rb0000644000175600017570000000207712730051546025620 0ustar pravipravimodule Fog module Image class OpenStack class V2 class Real def get_image_by_id(image_id) request( :expects => [200], :method => 'GET', :path => "images/#{image_id}" ) end end # class Real class Mock def get_image_by_id(image_id) response = Excon::Response.new response.status = [200][rand(1)] response.body = { "images" => [{ "name" => "mock-image-name", "size" => 25165824, "disk_format" => "ami", "container_format" => "ami", "id" => "0e09fbd6-43c5-448a-83e9-0d3d05f9747e", "checksum" => "2f81976cae15c16ef0010c51e3a6c163"}] } response end # def list_tenants end # class Mock end # class OpenStack end end # module Identity end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/image_v2/get_member_details.rb0000644000175600017570000000200112730051546026327 0ustar pravipravimodule Fog module Image class OpenStack class V2 class Real def get_member_details(image_id, member_id) request( :expects => [200], :method => 'GET', :path => "images/#{image_id}/members/#{member_id}" ).body end end # class Real class Mock def get_member_details(image_id, member_id) response = Excon::Response.new response.status = 200 response.body = { :status=> "pending", :created_at=> "2013-11-26T07:21:21Z", :updated_at=> "2013-11-26T07:21:21Z", :image_id=> "0ae74cc5-5147-4239-9ce2-b0c580f7067e", :member_id=> "8989447062e04a818baf9e073fd04fa7", :schema=> "/v2/schemas/member" } response end # def list_tenants end # class Mock end # class OpenStack end end # module Identity end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/metering/0000755000175600017570000000000012730051546022317 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/requests/metering/get_resource.rb0000644000175600017570000000124112730051546025330 0ustar pravipravimodule Fog module Metering class OpenStack class Real def get_resource(resource_id) request( :expects => 200, :method => 'GET', :path => "resources/#{resource_id}" ) end end class Mock def get_resource(resource_id) response = Excon::Response.new response.status = 200 response.body = { 'resource_id'=>'glance', 'project_id'=>'d646b40dea6347dfb8caee2da1484c56', 'user_id'=>'1d5fd9eda19142289a60ed9330b5d284', 'metadata'=>{}} response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/metering/get_samples.rb0000644000175600017570000000247012730051546025152 0ustar pravipravimodule Fog module Metering class OpenStack class Real def get_samples(meter_id, options=[]) data = { 'q' => Array.new } options.each do |opt| filter = {} ['field', 'op', 'value'].each do |key| filter[key] = opt[key] if opt[key] end data['q'] << filter unless filter.empty? end request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'GET', :path => "meters/#{meter_id}" ) end end class Mock def get_samples(meter_id) response = Excon::Response.new response.status = 200 response.body = [{ 'counter_name'=>'image.size', 'user_id'=>'1d5fd9eda19142289a60ed9330b5d284', 'resource_id'=>'glance', 'timestamp'=>'2013-04-03T23:44:21', 'resource_metadata'=>{}, 'source'=>'artificial', 'counter_unit'=>'bytes', 'counter_volume'=>10.0, 'project_id'=>'d646b40dea6347dfb8caee2da1484c56', 'message_id'=>'14e4a902-9cf3-11e2-a054-003048f5eafc', 'counter_type'=>'gauge'}] response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/metering/get_statistics.rb0000644000175600017570000000247312730051546025703 0ustar pravipravimodule Fog module Metering class OpenStack class Real def get_statistics(meter_id, options={}) data = { 'period' => options['period'], 'q' => Array.new } options['q'].each do |opt| filter = {} ['field', 'op', 'value'].each do |key| filter[key] = opt[key] if opt[key] end data['q'] << filter unless filter.empty? end if options['q'].is_a? Array request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'GET', :path => "meters/#{meter_id}/statistics" ) end end class Mock def get_statistics(meter_id, options={}) response = Excon::Response.new response.status = 200 response.body = [{ 'count'=>143, 'duration_start'=>'2013-04-03T23:44:21', 'min'=>10.0, 'max'=>10.0, 'duration_end'=>'2013-04-04T23:24:21', 'period'=>0, 'period_end'=>'2013-04-04T23:24:21', 'duration'=>85200.0, 'period_start'=>'2013-04-03T23:44:21', 'avg'=>10.0, 'sum'=>1430.0}] response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/metering/list_events.rb0000644000175600017570000000166212730051546025210 0ustar pravipravimodule Fog module Metering class OpenStack class Real def list_events(options=[]) data = { 'q' => Array.new } options.each do |opt| filter = {} ['field', 'op', 'value'].each do |key| filter[key] = opt[key] if opt[key] end data['q'] << filter unless filter.empty? end request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'GET', :path => 'events' ) end end class Mock def list_events(options={}) response = Excon::Response.new response.status = 200 response.body = [{ 'event_type'=>'compute.instance.create', 'message_id'=>'d646b40dea6347dfb8caee2da1484c56', }] response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/metering/list_resources.rb0000644000175600017570000000123212730051546025707 0ustar pravipravimodule Fog module Metering class OpenStack class Real def list_resources(options = {}) request( :expects => 200, :method => 'GET', :path => 'resources' ) end end class Mock def list_resources(options = {}) response = Excon::Response.new response.status = 200 response.body = [{ 'resource_id'=>'glance', 'project_id'=>'d646b40dea6347dfb8caee2da1484c56', 'user_id'=>'1d5fd9eda19142289a60ed9330b5d284', 'metadata'=>{}}] response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/metering/get_event.rb0000644000175600017570000000113212730051546024621 0ustar pravipravimodule Fog module Metering class OpenStack class Real def get_event(message_id) request( :expects => 200, :method => 'GET', :path => "events/#{message_id}" ) end end class Mock def get_event(message_id) response = Excon::Response.new response.status = 200 response.body = { 'event_type'=>'compute.instance.create', 'message_id'=>'d646b40dea6347dfb8caee2da1484c56', } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/metering/list_meters.rb0000644000175600017570000000205512730051546025200 0ustar pravipravimodule Fog module Metering class OpenStack class Real def list_meters(options=[]) data = { 'q' => Array.new } options.each do |opt| filter = {} ['field', 'op', 'value'].each do |key| filter[key] = opt[key] if opt[key] end data['q'] << filter unless filter.empty? end request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'GET', :path => 'meters' ) end end class Mock def list_meters(options={}) response = Excon::Response.new response.status = 200 response.body = [{ 'user_id'=>'1d5fd9eda19142289a60ed9330b5d284', 'name'=>'image.size', 'resource_id'=>'glance', 'project_id'=>'d646b40dea6347dfb8caee2da1484c56', 'type'=>'gauge', 'unit'=>'bytes'}] response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/planning/0000755000175600017570000000000012730051546022313 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/requests/planning/patch_plan.rb0000644000175600017570000000307312730051546024754 0ustar pravipravimodule Fog module Openstack class Planning class Real def patch_plan(plan_uuid, parameters) request( :expects => [201], :method => 'PATCH', :path => "plans/#{plan_uuid}", :body => Fog::JSON.encode(parameters) ) end end # class Real class Mock def patch_plan(plan_uuid, parameters) response = Excon::Response.new response.status = [201][rand(1)] response.body = { "created_at" => "2014-09-26T20:23:14.222815", "description" => "Development testing cloud", "name" => "dev-cloud", "parameters" => [ { "default" => "guest", "description" => "The password for RabbitMQ", "hidden" => true, "label" => nil, "name" => "compute-1::RabbitPassword", "value" => "secret-password" } ], "roles" => [ { "description" => "OpenStack hypervisor node. Can be wrapped in a ResourceGroup for scaling.\n", "name" => "compute", "uuid" => "b7b1583c-5c80-481f-a25b-708ed4a39734", "version" => 1 } ], "updated_at" => nil, "uuid" => "53268a27-afc8-4b21-839f-90227dd7a001" } response end # def patch_plans end # class Mock end # class Planning end # module Openstack end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/planning/delete_plan.rb0000644000175600017570000000105212730051546025112 0ustar pravipravimodule Fog module Openstack class Planning class Real def delete_plan(plan_uuid) request( :expects => [204], :method => 'DELETE', :path => "plans/#{plan_uuid}" ) end end # class Real class Mock def delete_plan(plan_uuid) response = Excon::Response.new response.status = [204][rand(1)] response end # def delete_plans end # class Mock end # class Planning end # module Openstack end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/planning/add_role_to_plan.rb0000644000175600017570000000243612730051546026132 0ustar pravipravimodule Fog module Openstack class Planning class Real def add_role_to_plan(plan_uuid, role_uuid) request( :expects => [201], :method => 'POST', :path => "plans/#{plan_uuid}/roles", :body => Fog::JSON.encode({'uuid' => role_uuid}) ) end end # class Real class Mock def add_role_to_plan(plan_uuid, role_uuid) response = Excon::Response.new response.status = [201][rand(1)] response.body = { "created_at" => "2014-09-26T20:23:14.222815", "description" => "Development testing cloud", "name" => "dev-cloud", "parameters" => [], "roles" => [ { "description" => "OpenStack hypervisor node. Can be wrapped in a ResourceGroup for scaling.\n", "name" => "compute", "uuid" => "f72c0656-5696-4c66-81a5-d6d88a48e385", "version" => 1 } ], "updated_at" => nil, "uuid" => "53268a27-afc8-4b21-839f-90227dd7a001" } response end # def add_role_to_plans end # class Mock end # class Planning end # module Openstack end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/planning/remove_role_from_plan.rb0000644000175600017570000000171012730051546027212 0ustar pravipravimodule Fog module Openstack class Planning class Real def remove_role_from_plan(plan_uuid, role_uuid) request( :expects => [200], :method => 'DELETE', :path => "plans/#{plan_uuid}/roles/#{role_uuid}" ) end end # class Real class Mock def remove_role_from_plan(plan_uuid, role_uuid) response = Excon::Response.new response.status = [200][rand(1)] response.body = { "created_at" => "2014-09-26T20:23:14.222815", "description" => "Development testing cloud", "name" => "dev-cloud", "parameters" => [], "roles" => [], "updated_at" => nil, "uuid" => "53268a27-afc8-4b21-839f-90227dd7a001" } response end # def remove_role_from_plan end # class Mock end # class Planning end # module Openstack end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/planning/create_plan.rb0000644000175600017570000000165012730051546025117 0ustar pravipravimodule Fog module Openstack class Planning class Real def create_plan(parameters) request( :expects => [201], :method => 'POST', :path => "plans", :body => Fog::JSON.encode(parameters) ) end end # class Real class Mock def create_plan(parameters) response = Excon::Response.new response.status = [201][rand(1)] response.body = { "created_at" => "2014-09-26T20:23:14.222815", "description" => "Development testing cloud", "name" => "dev-cloud", "parameters" => [], "roles" => [], "updated_at" => nil, "uuid" => "53268a27-afc8-4b21-839f-90227dd7a001" } response end # def create_plans end # class Mock end # class Planning end # module Openstack end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/planning/list_plans.rb0000644000175600017570000000356412730051546025020 0ustar pravipravimodule Fog module Openstack class Planning class Real def list_plans(options = {}) request( :expects => [200, 204], :method => 'GET', :path => 'plans', :query => options ) end end # class Real class Mock def list_plans(options = {}) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = [ { "created_at" => "2014-09-26T20:23:14.222815", "description" => "Development testing cloud", "name" => "dev-cloud", "parameters" => [ { "default" => "guest", "description" => "The password for RabbitMQ", "hidden" => true, "label" => nil, "name" => "compute-1 => =>RabbitPassword", "value" => "secret-password" }, { "default" => "default", "description" => "description", "hidden" => true, "label" => nil, "name" => "name", "value" => "value" }, ], "roles" => [ { "description" => "OpenStack hypervisor node. Can be wrapped in a ResourceGroup for scaling.\n", "name" => "compute", "uuid" => "b7b1583c-5c80-481f-a25b-708ed4a39734", "version" => 1 } ], "updated_at" => nil, "uuid" => "53268a27-afc8-4b21-839f-90227dd7a001" } ] response end # def list_plans end # class Mock end # class Planning end # module Openstack end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/planning/get_plan.rb0000644000175600017570000000337312730051546024437 0ustar pravipravimodule Fog module Openstack class Planning class Real def get_plan(plan_uuid) request( :expects => [200, 204], :method => 'GET', :path => "plans/#{plan_uuid}" ) end end # class Real class Mock def get_plan(parameters=nil) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = { "created_at" => "2014-09-26T20:23:14.222815", "description" => "Development testing cloud", "name" => "dev-cloud", "parameters" => [ { "default" => "guest", "description" => "The password for RabbitMQ", "hidden" => true, "label" => nil, "name" => "compute-1 => =>RabbitPassword", "value" => "secret-password" }, { "default" => "default", "description" => "description", "hidden" => true, "label" => nil, "name" => "name", "value" => "value" }, ], "roles" => [ { "description" => "OpenStack hypervisor node. Can be wrapped in a ResourceGroup for scaling.\n", "name" => "compute", "uuid" => "b7b1583c-5c80-481f-a25b-708ed4a39734", "version" => 1 } ], "updated_at" => nil, "uuid" => "53268a27-afc8-4b21-839f-90227dd7a001" } response end # def get_plan end # class Mock end # class Planning end # module Openstack end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/planning/get_plan_templates.rb0000644000175600017570000000151012730051546026504 0ustar pravipravimodule Fog module Openstack class Planning class Real def get_plan_templates(plan_uuid) request( :expects => [200, 204], :method => 'GET', :path => "plans/#{plan_uuid}/templates" ) end end # class Real class Mock def get_plan_templates(plan_uuid) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = { "environment.yaml" => "... content of template file ...", "plan.yaml" => "... content of template file ...", "provider-compute-1.yaml" => "... content of template file ..." } response end # def get_plan_templates end # class Mock end # class Planning end # module Openstack end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/planning/list_roles.rb0000644000175600017570000000161312730051546025020 0ustar pravipravimodule Fog module Openstack class Planning class Real def list_roles(options = {}) request( :expects => [200, 204], :method => 'GET', :path => 'roles', :query => options ) end end # class Real class Mock def list_roles(options = {}) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = [ { "description" => "OpenStack hypervisor node. Can be wrapped in a ResourceGroup for scaling.\n", "name" => "compute", "uuid" => "f72c0656-5696-4c66-81a5-d6d88a48e385", "version" => 1 } ] response end # def list_nodes end # class Mock end # class Planning end # module Openstack end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/orchestration/0000755000175600017570000000000012730051546023371 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/requests/orchestration/patch_stack.rb0000644000175600017570000000206112730051546026201 0ustar pravipravimodule Fog module Orchestration class OpenStack class Real # patch a stack. # # @param [Fog::Orchestration::OpenStack::Stack] the stack to patch. # @param [Hash] options # * :template [String] Structure containing the template body. # or (one of the two Template parameters is required) # * :template_url [String] URL of file containing the template body. # * :parameters [Hash] Hash of providers to supply to template. # def patch_stack(stack, options = {}) stack_name = stack.stack_name stack_id = stack.id request( :expects => 202, :path => "stacks/#{stack_name}/#{stack_id}", :method => 'PATCH', :body => Fog::JSON.encode(options) ) end end class Mock def patch_stack(stack, options = {}) response = Excon::Response.new response.status = 202 response.body = {} response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/orchestration/show_stack_details.rb0000644000175600017570000000102212730051546027563 0ustar pravipravimodule Fog module Orchestration class OpenStack class Real def show_stack_details(name, id) request( :method => 'GET', :path => "stacks/#{name}/#{id}", :expects => 200 ) end end class Mock def show_stack_details(name, id) stack = self.data[:stack].values Excon::Response.new( :body => { 'stack' => stack }, :status => 200 ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/orchestration/get_stack_template.rb0000644000175600017570000000061012730051546027552 0ustar pravipravimodule Fog module Orchestration class OpenStack class Real def get_stack_template(stack) request( :method => 'GET', :path => "stacks/#{stack.stack_name}/#{stack.id}/template", :expects => 200 ) end end class Mock def get_stack_template(stack) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/orchestration/preview_stack.rb0000644000175600017570000000052512730051546026566 0ustar pravipravimodule Fog module Orchestration class OpenStack class Real def preview_stack(options = {}) request( :body => Fog::JSON.encode(options), :expects => [200], :method => 'POST', :path => 'stacks/preview' ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/orchestration/create_stack.rb0000644000175600017570000000534212730051546026352 0ustar pravipravimodule Fog module Orchestration class OpenStack class Real # Create a stack. # # # * options [Hash]: # * :stack_name [String] Name of the stack to create. # * :template [String] Structure containing the template body. # or (one of the two Template parameters is required) # * :template_url [String] URL of file containing the template body. # * :disable_rollback [Boolean] Controls rollback on stack creation failure, defaults to false. # * :parameters [Hash] Hash of providers to supply to template # * :timeout_mins [Integer] Minutes to wait before status is set to CREATE_FAILED # # @see http://developer.openstack.org/api-ref-orchestration-v1.html def create_stack(arg1, arg2 = nil) if arg1.is_a?(Hash) # Normal use: create_stack(options) options = arg1 else # Deprecated: create_stack(stack_name, options = {}) Fog::Logger.deprecation("#create_stack(stack_name, options) is deprecated, use #create_stack(options) instead [light_black](#{caller.first})[/]") options = { :stack_name => arg1 }.merge(arg2.nil? ? {} : arg2) end request( :expects => 201, :path => 'stacks', :method => 'POST', :body => Fog::JSON.encode(options) ) end end class Mock def create_stack(arg1, arg2 = nil) if arg1.is_a?(Hash) # Normal use: create_stack(options) options = arg1 else # Deprecated: create_stack(stack_name, options = {}) Fog::Logger.deprecation("#create_stack(stack_name, options) is deprecated, use #create_stack(options) instead [light_black](#{caller.first})[/]") options = { :stack_name => arg1 }.merge(arg2.nil? ? {} : arg2) end stack_id = Fog::Mock.random_hex(32) stack = self.data[:stacks][stack_id] = { 'id' => stack_id, 'stack_name' => options[:stack_name], 'links' => [], 'description' => options[:description], 'stack_status' => 'CREATE_COMPLETE', 'stack_status_reason' => 'Stack successfully created', 'creation_time' => Time.now, 'updated_time' => Time.now } response = Excon::Response.new response.status = 201 response.body = { 'id' => stack_id, 'links'=>[{"href"=>"http://localhost:8004/v1/fake_tenant_id/stacks/#{options[:stack_name]}/#{stack_id}", "rel"=>"self"}]} response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/orchestration/list_stack_data.rb0000644000175600017570000000105312730051546027046 0ustar pravipravimodule Fog module Orchestration class OpenStack class Real def list_stack_data(options = {}) request( :method => 'GET', :path => 'stacks', :expects => 200, :query => options ) end end class Mock def list_stack_data(options = {}) stacks = self.data[:stacks].values Excon::Response.new( :body => { 'stacks' => stacks }, :status => 200 ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/orchestration/update_stack.rb0000644000175600017570000000450712730051546026373 0ustar pravipravimodule Fog module Orchestration class OpenStack class Real # Update a stack. # # @param [Fog::Orchestration::OpenStack::Stack] the stack to update. # @param [Hash] options # * :template [String] Structure containing the template body. # or (one of the two Template parameters is required) # * :template_url [String] URL of file containing the template body. # * :parameters [Hash] Hash of providers to supply to template. # def update_stack(arg1, arg2 = nil, arg3 = nil) if arg1.is_a?(Stack) # Normal use, update_stack(stack, options = {}) stack = arg1 stack_name = stack.stack_name stack_id = stack.id params = arg2.nil? ? {} : arg2 else # Deprecated, update_stack(stack_id, stack_name, options = {}) Fog::Logger.deprecation("#update_stack(stack_id, stack_name, options) is deprecated, use #update_stack(stack, options) instead [light_black](#{caller.first})[/]") stack_id = arg1 stack_name = arg2 params = { :stack_name => stack_name }.merge(arg3.nil? ? {} : arg3) end request( :expects => 202, :path => "stacks/#{stack_name}/#{stack_id}", :method => 'PUT', :body => Fog::JSON.encode(params) ) end end class Mock def update_stack(arg1, arg2 = nil, arg3 = nil) if arg1.is_a?(Stack) # Normal use, update_stack(stack, options = {}) stack = arg1 stack_name = stack.stack_name stack_id = stack.id params = arg2.nil? ? {} : arg2 else # Deprecated, update_stack(stack_id, stack_name, options = {}) Fog::Logger.deprecation("#update_stack(stack_id, stack_name, options) is deprecated, use #update_stack(stack, options) instead [light_black](#{caller.first})[/]") stack_id = arg1 stack_name = arg2 params = { :stack_name => stack_name }.merge(arg3.nil? ? {} : arg3) end response = Excon::Response.new response.status = 202 response.body = {} response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/orchestration/list_stack_events.rb0000644000175600017570000000154012730051546027442 0ustar pravipravimodule Fog module Orchestration class OpenStack class Real def list_stack_events(stack, options = {}) Fog::Logger.deprecation('Calling OpenStack[:orchestration].list_stack_events(stack, options)'\ ' is deprecated, call .list_events(:stack => stack) or '\ ' .list_events(:stack_name => value, :stack_id => value) instead') uri = "stacks/#{stack.stack_name}/#{stack.id}/events" request(:method => 'GET', :path => uri, :expects => 200, :query => options ) end end class Mock def list_stack_events(stack, options={}) events = self.data[:events].values Excon::Response.new( :body => { 'events' => events }, :status => 200 ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/orchestration/build_info.rb0000644000175600017570000000041012730051546026023 0ustar pravipravimodule Fog module Orchestration class OpenStack class Real def build_info request( :expects => [200], :method => 'GET', :path => 'build_info' ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/orchestration/show_event_details.rb0000644000175600017570000000116412730051546027606 0ustar pravipravimodule Fog module Orchestration class OpenStack class Real def show_event_details(stack, resource, event_id) request( :method => 'GET', :path => "stacks/#{stack.stack_name}/#{stack.id}/resources/#{resource.resource_name}/events/#{event_id}", :expects => 200 ) end end class Mock def show_event_details(stack, event) events = self.data[:events].values Excon::Response.new( :body => { 'events' => events }, :status => 200 ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/orchestration/show_resource_template.rb0000644000175600017570000000057612730051546030510 0ustar pravipravimodule Fog module Orchestration class OpenStack class Real def show_resource_template(name) request( :method => 'GET', :path => "resource_types/#{name}/template", :expects => 200 ) end end class Mock def show_resource_template(name) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/orchestration/list_resource_events.rb0000644000175600017570000000177612730051546030177 0ustar pravipravimodule Fog module Orchestration class OpenStack class Real def list_resource_events(stack, resource, options = {}) Fog::Logger.deprecation('Calling OpenStack[:orchestration].list_resource_events(stack, resource, options)'\ ' is deprecated, call .list_events(:stack => stack, :resource => resource) or '\ ' .list_events(:stack_name => value, :stack_id => value, :resource_name => value)'\ ' instead') uri = "stacks/#{stack.stack_name}/#{stack.id}/resources/#{resource.resource_name}/events" request(:method => 'GET', :path => uri, :expects => 200, :query => options) end end class Mock def list_resource_events(stack, resource, options={}) events = self.data[:events].values Excon::Response.new( :body => { 'events' => events }, :status => 200 ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/orchestration/list_events.rb0000644000175600017570000000302012730051546026250 0ustar pravipravimodule Fog module Orchestration class OpenStack class Real def list_events(options = {}) if !options.key?(:stack) && !(options.key?(:stack_name) && options.key?(:stack_id)) raise(ArgumentError, "Missing required options keys: :stack or :stack_name and :stack_id, while calling "\ " .list_events(options)") end stack = options.delete(:stack) stack_name = options.delete(:stack_name) stack_name ||= stack.stack_name if stack && stack.respond_to?(:stack_name) stack_id = options.delete(:stack_id) stack_id ||= stack.id if stack && stack.respond_to?(:id) resource = options.delete(:resource) resource_name = options.delete(:resource_name) resource_name ||= resource.resource_name if resource && resource.respond_to?(:resource_name) if resource_name path = "stacks/#{stack_name}/#{stack_id}/resources/#{resource_name}/events" else path = "stacks/#{stack_name}/#{stack_id}/events" end request(:method => 'GET', :path => path, :expects => 200, :query => options) end end class Mock def list_events(options = {}) events = self.data[:events].values Excon::Response.new( :body => { 'events' => events }, :status => 200 ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/orchestration/list_resources.rb0000644000175600017570000000342612730051546026770 0ustar pravipravimodule Fog module Orchestration class OpenStack class Real def list_resources(options = {}, options_deprecated = {}) if options.is_a?(Hash) if !options.key?(:stack) && !(options.key?(:stack_name) && options.key?(:stack_id)) raise(ArgumentError, "Missing required options keys: :stack or :stack_name and :stack_id, while calling "\ " .list_resources(options)") end stack = options.delete(:stack) stack_name = options.delete(:stack_name) stack_name ||= stack.stack_name if stack && stack.respond_to?(:stack_name) stack_id = options.delete(:stack_id) stack_id ||= stack.id if stack && stack.respond_to?(:id) path = "stacks/#{stack_name}/#{stack_id}/resources" params = options else Fog::Logger.deprecation('Calling OpenStack[:orchestration].list_resources(stack, options) is deprecated, '\ ' call .list_resources(:stack => stack) or '\ ' .list_resources(:stack_name => value, :stack_id => value) instead') path = "stacks/#{options.stack_name}/#{options.id}/resources" params = options_deprecated end request(:method => 'GET', :path => path, :expects => 200, :query => params) end end class Mock def list_resources(options = {}, options_deprecated = {}) resources = self.data[:resources].values Excon::Response.new( :body => { 'resources' => resources }, :status => 200 ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/orchestration/abandon_stack.rb0000644000175600017570000000047112730051546026507 0ustar pravipravimodule Fog module Orchestration class OpenStack class Real def abandon_stack(stack) request( :expects => [200], :method => 'DELETE', :path => "stacks/#{stack.stack_name}/#{stack.id}/abandon" ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/orchestration/show_resource_schema.rb0000644000175600017570000000044212730051546030125 0ustar pravipravimodule Fog module Orchestration class OpenStack class Real def show_resource_schema(name) request( :method => 'GET', :path => "resource_types/#{name}", :expects => 200 ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/orchestration/list_stack_data_detailed.rb0000644000175600017570000000407512730051546030710 0ustar pravipravimodule Fog module Orchestration class OpenStack class Real def list_stack_data_detailed(options = {}) request( :method => 'GET', :path => 'stacks/detail', :expects => 200, :query => options ) end end class Mock def list_stack_data_detailed(options = {}) Excon::Response.new( :body => { 'stacks' => [{"parent" => nil, "disable_rollback" => true, "description" => "No description", "links" => [{"href"=>"http://192.0.2.1:8004/v1/ae084f19a7974d5b95703f633e57fd64/stacks/overcloud/9ea5226f-0bb3-40bf-924b-f89ea11bb69c", "rel"=>"self"}], "stack_status_reason" => "Stack CREATE completed successfully", "stack_name" => "overcloud", "stack_user_project_id" => "ae084f19a7974d5b95703f633e57fd64", "stack_owner" => "admin", "creation_time" => "2015-06-24T07:19:01Z", "capabilities" => [], "notification_topics" => [], "updated_time" => nil, "timeout_mins" => nil, "stack_status" => "CREATE_COMPLETE", "parameters" => {"Controller-1::SSLKey"=>"******", "Compute-1::RabbitClientUseSSL"=>"False", "Controller-1::KeystoneSSLCertificate"=>"", "Controller-1::CinderLVMLoopDeviceSize"=>"5000"}, "id" => "9ea5226f-0bb3-40bf-924b-f89ea11bb69c", "outputs" => [], "template_description" => "No description"}] }, :status => 200 ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/orchestration/show_resource_metadata.rb0000644000175600017570000000117012730051546030444 0ustar pravipravimodule Fog module Orchestration class OpenStack class Real def show_resource_metadata(stack, resource_name) request( :method => 'GET', :path => "stacks/#{stack.stack_name}/#{stack.id}/resources/#{resource_name}/metadata", :expects => 200 ) end end class Mock def show_resource_metadata(stack, resource_name) resources = self.data[:resources].values Excon::Response.new( :body => { 'resources' => resources }, :status => 200 ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/orchestration/validate_template.rb0000644000175600017570000000052312730051546027402 0ustar pravipravimodule Fog module Orchestration class OpenStack class Real def validate_template(options = {}) request( :body => Fog::JSON.encode(options), :expects => [200], :method => 'POST', :path => 'validate' ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/orchestration/show_resource_data.rb0000644000175600017570000000117712730051546027604 0ustar pravipravimodule Fog module Orchestration class OpenStack class Real def show_resource_data(stack_name, stack_id, resource_name) request( :method => 'GET', :path => "stacks/#{stack_name}/#{stack_id}/resources/#{resource_name}", :expects => 200 ) end end class Mock def show_resource_data(stack_name, stack_id, resource_name) resources = self.data[:resources].values Excon::Response.new( :body => { 'resources' => resources }, :status => 200 ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/orchestration/list_resource_types.rb0000644000175600017570000000107612730051546030030 0ustar pravipravimodule Fog module Orchestration class OpenStack class Real def list_resource_types(options = {}) request( :method => 'GET', :path => "resource_types", :expects => 200, :query => {} ) end end class Mock def list_resource_types resources = self.data[:resource_types].values Excon::Response.new( :body => { 'resource_types' => resources }, :status => 200 ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/orchestration/delete_stack.rb0000644000175600017570000000330512730051546026346 0ustar pravipravimodule Fog module Orchestration class OpenStack class Real # Delete a stack. # # @param [Stack] Stack to be deleted # # @return [Excon::Response] # # @see http://developer.openstack.org/api-ref-orchestration-v1.html def delete_stack(arg1, arg2 = nil) if arg1.is_a?(Stack) # Normal use: delete_stack(stack) stack = arg1 stack_name = stack.stack_name stack_id = stack.id else # Deprecated: delete_stack(stack_name, stack_id) Fog::Logger.deprecation("#delete_stack(stack_name, stack_id) is deprecated, use #delete_stack(stack) instead [light_black](#{caller.first})[/]") stack_name = arg1 stack_id = arg2 end request( :expects => 204, :path => "stacks/#{stack_name}/#{stack_id}", :method => 'DELETE' ) end end class Mock def delete_stack(arg1, arg2 = nil) if arg1.is_a?(Stack) # Normal use: delete_stack(stack) stack = arg1 stack_name = stack.stack_name stack_id = stack.id else # Deprecated: delete_stack(stack_name, stack_id) Fog::Logger.deprecation("#delete_stack(stack_name, stack_id) is deprecated, use #delete_stack(stack) instead [light_black](#{caller.first})[/]") stack_name = arg1 stack_id = arg2 end self.data[:stacks].delete(stack_id) response = Excon::Response.new response.status = 204 response.body = {} response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/image_v1/0000755000175600017570000000000012730051546022175 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/requests/image_v1/update_image.rb0000644000175600017570000000501412730051546025146 0ustar pravipravimodule Fog module Image class OpenStack class V1 class Real def update_image(attributes) data = { 'x-image-meta-name' => attributes[:name], 'x-image-meta-disk-format' => attributes[:disk_format], 'x-image-meta-container-format' => attributes[:container_format], 'x-image-meta-size' => attributes[:size], 'x-image-meta-is-public' => attributes[:is_public], 'x-image-meta-min-ram' => attributes[:min_ram], 'x-image-meta-min-disk' => attributes[:min_disk], 'x-image-meta-checksum' => attributes[:checksum], 'x-image-meta-owner' => attributes[:owner] }.reject { |k, v| v.nil? } unless attributes[:properties].nil? attributes[:properties].each do |key, value| data["x-image-meta-property-#{key}"] = value end end request( :headers => data, :expects => 200, :method => 'PUT', :path => "images/#{attributes[:id]}" ) end end class Mock def update_image(attributes) response = Excon::Response.new response.status = 200 image = self.images.last response.body = { 'image' => { 'name' => attributes[:name] || image.name, 'size' => image.size, 'min_disk' => (attributes[:min_disk] || image.min_disk).to_i, 'disk_format' => attributes[:disk_format] || image.disk_format, 'created_at' => image.created_at, 'container_format' => attributes[:container_format] || image.container_format, 'deleted_at' => nil, 'updated_at' => Time.now.to_s, 'checksum' => image.checksum, 'id' => attributes[:id], 'deleted' => false, 'protected' => false, 'is_public' => attributes[:is_public] || image.is_public, 'status' => image.status, 'min_ram' => (attributes[:min_ram] || image.min_ram).to_i, 'owner' => attributes[:owner] || image.owner, 'properties' => attributes[:properties] || image.properties } } response end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/image_v1/delete_image.rb0000644000175600017570000000076712730051546025140 0ustar pravipravimodule Fog module Image class OpenStack class V1 class Real def delete_image(image_id) request( :expects => 200, :method => 'DELETE', :path => "images/#{image_id}" ) end end class Mock def delete_image(image_id) response = Excon::Response.new response.status = 200 response end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/image_v1/remove_member_from_image.rb0000644000175600017570000000125712730051546027540 0ustar pravipravimodule Fog module Image class OpenStack class V1 class Real def remove_member_from_image(image_id, member_id) request( :expects => [200, 204], :method => 'DELETE', :path => "images/#{image_id}/members/#{member_id}" ) end end # class Real class Mock def remove_member_from_image(image_id, member_id) response = Excon::Response.new response.status = [200, 204][rand(1)] response end # def list_tenants end # class Mock end # class OpenStack end end # module Identity end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/image_v1/create_image.rb0000644000175600017570000000567012730051546025137 0ustar pravipravimodule Fog module Image class OpenStack class V1 class Real def create_image(attributes) data = { 'Content-Type' => 'application/octet-stream', 'x-image-meta-name' => attributes[:name], 'x-image-meta-disk-format' => attributes[:disk_format], 'x-image-meta-container-format' => attributes[:container_format], 'x-image-meta-size' => attributes[:size], 'x-image-meta-is-public' => attributes[:is_public], 'x-image-meta-min-ram' => attributes[:min_ram], 'x-image-meta-min-disk' => attributes[:min_disk], 'x-image-meta-checksum' => attributes[:checksum], 'x-image-meta-owner' => attributes[:owner], 'x-glance-api-copy-from' => attributes[:copy_from] }.reject { |k, v| v.nil? } body = String.new if attributes[:location] body = File.open(attributes[:location], "rb") # Make sure the image file size is always present data['x-image-meta-size'] = File.size(body) end unless attributes[:properties].nil? attributes[:properties].each do |key, value| data["x-image-meta-property-#{key}"] = value end end request( :headers => data, :body => body, :expects => 201, :method => 'POST', :path => "images" ) ensure body.close if body.respond_to?(:close) end end class Mock def create_image(attributes) response = Excon::Response.new response.status = 201 image_id = Fog::Mock.random_hex(32) image = self.data[:images][image_id] = { 'name' => attributes[:name], 'size' => attributes[:size] || Fog::Mock.random_numbers(8).to_i, 'min_disk' => attributes[:min_disk] || 0, 'disk_format' => attributes[:disk_format] || 'raw', 'created_at' => Time.now.strftime('%FT%T.%6N'), 'container_format' => attributes[:container_format] || 'bare', 'deleted_at' => nil, 'updated_at' => Time.now.strftime('%FT%T.%6N'), 'checksum' => attributes[:checksum] || Fog::Mock.random_hex(32), 'id' => image_id, 'deleted' => false, 'protected' => false, 'is_public' => attributes[:is_public].to_s == 'true', 'status' => 'queued', 'min_ram' => attributes[:min_ram] || 0, 'owner' => attributes[:owner], 'properties' => attributes[:properties] || {} } response.body = {'image' => image} response end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/image_v1/list_public_images_detailed.rb0000644000175600017570000000234312730051546030215 0ustar pravipravimodule Fog module Image class OpenStack class V1 class Real def list_public_images_detailed(options = {}, query_deprecated = nil) if options.is_a?(Hash) query = options elsif options Fog::Logger.deprecation("Calling OpenStack[:glance].list_public_images_detailed(attribute, query) format"\ " is deprecated, call .list_public_images_detailed(attribute => query) instead") query = {options => query_deprecated} else query = {} end request( :expects => [200, 204], :method => 'GET', :path => 'images/detail', :query => query ) end end # class Real class Mock def list_public_images_detailed(options = {}, query_deprecated = nil) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = {'images' => self.data[:images].values} response end # def list_public_images_detailed end # class Mock end # class OpenStack end end # module Image end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/image_v1/set_tenant.rb0000644000175600017570000000065412730051546024673 0ustar pravipravimodule Fog module Image class OpenStack class V1 class Real def set_tenant(tenant) @openstack_must_reauthenticate = true @openstack_tenant = tenant.to_s authenticate end end class Mock def set_tenant(tenant) true end end end # class OpenStack end end # module Image end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/image_v1/list_public_images.rb0000644000175600017570000000217212730051546026362 0ustar pravipravimodule Fog module Image class OpenStack class V1 class Real def list_public_images(options = {}) request( :expects => [200, 204], :method => 'GET', :path => 'images', :query => options ) end end # class Real class Mock def list_public_images(options = {}) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = { "images" => [{ "name" => Fog::Mock.random_letters(10), "size" => Fog::Mock.random_numbers(8).to_i, "disk_format" => "iso", "container_format" => "bare", "id" => Fog::Mock.random_hex(36), "checksum" => Fog::Mock.random_hex(32)}] } response end # def list_tenants end # class Mock end # class OpenStack end end # module Identity end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/image_v1/get_image_members.rb0000644000175600017570000000151312730051546026155 0ustar pravipravimodule Fog module Image class OpenStack class V1 class Real def get_image_members(image_id) request( :expects => [200, 204], :method => 'GET', :path => "images/#{image_id}/members" ) end end # class Real class Mock def get_image_members(image_id) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = { "members" => [ {"member_id" => "ff528b20431645ebb5fa4b0a71ca002f", "can_share" => false} ] } response end # def list_tenants end # class Mock end # class OpenStack end end # module Identity end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/image_v1/update_image_members.rb0000644000175600017570000000224612730051546026664 0ustar pravipravimodule Fog module Image class OpenStack class V1 class Real def update_image_members(image_id, members) # Sample members # [ # {'member_id' => 'tenant1', 'can_share' => true }, # {'member_id' => 'tenant2', 'can_share' => false } # ] data = {'memberships' => members} request( :body => Fog::JSON.encode(data), :expects => [204], :method => 'PUT', :path => "images/#{image_id}/members" ) end end # class Real class Mock def update_image_members(image_id, members) response = Excon::Response.new response.status = 204 response.body = { 'members' => [ {'member_id' => 'ff528b20431645ebb5fa4b0a71ca002f', 'can_share' => false}, {'member_id' => 'ff528b20431645ebb5fa4b0a71ca002f', 'can_share' => true} ] } response end end # class Mock end # class OpenStack end end # module Identity end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/image_v1/get_image.rb0000644000175600017570000000447012730051546024450 0ustar pravipravimodule Fog module Image class OpenStack class V1 class Real def get_image(image_id) request( :expects => [200, 204], :method => 'HEAD', :path => "images/#{image_id}" ) end end # class Real class Mock def get_image(image_id) response = Excon::Response.new response.status = [200, 204][rand(1)] response.headers= {"X-Image-Meta-Is_public" => "True", "X-Image-Meta-Min_disk" => "0", "X-Image-Meta-Property-Ramdisk_id" => "b45aa128-cd36-4ad9-a026-1a1c2bfd8fdc", "X-Image-Meta-Disk_format" => "ami", "X-Image-Meta-Created_at" => "2012-02-21T07:32:26", "X-Image-Meta-Container_format" => "ami", "Etag" => "2f81976cae15c16ef0010c51e3a6c163", "Location" => "http://192.168.27.100:9292/v1/images/0e09fbd6-43c5-448a-83e9-0d3d05f9747e", "X-Image-Meta-Protected" => "False", "Date" => "Fri, 24 Feb 2012 02:14:25 GMT", "X-Image-Meta-Name" => "cirros-0.3.0-x86_64-blank", "X-Image-Meta-Min_ram" => "0", "Content-Type" => "text/html; charset=UTF-8", "X-Image-Meta-Updated_at" => "2012-02-21T07:32:29", "X-Image-Meta-Property-Kernel_id" => "cd28951e-e1c2-4bc5-95d3-f0495abbcdc5", "X-Image-Meta-Size" => "25165824", "X-Image-Meta-Checksum" => "2f81976cae15c16ef0010c51e3a6c163", "X-Image-Meta-Deleted" => "False", "Content-Length" => "0", "X-Image-Meta-Owner" => "ff528b20431645ebb5fa4b0a71ca002f", "X-Image-Meta-Status" => "active", "X-Image-Meta-Id" => "0e09fbd6-43c5-448a-83e9-0d3d05f9747e"} response.body = "" response end # def list_tenants end # class Mock end # class OpenStack end end # module Identity end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/image_v1/add_member_to_image.rb0000644000175600017570000000121312730051546026442 0ustar pravipravimodule Fog module Image class OpenStack class V1 class Real def add_member_to_image(image_id, tenant_id) request( :expects => [200, 204], :method => 'PUT', :path => "images/#{image_id}/members/#{tenant_id}" ) end end # class Real class Mock def add_member_to_image(image_id, tenant_id) response = Excon::Response.new response.status = [200, 204][rand(1)] response end # def list_tenants end # class Mock end # class V1 end # class OpenStack end # module Identity end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/image_v1/get_shared_images.rb0000644000175600017570000000152212730051546026154 0ustar pravipravimodule Fog module Image class OpenStack class V1 class Real def get_shared_images(tenant_id) request( :expects => [200, 204], :method => 'GET', :path => "shared-images/#{tenant_id}" ) end end # class Real class Mock def get_shared_images(tenant_id) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = { "shared_images" => [ {"image_id" => "ff528b20431645ebb5fa4b0a71ca002f", "can_share" => false} ] } response end # def list_tenants end # class Mock end # class OpenStack end end # module Identity end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/image_v1/get_image_by_id.rb0000644000175600017570000000211112730051546025604 0ustar pravipravimodule Fog module Image class OpenStack class V1 class Real def get_image_by_id(image_id) request( :expects => [200, 204], :method => 'GET', :path => "images/#{image_id}" ) end end # class Real class Mock def get_image_by_id(image_id) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = { "images" => [{ "name" => "mock-image-name", "size" => 25165824, "disk_format" => "ami", "container_format" => "ami", "id" => "0e09fbd6-43c5-448a-83e9-0d3d05f9747e", "checksum" => "2f81976cae15c16ef0010c51e3a6c163"}] } response end # def list_tenants end # class Mock end # class OpenStack end end # module Identity end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/introspection/0000755000175600017570000000000012730051546023405 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/requests/introspection/create_rules.rb0000644000175600017570000000150512730051546026410 0ustar pravipravimodule Fog module Introspection class OpenStack class Real def create_rules(attributes) attributes_valid = [ :actions, :conditions, :uuid, :description ] # Filter only allowed creation attributes data = attributes.select do |key, _| attributes_valid.include?(key.to_sym) end request( :body => Fog::JSON.encode(data), :expects => 200, :method => "POST", :path => "rules" ) end end class Mock def create_rules(_) response = Excon::Response.new response.status = 200 response.body = {"rules" => data[:rules].first} response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/introspection/get_introspection_details.rb0000644000175600017570000000104512730051546031176 0ustar pravipravimodule Fog module Introspection class OpenStack class Real def get_introspection_details(node_id) request( :expects => 200, :method => 'GET', :path => "introspection/#{node_id}/data" ) end end class Mock def get_introspection_details(_node_id) response = Excon::Response.new response.status = 200 response.body = {"data" => data[:introspection_data]} response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/introspection/delete_rules.rb0000644000175600017570000000070112730051546026404 0ustar pravipravimodule Fog module Introspection class OpenStack class Real def delete_rules(rule_id) request( :expects => 204, :method => "DELETE", :path => "rules/#{rule_id}" ) end end class Mock def delete_rules(_rule_id) response = Excon::Response.new response.status = 204 response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/introspection/create_introspection.rb0000644000175600017570000000151012730051546030152 0ustar pravipravimodule Fog module Introspection class OpenStack class Real def create_introspection(node_id, options = {}) if options data = { 'new_ipmi_username' => options[:new_ipmi_username], 'new_ipmi_password' => options[:new_ipmi_password] } body = Fog::JSON.encode(data) else body = "" end request( :body => body, :expects => 202, :method => "POST", :path => "introspection/#{node_id}" ) end end class Mock def create_introspection(_node_id, _options = {}) response = Excon::Response.new response.status = 202 response.body = "" response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/introspection/list_rules.rb0000644000175600017570000000072612730051546026124 0ustar pravipravimodule Fog module Introspection class OpenStack class Real def list_rules request( :expects => 200, :method => 'GET', :path => "rules" ) end end class Mock def list_rules response = Excon::Response.new response.status = 200 response.body = {"rules" => data[:rules].first} response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/introspection/abort_introspection.rb0000644000175600017570000000102412730051546030016 0ustar pravipravimodule Fog module Introspection class OpenStack class Real def abort_introspection(node_id) request( :body => "", :expects => 202, :method => "POST", :path => "introspection/#{node_id}/abort" ) end end class Mock def abort_introspection(_node_id) response = Excon::Response.new response.status = 202 response.body = "" response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/introspection/get_rules.rb0000644000175600017570000000076212730051546025730 0ustar pravipravimodule Fog module Introspection class OpenStack class Real def get_rules(rule_id) request( :expects => 200, :method => 'GET', :path => "rules/#{rule_id}" ) end end class Mock def get_rules(_rule_id) response = Excon::Response.new response.status = 200 response.body = {"rules" => data[:rules].first} response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/introspection/get_introspection.rb0000644000175600017570000000102412730051546027466 0ustar pravipravimodule Fog module Introspection class OpenStack class Real def get_introspection(node_id) request( :expects => 200, :method => "GET", :path => "introspection/#{node_id}" ) end end class Mock def get_introspection(_node_id) response = Excon::Response.new response.status = 200 response.body = {"error" => "null", "finished" => "true"} response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/introspection/delete_rules_all.rb0000644000175600017570000000065312730051546027242 0ustar pravipravimodule Fog module Introspection class OpenStack class Real def delete_rules_all request( :expects => 204, :method => "DELETE", :path => "rules" ) end end class Mock def delete_rules_all response = Excon::Response.new response.status = 204 response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/0000755000175600017570000000000012730051546022746 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/get_role.rb0000644000175600017570000000057412730051546025101 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def get_role(id) request( :expects => [200], :method => 'GET', :path => "roles/#{id}" ) end end class Mock def get_role(id) end end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/list_user_groups.rb0000644000175600017570000000063112730051546026703 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def list_user_groups(user_id) request( :expects => [200], :method => 'GET', :path => "users/#{user_id}/groups" ) end end class Mock def list_user_groups end end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/delete_service.rb0000644000175600017570000000053612730051546026261 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def delete_service(id) request( :expects => [204], :method => 'DELETE', :path => "services/#{id}" ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/delete_os_credential.rb0000644000175600017570000000054712730051546027436 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def delete_os_credential(id) request( :expects => [204], :method => 'DELETE', :path => "credentials/#{id}" ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/get_group.rb0000644000175600017570000000057712730051546025277 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def get_group(id) request( :expects => [200], :method => 'GET', :path => "groups/#{id}" ) end end class Mock def get_group(id) end end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/create_os_credential.rb0000644000175600017570000000065512730051546027437 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def create_os_credential(credential) request( :expects => [201], :method => 'POST', :path => "credentials", :body => Fog::JSON.encode(:credential => credential) ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/list_services.rb0000644000175600017570000000067112730051546026155 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def list_services(options = {}) request( :expects => [200], :method => 'GET', :path => "services", :query => options ) end end class Mock def list_services(options = {}) end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/list_domains.rb0000644000175600017570000000066612730051546025770 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def list_domains(options = {}) request( :expects => [200], :method => 'GET', :path => "domains", :query => options ) end end class Mock def list_domains(options = {}) end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/update_project.rb0000644000175600017570000000064612730051546026311 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def update_project(id, project) request( :expects => [200], :method => 'PATCH', :path => "projects/#{id}", :body => Fog::JSON.encode(:project => project) ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/update_user.rb0000644000175600017570000000062712730051546025620 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def update_user(id, user) request( :expects => [200], :method => 'PATCH', :path => "users/#{id}", :body => Fog::JSON.encode(:user => user) ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/revoke_project_group_role.rb0000644000175600017570000000064012730051546030551 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def revoke_project_group_role(id, group_id, role_id) request( :expects => [204], :method => 'DELETE', :path => "projects/#{id}/groups/#{group_id}/roles/#{role_id}" ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/create_service.rb0000644000175600017570000000063312730051546026260 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def create_service(service) request( :expects => [201], :method => 'POST', :path => "services", :body => Fog::JSON.encode(:service => service) ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/grant_domain_user_role.rb0000644000175600017570000000062612730051546030020 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def grant_domain_user_role(id, user_id, role_id) request( :expects => [204], :method => 'PUT', :path => "domains/#{id}/users/#{user_id}/roles/#{role_id}" ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/get_project.rb0000644000175600017570000000064412730051546025604 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def get_project(id, options=[]) request( :expects => [200], :method => 'GET', :path => "projects/#{id}?#{options.join '&'}" ) end end class Mock def get_domain(id) end end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/list_domain_group_roles.rb0000644000175600017570000000071012730051546030213 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def list_domain_group_roles(id, group_id) request( :expects => [200], :method => 'GET', :path => "domains/#{id}/groups/#{group_id}/roles" ) end end class Mock def list_domain_user_roles(id, group_id) end end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/list_role_assignments.rb0000644000175600017570000000207412730051546027705 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def list_role_assignments(options = {}) # Backwards compatibility name mapping, also serves as single pane of glass, since keystone broke # consistency in naming of options, just for this one API call name_mapping = { :group_id => 'group.id', :role_id => 'role.id', :domain_id => 'scope.domain.id', :project_id => 'scope.project.id', :user_id => 'user.id', } name_mapping.keys.each do |key| if (opt = options.delete(key)) options[name_mapping[key]] = opt end end request( :expects => [200], :method => 'GET', :path => "role_assignments", :query => options ) end end class Mock def list_role_assignments(options = {}) end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/delete_group.rb0000644000175600017570000000053212730051546025751 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def delete_group(id) request( :expects => [204], :method => 'DELETE', :path => "groups/#{id}" ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/list_users.rb0000644000175600017570000000066012730051546025471 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def list_users(options = {}) request( :expects => [200], :method => 'GET', :path => "users", :query => options ) end end class Mock def list_users(options = {}) end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/list_group_users.rb0000644000175600017570000000067512730051546026713 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def list_group_users(id, options={}) request( :expects => [200], :method => 'GET', :path => "groups/#{id}/users", :query => options ) end end class Mock def list_group_users end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/list_endpoints.rb0000644000175600017570000000067212730051546026336 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def list_endpoints(options = {}) request( :expects => [200], :method => 'GET', :path => "endpoints", :query => options ) end end class Mock def list_endpoints(options={}) end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/revoke_domain_group_role.rb0000644000175600017570000000063612730051546030357 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def revoke_domain_group_role(id, group_id, role_id) request( :expects => [204], :method => 'DELETE', :path => "domains/#{id}/groups/#{group_id}/roles/#{role_id}" ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/check_project_user_role.rb0000644000175600017570000000063112730051546030155 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def check_project_user_role(id, user_id, role_id) request( :expects => [204], :method => 'HEAD', :path => "projects/#{id}/users/#{user_id}/roles/#{role_id}" ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/auth_domains.rb0000644000175600017570000000065512730051546025754 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def auth_domains(options={}) request( :expects => [200], :method => 'GET', :path => "auth/domains", :query => options ) end end class Mock def auth_domains end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/create_group.rb0000644000175600017570000000062112730051546025751 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def create_group(group) request( :expects => [201], :method => 'POST', :path => "groups", :body => Fog::JSON.encode(:group => group) ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/token_check.rb0000644000175600017570000000071012730051546025546 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def token_check(subject_token) request( :expects => [200, 204], :method => 'HEAD', :path => "auth/tokens", :headers => {"X-Subject-Token" => subject_token, "X-Auth-Token" => auth_token, } ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/delete_role.rb0000644000175600017570000000053012730051546025554 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def delete_role(id) request( :expects => [204], :method => 'DELETE', :path => "roles/#{id}" ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/group_user_check.rb0000644000175600017570000000060212730051546026620 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def group_user_check(group_id, user_id) request( :expects => [204], :method => 'HEAD', :path => "groups/#{group_id}/users/#{user_id}" ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/grant_project_group_role.rb0000644000175600017570000000063412730051546030374 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def grant_project_group_role(id, group_id, role_id) request( :expects => [204], :method => 'PUT', :path => "projects/#{id}/groups/#{group_id}/roles/#{role_id}" ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/update_service.rb0000644000175600017570000000064612730051546026303 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def update_service(id, service) request( :expects => [200], :method => 'PATCH', :path => "services/#{id}", :body => Fog::JSON.encode(:service => service) ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/update_role.rb0000644000175600017570000000062712730051546025603 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def update_role(id, role) request( :expects => [200], :method => 'PATCH', :path => "roles/#{id}", :body => Fog::JSON.encode(:role => role) ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/check_domain_user_role.rb0000644000175600017570000000062712730051546027763 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def check_domain_user_role(id, user_id, role_id) request( :expects => [204], :method => 'HEAD', :path => "domains/#{id}/users/#{user_id}/roles/#{role_id}" ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/get_policy.rb0000644000175600017570000000060312730051546025430 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def get_policy(id) request( :expects => [200], :method => 'GET', :path => "policies/#{id}" ) end end class Mock def get_policy(id) end end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/delete_endpoint.rb0000644000175600017570000000054012730051546026434 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def delete_endpoint(id) request( :expects => [204], :method => 'DELETE', :path => "endpoints/#{id}" ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/create_domain.rb0000644000175600017570000000062612730051546026071 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def create_domain(domain) request( :expects => [201], :method => 'POST', :path => "domains", :body => Fog::JSON.encode(:domain => domain) ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/create_project.rb0000644000175600017570000000063312730051546026266 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def create_project(project) request( :expects => [201], :method => 'POST', :path => "projects", :body => Fog::JSON.encode(:project => project) ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/update_group.rb0000644000175600017570000000063412730051546025774 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def update_group(id, group) request( :expects => [200], :method => 'PATCH', :path => "groups/#{id}", :body => Fog::JSON.encode(:group => group) ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/update_domain.rb0000644000175600017570000000064112730051546026105 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def update_domain(id, domain) request( :expects => [200], :method => 'PATCH', :path => "domains/#{id}", :body => Fog::JSON.encode(:domain => domain) ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/revoke_project_user_role.rb0000644000175600017570000000063412730051546030376 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def revoke_project_user_role(id, user_id, role_id) request( :expects => [204], :method => 'DELETE', :path => "projects/#{id}/users/#{user_id}/roles/#{role_id}" ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/list_project_group_roles.rb0000644000175600017570000000071312730051546030415 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def list_project_group_roles(id, group_id) request( :expects => [200], :method => 'GET', :path => "projects/#{id}/groups/#{group_id}/roles" ) end end class Mock def list_project_user_roles(id, group_id) end end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/add_user_to_group.rb0000644000175600017570000000060212730051546026775 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def add_user_to_group(group_id, user_id) request( :expects => [204], :method => 'PUT', :path => "groups/#{group_id}/users/#{user_id}" ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/get_os_credential.rb0000644000175600017570000000062412730051546026747 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def get_os_credential(id) request( :expects => [200], :method => 'GET', :path => "credentials/#{id}" ) end end class Mock def get_os_credential(id) end end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/remove_user_from_group.rb0000644000175600017570000000061212730051546030064 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def remove_user_from_group(group_id, user_id) request( :expects => [204], :method => 'DELETE', :path => "groups/#{group_id}/users/#{user_id}" ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/update_os_credential.rb0000644000175600017570000000067012730051546027453 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def update_os_credential(id, credential) request( :expects => [200], :method => 'PATCH', :path => "credentials/#{id}", :body => Fog::JSON.encode(:credential => credential) ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/token_revoke.rb0000644000175600017570000000071312730051546025767 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def token_revoke(subject_token) request( :expects => [200, 204], :method => 'DELETE', :path => "auth/tokens", :headers => {"X-Subject-Token" => subject_token, "X-Auth-Token" => auth_token, } ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/list_user_projects.rb0000644000175600017570000000063712730051546027223 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def list_user_projects(user_id) request( :expects => [200], :method => 'GET', :path => "users/#{user_id}/projects" ) end end class Mock def list_user_projects end end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/get_user.rb0000644000175600017570000000057412730051546025116 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def get_user(id) request( :expects => [200], :method => 'GET', :path => "users/#{id}" ) end end class Mock def get_user(id) end end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/create_role.rb0000644000175600017570000000061412730051546025560 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def create_role(role) request( :expects => [201], :method => 'POST', :path => "roles", :body => Fog::JSON.encode(:role => role) ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/get_domain.rb0000644000175600017570000000060212730051546025377 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def get_domain(id) request( :expects => [200], :method => 'GET', :path => "domains/#{id}" ) end end class Mock def get_domain(id) end end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/grant_project_user_role.rb0000644000175600017570000000063012730051546030212 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def grant_project_user_role(id, user_id, role_id) request( :expects => [204], :method => 'PUT', :path => "projects/#{id}/users/#{user_id}/roles/#{role_id}" ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/get_service.rb0000644000175600017570000000060512730051546025573 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def get_service(id) request( :expects => [200], :method => 'GET', :path => "projects/#{id}" ) end end class Mock def get_service(id) end end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/token_validate.rb0000644000175600017570000000070412730051546026265 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def token_validate(subject_token) request( :expects => [200], :method => 'GET', :path => "auth/tokens", :headers => {"X-Subject-Token" => subject_token, "X-Auth-Token" => auth_token} ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/check_domain_group_role.rb0000644000175600017570000000063312730051546030136 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def check_domain_group_role(id, group_id, role_id) request( :expects => [204], :method => 'HEAD', :path => "domains/#{id}/groups/#{group_id}/roles/#{role_id}" ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/list_policies.rb0000644000175600017570000000067112730051546026141 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def list_policies(options = {}) request( :expects => [200], :method => 'GET', :path => "policies", :query => options ) end end class Mock def list_policies(options = {}) end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/revoke_domain_user_role.rb0000644000175600017570000000063212730051546030175 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def revoke_domain_user_role(id, user_id, role_id) request( :expects => [204], :method => 'DELETE', :path => "domains/#{id}/users/#{user_id}/roles/#{role_id}" ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/list_groups.rb0000644000175600017570000000120112730051546025637 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def list_groups(options = {}) user_id = options.delete('user_id') || options.delete(:user_id) if user_id path = "users/#{user_id}groups" else path = "groups" end request( :expects => [200], :method => 'GET', :path => path, :query => options ) end end class Mock def list_groups(options = {}) end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/delete_domain.rb0000644000175600017570000000053412730051546026066 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def delete_domain(id) request( :expects => [204], :method => 'DELETE', :path => "domains/#{id}" ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/token_authenticate.rb0000644000175600017570000000062012730051546027147 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def token_authenticate(auth) request( :expects => [201], :method => 'POST', :path => "auth/tokens", :body => Fog::JSON.encode(auth) ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/delete_user.rb0000644000175600017570000000053012730051546025571 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def delete_user(id) request( :expects => [204], :method => 'DELETE', :path => "users/#{id}" ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/delete_project.rb0000644000175600017570000000053612730051546026267 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def delete_project(id) request( :expects => [204], :method => 'DELETE', :path => "projects/#{id}" ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/list_project_user_roles.rb0000644000175600017570000000070612730051546030241 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def list_project_user_roles(id, user_id) request( :expects => [200], :method => 'GET', :path => "projects/#{id}/users/#{user_id}/roles" ) end end class Mock def list_project_user_roles(id, user_id) end end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/create_endpoint.rb0000644000175600017570000000064012730051546026436 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def create_endpoint(endpoint) request( :expects => [201], :method => 'POST', :path => "endpoints", :body => Fog::JSON.encode(:endpoint => endpoint) ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/auth_projects.rb0000644000175600017570000000066012730051546026147 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def auth_projects(options = {}) request( :expects => [200], :method => 'GET', :path => "auth/projects", :query => options ) end end class Mock def auth_projects end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/update_endpoint.rb0000644000175600017570000000065312730051546026461 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def update_endpoint(id, endpoint) request( :expects => [200], :method => 'PATCH', :path => "endpoints/#{id}", :body => Fog::JSON.encode(:endpoint => endpoint) ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/grant_domain_group_role.rb0000644000175600017570000000063212730051546030173 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def grant_domain_group_role(id, group_id, role_id) request( :expects => [204], :method => 'PUT', :path => "domains/#{id}/groups/#{group_id}/roles/#{role_id}" ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/list_domain_user_roles.rb0000644000175600017570000000070312730051546030037 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def list_domain_user_roles(id, user_id) request( :expects => [200], :method => 'GET', :path => "domains/#{id}/users/#{user_id}/roles" ) end end class Mock def list_domain_user_roles(id, user_id) end end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/update_policy.rb0000644000175600017570000000064212730051546026136 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def update_policy(id, policy) request( :expects => [200], :method => 'PATCH', :path => "policies/#{id}", :body => Fog::JSON.encode(:policy => policy) ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/list_os_credentials.rb0000644000175600017570000000071012730051546027322 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def list_os_credentials(options = {}) request( :expects => [200], :method => 'GET', :path => "credentials", :query => options ) end end class Mock def list_os_credentials(options = {}) end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/create_policy.rb0000644000175600017570000000062712730051546026122 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def create_policy(policy) request( :expects => [201], :method => 'POST', :path => "policies", :body => Fog::JSON.encode(:policy => policy) ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/get_endpoint.rb0000644000175600017570000000061012730051546025747 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def get_endpoint(id) request( :expects => [200], :method => 'GET', :path => "endpoints/#{id}" ) end end class Mock def get_endpoint(id) end end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/create_user.rb0000644000175600017570000000061412730051546025575 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def create_user(user) request( :expects => [201], :method => 'POST', :path => "users", :body => Fog::JSON.encode(:user => user) ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/list_projects.rb0000644000175600017570000000121112730051546026152 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def list_projects(options = {}) user_id = options.delete('user_id') || options.delete(:user_id) if user_id path = "users/#{user_id}/projects" else path = "projects" end request( :expects => [200], :method => 'GET', :path => path, :query => options ) end end class Mock def list_projects(options = {}) end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/delete_policy.rb0000644000175600017570000000053512730051546026117 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def delete_policy(id) request( :expects => [204], :method => 'DELETE', :path => "policies/#{id}" ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/list_roles.rb0000644000175600017570000000066012730051546025454 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def list_roles(options = {}) request( :expects => [200], :method => 'GET', :path => "roles", :query => options ) end end class Mock def list_roles(options = {}) end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v3/check_project_group_role.rb0000644000175600017570000000063512730051546030337 0ustar pravipravimodule Fog module Identity class OpenStack class V3 class Real def check_project_group_role(id, group_id, role_id) request( :expects => [204], :method => 'HEAD', :path => "projects/#{id}/groups/#{group_id}/roles/#{role_id}" ) end end class Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/nfv/0000755000175600017570000000000012730051546021276 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/requests/nfv/list_vnfs.rb0000644000175600017570000000077712730051546023645 0ustar pravipravimodule Fog module NFV class OpenStack class Real def list_vnfs(options = {}) request( :expects => 200, :method => 'GET', :path => "vnfs", :query => options ) end end class Mock def list_vnfs(_options = {}) response = Excon::Response.new response.status = 200 response.body = {"vnfs" => data[:vnfs]} response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/nfv/list_vnfds.rb0000644000175600017570000000100412730051546023771 0ustar pravipravimodule Fog module NFV class OpenStack class Real def list_vnfds(options = {}) request( :expects => 200, :method => 'GET', :path => "vnfds", :query => options ) end end class Mock def list_vnfds(_options = {}) response = Excon::Response.new response.status = 200 response.body = {"vnfds" => data[:vnfds]} response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/nfv/get_vnfd.rb0000644000175600017570000000074512730051546023425 0ustar pravipravimodule Fog module NFV class OpenStack class Real def get_vnfd(vnfd_id) request( :expects => 200, :method => 'GET', :path => "vnfds/#{vnfd_id}" ) end end class Mock def get_vnfd(_vnfd_id) response = Excon::Response.new response.status = 200 response.body = {"vnfd" => data[:vnfds].first} response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/nfv/delete_vnf.rb0000644000175600017570000000065712730051546023746 0ustar pravipravimodule Fog module NFV class OpenStack class Real def delete_vnf(vnf_id) request( :expects => 204, :method => "DELETE", :path => "vnfs/#{vnf_id}" ) end end class Mock def delete_vnf(_vnf_id) response = Excon::Response.new response.status = 204 response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/nfv/delete_vnfd.rb0000644000175600017570000000066512730051546024111 0ustar pravipravimodule Fog module NFV class OpenStack class Real def delete_vnfd(vnfd_id) request( :expects => 204, :method => "DELETE", :path => "vnfds/#{vnfd_id}" ) end end class Mock def delete_vnfd(_vnfd_id) response = Excon::Response.new response.status = 204 response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/nfv/update_vnf.rb0000644000175600017570000000144212730051546023757 0ustar pravipravimodule Fog module NFV class OpenStack class Real def update_vnf(id, options) options_valid = [ :auth, :vnf, ] # Filter only allowed creation attributes data = options.select do |key, _| options_valid.include?(key.to_sym) || options_valid.include?(key.to_s) end request( :body => Fog::JSON.encode(data), :expects => 200, :method => "PUT", :path => "vnfs/#{id}", ) end end class Mock def update_vnf(_, _) response = Excon::Response.new response.status = 200 response.body = {"vnf" => data[:vnfs].first} response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/nfv/create_vnf.rb0000644000175600017570000000152312730051546023740 0ustar pravipravimodule Fog module NFV class OpenStack class Real def create_vnf(options) options_valid = [ :auth, :vnf, ] # Filter only allowed creation attributes data = options.select do |key, _| options_valid.include?(key.to_sym) || options_valid.include?(key.to_s) end request( :body => Fog::JSON.encode(data), :expects => 201, :method => "POST", :path => "vnfs" ) end end class Mock def create_vnf(_) response = Excon::Response.new response.status = 201 create_data = data[:vnfs].first.merge("vnfd_id" => "id") response.body = {"vnf" => create_data} response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/nfv/create_vnfd.rb0000644000175600017570000000143312730051546024104 0ustar pravipravimodule Fog module NFV class OpenStack class Real def create_vnfd(options) options_valid = [ :auth, :vnfd, ] # Filter only allowed creation attributes data = options.select do |key, _| options_valid.include?(key.to_sym) || options_valid.include?(key.to_s) end request( :body => Fog::JSON.encode(data), :expects => 201, :method => "POST", :path => "vnfds" ) end end class Mock def create_vnfd(_) response = Excon::Response.new response.status = 201 response.body = {"vnfd" => data[:vnfds].first} response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/nfv/get_vnf.rb0000644000175600017570000000073512730051546023260 0ustar pravipravimodule Fog module NFV class OpenStack class Real def get_vnf(vnf_id) request( :expects => 200, :method => 'GET', :path => "vnfs/#{vnf_id}" ) end end class Mock def get_vnf(_vnf_id) response = Excon::Response.new response.status = 200 response.body = {"vnf" => data[:vnfs].first} response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/0000755000175600017570000000000012730051546022176 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/requests/network/delete_network.rb0000644000175600017570000000125212730051546025536 0ustar pravipravimodule Fog module Network class OpenStack class Real def delete_network(network_id) request( :expects => 204, :method => 'DELETE', :path => "networks/#{network_id}" ) end end class Mock def delete_network(network_id) response = Excon::Response.new if list_networks.body['networks'].map { |r| r['id'] }.include? network_id self.data[:networks].delete(network_id) response.status = 204 response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/create_floating_ip.rb0000644000175600017570000000253012730051546026341 0ustar pravipravimodule Fog module Network class OpenStack class Real def create_floating_ip(floating_network_id, options = {}) data = { 'floatingip' => { 'floating_network_id' => floating_network_id } } vanilla_options = [:port_id, :tenant_id, :fixed_ip_address ] vanilla_options.reject{ |o| options[o].nil? }.each do |key| data['floatingip'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => [201], :method => 'POST', :path => 'floatingips' ) end end class Mock def create_floating_ip(floating_network_id, options = {}) response = Excon::Response.new response.status = 201 data = { 'id' => floating_network_id, 'floating_network_id' => floating_network_id, 'port_id' => options[:port_id], 'tenant_id' => options[:tenant_id], 'fixed_ip_address' => options[:fixed_ip_address], 'router_id' => nil, } self.data[:floating_ips][data['id']] = data response.body = { 'floatingip' => data } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/update_rbac_policy.rb0000644000175600017570000000221112730051546026347 0ustar pravipravimodule Fog module Network class OpenStack class Real def update_rbac_policy(rbac_policy_id, options = {}) data = {'rbac_policy' => {}} vanilla_options = [:target_tenant] vanilla_options.select { |o| options.key?(o) }.each do |key| data['rbac_policy'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'PUT', :path => "rbac-policies/#{rbac_policy_id}" ) end end class Mock def update_rbac_policy(rbac_policy_id, options = {}) response = Excon::Response.new rbac_policy = list_rbac_policies.body['rbac_policies'].detect do |instance| instance['id'] == rbac_policy_id end if rbac_policy rbac_policy['target_tenant'] = options[:target_tenant] response.body = {'rbac_policy' => rbac_policy} response.status = 200 response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/list_lb_members.rb0000644000175600017570000000102312730051546025661 0ustar pravipravimodule Fog module Network class OpenStack class Real def list_lb_members(filters = {}) request( :expects => 200, :method => 'GET', :path => 'lb/members', :query => filters ) end end class Mock def list_lb_members(filters = {}) Excon::Response.new( :body => { 'members' => self.data[:lb_members].values }, :status => 200 ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/get_lb_member.rb0000644000175600017570000000120212730051546025301 0ustar pravipravimodule Fog module Network class OpenStack class Real def get_lb_member(member_id) request( :expects => [200], :method => 'GET', :path => "lb/members/#{member_id}" ) end end class Mock def get_lb_member(member_id) response = Excon::Response.new if data = self.data[:lb_members][member_id] response.status = 200 response.body = { 'member' => data } response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/list_lb_health_monitors.rb0000644000175600017570000000107312730051546027433 0ustar pravipravimodule Fog module Network class OpenStack class Real def list_lb_health_monitors(filters = {}) request( :expects => 200, :method => 'GET', :path => 'lb/health_monitors', :query => filters ) end end class Mock def list_lb_health_monitors(filters = {}) Excon::Response.new( :body => { 'health_monitors' => self.data[:lb_health_monitors].values }, :status => 200 ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/delete_ipsec_policy.rb0000644000175600017570000000134312730051546026530 0ustar pravipravimodule Fog module Network class OpenStack class Real def delete_ipsec_policy(ipsec_policy_id) request( :expects => 204, :method => 'DELETE', :path => "vpn/ipsecpolicies/#{ipsec_policy_id}" ) end end class Mock def delete_ipsec_policy(ipsec_policy_id) response = Excon::Response.new if list_ipsec_policies.body['ipsecpolicies'].collect { |r| r['id'] }.include? ipsec_policy_id data[:ipsec_policies].delete(ipsec_policy_id) response.status = 204 response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/get_lb_pool_stats.rb0000644000175600017570000000146712730051546026236 0ustar pravipravimodule Fog module Network class OpenStack class Real def get_lb_pool_stats(pool_id) request( :expects => [200], :method => 'GET', :path => "lb/pools/#{pool_id}/stats" ) end end class Mock def get_lb_pool_stats(pool_id) response = Excon::Response.new if data = self.data[:lb_pools][pool_id] stats = {} stats["active_connections"] = 0 stats["bytes_in"] = 0 stats["bytes_out"] = 0 stats["total_connections"] = 0 response.status = 200 response.body = { 'stats' => stats } response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/create_security_group.rb0000644000175600017570000001026612730051546027136 0ustar pravipravimodule Fog module Network class OpenStack class Real # Create a new security group # # ==== Parameters # * options<~Hash>: # * 'name'<~String> - Name of the security group # * 'description'<~String> - Description of the security group # * 'tenant_id'<~String> - TenantId different than the current user, that should own the security group. Only allowed if user has 'admin' role. # # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: # * 'security_groups'<~Array>: # * 'id'<~String> - UUID of the security group # * 'name'<~String> - Name of the security group # * 'description'<~String> - Description of the security group # * 'tenant_id'<~String> - Tenant id that owns the security group # * 'security_group_rules'<~Array>: - Array of security group rules # * 'id'<~String> - UUID of the security group rule # * 'direction'<~String> - Direction of traffic, must be in ['ingress', 'egress'] # * 'port_range_min'<~Integer> - Start port for rule i.e. 22 (or -1 for ICMP wildcard) # * 'port_range_max'<~Integer> - End port for rule i.e. 22 (or -1 for ICMP wildcard) # * 'protocol'<~String> - IP protocol for rule, must be in ['tcp', 'udp', 'icmp'] # * 'ethertype'<~String> - Type of ethernet support, must be in ['IPv4', 'IPv6'] # * 'security_group_id'<~String> - UUID of the parent security group # * 'remote_group_id'<~String> - UUID of the remote security group # * 'remote_ip_prefix'<~String> - IP cidr range address i.e. '0.0.0.0/0' # * 'tenant_id'<~String> - Tenant id that owns the security group rule def create_security_group(options = {}) data = {"security_group" => {}} desired_options = [:name, :description, :tenant_id] selected_options = desired_options.select{|o| options[o]} selected_options.each { |key| data["security_group"][key] = options[key] } request( :body => Fog::JSON.encode(data), :expects => 201, :method => "POST", :path => "security-groups" ) end end class Mock def create_security_group(options = {}) # Spaces are NOT removed from name and description, as in case of compute sec groups tenant_id = Fog::Mock.random_numbers(14).to_s sec_group_id = Fog::UUID.uuid response = Excon::Response.new response.status = 201 # by default every security group will come setup with an egress rule to "allow all out" data = { "security_group_rules" => [ { "remote_group_id" => nil, "direction" => "egress", "remote_ip_prefix" => nil, "protocol" => nil, "ethertype" => "IPv4", "tenant_id" => tenant_id, "port_range_max" => nil, "port_range_min" => nil, "id" => Fog::UUID.uuid, "security_group_id" => sec_group_id }, { "remote_group_id" => nil, "direction" => "egress", "remote_ip_prefix" => nil, "protocol" => nil, "ethertype" => "IPv6", "tenant_id" => tenant_id, "port_range_max" => nil, "port_range_min" => nil, "id" => Fog::UUID.uuid, "security_group_id" => sec_group_id } ], "id" => sec_group_id, "tenant_id" => tenant_id, "name" => options[:name] || "", "description" => options[:description] || "" } self.data[:security_groups][data["id"]] = data response.body = {"security_group" => data} response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/remove_router_interface.rb0000644000175600017570000000154612730051546027446 0ustar pravipravimodule Fog module Network class OpenStack class Real def remove_router_interface(router_id, subnet_id, options = {}) data = { 'subnet_id' => subnet_id, } request( :body => Fog::JSON.encode(data), :expects => [200], :method => 'PUT', :path => "routers/#{router_id}/remove_router_interface" ) end end class Mock def remove_router_interface(router_id, subnet_id, options = {}) response = Excon::Response.new response.status = 201 data = { 'subnet_id' => 'a2f1f29d-571b-4533-907f-5803ab96ead1' } self.data[:routers][data['router_id']] = data response.body = { 'router' => data } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/get_quotas.rb0000644000175600017570000000075612730051546024706 0ustar pravipravimodule Fog module Network class OpenStack class Real def get_quotas request( :expects => 200, :method => 'GET', :path => "/quotas" ) end end class Mock def get_quotas response = Excon::Response.new response.status = 200 response.body = { 'quotas' => self.data[:quotas] } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/update_network.rb0000644000175600017570000000223112730051546025554 0ustar pravipravimodule Fog module Network class OpenStack class Real def update_network(network_id, options = {}) data = { 'network' => {} } vanilla_options = [:name, :shared, :admin_state_up] vanilla_options.select{ |o| options.key?(o) }.each do |key| data['network'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'PUT', :path => "networks/#{network_id}.json" ) end end class Mock def update_network(network_id, options = {}) response = Excon::Response.new if network = list_networks.body['networks'].find { |_| _['id'] == network_id } network['name'] = options[:name] network['shared'] = options[:shared] network['admin_state_up'] = options[:admin_state_up] response.body = { 'network' => network } response.status = 200 response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/list_routers.rb0000644000175600017570000000100712730051546025257 0ustar pravipravimodule Fog module Network class OpenStack class Real def list_routers(filters = {}) request( :expects => 200, :method => 'GET', :path => 'routers', :query => filters ) end end class Mock def list_routers(filters = {}) Excon::Response.new( :body => { 'routers' => self.data[:routers].values }, :status => 200 ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/update_lb_health_monitor.rb0000644000175600017570000000314312730051546027557 0ustar pravipravimodule Fog module Network class OpenStack class Real def update_lb_health_monitor(health_monitor_id, options = {}) data = { 'health_monitor' => {} } vanilla_options = [:delay, :timeout, :max_retries, :http_method, :url_path, :expected_codes, :admin_state_up] vanilla_options.select{ |o| options.key?(o) }.each do |key| data['health_monitor'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'PUT', :path => "lb/health_monitors/#{health_monitor_id}" ) end end class Mock def update_lb_health_monitor(health_monitor_id, options = {}) response = Excon::Response.new if health_monitor = list_lb_health_monitors.body['health_monitors'].find { |_| _['id'] == health_monitor_id } health_monitor['delay'] = options[:delay] health_monitor['timeout'] = options[:timeout] health_monitor['max_retries'] = options[:max_retries] health_monitor['http_method'] = options[:http_method] health_monitor['url_path'] = options[:url_path] health_monitor['expected_codes'] = options[:expected_codes] health_monitor['admin_state_up'] = options[:admin_state_up] response.body = { 'health_monitor' => health_monitor } response.status = 200 response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/create_security_group_rule.rb0000644000175600017570000000741012730051546030162 0ustar pravipravimodule Fog module Network class OpenStack class Real # Create a new security group rule # # ==== Parameters # * 'security_group_id'<~String> - UUID of the parent security group # * 'direction'<~String> - Direction of traffic, must be in ['ingress', 'egress'] # * options<~Hash>: # * 'port_range_min'<~Integer> - Start port for rule i.e. 22 (or -1 for ICMP wildcard) # * 'port_range_max'<~Integer> - End port for rule i.e. 22 (or -1 for ICMP wildcard) # * 'protocol'<~String> - IP protocol for rule, must be in ['tcp', 'udp', 'icmp'] # * 'ethertype'<~String> - Type of ethernet support, must be in ['IPv4', 'IPv6'] # * 'remote_group_id'<~String> - UUID of the remote security group # * 'remote_ip_prefix'<~String> - IP cidr range address i.e. '0.0.0.0/0' # * 'tenant_id'<~String> - TenantId different than the current user, that should own the security group. Only allowed if user has 'admin' role. # # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: # * 'security_group_rule'<~Hash>: # * 'id'<~String> - UUID of the security group rule # * 'direction'<~String> - Direction of traffic, must be in ['ingress', 'egress'] # * 'port_range_min'<~String> - Start port for rule i.e. 22 (or -1 for ICMP wildcard) # * 'port_range_max'<~String> - End port for rule i.e. 22 (or -1 for ICMP wildcard) # * 'protocol'<~String> - IP protocol for rule, must be in ['tcp', 'udp', 'icmp'] # * 'ethertype'<~String> - Type of ethernet support, must be in ['IPv4', 'IPv6'] # * 'security_group_id'<~String> - UUID of the parent security group # * 'remote_group_id'<~String> - UUID of the source security group # * 'remote_ip_prefix'<~String> - IP cidr range address i.e. '0.0.0.0/0' # * 'tenant_id'<~String> - Tenant id that owns the security group rule def create_security_group_rule(security_group_id, direction, options = {}) data = {"security_group_rule" => {"security_group_id" => security_group_id, "direction" => direction}} desired_options = [ :port_range_min, :port_range_max, :protocol, :ethertype, :remote_group_id, :remote_ip_prefix, :tenant_id ] selected_options = desired_options.select{ |o| options[o] } selected_options.each { |key| data["security_group_rule"][key] = options[key] } request( :body => Fog::JSON.encode(data), :expects => 201, :method => "POST", :path => "security-group-rules" ) end end class Mock def create_security_group_rule(security_group_id, direction, options = {}) response = Excon::Response.new data = { "id" => Fog::UUID.uuid, "remote_group_id" => options[:remote_group_id], "direction" => direction, "remote_ip_prefix" => options[:remote_ip_prefix], "protocol" => options[:protocol], "ethertype" => options[:ethertype] || "IPv4", "tenant_id" => options[:tenant_id] || Fog::Mock.random_numbers(14).to_s, "port_range_max" => options[:port_range_max], "port_range_min" => options[:port_range_min], "security_group_id" => security_group_id } self.data[:security_group_rules][data["id"]] = data response.status = 201 response.body = {"security_group_rule" => data} response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/get_ipsec_policy.rb0000644000175600017570000000126012730051546026043 0ustar pravipravimodule Fog module Network class OpenStack class Real def get_ipsec_policy(ipsec_policy_id) request( :expects => [200], :method => 'GET', :path => "vpn/ipsecpolicies/#{ipsec_policy_id}" ) end end class Mock def get_ipsec_policy(ipsec_policy_id) response = Excon::Response.new if data = self.data[:ipsec_policies][ipsec_policy_id] response.status = 200 response.body = {'ipsecpolicy' => data} response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/add_router_interface.rb0000644000175600017570000000322712730051546026677 0ustar pravipravimodule Fog module Network class OpenStack class Real def add_router_interface(router_id, subnet_id_or_options) if(subnet_id_or_options.is_a? String) data = { 'subnet_id' => subnet_id_or_options, } elsif subnet_id_or_options.is_a? Hash data = subnet_id_or_options else raise ArgumentError,'Please pass a subnet id or hash {subnet_id:xxx,port_id:xxx}' end request( :body => Fog::JSON.encode(data), :expects => [200], :method => 'PUT', :path => "routers/#{router_id}/add_router_interface" ) end end class Mock def add_router_interface(router_id, subnet_id, options = {}) response = Excon::Response.new response.status = 201 data = { 'status' => 'ACTIVE', 'name' => '', 'admin_state_up' => true, 'network_id' => '5307648b-e836-4658-8f1a-ff7536870c64', 'tenant_id' => '6b96ff0cb17a4b859e1e575d221683d3', 'device_owner' => 'network:router_interface', 'mac_address' => 'fa:16:3e:f7:d1:9c', 'fixed_ips' => { 'subnet_id' => 'a2f1f29d-571b-4533-907f-5803ab96ead1', 'ip_address' => '10.1.1.1' }, 'id' => '3a44f4e5-1694-493a-a1fb-393881c673a4', 'device_id' => '7177abc4-5ae9-4bb7-b0d4-89e94a4abf3b' } self.data[:routers][data['router_id']] = data response.body = { 'router' => data } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/list_floating_ips.rb0000644000175600017570000000103612730051546026234 0ustar pravipravimodule Fog module Network class OpenStack class Real def list_floating_ips(filters = {}) request( :expects => 200, :method => 'GET', :path => 'floatingips', :query => filters ) end end class Mock def list_floating_ips(filters = {}) Excon::Response.new( :body => { 'floatingips' => self.data[:floating_ips].values }, :status => 200 ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/create_subnet.rb0000644000175600017570000000336112730051546025351 0ustar pravipravimodule Fog module Network class OpenStack class Real def create_subnet(network_id, cidr, ip_version, options = {}) data = { 'subnet' => { 'network_id' => network_id, 'cidr' => cidr, 'ip_version' => ip_version } } vanilla_options = [:name, :gateway_ip, :allocation_pools, :dns_nameservers, :host_routes, :enable_dhcp, :tenant_id] vanilla_options.select{ |o| options.key?(o) }.each do |key| data['subnet'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => [201], :method => 'POST', :path => 'subnets' ) end end class Mock def create_subnet(network_id, cidr, ip_version, options = {}) response = Excon::Response.new response.status = 201 data = { 'id' => Fog::Mock.random_numbers(6).to_s, 'name' => options[:name], 'network_id' => network_id, 'cidr' => cidr, 'ip_version' => ip_version, 'gateway_ip' => options[:gateway_ip], 'allocation_pools' => options[:allocation_pools], 'dns_nameservers' => options[:dns_nameservers], 'host_routes' => options[:host_routes], 'enable_dhcp' => options[:enable_dhcp], 'tenant_id' => options[:tenant_id] } self.data[:subnets][data['id']] = data response.body = { 'subnet' => data } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/create_lb_health_monitor.rb0000644000175600017570000000335012730051546027540 0ustar pravipravimodule Fog module Network class OpenStack class Real def create_lb_health_monitor(type, delay, timeout, max_retries, options = {}) data = { 'health_monitor' => { 'type' => type, 'delay' => delay, 'timeout' => timeout, 'max_retries' => max_retries } } vanilla_options = [:http_method, :url_path, :expected_codes, :admin_state_up, :tenant_id] vanilla_options.reject{ |o| options[o].nil? }.each do |key| data['health_monitor'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => [201], :method => 'POST', :path => 'lb/health_monitors' ) end end class Mock def create_lb_health_monitor(type, delay, timeout, max_retries, options = {}) response = Excon::Response.new response.status = 201 data = { 'id' => Fog::Mock.random_numbers(6).to_s, 'type' => type, 'delay' => delay, 'timeout' => timeout, 'max_retries' => max_retries, 'http_method' => options[:http_method], 'url_path' => options[:url_path], 'expected_codes' => options[:expected_codes], 'status' => 'ACTIVE', 'admin_state_up' => options[:admin_state_up], 'tenant_id' => options[:tenant_id], } self.data[:lb_health_monitors][data['id']] = data response.body = { 'health_monitor' => data } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/create_network.rb0000644000175600017570000000625212730051546025544 0ustar pravipravimodule Fog module Network class OpenStack class Real def create_network(options = {}) data = { 'network' => {} } vanilla_options = [ :name, :shared, :admin_state_up, :tenant_id ] vanilla_options.reject{ |o| options[o].nil? }.each do |key| data['network'][key] = options[key] end # Advanced Features through API Extensions # # Not strictly required but commonly found in OpenStack # installs with Quantum networking. # # @see http://docs.openstack.org/trunk/openstack-network/admin/content/provider_attributes.html provider_options = [ :router_external, :provider_network_type, :provider_segmentation_id, :provider_physical_network ] # Map Fog::Network::OpenStack::Network # model attributes to OpenStack provider attributes aliases = { :provider_network_type => 'provider:network_type', # Not applicable to the "local" or "gre" network types :provider_physical_network => 'provider:physical_network', :provider_segmentation_id => 'provider:segmentation_id', :router_external => 'router:external' } provider_options.reject{ |o| options[o].nil? }.each do |key| aliased_key = aliases[key] || key data['network'][aliased_key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => [201], :method => 'POST', :path => 'networks' ) end end class Mock def create_network(options = {}) response = Excon::Response.new response.status = 201 data = { 'id' => Fog::Mock.random_numbers(6).to_s, 'name' => options[:name], 'shared' => options[:shared], 'subnets' => [], 'status' => 'ACTIVE', 'admin_state_up' => options[:admin_state_up], 'tenant_id' => options[:tenant_id], } # Add provider specific attributes when found # provider_options = [ :router_external, :provider_network_type, :provider_segmentation_id, :provider_physical_network ] aliases = { :provider_network_type => 'provider:network_type', # Not applicable to the "local" or "gre" network types :provider_physical_network => 'provider:physical_network', :provider_segmentation_id => 'provider:segmentation_id', :router_external => 'router:external' } provider_options.reject{ |o| options[o].nil? }.each do |key| aliased_key = aliases[key] || key data[aliased_key] = options[key] end self.data[:networks][data['id']] = data response.body = { 'network' => data } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/update_lb_member.rb0000644000175600017570000000222112730051546026006 0ustar pravipravimodule Fog module Network class OpenStack class Real def update_lb_member(member_id, options = {}) data = { 'member' => {} } vanilla_options = [:pool_id, :weight, :admin_state_up] vanilla_options.select{ |o| options.key?(o) }.each do |key| data['member'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'PUT', :path => "lb/members/#{member_id}" ) end end class Mock def update_lb_member(member_id, options = {}) response = Excon::Response.new if member = list_lb_members.body['members'].find { |_| _['id'] == member_id } member['pool_id'] = options[:pool_id] member['weight'] = options[:weight] member['admin_state_up'] = options[:admin_state_up] response.body = { 'member' => member } response.status = 200 response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/get_lb_pool.rb0000644000175600017570000000116012730051546025006 0ustar pravipravimodule Fog module Network class OpenStack class Real def get_lb_pool(pool_id) request( :expects => [200], :method => 'GET', :path => "lb/pools/#{pool_id}" ) end end class Mock def get_lb_pool(pool_id) response = Excon::Response.new if data = self.data[:lb_pools][pool_id] response.status = 200 response.body = { 'pool' => data } response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/delete_lb_pool.rb0000644000175600017570000000122512730051546025473 0ustar pravipravimodule Fog module Network class OpenStack class Real def delete_lb_pool(pool_id) request( :expects => 204, :method => 'DELETE', :path => "lb/pools/#{pool_id}" ) end end class Mock def delete_lb_pool(pool_id) response = Excon::Response.new if list_lb_pools.body['pools'].map { |r| r['id'] }.include? pool_id self.data[:lb_pools].delete(pool_id) response.status = 204 response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/update_lb_vip.rb0000644000175600017570000000255212730051546025344 0ustar pravipravimodule Fog module Network class OpenStack class Real def update_lb_vip(vip_id, options = {}) data = { 'vip' => {} } vanilla_options = [:pool_id, :name, :description, :session_persistence, :connection_limit, :admin_state_up] vanilla_options.select{ |o| options.key?(o) }.each do |key| data['vip'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'PUT', :path => "lb/vips/#{vip_id}" ) end end class Mock def update_lb_vip(vip_id, options = {}) response = Excon::Response.new if vip = list_lb_vips.body['vips'].find { |_| _['id'] == vip_id } vip['pool_id'] = options[:pool_id] vip['name'] = options[:name] vip['description'] = options[:description] vip['session_persistence'] = options[:session_persistence] vip['connection_limit'] = options[:connection_limit] vip['admin_state_up'] = options[:admin_state_up] response.body = { 'vip' => vip } response.status = 200 response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/get_subnet.rb0000644000175600017570000000246312730051546024667 0ustar pravipravimodule Fog module Network class OpenStack class Real def get_subnet(subnet_id) request( :expects => [200], :method => 'GET', :path => "subnets/#{subnet_id}" ) end end class Mock def get_subnet(subnet_id) response = Excon::Response.new if data = self.data[:subnets][subnet_id] response.status = 200 response.body = { "subnet" => { "id" => "2e4ec6a4-0150-47f5-8523-e899ac03026e", "name" => "subnet_1", "network_id" => "e624a36d-762b-481f-9b50-4154ceb78bbb", "cidr" => "10.2.2.0/24", "ip_version" => 4, "gateway_ip" => "10.2.2.1", "allocation_pools" => [ { "start" => "10.2.2.2", "end" => "10.2.2.254" } ], "dns_nameservers" => [], "host_routes" => [], "enable_dhcp" => true, "tenant_id" => "f8b26a6032bc47718a7702233ac708b9", } } response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/create_rbac_policy.rb0000644000175600017570000000233312730051546026335 0ustar pravipravimodule Fog module Network class OpenStack class Real def create_rbac_policy(options = {}) data = {'rbac_policy' => {}} vanilla_options = [:object_type, :object_id, :tenant_id, :target_tenant, :action] vanilla_options.select { |o| options.key?(o) }.each do |key| data['rbac_policy'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => [201], :method => 'POST', :path => 'rbac-policies' ) end end class Mock def create_rbac_policy(options = {}) response = Excon::Response.new response.status = 201 data = { 'id' => Fog::Mock.random_numbers(6).to_s, 'object_type' => options[:object_type], 'object_id' => options[:object_id], 'tenant_id' => options[:tenant_id], 'target_tenant' => options[:target_tenant], 'action' => options[:action] } self.data[:rbac_policies][data['id']] = data response.body = {'rbac_policy' => data} response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/associate_floating_ip.rb0000644000175600017570000000272712730051546027061 0ustar pravipravimodule Fog module Network class OpenStack class Real def associate_floating_ip(floating_ip_id, port_id, options = {}) data = { 'floatingip' => { 'port_id' => port_id, } } vanilla_options = [:fixed_ip_address] vanilla_options.reject{ |o| options[o].nil? }.each do |key| data['floatingip'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => [200], :method => 'PUT', :path => "floatingips/#{floating_ip_id}" ) end end class Mock def associate_floating_ip(floating_ip_id, port_id, options = {}) response = Excon::Response.new response.status = 201 data = { 'id' => '00000000-0000-0000-0000-000000000000', 'router_id' => '00000000-0000-0000-0000-000000000000', 'tenant_id' => options["tenant_id"], 'floating_network_id' => options["floating_network_id"], 'fixed_ip_address' => options["fixed_ip_address"], 'floating_ip_address' => options["floating_ip_address"], 'port_id' => port_id, } self.data[:floating_ips][data['floating_ip_id']] = data response.body = { 'floatingip' => data } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/delete_port.rb0000644000175600017570000000121112730051546025024 0ustar pravipravimodule Fog module Network class OpenStack class Real def delete_port(port_id) request( :expects => 204, :method => 'DELETE', :path => "ports/#{port_id}" ) end end class Mock def delete_port(port_id) response = Excon::Response.new if list_ports.body['ports'].map { |r| r['id'] }.include? port_id self.data[:ports].delete(port_id) response.status = 204 response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/create_router.rb0000644000175600017570000000501012730051546025362 0ustar pravipravimodule Fog module Network class OpenStack class Real def create_router(name, options = {}) data = { 'router' => { 'name' => name, } } vanilla_options = [ :admin_state_up, :tenant_id, :network_id, :status, :subnet_id ] vanilla_options.reject{ |o| options[o].nil? }.each do |key| data['router'][key] = options[key] end # remove this in a future egi = options[:external_gateway_info] if egi if egi.is_a?(Fog::Network::OpenStack::Network) Fog::Logger.deprecation "Passing a model objects into options[:external_gateway_info] is deprecated. \ Please pass external external gateway as follows options[:external_gateway_info] = { :network_id => NETWORK_ID }]" data['router'][:external_gateway_info] = { :network_id => egi.id } elsif egi.is_a?(Hash) && egi[:network_id] data['router'][:external_gateway_info] = egi else raise ArgumentError.new('Invalid external_gateway_info attribute') end end request( :body => Fog::JSON.encode(data), :expects => [201], :method => 'POST', :path => 'routers' ) end end class Mock def create_router(name, options = {}) response = Excon::Response.new response.status = 201 # remove this in a future egi = options[:external_gateway_info] if egi && egi.is_a?(Fog::Network::OpenStack::Network) Fog::Logger.deprecation "Passing a model objects into options[:external_gateway_info] is deprecated. \ Please pass external external gateway as follows options[:external_gateway_info] = { :network_id => NETWORK_ID }]" egi = { :network_id => egi.id } end data = { 'router' => { :id => Fog::Mock.random_numbers(6).to_s, :status => options[:status] || 'ACTIVE', :external_gateway_info => egi, :name => name, :admin_state_up => options[:admin_state_up], :tenant_id => '6b96ff0cb17a4b859e1e575d221683d3' } } self.data[:routers][data['router'][:id]] = data['router'] response.body = data response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/list_networks.rb0000644000175600017570000000101412730051546025426 0ustar pravipravimodule Fog module Network class OpenStack class Real def list_networks(filters = {}) request( :expects => 200, :method => 'GET', :path => 'networks', :query => filters ) end end class Mock def list_networks(filters = {}) Excon::Response.new( :body => { 'networks' => self.data[:networks].values }, :status => 200 ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/get_router.rb0000644000175600017570000000125712730051546024707 0ustar pravipravimodule Fog module Network class OpenStack class Real def get_router(router_id) request( :expects => [200], :method => 'GET', :path => "routers/#{router_id}" ) end end class Mock def get_router(router_id) response = Excon::Response.new if data = (self.data[:routers].find { |id,value| id == router_id }) response.status = 200 response.body = { 'router' => data[1], } response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/update_ipsec_policy.rb0000644000175600017570000000374212730051546026555 0ustar pravipravimodule Fog module Network class OpenStack class Real def update_ipsec_policy(ipsec_policy_id, options = {}) data = {'ipsecpolicy' => {}} vanilla_options = [:name, :description, :tenant_id, :auth_algorithm, :encryption_algorithm, :pfs, :transform_protocol, :encapsulation_mode, :lifetime, :ipsec_version ] vanilla_options.select { |o| options.key?(o) }.each do |key| data['ipsecpolicy'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'PUT', :path => "vpn/ipsecpolicies/#{ipsec_policy_id}" ) end end class Mock def update_ipsec_policy(ipsec_policy_id, options = {}) response = Excon::Response.new ipsec_policy = list_ipsec_policies.body['ipsecpolicies'].detect do |instance| instance['id'] == ipsec_policy_id end if ipsec_policy ipsec_policy['name'] = options[:name] ipsec_policy['description'] = options[:description] ipsec_policy['tenant_id'] = options[:tenant_id] ipsec_policy['auth_algorithm'] = options[:auth_algorithm] ipsec_policy['encryption_algorithm'] = options[:encryption_algorithm] ipsec_policy['pfs'] = options[:pfs] ipsec_policy['transform_protocol'] = options[:transform_protocol] ipsec_policy['encapsulation_mode'] = options[:encapsulation_mode] ipsec_policy['lifetime'] = options[:lifetime] response.body = {'ipsecpolicy' => ipsec_policy} response.status = 200 response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/update_ike_policy.rb0000644000175600017570000000361312730051546026217 0ustar pravipravimodule Fog module Network class OpenStack class Real def update_ike_policy(ike_policy_id, options = {}) data = {'ikepolicy' => {}} vanilla_options = [:name, :description, :tenant_id, :auth_algorithm, :encryption_algorithm, :pfs, :phase1_negotiation_mode, :lifetime, :ike_version ] vanilla_options.select { |o| options.key?(o) }.each do |key| data['ikepolicy'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'PUT', :path => "vpn/ikepolicies/#{ike_policy_id}" ) end end class Mock def update_ike_policy(ike_policy_id, options = {}) response = Excon::Response.new if ike_policy = list_ike_policies.body['ikepolicies'].detect { |instance| instance['id'] == ike_policy_id } ike_policy['name'] = options[:name] ike_policy['description'] = options[:description] ike_policy['tenant_id'] = options[:tenant_id] ike_policy['auth_algorithm'] = options[:auth_algorithm] ike_policy['encryption_algorithm'] = options[:encryption_algorithm] ike_policy['pfs'] = options[:pfs] ike_policy['phase1_negotiation_mode'] = options[:phase1_negotiation_mode] ike_policy['lifetime'] = options[:lifetime] ike_policy['ike_version'] = options[:ike_version] response.body = {'ikepolicy' => ike_policy} response.status = 200 response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/list_lb_pools.rb0000644000175600017570000000101112730051546025360 0ustar pravipravimodule Fog module Network class OpenStack class Real def list_lb_pools(filters = {}) request( :expects => 200, :method => 'GET', :path => 'lb/pools', :query => filters ) end end class Mock def list_lb_pools(filters = {}) Excon::Response.new( :body => { 'pools' => self.data[:lb_pools].values }, :status => 200 ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/delete_security_group_rule.rb0000644000175600017570000000164112730051546030161 0ustar pravipravimodule Fog module Network class OpenStack class Real # Delete a security group rule # # ==== Parameters # * 'security_group_rule_id'<~String> - UUID of the security group rule to delete def delete_security_group_rule(security_group_rule_id) request( :expects => 204, :method => "DELETE", :path => "security-group-rules/#{security_group_rule_id}" ) end end class Mock def delete_security_group_rule(security_group_rule_id) response = Excon::Response.new if self.data[:security_group_rules][security_group_rule_id] self.data[:security_group_rules].delete(security_group_rule_id) response.status = 204 response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/delete_lb_health_monitor.rb0000644000175600017570000000140312730051546027534 0ustar pravipravimodule Fog module Network class OpenStack class Real def delete_lb_health_monitor(health_monitor_id) request( :expects => 204, :method => 'DELETE', :path => "lb/health_monitors/#{health_monitor_id}" ) end end class Mock def delete_lb_health_monitor(health_monitor_id) response = Excon::Response.new if list_lb_health_monitors.body['health_monitors'].map { |r| r['id'] }.include? health_monitor_id self.data[:lb_health_monitors].delete(health_monitor_id) response.status = 204 response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/delete_quota.rb0000644000175600017570000000070512730051546025200 0ustar pravipravimodule Fog module Network class OpenStack class Real def delete_quota(tenant_id) request( :expects => 204, :method => 'DELETE', :path => "/quotas/#{tenant_id}" ) end end class Mock def delete_quota(tenant_id) response = Excon::Response.new response.status = 204 response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/get_vpn_service.rb0000644000175600017570000000124512730051546025707 0ustar pravipravimodule Fog module Network class OpenStack class Real def get_vpn_service(vpn_service_id) request( :expects => [200], :method => 'GET', :path => "vpn/vpnservices/#{vpn_service_id}" ) end end class Mock def get_vpn_service(vpn_service_id) response = Excon::Response.new if data = self.data[:vpn_services][vpn_service_id] response.status = 200 response.body = {'vpnservice' => data} response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/disassociate_floating_ip.rb0000644000175600017570000000262712730051546027560 0ustar pravipravimodule Fog module Network class OpenStack class Real def disassociate_floating_ip(floating_ip_id, options = {}) data = { 'floatingip' => { 'port_id' => nil, } } vanilla_options = [:fixed_ip_address] vanilla_options.reject{ |o| options[o].nil? }.each do |key| data['floatingip'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => [200], :method => 'PUT', :path => "floatingips/#{floating_ip_id}" ) end end class Mock def disassociate_floating_ip(floating_ip_id, options = {}) response = Excon::Response.new response.status = 200 data = { 'id' => '00000000-0000-0000-0000-000000000000', 'router_id' => nil, 'tenant_id' => options["tenant_id"], 'floating_network_id' => options["floating_network_id"], 'fixed_ip_address' => nil, 'floating_ip_address' => options["floating_ip_address"], 'port_id' => options["port_id"], } self.data[:floating_ips][data['floating_ip_id']] = data response.body = { 'floatingip' => data } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/create_lb_vip.rb0000644000175600017570000000377712730051546025337 0ustar pravipravimodule Fog module Network class OpenStack class Real def create_lb_vip(subnet_id, pool_id, protocol, protocol_port, options = {}) data = { 'vip' => { 'subnet_id' => subnet_id, 'pool_id' => pool_id, 'protocol' => protocol, 'protocol_port' => protocol_port } } vanilla_options = [:name, :description, :address, :session_persistence, :connection_limit, :admin_state_up, :tenant_id] vanilla_options.reject{ |o| options[o].nil? }.each do |key| data['vip'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => [201], :method => 'POST', :path => 'lb/vips' ) end end class Mock def create_lb_vip(subnet_id, pool_id, protocol, protocol_port, options = {}) response = Excon::Response.new response.status = 201 data = { 'id' => Fog::Mock.random_numbers(6).to_s, 'subnet_id' => subnet_id, 'pool_id' => pool_id, 'protocol' => protocol, 'protocol_port' => protocol_port, 'name' => options[:name], 'description' => options[:description], 'address' => options[:address], 'port_id' => Fog::Mock.random_numbers(6).to_s, 'session_persistence' => options[:session_persistence], 'connection_limit' => options[:connection_limit], 'status' => 'ACTIVE', 'admin_state_up' => options[:admin_state_up], 'tenant_id' => options[:tenant_id], } self.data[:lb_vips][data['id']] = data response.body = { 'vip' => data } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/disassociate_lb_health_monitor.rb0000644000175600017570000000150512730051546030750 0ustar pravipravimodule Fog module Network class OpenStack class Real def disassociate_lb_health_monitor(pool_id, health_monitor_id) request( :expects => [204], :method => 'DELETE', :path => "lb/pools/#{pool_id}/health_monitors/#{health_monitor_id}" ) end end class Mock def disassociate_lb_health_monitor(pool_id, health_monitor_id) response = Excon::Response.new if pool = list_lb_pools.body['pools'].find { |_| _['id'] == pool_id } pool['health_monitors'].delete(health_monitor_id) self.data[:lb_pools][pool_id] = pool response.status = 204 response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/get_security_group_rule.rb0000644000175600017570000000363312730051546027501 0ustar pravipravimodule Fog module Network class OpenStack class Real # Get details about a security group rule # # ==== Parameters # * 'security_group_rule_id'<~String> - UUID of the security group rule # # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: # * 'security_group_rule'<~Hash>: # * 'id'<~String> - UUID of the security group rule # * 'direction'<~String> - Direction of traffic, must be in ['ingress', 'egress'] # * 'port_range_min'<~Integer> - Start port for rule i.e. 22 (or -1 for ICMP wildcard) # * 'port_range_max'<~Integer> - End port for rule i.e. 22 (or -1 for ICMP wildcard) # * 'protocol'<~String> - IP protocol for rule, must be in ['tcp', 'udp', 'icmp'] # * 'ethertype'<~String> - Type of ethernet support, must be in ['IPv4', 'IPv6'] # * 'security_group_id'<~String> - UUID of the parent security group # * 'remote_group_id'<~String> - UUID of the remote security group # * 'remote_ip_prefix'<~String> - IP cidr range address i.e. '0.0.0.0/0' # * 'tenant_id'<~String> - Tenant id that owns the security group rule def get_security_group_rule(security_group_rule_id) request( :expects => 200, :method => "GET", :path => "security-group-rules/#{security_group_rule_id}" ) end end class Mock def get_security_group_rule(security_group_rule_id) response = Excon::Response.new if sec_group_rule = self.data[:security_group_rules][security_group_rule_id] response.status = 200 response.body = {"security_group_rule" => sec_group_rule} response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/list_subnets.rb0000644000175600017570000000100712730051546025237 0ustar pravipravimodule Fog module Network class OpenStack class Real def list_subnets(filters = {}) request( :expects => 200, :method => 'GET', :path => 'subnets', :query => filters ) end end class Mock def list_subnets(filters = {}) Excon::Response.new( :body => { 'subnets' => self.data[:subnets].values }, :status => 200 ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/update_port.rb0000644000175600017570000000301212730051546025045 0ustar pravipravimodule Fog module Network class OpenStack class Real def update_port(port_id, options = {}) data = { 'port' => {} } vanilla_options = [:name, :fixed_ips, :admin_state_up, :device_owner, :device_id, :security_groups, :allowed_address_pairs] vanilla_options.select{ |o| options.key?(o) }.each do |key| data['port'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'PUT', :path => "ports/#{port_id}.json" ) end end class Mock def update_port(port_id, options = {}) response = Excon::Response.new if port = list_ports.body['ports'].find { |_| _['id'] == port_id } port['name'] = options[:name] port['fixed_ips'] = options[:fixed_ips] || [] port['admin_state_up'] = options[:admin_state_up] port['device_owner'] = options[:device_owner] port['device_id'] = options[:device_id] port['security_groups'] = options[:security_groups] || [] port['allowed_address_pairs'] = options[:allowed_address_pairs] || [] response.body = { 'port' => port } response.status = 200 response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/update_router.rb0000644000175600017570000000503212730051546025405 0ustar pravipravimodule Fog module Network class OpenStack class Real # Update Router # # Beyond the name and the administrative state, the only # parameter which can be updated with this operation is # the external gateway. # @see http://docs.openstack.org/api/openstack-network/2.0/content/router_update.html def update_router(router_id, options = {}) data = { 'router' => {} } [:name, :admin_state_up].each do |key| data['router'][key] = options[key] if options[key] end # remove this in a future egi = options[:external_gateway_info] if egi if egi.is_a?(Fog::Network::OpenStack::Network) Fog::Logger.deprecation "Passing a model objects into options[:external_gateway_info] is deprecated. \ Please pass external external gateway as follows options[:external_gateway_info] = { :network_id => NETWORK_ID }]" data['router'][:external_gateway_info] = { :network_id => egi.id } elsif egi.is_a?(Hash) and egi[:network_id] data['router'][:external_gateway_info] = egi else raise ArgumentError.new('Invalid external_gateway_info attribute') end end request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'PUT', :path => "routers/#{router_id}.json" ) end end class Mock def update_router(router_id, options = {}) response = Excon::Response.new router = list_routers.body['routers'].find {|r| r[:id] == router_id} raise Fog::Network::OpenStack::NotFound unless router options.keys.each {|k| router[k] = options[k] } # remove this in a future egi = options[:external_gateway_info] if egi if egi.is_a?(Fog::Network::OpenStack::Network) Fog::Logger.deprecation "Passing a model objects into options[:external_gateway_info] is deprecated. \ Please pass external external gateway as follows options[:external_gateway_info] = { :network_id => NETWORK_ID }]" router[:external_gateway_info] = { :network_id => egi.id } else egi.is_a?(Hash) && egi[:network_id] router[:external_gateway_info] = egi end end response.body = { 'router' => router } response.status = 200 response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/delete_rbac_policy.rb0000644000175600017570000000132612730051546026335 0ustar pravipravimodule Fog module Network class OpenStack class Real def delete_rbac_policy(rbac_policy_id) request( :expects => 204, :method => 'DELETE', :path => "rbac-policies/#{rbac_policy_id}" ) end end class Mock def delete_rbac_policy(rbac_policy_id) response = Excon::Response.new if list_rbac_policies.body['rbac_policies'].collect { |r| r['id'] }.include? rbac_policy_id data[:rbac_policies].delete(rbac_policy_id) response.status = 204 response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/delete_vpn_service.rb0000644000175600017570000000132412730051546026370 0ustar pravipravimodule Fog module Network class OpenStack class Real def delete_vpn_service(vpn_service_id) request( :expects => 204, :method => 'DELETE', :path => "vpn/vpnservices/#{vpn_service_id}" ) end end class Mock def delete_vpn_service(vpn_service_id) response = Excon::Response.new if list_vpn_services.body['vpnservices'].collect { |r| r['id'] }.include? vpn_service_id data[:vpn_services].delete(vpn_service_id) response.status = 204 response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/delete_floating_ip.rb0000644000175600017570000000132412730051546026340 0ustar pravipravimodule Fog module Network class OpenStack class Real def delete_floating_ip(floating_ip_id) request( :expects => 204, :method => 'DELETE', :path => "floatingips/#{floating_ip_id}" ) end end class Mock def delete_floating_ip(floating_ip_id) response = Excon::Response.new if list_floating_ips.body['floatingips'].map { |r| r['id'] }.include? floating_ip_id self.data[:floating_ips].delete(floating_ip_id) response.status = 204 response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/set_tenant.rb0000644000175600017570000000054612730051546024674 0ustar pravipravimodule Fog module Network class OpenStack class Real def set_tenant(tenant) @openstack_must_reauthenticate = true @openstack_tenant = tenant.to_s authenticate set_api_path end end class Mock def set_tenant(tenant) true end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/get_port.rb0000644000175600017570000000316012730051546024346 0ustar pravipravimodule Fog module Network class OpenStack class Real def get_port(port_id) request( :expects => [200], :method => 'GET', :path => "ports/#{port_id}" ) end end class Mock def get_port(port_id) response = Excon::Response.new if data = self.data[:ports][port_id] response.status = 200 response.body = { 'port' => { 'id' => '5c81d975-5fea-4674-9c1f-b8aa10bf9a79', 'name' => 'port_1', 'network_id' => 'e624a36d-762b-481f-9b50-4154ceb78bbb', 'fixed_ips' => [ { 'ip_address' => '10.2.2.2', 'subnet_id' => '2e4ec6a4-0150-47f5-8523-e899ac03026e', } ], 'mac_address' => 'fa:16:3e:62:91:7f', 'status' => 'ACTIVE', 'admin_state_up' => true, 'device_id' => 'dhcp724fc160-2b2e-597e-b9ed-7f65313cd73f-e624a36d-762b-481f-9b50-4154ceb78bbb', 'device_owner' => 'network:dhcp', 'tenant_id' => 'f8b26a6032bc47718a7702233ac708b9', 'security_groups' => ['3ddde803-e550-4737-b5de-0862401dc834'], 'allowed_address_pairs' => [ 'ip_address' => '10.1.1.1', 'mac_address' => 'fa:16:3e:3d:2a:cc' ] } } response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/create_lb_pool.rb0000644000175600017570000000347612730051546025506 0ustar pravipravimodule Fog module Network class OpenStack class Real def create_lb_pool(subnet_id, protocol, lb_method, options = {}) data = { 'pool' => { 'subnet_id' => subnet_id, 'protocol' => protocol, 'lb_method' => lb_method } } vanilla_options = [:name, :description, :admin_state_up, :tenant_id] vanilla_options.reject{ |o| options[o].nil? }.each do |key| data['pool'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => [201], :method => 'POST', :path => 'lb/pools' ) end end class Mock def create_lb_pool(subnet_id, protocol, lb_method, options = {}) response = Excon::Response.new response.status = 201 data = { 'id' => Fog::Mock.random_numbers(6).to_s, 'subnet_id' => subnet_id, 'protocol' => protocol, 'lb_method' => lb_method, 'name' => options[:name], 'description' => options[:description], 'health_monitors' => [], 'members' => [], 'status' => 'ACTIVE', 'admin_state_up' => options[:admin_state_up], 'vip_id' => nil, 'tenant_id' => options[:tenant_id], 'active_connections' => nil, 'bytes_in' => nil, 'bytes_out' => nil, 'total_connections' => nil } self.data[:lb_pools][data['id']] = data response.body = { 'pool' => data } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/delete_router.rb0000644000175600017570000000123112730051546025362 0ustar pravipravimodule Fog module Network class OpenStack class Real def delete_router(router_id) request( :expects => 204, :method => 'DELETE', :path => "routers/#{router_id}" ) end end class Mock def delete_router(router_id) response = Excon::Response.new if list_routers.body['routers'].find { |r| r[:id] == router_id } self.data[:routers].delete(router_id) response.status = 204 response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/get_ipsec_site_connection.rb0000644000175600017570000000140112730051546027724 0ustar pravipravimodule Fog module Network class OpenStack class Real def get_ipsec_site_connection(ipsec_site_connection_id) request( :expects => [200], :method => 'GET', :path => "vpn/ipsec-site-connections/#{ipsec_site_connection_id}" ) end end class Mock def get_ipsec_site_connection(ipsec_site_connection_id) response = Excon::Response.new if data = self.data[:ipsec_site_connections][ipsec_site_connection_id] response.status = 200 response.body = {'ipsec_site_connection' => data} response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/create_ipsec_site_connection.rb0000644000175600017570000000474612730051546030427 0ustar pravipravimodule Fog module Network class OpenStack class Real def create_ipsec_site_connection(vpn_service_id, ike_policy_id, ipsec_policy_id, options = {}) data = { 'ipsec_site_connection' => { 'vpnservice_id' => vpn_service_id, 'ikepolicy_id' => ike_policy_id, 'ipsecpolicy_id' => ipsec_policy_id } } vanilla_options = [:name, :description, :tenant_id, :peer_address, :peer_id, :peer_cidrs, :psk, :mtu, :dpd, :initiator, :admin_state_up ] vanilla_options.reject { |o| options[o].nil? }.each do |key| data['ipsec_site_connection'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => [201], :method => 'POST', :path => 'vpn/ipsec-site-connections' ) end end class Mock def create_ipsec_site_connection(vpn_service_id, ike_policy_id, ipsec_policy_id, options = {}) response = Excon::Response.new response.status = 201 data = { 'id' => Fog::Mock.random_numbers(6).to_s, 'name' => options[:name], 'description' => options[:description], 'status' => 'ACTIVE', 'tenant_id' => options[:tenant_id], 'admin_state_up' => options[:admin_state_up], 'psk' => options[:psk], 'initiator' => options[:initiator], 'auth_mode' => "psk", 'peer_cidrs' => options[:peer_cidrs], 'mtu' => options[:mtu], 'peer_ep_group_id' => Fog::Mock.random_numbers(6).to_s, 'ikepolicy_id' => ike_policy_id, 'vpnservice_id' => vpn_service_id, 'dpd' => options[:dpd], 'route_mode' => "static", 'ipsecpolicy_id' => ipsec_policy_id, 'local_ep_group_id' => Fog::Mock.random_numbers(6).to_s, 'peer_address' => options[:peer_address], 'peer_id' => options[:peer_id] } self.data[:ipsec_site_connections][data['id']] = data response.body = {'ipsec_site_connection' => data} response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/get_rbac_policy.rb0000644000175600017570000000124512730051546025652 0ustar pravipravimodule Fog module Network class OpenStack class Real def get_rbac_policy(rbac_policy_id) request( :expects => [200], :method => 'GET', :path => "rbac-policies/#{rbac_policy_id}" ) end end class Mock def get_rbac_policy(rbac_policy_id) response = Excon::Response.new if data = self.data[:rbac_policies][rbac_policy_id] response.status = 200 response.body = {'rbac_policy' => data} response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/list_security_group_rules.rb0000644000175600017570000000347512730051546030064 0ustar pravipravimodule Fog module Network class OpenStack class Real # List all security group rules # # ==== Parameters # * options<~Hash>: # # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: # * 'security_group_rules'<~Array>: # * 'id'<~String> - UUID of the security group rule # * 'direction'<~String> - Direction of traffic, must be in ['ingress', 'egress'] # * 'port_range_min'<~Integer> - Start port for rule i.e. 22 (or -1 for ICMP wildcard) # * 'port_range_max'<~Integer> - End port for rule i.e. 22 (or -1 for ICMP wildcard) # * 'protocol'<~String> - IP protocol for rule, must be in ['tcp', 'udp', 'icmp'] # * 'ethertype'<~String> - Type of ethernet support, must be in ['IPv4', 'IPv6'] # * 'security_group_id'<~String> - UUID of the parent security group # * 'remote_group_id'<~String> - UUID of the remote security group # * 'remote_ip_prefix'<~String> - IP cidr range address i.e. '0.0.0.0/0' # * 'tenant_id'<~String> - Tenant id that owns the security group rule def list_security_group_rules(options = {}) request( :expects => 200, :method => 'GET', :path => 'security-group-rules', :query => options ) end end class Mock def list_security_group_rules(options = {}) response = Excon::Response.new sec_group_rules = [] sec_group_rules = self.data[:security_group_rules].values unless self.data[:security_group_rules].nil? response.status = 200 response.body = { 'security_group_rules' => sec_group_rules } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/update_vpn_service.rb0000644000175600017570000000320212730051546026405 0ustar pravipravimodule Fog module Network class OpenStack class Real def update_vpn_service(vpn_service_id, options = {}) data = {'vpnservice' => {}} vanilla_options = [:name, :description, :admin_state_up] vanilla_options.select { |o| options.key?(o) }.each do |key| data['vpnservice'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'PUT', :path => "vpn/vpnservices/#{vpn_service_id}" ) end end class Mock def update_vpn_service(vpn_service_id, options = {}) response = Excon::Response.new if vpn_service = list_vpn_services.body['vpnservices'].detect { |instance| instance['id'] == vpn_service_id } vpn_service['id'] = vpn_service_id vpn_service['subnet_id'] = options[:subnet_id] vpn_service['router_id'] = options[:router_id] vpn_service['name'] = options[:name] vpn_service['description'] = options[:description] vpn_service['status'] = 'ACTIVE' vpn_service['admin_state_up'] = options[:admin_state_up] vpn_service['tenant_id'] = options[:tenant_id] vpn_service['external_v4_ip'] = '1.2.3.4' vpn_service['external_v6_ip'] = '::1' response.body = {'vpnservice' => vpn_service} response.status = 200 response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/list_ipsec_policies.rb0000644000175600017570000000103212730051546026544 0ustar pravipravimodule Fog module Network class OpenStack class Real def list_ipsec_policies(filters = {}) request( :expects => 200, :method => 'GET', :path => 'vpn/ipsecpolicies', :query => filters ) end end class Mock def list_ipsec_policies(*) Excon::Response.new( :body => {'ipsecpolicies' => data[:ipsec_policies].values}, :status => 200 ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/update_subnet.rb0000644000175600017570000000270212730051546025366 0ustar pravipravimodule Fog module Network class OpenStack class Real def update_subnet(subnet_id, options = {}) data = { 'subnet' => {} } vanilla_options = [:name, :gateway_ip, :allocation_pools, :dns_nameservers, :host_routes, :enable_dhcp] vanilla_options.select{ |o| options.key?(o) }.each do |key| data['subnet'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'PUT', :path => "subnets/#{subnet_id}" ) end end class Mock def update_subnet(subnet_id, options = {}) response = Excon::Response.new if subnet = list_subnets.body['subnets'].find { |_| _['id'] == subnet_id } subnet['name'] = options[:name] subnet['gateway_ip'] = options[:gateway_ip] subnet['dns_nameservers'] = options[:dns_nameservers] || [] subnet['host_routes'] = options[:host_routes] || [] subnet['allocation_pools'] = options[:allocation_pools] || [] subnet['enable_dhcp'] = options[:enable_dhcp] response.body = { 'subnet' => subnet } response.status = 200 response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/associate_lb_health_monitor.rb0000644000175600017570000000200412730051546030243 0ustar pravipravimodule Fog module Network class OpenStack class Real def associate_lb_health_monitor(pool_id, health_monitor_id) data = { 'health_monitor' => { 'id' => health_monitor_id, } } request( :body => Fog::JSON.encode(data), :expects => [201], :method => 'POST', :path => "lb/pools/#{pool_id}/health_monitors" ) end end class Mock def associate_lb_health_monitor(pool_id, health_monitor_id) response = Excon::Response.new if pool = list_lb_pools.body['pools'].find { |_| _['id'] == pool_id } pool['health_monitors'] << health_monitor_id self.data[:lb_pools][pool_id] = pool response.body = { 'health_monitor' => {} } response.status = 200 response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/get_lb_health_monitor.rb0000644000175600017570000000131212730051546027050 0ustar pravipravimodule Fog module Network class OpenStack class Real def get_lb_health_monitor(health_monitor_id) request( :expects => [200], :method => 'GET', :path => "lb/health_monitors/#{health_monitor_id}" ) end end class Mock def get_lb_health_monitor(health_monitor_id) response = Excon::Response.new if data = self.data[:lb_health_monitors][health_monitor_id] response.status = 200 response.body = { 'health_monitor' => data } response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/delete_lb_vip.rb0000644000175600017570000000121212730051546025314 0ustar pravipravimodule Fog module Network class OpenStack class Real def delete_lb_vip(vip_id) request( :expects => 204, :method => 'DELETE', :path => "lb/vips/#{vip_id}" ) end end class Mock def delete_lb_vip(vip_id) response = Excon::Response.new if list_lb_vips.body['vips'].map { |r| r['id'] }.include? vip_id self.data[:lb_vips].delete(vip_id) response.status = 204 response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/get_quota.rb0000644000175600017570000000105412730051546024513 0ustar pravipravimodule Fog module Network class OpenStack class Real def get_quota(tenant_id) request( :expects => 200, :method => 'GET', :path => "/quotas/#{tenant_id}" ) end end class Mock def get_quota(tenant_id) response = Excon::Response.new response.status = 200 response.body = { 'quota' => (self.data[:quota_updated] or self.data[:quota]) } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/update_lb_pool.rb0000644000175600017570000000227412730051546025520 0ustar pravipravimodule Fog module Network class OpenStack class Real def update_lb_pool(pool_id, options = {}) data = { 'pool' => {} } vanilla_options = [:name, :description, :lb_method, :admin_state_up] vanilla_options.select{ |o| options.key?(o) }.each do |key| data['pool'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'PUT', :path => "lb/pools/#{pool_id}" ) end end class Mock def update_lb_pool(pool_id, options = {}) response = Excon::Response.new if pool = list_lb_pools.body['pools'].find { |_| _['id'] == pool_id } pool['name'] = options[:name] pool['description'] = options[:description] pool['lb_method'] = options[:lb_method] pool['admin_state_up'] = options[:admin_state_up] response.body = { 'pool' => pool } response.status = 200 response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/create_lb_member.rb0000644000175600017570000000301112730051546025765 0ustar pravipravimodule Fog module Network class OpenStack class Real def create_lb_member(pool_id, address, protocol_port, weight, options = {}) data = { 'member' => { 'pool_id' => pool_id, 'address' => address, 'protocol_port' => protocol_port, 'weight' => weight } } vanilla_options = [:admin_state_up, :tenant_id] vanilla_options.reject{ |o| options[o].nil? }.each do |key| data['member'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => [201], :method => 'POST', :path => 'lb/members' ) end end class Mock def create_lb_member(pool_id, address, protocol_port, weight, options = {}) response = Excon::Response.new response.status = 201 data = { 'id' => Fog::Mock.random_numbers(6).to_s, 'pool_id' => pool_id, 'address' => address, 'protocol_port' => protocol_port, 'weight' => weight, 'status' => 'ACTIVE', 'admin_state_up' => options[:admin_state_up], 'tenant_id' => options[:tenant_id], } self.data[:lb_members][data['id']] = data response.body = { 'member' => data } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/delete_ipsec_site_connection.rb0000644000175600017570000000157012730051546030416 0ustar pravipravimodule Fog module Network class OpenStack class Real def delete_ipsec_site_connection(ipsec_site_connection_id) request( :expects => 204, :method => 'DELETE', :path => "vpn/ipsec-site-connections/#{ipsec_site_connection_id}" ) end end class Mock def delete_ipsec_site_connection(ipsec_site_connection_id) response = Excon::Response.new ip_site_connections = list_ipsec_site_connections.body['ipsec_site_connections'] if ip_site_connections.collect { |r| r['id'] }.include? ipsec_site_connection_id data[:ipsec_site_connections].delete(ipsec_site_connection_id) response.status = 204 response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/list_ike_policies.rb0000644000175600017570000000102012730051546026206 0ustar pravipravimodule Fog module Network class OpenStack class Real def list_ike_policies(filters = {}) request( :expects => 200, :method => 'GET', :path => 'vpn/ikepolicies', :query => filters ) end end class Mock def list_ike_policies(*) Excon::Response.new( :body => {'ikepolicies' => data[:ike_policies].values}, :status => 200 ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/delete_ike_policy.rb0000644000175600017570000000131512730051546026174 0ustar pravipravimodule Fog module Network class OpenStack class Real def delete_ike_policy(ike_policy_id) request( :expects => 204, :method => 'DELETE', :path => "vpn/ikepolicies/#{ike_policy_id}" ) end end class Mock def delete_ike_policy(ike_policy_id) response = Excon::Response.new if list_ike_policies.body['ikepolicies'].collect { |r| r['id'] }.include? ike_policy_id data[:ike_policies].delete(ike_policy_id) response.status = 204 response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/create_vpn_service.rb0000644000175600017570000000301612730051546026371 0ustar pravipravimodule Fog module Network class OpenStack class Real def create_vpn_service(subnet_id, router_id, options = {}) data = { 'vpnservice' => { 'subnet_id' => subnet_id, 'router_id' => router_id } } vanilla_options = [:name, :description, :admin_state_up, :tenant_id] vanilla_options.reject { |o| options[o].nil? }.each do |key| data['vpnservice'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => [201], :method => 'POST', :path => 'vpn/vpnservices' ) end end class Mock def create_vpn_service(subnet_id, router_id, options = {}) response = Excon::Response.new response.status = 201 data = { 'id' => Fog::Mock.random_numbers(6).to_s, 'subnet_id' => subnet_id, 'router_id' => router_id, 'name' => options[:name], 'description' => options[:description], 'status' => 'ACTIVE', 'admin_state_up' => options[:admin_state_up], 'tenant_id' => options[:tenant_id], 'external_v4_ip' => '1.2.3.4', 'external_v6_ip' => '::1' } self.data[:vpn_services][data['id']] = data response.body = {'vpnservice' => data} response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/create_ipsec_policy.rb0000644000175600017570000000335312730051546026534 0ustar pravipravimodule Fog module Network class OpenStack class Real def create_ipsec_policy(options = {}) data = { 'ipsecpolicy' => { } } vanilla_options = [:name, :description, :tenant_id, :auth_algorithm, :encryption_algorithm, :pfs, :transform_protocol, :lifetime, :encapsulation_mode ] vanilla_options.reject { |o| options[o].nil? }.each do |key| data['ipsecpolicy'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => [201], :method => 'POST', :path => 'vpn/ipsecpolicies' ) end end class Mock def create_ipsec_policy(options = {}) response = Excon::Response.new response.status = 201 data = { 'id' => Fog::Mock.random_numbers(6).to_s, 'name' => options[:name], 'description' => options[:description], 'tenant_id' => options[:tenant_id], 'auth_algorithm' => options[:auth_algorithm], 'encryption_algorithm' => options[:encryption_algorithm], 'pfs' => options[:pfs], 'transform_protocol' => options[:transform_protocol], 'lifetime' => options[:lifetime], 'encapsulation_mode' => options[:encapsulation_mode] } self.data[:ipsec_policies][data['id']] = data response.body = {'ipsecpolicy' => data} response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/get_floating_ip.rb0000644000175600017570000000227112730051546025657 0ustar pravipravimodule Fog module Network class OpenStack class Real def get_floating_ip(floating_ip_id) request( :expects => [200], :method => 'GET', :path => "floatingips/#{floating_ip_id}" ) end end class Mock def get_floating_ip(floating_ip_id) response = Excon::Response.new if data = self.data[:floating_ips][floating_ip_id] response.status = 200 response.body = { "floatingip" => { "id" => "00000000-0000-0000-0000-000000000000", # changed # "floating_ip_id" => floating_ip_id, "port_id" => data["port_id"], "tenant_id" => data["tenant_id"], "fixed_ip_address" => data["fixed_ip_address"], "router_id" => "00000000-0000-0000-0000-000000000000", "floating_ip_address" => data["floating_ip_address"], } } response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/create_port.rb0000644000175600017570000000345212730051546025036 0ustar pravipravimodule Fog module Network class OpenStack class Real def create_port(network_id, options = {}) data = { 'port' => { 'network_id' => network_id, } } vanilla_options = [:name, :fixed_ips, :mac_address, :admin_state_up, :device_owner, :device_id, :tenant_id, :security_groups, :allowed_address_pairs] vanilla_options.reject{ |o| options[o].nil? }.each do |key| data['port'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => [201], :method => 'POST', :path => 'ports' ) end end class Mock def create_port(network_id, options = {}) response = Excon::Response.new response.status = 201 data = { 'id' => Fog::Mock.random_numbers(6).to_s, 'name' => options[:name], 'network_id' => network_id, 'fixed_ips' => options[:fixed_ips], 'mac_address' => options[:mac_address], 'status' => 'ACTIVE', 'admin_state_up' => options[:admin_state_up], 'device_owner' => options[:device_owner], 'device_id' => options[:device_id], 'tenant_id' => options[:tenant_id], 'security_groups' => options[:security_groups], 'allowed_address_pairs' => options[:allowed_address_pairs], } self.data[:ports][data['id']] = data response.body = { 'port' => data } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/create_ike_policy.rb0000644000175600017570000000336712730051546026206 0ustar pravipravimodule Fog module Network class OpenStack class Real def create_ike_policy(options = {}) data = { 'ikepolicy' => { } } vanilla_options = [:name, :description, :tenant_id, :auth_algorithm, :encryption_algorithm, :pfs, :phase1_negotiation_mode, :lifetime, :ike_version ] vanilla_options.reject { |o| options[o].nil? }.each do |key| data['ikepolicy'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => [201], :method => 'POST', :path => 'vpn/ikepolicies' ) end end class Mock def create_ike_policy(options = {}) response = Excon::Response.new response.status = 201 data = { 'id' => Fog::Mock.random_numbers(6).to_s, 'name' => options[:name], 'description' => options[:description], 'tenant_id' => options[:tenant_id], 'auth_algorithm' => options[:auth_algorithm], 'encryption_algorithm' => options[:encryption_algorithm], 'pfs' => options[:pfs], 'phase1_negotiation_mode' => options[:phase1_negotiation_mode], 'lifetime' => options[:lifetime], 'ike_version' => options[:ike_version] } self.data[:ike_policies][data['id']] = data response.body = {'ikepolicy' => data} response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/delete_subnet.rb0000644000175600017570000000123712730051546025350 0ustar pravipravimodule Fog module Network class OpenStack class Real def delete_subnet(subnet_id) request( :expects => 204, :method => 'DELETE', :path => "subnets/#{subnet_id}" ) end end class Mock def delete_subnet(subnet_id) response = Excon::Response.new if list_subnets.body['subnets'].map { |r| r['id'] }.include? subnet_id self.data[:subnets].delete(subnet_id) response.status = 204 response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/get_network.rb0000644000175600017570000000117512730051546025057 0ustar pravipravimodule Fog module Network class OpenStack class Real def get_network(network_id) request( :expects => [200], :method => 'GET', :path => "networks/#{network_id}" ) end end class Mock def get_network(network_id) response = Excon::Response.new if data = self.data[:networks][network_id] response.status = 200 response.body = {'network' => data} response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/update_ipsec_site_connection.rb0000644000175600017570000000571412730051546030442 0ustar pravipravimodule Fog module Network class OpenStack class Real def update_ipsec_site_connection(ipsec_site_connection_id, options = {}) data = {'ipsec_site_connection' => {}} vanilla_options = [:name, :description, :tenant_id, :peer_address, :peer_id, :peer_cidrs, :psk, :mtu, :dpd, :initiator, :admin_state_up, :ikepolicy_id, :ipsecpolicy_id, :vpnservice_id ] vanilla_options.select { |o| options.key?(o) }.each do |key| data['ipsec_site_connection'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'PUT', :path => "vpn/ipsec-site-connections/#{ipsec_site_connection_id}" ) end end class Mock def update_ipsec_site_connection(ipsec_site_connection_id, options = {}) response = Excon::Response.new ipsec_site_connection = list_ipsec_site_connections.body['ipsec_site_connections'].detect do |instance| instance['id'] == ipsec_site_connection_id end if ipsec_site_connection ipsec_site_connection['name'] = options[:name] ipsec_site_connection['description'] = options[:description] ipsec_site_connection['tenant_id'] = options[:tenant_id] ipsec_site_connection['status'] = 'ACTIVE' ipsec_site_connection['admin_state_up'] = options[:admin_state_up] ipsec_site_connection['psk'] = options[:psk] ipsec_site_connection['initiator'] = options[:initiator] ipsec_site_connection['auth_mode'] = "psk" ipsec_site_connection['peer_cidrs'] = options[:peer_cidrs] ipsec_site_connection['mtu'] = options[:mtu] ipsec_site_connection['peer_ep_group_id'] = Fog::Mock.random_numbers(6).to_s ipsec_site_connection['ikepolicy_id'] = options[:ikepolicy_id] || 'ike' ipsec_site_connection['vpnservice_id'] = options[:vpnservice_id] || 'vpn' ipsec_site_connection['dpd'] = options[:dpd] ipsec_site_connection['route_mode'] = "static" ipsec_site_connection['ipsecpolicy_id'] = options[:ipsecpolicy_id] || 'ipsec' ipsec_site_connection['local_ep_group_id'] = Fog::Mock.random_numbers(6).to_s ipsec_site_connection['peer_address'] = options[:peer_address] ipsec_site_connection['peer_id'] = options[:peer_id] response.body = {'ipsec_site_connection' => ipsec_site_connection} response.status = 200 response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/update_quota.rb0000644000175600017570000000125312730051546025217 0ustar pravipravimodule Fog module Network class OpenStack class Real def update_quota(tenant_id, options = {}) request( :body => Fog::JSON.encode({ 'quota' => options} ), :expects => 200, :method => 'PUT', :path => "/quotas/#{tenant_id}" ) end end class Mock def update_quota(tenant_id, options = {}) self.data[:quota_updated] = self.data[:quota].merge options response = Excon::Response.new response.status = 200 response.body = { 'quota' => self.data[:quota_updated] } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/get_ike_policy.rb0000644000175600017570000000123612730051546025513 0ustar pravipravimodule Fog module Network class OpenStack class Real def get_ike_policy(ike_policy_id) request( :expects => [200], :method => 'GET', :path => "vpn/ikepolicies/#{ike_policy_id}" ) end end class Mock def get_ike_policy(ike_policy_id) response = Excon::Response.new if data = self.data[:ike_policies][ike_policy_id] response.status = 200 response.body = {'ikepolicy' => data} response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/list_rbac_policies.rb0000644000175600017570000000102312730051546026350 0ustar pravipravimodule Fog module Network class OpenStack class Real def list_rbac_policies(filters = {}) request( :expects => 200, :method => 'GET', :path => 'rbac-policies', :query => filters ) end end class Mock def list_rbac_policies(*) Excon::Response.new( :body => {'rbac_policies' => data[:rbac_policies].values}, :status => 200 ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/list_vpn_services.rb0000644000175600017570000000102012730051546026255 0ustar pravipravimodule Fog module Network class OpenStack class Real def list_vpn_services(filters = {}) request( :expects => 200, :method => 'GET', :path => 'vpn/vpnservices', :query => filters ) end end class Mock def list_vpn_services(*) Excon::Response.new( :body => {'vpnservices' => data[:vpn_services].values}, :status => 200 ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/delete_lb_member.rb0000644000175600017570000000125312730051546025772 0ustar pravipravimodule Fog module Network class OpenStack class Real def delete_lb_member(member_id) request( :expects => 204, :method => 'DELETE', :path => "lb/members/#{member_id}" ) end end class Mock def delete_lb_member(member_id) response = Excon::Response.new if list_lb_members.body['members'].map { |r| r['id'] }.include? member_id self.data[:lb_members].delete(member_id) response.status = 204 response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/get_lb_vip.rb0000644000175600017570000000114712730051546024640 0ustar pravipravimodule Fog module Network class OpenStack class Real def get_lb_vip(vip_id) request( :expects => [200], :method => 'GET', :path => "lb/vips/#{vip_id}" ) end end class Mock def get_lb_vip(vip_id) response = Excon::Response.new if data = self.data[:lb_vips][vip_id] response.status = 200 response.body = { 'vip' => data } response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/list_ipsec_site_connections.rb0000644000175600017570000000110412730051546030303 0ustar pravipravimodule Fog module Network class OpenStack class Real def list_ipsec_site_connections(filters = {}) request( :expects => 200, :method => 'GET', :path => 'vpn/ipsec-site-connections', :query => filters ) end end class Mock def list_ipsec_site_connections(*) Excon::Response.new( :body => {'ipsec_site_connections' => data[:ipsec_site_connections].values}, :status => 200 ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/list_security_groups.rb0000644000175600017570000000417312730051546027031 0ustar pravipravimodule Fog module Network class OpenStack class Real # List all security groups # # ==== Parameters # * options<~Hash>: # # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: # * 'security_groups'<~Array>: # * 'id'<~String> - UUID of the security group # * 'name'<~String> - Name of the security group # * 'description'<~String> - Description of the security group # * 'tenant_id'<~String> - Tenant id that owns the security group # * 'security_group_rules'<~Array>: - Array of security group rules # * 'id'<~String> - UUID of the security group rule # * 'direction'<~String> - Direction of traffic, must be in ['ingress', 'egress'] # * 'port_range_min'<~Integer> - Start port for rule i.e. 22 (or -1 for ICMP wildcard) # * 'port_range_max'<~Integer> - End port for rule i.e. 22 (or -1 for ICMP wildcard) # * 'protocol'<~String> - IP protocol for rule, must be in ['tcp', 'udp', 'icmp'] # * 'ethertype'<~String> - Type of ethernet support, must be in ['IPv4', 'IPv6'] # * 'security_group_id'<~String> - UUID of the parent security group # * 'remote_group_id'<~String> - UUID of the remote security group # * 'remote_ip_prefix'<~String> - IP cidr range address i.e. '0.0.0.0/0' # * 'tenant_id'<~String> - Tenant id that owns the security group rule def list_security_groups(options = {}) request( :expects => 200, :method => 'GET', :path => 'security-groups', :query => options ) end end class Mock def list_security_groups(options = {}) response = Excon::Response.new sec_groups = [] sec_groups = self.data[:security_groups].values unless self.data[:security_groups].nil? response.status = 200 response.body = { 'security_groups' => sec_groups } response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/list_lb_vips.rb0000644000175600017570000000100412730051546025207 0ustar pravipravimodule Fog module Network class OpenStack class Real def list_lb_vips(filters = {}) request( :expects => 200, :method => 'GET', :path => 'lb/vips', :query => filters ) end end class Mock def list_lb_vips(filters = {}) Excon::Response.new( :body => { 'vips' => self.data[:lb_vips].values }, :status => 200 ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/get_security_group.rb0000644000175600017570000000430612730051546026450 0ustar pravipravimodule Fog module Network class OpenStack class Real # Get details about a security group # # ==== Parameters # * 'security_group_id'<~String> - UUID of the security group # # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: # * 'security_group'<~Array>: # * 'id'<~String> - UUID of the security group # * 'name'<~String> - Name of the security group # * 'description'<~String> - Description of the security group # * 'tenant_id'<~String> - Tenant id that owns the security group # * 'security_group_rules'<~Array>: - Array of security group rules # * 'id'<~String> - UUID of the security group rule # * 'direction'<~String> - Direction of traffic, must be in ['ingress', 'egress'] # * 'port_range_min'<~Integer> - Start port for rule i.e. 22 (or -1 for ICMP wildcard) # * 'port_range_max'<~Integer> - End port for rule i.e. 22 (or -1 for ICMP wildcard) # * 'protocol'<~String> - IP protocol for rule, must be in ['tcp', 'udp', 'icmp'] # * 'ethertype'<~String> - Type of ethernet support, must be in ['IPv4', 'IPv6'] # * 'security_group_id'<~String> - UUID of the parent security group # * 'remote_group_id'<~String> - UUID of the remote security group # * 'remote_ip_prefix'<~String> - IP cidr range address i.e. '0.0.0.0/0' # * 'tenant_id'<~String> - Tenant id that owns the security group rule def get_security_group(security_group_id) request( :expects => 200, :method => "GET", :path => "security-groups/#{security_group_id}" ) end end class Mock def get_security_group(security_group_id) response = Excon::Response.new if sec_group = self.data[:security_groups][security_group_id] response.status = 200 response.body = {"security_group" => sec_group} response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/delete_security_group.rb0000644000175600017570000000154012730051546027130 0ustar pravipravimodule Fog module Network class OpenStack class Real # Delete a security group # # ==== Parameters # * 'security_group_id'<~String> - UUID of the security group to delete def delete_security_group(security_group_id) request( :expects => 204, :method => 'DELETE', :path => "security-groups/#{security_group_id}" ) end end class Mock def delete_security_group(security_group_id) response = Excon::Response.new if self.data[:security_groups][security_group_id] self.data[:security_groups].delete(security_group_id) response.status = 204 response else raise Fog::Network::OpenStack::NotFound end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/network/list_ports.rb0000644000175600017570000000077512730051546024736 0ustar pravipravimodule Fog module Network class OpenStack class Real def list_ports(filters = {}) request( :expects => 200, :method => 'GET', :path => 'ports', :query => filters ) end end class Mock def list_ports(filters = {}) Excon::Response.new( :body => { 'ports' => self.data[:ports].values }, :status => 200 ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v2/0000755000175600017570000000000012730051546022745 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/requests/identity_v2/get_role.rb0000644000175600017570000000135512730051546025076 0ustar pravipravimodule Fog module Identity class OpenStack class V2 class Real def get_role(id) request( :expects => [200, 204], :method => 'GET', :path => "/OS-KSADM/roles/#{id}" ) end end class Mock def get_role(id) response = Excon::Response.new if data = self.data[:roles][id] response.status = 200 response.body = {'role' => data} response else raise Fog::Identity::OpenStack::NotFound end end end # class Mock end # class V2 end # class OpenStack end # module Identity end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v2/delete_tenant.rb0000644000175600017570000000162312730051546026107 0ustar pravipravimodule Fog module Identity class OpenStack class V2 class Real def delete_tenant(id) request( :expects => [200, 204], :method => 'DELETE', :path => "tenants/#{id}" ) end # def create_tenant end # class Real class Mock def delete_tenant(attributes) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = { 'tenant' => { 'id' => '1', 'description' => 'Has access to everything', 'enabled' => true, 'name' => 'admin' } } response end # def create_tenant end # class Mock end # class V2 end # class OpenStack end # module Identity end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v2/update_user.rb0000644000175600017570000000156212730051546025616 0ustar pravipravimodule Fog module Identity class OpenStack class V2 class Real def update_user(user_id, options = {}) url = options.delete('url') || "/users/#{user_id}" request( :body => Fog::JSON.encode({'user' => options}), :expects => 200, :method => 'PUT', :path => url ) end end class Mock def update_user(user_id, options) response = Excon::Response.new if user = self.data[:users][user_id] if options['name'] user['name'] = options['name'] end response.status = 200 response else raise Fog::Identity::OpenStack::NotFound end end end end # class V2 end end end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v2/get_user_by_name.rb0000644000175600017570000000125212730051546026601 0ustar pravipravimodule Fog module Identity class OpenStack class V2 class Real def get_user_by_name(name) request( :expects => [200, 203], :method => 'GET', :path => "users?name=#{name}" ) end end class Mock def get_user_by_name(name) response = Excon::Response.new response.status = 200 user = self.data[:users].values.select { |user| user['name'] == name }[0] response.body = { 'user' => user } response end end end # class V2 end end end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v2/list_users.rb0000644000175600017570000000244212730051546025470 0ustar pravipravimodule Fog module Identity class OpenStack class V2 class Real def list_users(options = {}) if options.is_a?(Hash) tenant_id = options.delete(:tenant_id) query = options else Fog::Logger.deprecation('Calling OpenStack[:identity].list_users(tenant_id) is deprecated, use .list_users(:tenant_id => value)') tenant_id = options query = {} end path = tenant_id ? "tenants/#{tenant_id}/users" : 'users' request( :expects => [200, 204], :method => 'GET', :path => path, :query => query ) end end # class Real class Mock def list_users(options = {}) tenant_id = options[:tenant_id] users = self.data[:users].values if tenant_id users = users.select { |user| user['tenantId'] == tenant_id } end Excon::Response.new( :body => {'users' => users}, :status => 200 ) end end # class Mock end # class V2 end # class OpenStack end # module Identity end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v2/list_roles_for_user_on_tenant.rb0000644000175600017570000000204012730051546031416 0ustar pravipravimodule Fog module Identity class OpenStack class V2 class Real def list_roles_for_user_on_tenant(tenant_id, user_id) request( :expects => [200], :method => 'GET', :path => "tenants/#{tenant_id}/users/#{user_id}/roles" ) end # def list_roles_for_user_on_tenant end # class Real class Mock def list_roles_for_user_on_tenant(tenant_id, user_id) self.data[:user_tenant_membership][tenant_id] ||= {} self.data[:user_tenant_membership][tenant_id][user_id] ||= [] roles = self.data[:user_tenant_membership][tenant_id][user_id].map do |role_id| self.data[:roles][role_id] end Excon::Response.new( :body => {'roles' => roles}, :status => 200 ) end # def list_roles_for_user_on_tenant end # class Mock end # class V2 end # class OpenStack end # module Identity end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v2/check_token.rb0000644000175600017570000000074512730051546025555 0ustar pravipravimodule Fog module Identity class OpenStack class V2 class Real def check_token(token_id, tenant_id=nil) request( :expects => [200, 203], :method => 'HEAD', :path => "tokens/#{token_id}"+(tenant_id ? "?belongsTo=#{tenant_id}" : '') ) end end class Mock def check_token(token_id, tenant_id=nil) end end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v2/list_endpoints_for_token.rb0000644000175600017570000000061312730051546030376 0ustar pravipravimodule Fog module Identity class OpenStack class V2 class Real def list_endpoints_for_token(token_id) request( :expects => [200, 203], :method => 'HEAD', :path => "tokens/#{token_id}/endpoints" ) end end class Mock end end # class V2 end end end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v2/delete_role.rb0000644000175600017570000000130612730051546025555 0ustar pravipravimodule Fog module Identity class OpenStack class V2 class Real def delete_role(role_id) request( :expects => [200, 204], :method => 'DELETE', :path => "/OS-KSADM/roles/#{role_id}" ) end end class Mock def delete_role(role_id) response = Excon::Response.new if self.data[:roles][role_id] self.data[:roles].delete(role_id) response.status = 204 response else raise Fog::Identity::OpenStack::NotFound end end end end # class V2 end end end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v2/update_tenant.rb0000644000175600017570000000156412730051546026133 0ustar pravipravimodule Fog module Identity class OpenStack class V2 class Real def update_tenant(id, attributes) request( :expects => [200], :method => 'PUT', :path => "tenants/#{id}", :body => Fog::JSON.encode({'tenant' => attributes}) ) end # def create_tenant end # class Real class Mock def update_tenant(id, attributes) response = Excon::Response.new response.status = [200, 204][rand(1)] attributes = {'enabled' => true, 'id' => '1'}.merge(attributes) response.body = { 'tenant' => attributes } response end # def create_tenant end # class Mock end # class V2 end # class OpenStack end # module Identity end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v2/get_user_by_id.rb0000644000175600017570000000153512730051546026261 0ustar pravipravimodule Fog module Identity class OpenStack class V2 class Real def get_user_by_id(user_id) request( :expects => [200, 203], :method => 'GET', :path => "users/#{user_id}" ) end end class Mock def get_user_by_id(user_id) response = Excon::Response.new response.status = 200 existing_user = self.data[:users].find do |u| u[0] == user_id || u[1]['name'] == 'mock' end existing_user = existing_user[1] if existing_user response.body = { 'user' => existing_user || create_user('mock', 'mock', 'mock@email.com').body['user'] } response end end end # class V2 end end end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v2/get_tenants_by_name.rb0000644000175600017570000000056412730051546027304 0ustar pravipravimodule Fog module Identity class OpenStack class V2 class Real def get_tenants_by_name(name) request( :expects => [200], :method => 'GET', :path => "tenants?name=#{name}" ) end end class Mock end end # class V2 end end end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v2/set_tenant.rb0000644000175600017570000000067512730051546025446 0ustar pravipravimodule Fog module Identity class OpenStack class V2 class Real def set_tenant(tenant) @openstack_must_reauthenticate = true @openstack_tenant = tenant.to_s authenticate end end class Mock def set_tenant(tenant) true end end end # class V2 end # class OpenStack end # module Identity end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v2/add_user_to_tenant.rb0000644000175600017570000000217212730051546027135 0ustar pravipravimodule Fog module Identity class OpenStack class V2 class Real def add_user_to_tenant(tenant_id, user_id, role_id) request( :expects => 200, :method => 'PUT', :path => "/tenants/#{tenant_id}/users/#{user_id}/roles/OS-KSADM/#{role_id}" ) end end # class Real class Mock def add_user_to_tenant(tenant_id, user_id, role_id) role = self.data[:roles][role_id] self.data[:user_tenant_membership][tenant_id] ||= {} self.data[:user_tenant_membership][tenant_id][user_id] ||= [] self.data[:user_tenant_membership][tenant_id][user_id].push(role['id']).uniq! response = Excon::Response.new response.status = 200 response.body = { 'role' => { 'id' => role['id'], 'name' => role['name'] } } response end # def add_user_to_tenant end # class Mock end # class V2 end # class OpenStack end # module Identity end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v2/list_user_global_roles.rb0000644000175600017570000000057412730051546030035 0ustar pravipravimodule Fog module Identity class OpenStack class V2 class Real def list_user_global_roles(user_id) request( :expects => [200], :method => 'GET', :path => "users/#{user_id}/roles" ) end end class Mock end end # class V2 end end end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v2/create_user_role.rb0000644000175600017570000000121312730051546026611 0ustar pravipravimodule Fog module Identity class OpenStack class V2 class Real def create_user_role(tenant_id, user_id, role_id) request( :expects => 200, :method => 'PUT', :path => "/tenants/#{tenant_id}/users/#{user_id}/roles/OS-KSADM/#{role_id}" ) end end class Mock def create_user_role(tenant_id, user_id, role_id) Excon::Response.new( :body => {'role' => self.data[:roles][role_id]}, :status => 200 ) end end end # class V2 end end end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v2/create_tenant.rb0000644000175600017570000000203212730051546026103 0ustar pravipravimodule Fog module Identity class OpenStack class V2 class Real def create_tenant(attributes) request( :expects => [200], :method => 'POST', :path => "tenants", :body => Fog::JSON.encode({'tenant' => attributes}) ) end # def create_tenant end # class Real class Mock def create_tenant(attributes) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = { 'tenant' => { 'id' => "df9a815161eba9b76cc748fd5c5af73e", 'description' => attributes[:description] || 'normal tenant', 'enabled' => true, 'name' => attributes[:name] || 'default' } } response end # def create_tenant end # class Mock end # class V2 end # class OpenStack end # module Identity end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v2/delete_ec2_credential.rb0000644000175600017570000000230012730051546027452 0ustar pravipravimodule Fog module Identity class OpenStack class V2 class Real ## # Destroy an EC2 credential for a user. Requires administrator # credentials. # # ==== Parameters # * user_id<~String>: The id of the user to delete the credential # for # * access<~String>: The access key of the credential to destroy # # ==== Returns # * response<~Excon::Response>: # * body<~String>: Empty string def delete_ec2_credential(user_id, access) request( :expects => [200, 204], :method => 'DELETE', :path => "users/#{user_id}/credentials/OS-EC2/#{access}" ) end end class Mock def delete_ec2_credential(user_id, access) raise Fog::Identity::OpenStack::NotFound unless self.data[:ec2_credentials][user_id][access] self.data[:ec2_credentials][user_id].delete access response = Excon::Response.new response.status = 204 response rescue end end end # class V2 end end end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v2/create_role.rb0000644000175600017570000000153712730051546025564 0ustar pravipravimodule Fog module Identity class OpenStack class V2 class Real def create_role(name) data = { 'role' => { 'name' => name } } request( :body => Fog::JSON.encode(data), :expects => [200, 202], :method => 'POST', :path => '/OS-KSADM/roles' ) end end class Mock def create_role(name) data = { 'id' => Fog::Mock.random_hex(32), 'name' => name } self.data[:roles][data['id']] = data Excon::Response.new( :body => {'role' => data}, :status => 202 ) end end end # class V2 end end end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v2/get_tenants_by_id.rb0000644000175600017570000000056712730051546026763 0ustar pravipravimodule Fog module Identity class OpenStack class V2 class Real def get_tenants_by_id(tenant_id) request( :expects => [200], :method => 'GET', :path => "tenants/#{tenant_id}" ) end end class Mock end end # class V2 end end end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v2/create_ec2_credential.rb0000644000175600017570000000334712730051546027467 0ustar pravipravimodule Fog module Identity class OpenStack class V2 class Real ## # Create an EC2 credential for a user in a tenant. Requires # administrator credentials. # # ==== Parameters # * user_id<~String>: The id of the user to create an EC2 credential # for # * tenant_id<~String>: The id of the tenant to create the credential # in # # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: # * 'credential'<~Hash>: Created EC2 credential # * 'access'<~String>: The access key # * 'secret'<~String>: The secret key # * 'user_id'<~String>: The user id # * 'tenant_id'<~String>: The tenant id def create_ec2_credential(user_id, tenant_id) data = {'tenant_id' => tenant_id} request( :body => Fog::JSON.encode(data), :expects => [200, 202], :method => 'POST', :path => "users/#{user_id}/credentials/OS-EC2" ) end end class Mock def create_ec2_credential(user_id, tenant_id) response = Excon::Response.new response.status = 200 data = { 'access' => Fog::Mock.random_hex(32), 'secret' => Fog::Mock.random_hex(32), 'tenant_id' => tenant_id, 'user_id' => user_id, } self.data[:ec2_credentials][user_id][data['access']] = data response.body = {'credential' => data} response end end end # class V2 end end end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v2/get_ec2_credential.rb0000644000175600017570000000307112730051546026775 0ustar pravipravimodule Fog module Identity class OpenStack class V2 class Real ## # Retrieves an EC2 credential for a user. Requires administrator # credentials. # # ==== Parameters # * user_id<~String>: The id of the user to retrieve the credential # for # * access<~String>: The access key of the credential to retrieve # # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: # * 'credential'<~Hash>: The EC2 credential # * 'access'<~String>: The access key # * 'secret'<~String>: The secret key # * 'user_id'<~String>: The user id # * 'tenant_id'<~String>: The tenant id def get_ec2_credential(user_id, access) request( :expects => [200, 202], :method => 'GET', :path => "users/#{user_id}/credentials/OS-EC2/#{access}" ) rescue Excon::Errors::Unauthorized raise Fog::Identity::OpenStack::NotFound end end class Mock def get_ec2_credential(user_id, access) ec2_credential = self.data[:ec2_credentials][user_id][access] raise Fog::OpenStack::Identity::NotFound unless ec2_credential response = Excon::Response.new response.status = 200 response.body = {'credential' => ec2_credential} response end end end # class V2 end end end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v2/delete_user.rb0000644000175600017570000000130312730051546025567 0ustar pravipravimodule Fog module Identity class OpenStack class V2 class Real def delete_user(user_id) request( :expects => [200, 204], :method => 'DELETE', :path => "users/#{user_id}" ) end end class Mock def delete_user(user_id) self.data[:users].delete( list_users.body['users'].find { |x| x['id'] == user_id }['id']) response = Excon::Response.new response.status = 204 response rescue raise Fog::Identity::OpenStack::NotFound end end end # class V2 end end end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v2/remove_user_from_tenant.rb0000644000175600017570000000116012730051546030217 0ustar pravipravimodule Fog module Identity class OpenStack class V2 class Real def remove_user_from_tenant(tenant_id, user_id, role_id) request( :expects => [200, 204], :method => 'DELETE', :path => "/tenants/#{tenant_id}/users/#{user_id}/roles/OS-KSADM/#{role_id}" ) end end # class Real class Mock def remove_user_from_tenant(tenant_id, user_id, role_id) end # def remove_user_from_tenant end # class Mock end # class V2 end # class OpenStack end # module Identity end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v2/get_tenant.rb0000644000175600017570000000155412730051546025427 0ustar pravipravimodule Fog module Identity class OpenStack class V2 class Real def get_tenant(id) request( :expects => [200, 204], :method => 'GET', :path => "tenants/#{id}" ) end end # class Real class Mock def get_tenant(id) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = { 'tenant' => { 'id' => id, 'description' => 'Has access to everything', 'enabled' => true, 'name' => 'admin' } } response end # def list_tenants end # class Mock end # class V2 end # class OpenStack end # module Identity end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v2/list_ec2_credentials.rb0000644000175600017570000000354012730051546027355 0ustar pravipravimodule Fog module Identity class OpenStack class V2 class Real ## # List EC2 credentials for a user. Requires administrator # credentials. # # ==== Parameters hash # * :user_id<~String>: The id of the user to retrieve the credential # for # # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: # * 'credentials'<~Array>: The user's EC2 credentials # * 'access'<~String>: The access key # * 'secret'<~String>: The secret key # * 'user_id'<~String>: The user id # * 'tenant_id'<~String>: The tenant id def list_ec2_credentials(options = {}) if options.is_a?(Hash) user_id = options.delete(:user_id) query = options else Fog::Logger.deprecation('Calling OpenStack[:identity].list_ec2_credentials(user_id) is deprecated, use .list_ec2_credentials(:user_id => value)') user_id = options query = {} end request( :expects => [200, 202], :method => 'GET', :path => "users/#{user_id}/credentials/OS-EC2", :query => query ) end end class Mock def list_ec2_credentials(options = {}) if options.is_a?(Hash) user_id = options.delete(:user_id) else user_id = options end ec2_credentials = self.data[:ec2_credentials][user_id].values response = Excon::Response.new response.status = 200 response.body = {'credentials' => ec2_credentials} response end end end # class V2 end end end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v2/list_tenants.rb0000644000175600017570000000346312730051546026007 0ustar pravipravimodule Fog module Identity class OpenStack class V2 class Real def list_tenants(options = nil, marker = nil) if options.is_a?(Hash) params = options else Fog::Logger.deprecation('Calling OpenStack[:identity].list_tenants(limit, marker) is deprecated, use'\ ' .list_ec2_credentials(:limit => value, :marker => value)') params = {} params['limit'] = options if options params['marker'] = marker if marker end request( :expects => [200, 204], :method => 'GET', :path => "tenants", :query => params ) end end # class Real class Mock def list_tenants(options = nil, marker = nil) Excon::Response.new( :body => { 'tenants_links' => [], 'tenants' => [ {'id' => '1', 'description' => 'Has access to everything', 'enabled' => true, 'name' => 'admin'}, {'id' => '2', 'description' => 'Normal tenant', 'enabled' => true, 'name' => 'default'}, {'id' => '3', 'description' => 'Disabled tenant', 'enabled' => false, 'name' => 'disabled'} ] }, :status => [200, 204][rand(1)] ) end # def list_tenants end # class Mock end # class V2 end # class OpenStack end # module Identity end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v2/validate_token.rb0000644000175600017570000000075212730051546026267 0ustar pravipravimodule Fog module Identity class OpenStack class V2 class Real def validate_token(token_id, tenant_id=nil) request( :expects => [200, 203], :method => 'GET', :path => "tokens/#{token_id}"+(tenant_id ? "?belongsTo=#{tenant_id}" : '') ) end end class Mock def validate_token(token_id, tenant_id=nil) end end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/identity_v2/delete_user_role.rb0000644000175600017570000000114112730051546026610 0ustar pravipravimodule Fog module Identity class OpenStack class V2 class Real def delete_user_role(tenant_id, user_id, role_id) request( :expects => 204, :method => 'DELETE', :path => "/tenants/#{tenant_id}/users/#{user_id}/roles/OS-KSADM/#{role_id}" ) end end class Mock def delete_user_role(tenant_id, user_id, role_id) response = Excon::Response.new response.status = 204 response end end end # class V2 end end end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v2/create_user.rb0000644000175600017570000000233712730051546025600 0ustar pravipravimodule Fog module Identity class OpenStack class V2 class Real def create_user(name, password, email, tenantId=nil, enabled=true) data = { 'user' => { 'name' => name, 'password' => password, 'tenantId' => tenantId, 'email' => email, 'enabled' => enabled, } } request( :body => Fog::JSON.encode(data), :expects => [200, 202], :method => 'POST', :path => '/users' ) end end class Mock def create_user(name, password, email, tenantId=nil, enabled=true) response = Excon::Response.new response.status = 200 data = { 'id' => Fog::Mock.random_hex(32), 'name' => name, 'email' => email, 'tenantId' => tenantId, 'enabled' => enabled } self.data[:users][data['id']] = data response.body = {'user' => data} response end end end # class V2 end end end fog-openstack-0.1.6/lib/fog/openstack/requests/identity_v2/list_roles.rb0000644000175600017570000000150712730051546025454 0ustar pravipravimodule Fog module Identity class OpenStack class V2 class Real def list_roles(options = {}) request( :expects => 200, :method => 'GET', :path => '/OS-KSADM/roles', :query => options ) end end class Mock def list_roles(options = {}) if self.data[:roles].empty? ['admin', 'Member'].each do |name| id = Fog::Mock.random_hex(32) self.data[:roles][id] = {'id' => id, 'name' => name} end end Excon::Response.new( :body => {'roles' => self.data[:roles].values}, :status => 200 ) end end end # class V2 end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/0000755000175600017570000000000012730051546022423 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/create_volume_type.rb0000644000175600017570000000015712730051546026646 0ustar pravipravirequire 'fog/openstack/requests/volume/create_volume_type' require 'fog/openstack/requests/volume_v2/real_mock'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/create_snapshot.rb0000644000175600017570000000231612730051546026134 0ustar pravipravirequire 'fog/openstack/requests/volume/create_snapshot' module Fog module Volume class OpenStack class V2 class Real include Fog::Volume::OpenStack::Real def create_snapshot(volume_id, name, description, force = false) data = { 'snapshot' => { 'volume_id' => volume_id, 'name' => name, 'description' => description, 'force' => force.nil? ? false : force } } _create_snapshot(data) end end class Mock def create_snapshot(volume_id, name, description, _force = false) response = Excon::Response.new response.status = 202 response.body = { "snapshot" => { "status" => "creating", "name" => name, "created_at" => Time.now, "description" => description, "volume_id" => volume_id, "id" => "5", "size" => 1 } } response end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/get_transfer_details.rb0000644000175600017570000000015412730051546027140 0ustar pravipravirequire 'fog/openstack/requests/volume/get_transfer_details' require 'fog/openstack/requests/volume_v2/real'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/list_transfers_detailed.rb0000644000175600017570000000015712730051546027650 0ustar pravipravirequire 'fog/openstack/requests/volume/list_transfers_detailed' require 'fog/openstack/requests/volume_v2/real'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/update_volume_type.rb0000644000175600017570000000015712730051546026665 0ustar pravipravirequire 'fog/openstack/requests/volume/update_volume_type' require 'fog/openstack/requests/volume_v2/real_mock'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/update_metadata.rb0000644000175600017570000000015012730051546026066 0ustar pravipravirequire 'fog/openstack/requests/volume/update_metadata' require 'fog/openstack/requests/volume_v2/real' fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/get_quota_defaults.rb0000644000175600017570000000015712730051546026632 0ustar pravipravirequire 'fog/openstack/requests/volume/get_quota_defaults' require 'fog/openstack/requests/volume_v2/real_mock'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/get_volume_type_details.rb0000644000175600017570000000016412730051546027665 0ustar pravipravirequire 'fog/openstack/requests/volume/get_volume_type_details' require 'fog/openstack/requests/volume_v2/real_mock'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/list_zones.rb0000644000175600017570000000014712730051546025143 0ustar pravipravirequire 'fog/openstack/requests/volume/list_zones' require 'fog/openstack/requests/volume_v2/real_mock'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/list_volumes.rb0000644000175600017570000000312112730051546025472 0ustar pravipravirequire 'fog/openstack/requests/volume/list_volumes' module Fog module Volume class OpenStack class V2 class Real include Fog::Volume::OpenStack::Real end class Mock def list_volumes(options = true, options_deprecated = {}) response = Excon::Response.new response.status = 200 self.data[:volumes] ||= [ {"status" => "available", "description" => "test 1 desc", "availability_zone" => "nova", "name" => "Volume1", "attachments" => [{}], "volume_type" => nil, "snapshot_id" => nil, "size" => 1, "id" => 1, "created_at" => Time.now, "metadata" => {}}, {"status" => "available", "description" => "test 2 desc", "availability_zone" => "nova", "name" => "Volume2", "attachments" => [{}], "volume_type" => nil, "snapshot_id" => nil, "size" => 1, "id" => 2, "created_at" => Time.now, "metadata" => {}} ] response.body = {'volumes' => self.data[:volumes]} response end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/create_transfer.rb0000644000175600017570000000014712730051546026121 0ustar pravipravirequire 'fog/openstack/requests/volume/create_transfer' require 'fog/openstack/requests/volume_v2/real'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/action.rb0000644000175600017570000000013712730051546024226 0ustar pravipravirequire 'fog/openstack/requests/volume/action' require 'fog/openstack/requests/volume_v2/real' fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/list_volumes_detailed.rb0000644000175600017570000000312412730051546027330 0ustar pravipravirequire 'fog/openstack/requests/volume/list_volumes_detailed' module Fog module Volume class OpenStack class V2 class Real include Fog::Volume::OpenStack::Real end class Mock def list_volumes_detailed(options = {}) response = Excon::Response.new response.status = 200 self.data[:volumes] ||= [ {"status" => "available", "description" => "test 1 desc", "availability_zone" => "nova", "name" => "Volume1", "attachments" => [{}], "volume_type" => nil, "snapshot_id" => nil, "size" => 1, "id" => 1, "created_at" => Time.now, "metadata" => {}}, {"status" => "available", "description" => "test 2 desc", "availability_zone" => "nova", "name" => "Volume2", "attachments" => [{}], "volume_type" => nil, "snapshot_id" => nil, "size" => 1, "id" => 2, "created_at" => Time.now, "metadata" => {}} ] response.body = {'volumes' => self.data[:volumes]} response end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/real_mock.rb0000644000175600017570000000036512730051546024710 0ustar pravipravimodule Fog module Volume class OpenStack class V2 class Real include Fog::Volume::OpenStack::Real end class Mock include Fog::Volume::OpenStack::Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/delete_volume.rb0000644000175600017570000000015212730051546025577 0ustar pravipravirequire 'fog/openstack/requests/volume/delete_volume' require 'fog/openstack/requests/volume_v2/real_mock'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/list_snapshots.rb0000644000175600017570000000015312730051546026024 0ustar pravipravirequire 'fog/openstack/requests/volume/list_snapshots' require 'fog/openstack/requests/volume_v2/real_mock'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/update_snapshot.rb0000644000175600017570000000015012730051546026145 0ustar pravipravirequire 'fog/openstack/requests/volume/update_snapshot' require 'fog/openstack/requests/volume_v2/real' fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/update_volume.rb0000644000175600017570000000014612730051546025622 0ustar pravipravirequire 'fog/openstack/requests/volume/update_volume' require 'fog/openstack/requests/volume_v2/real' fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/get_quota_usage.rb0000644000175600017570000000015412730051546026124 0ustar pravipravirequire 'fog/openstack/requests/volume/get_quota_usage' require 'fog/openstack/requests/volume_v2/real_mock'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/set_tenant.rb0000644000175600017570000000014712730051546025116 0ustar pravipravirequire 'fog/openstack/requests/volume/set_tenant' require 'fog/openstack/requests/volume_v2/real_mock'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/delete_volume_type.rb0000644000175600017570000000015712730051546026645 0ustar pravipravirequire 'fog/openstack/requests/volume/delete_volume_type' require 'fog/openstack/requests/volume_v2/real_mock'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/delete_snapshot.rb0000644000175600017570000000015412730051546026131 0ustar pravipravirequire 'fog/openstack/requests/volume/delete_snapshot' require 'fog/openstack/requests/volume_v2/real_mock'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/update_snapshot_metadata.rb0000644000175600017570000000016112730051546030007 0ustar pravipravirequire 'fog/openstack/requests/volume/update_snapshot_metadata' require 'fog/openstack/requests/volume_v2/real' fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/extend_volume.rb0000644000175600017570000000015212730051546025624 0ustar pravipravirequire 'fog/openstack/requests/volume/extend_volume' require 'fog/openstack/requests/volume_v2/real_mock'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/list_snapshots_detailed.rb0000644000175600017570000000016412730051546027661 0ustar pravipravirequire 'fog/openstack/requests/volume/list_snapshots_detailed' require 'fog/openstack/requests/volume_v2/real_mock'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/real.rb0000644000175600017570000000024712730051546023676 0ustar pravipravimodule Fog module Volume class OpenStack class V2 class Real include Fog::Volume::OpenStack::Real end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/get_quota.rb0000644000175600017570000000014612730051546024741 0ustar pravipravirequire 'fog/openstack/requests/volume/get_quota' require 'fog/openstack/requests/volume_v2/real_mock'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/list_volume_types.rb0000644000175600017570000000015612730051546026540 0ustar pravipravirequire 'fog/openstack/requests/volume/list_volume_types' require 'fog/openstack/requests/volume_v2/real_mock'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/accept_transfer.rb0000644000175600017570000000014712730051546026115 0ustar pravipravirequire 'fog/openstack/requests/volume/accept_transfer' require 'fog/openstack/requests/volume_v2/real'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/replace_metadata.rb0000644000175600017570000000015112730051546026220 0ustar pravipravirequire 'fog/openstack/requests/volume/replace_metadata' require 'fog/openstack/requests/volume_v2/real' fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/delete_snapshot_metadata.rb0000644000175600017570000000016112730051546027767 0ustar pravipravirequire 'fog/openstack/requests/volume/delete_snapshot_metadata' require 'fog/openstack/requests/volume_v2/real' fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/get_volume_details.rb0000644000175600017570000000207412730051546026626 0ustar pravipravirequire 'fog/openstack/requests/volume/get_volume_details' module Fog module Volume class OpenStack class V2 class Real include Fog::Volume::OpenStack::Real end class Mock def get_volume_details(detailed=true) response = Excon::Response.new response.status = 200 response.body = { 'volume' => { 'id' => '1', 'name' => Fog::Mock.random_letters(rand(8) + 5), 'description' => Fog::Mock.random_letters(rand(12) + 10), 'size' => 3, 'volume_type' => nil, 'snapshot_id' => '4', 'status' => 'online', 'availability_zone' => 'nova', 'created_at' => Time.now, 'attachments' => [] } } response end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/delete_transfer.rb0000644000175600017570000000014712730051546026120 0ustar pravipravirequire 'fog/openstack/requests/volume/delete_transfer' require 'fog/openstack/requests/volume_v2/real'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/get_snapshot_details.rb0000644000175600017570000000157612730051546027164 0ustar pravipravirequire 'fog/openstack/requests/volume/get_snapshot_details' module Fog module Volume class OpenStack class V2 class Real include Fog::Volume::OpenStack::Real end class Mock def get_snapshot_details(detailed=true) response = Excon::Response.new response.status = 200 response.body = { 'snapshot' => { 'id' => '1', 'name' => 'Snapshot1', 'description' => 'Volume1 snapshot', 'size' => 1, 'volume_id' => '1', 'status' => 'available', 'created_at' => Time.now } } response end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/create_volume.rb0000644000175600017570000000303612730051546025604 0ustar pravipravirequire 'fog/openstack/requests/volume/create_volume' module Fog module Volume class OpenStack class V2 class Real def create_volume(name, description, size, options={}) data = { 'volume' => { 'name' => name, 'description' => description, 'size' => size } } _create_volume(data, options) end include Fog::Volume::OpenStack::Real end class Mock def create_volume(name, description, size, options={}) response = Excon::Response.new response.status = 202 response.body = { 'volume' => { 'id' => Fog::Mock.random_numbers(2), 'name' => name, 'description' => description, 'metadata' => options['metadata'] || {}, 'size' => size, 'status' => 'creating', 'snapshot_id' => options[:snapshot_id] || nil, 'image_id' => options[:imageRef] || nil, 'volume_type' => nil, 'availability_zone' => 'nova', 'created_at' => Time.now, 'attachments' => [] } } response end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/update_quota.rb0000644000175600017570000000015112730051546025440 0ustar pravipravirequire 'fog/openstack/requests/volume/update_quota' require 'fog/openstack/requests/volume_v1/real_mock'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/list_transfers.rb0000644000175600017570000000014612730051546026013 0ustar pravipravirequire 'fog/openstack/requests/volume/list_transfers' require 'fog/openstack/requests/volume_v2/real'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v2/delete_metadata.rb0000644000175600017570000000015012730051546026046 0ustar pravipravirequire 'fog/openstack/requests/volume/delete_metadata' require 'fog/openstack/requests/volume_v2/real' fog-openstack-0.1.6/lib/fog/openstack/requests/baremetal/0000755000175600017570000000000012730051546022441 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/requests/baremetal/list_chassis.rb0000644000175600017570000000232412730051546025457 0ustar pravipravimodule Fog module Baremetal class OpenStack class Real def list_chassis(options = {}) request( :expects => [200, 204], :method => 'GET', :path => 'chassis', :query => options ) end end # class Real class Mock def list_chassis(parameters=nil) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = { "chassis" => [ { "description" => "Sample chassis", "links" => [ { "href" => "http =>//localhost:6385/v1/chassis/eaaca217-e7d8-47b4-bb41-3f99f20eed89", "rel" => "self" }, { "href" => "http =>//localhost:6385/chassis/eaaca217-e7d8-47b4-bb41-3f99f20eed89", "rel" => "bookmark" } ], "uuid" => Fog::UUID.uuid } ] } response end # def list_chassis end # class Mock end # class OpenStack end # module Baremetal end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/baremetal/delete_chassis.rb0000644000175600017570000000106312730051546025745 0ustar pravipravimodule Fog module Baremetal class OpenStack class Real def delete_chassis(chassis_uuid) data = { :chassis_uuid => chassis_uuid } request( :body => Fog::JSON.encode(data), :expects => [200, 204], :method => 'DELETE', :path => 'chassis' ) end end class Mock def delete_chassis(chassis_uuid) response = Excon::Response.new response.status = 200 response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/baremetal/list_chassis_detailed.rb0000644000175600017570000000127512730051546027316 0ustar pravipravimodule Fog module Baremetal class OpenStack class Real def list_chassis_detailed(options = {}) request( :expects => [200, 204], :method => 'GET', :path => 'chassis/detail', :query => options ) end end # class Real class Mock def list_chassis_detailed(options = {}) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = { "chassis" => self.data[:chassis_collection] } response end # def list_chassis_detailed end # class Mock end # class OpenStack end # module Baremetal end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/baremetal/create_chassis.rb0000644000175600017570000000241412730051546025747 0ustar pravipravimodule Fog module Baremetal class OpenStack class Real # Create a new chassis # # === Attributes === # description = Free text description of the chassis # extra = Record arbitrary key/value metadata. Can be specified multiple times def create_chassis(attributes) desired_options = [ :description, :extra ] # Filter only allowed creation attributes data = attributes.select { |key, value| desired_options.include?(key.to_sym) } request( :body => Fog::JSON.encode(data), :expects => [200,201], :method => 'POST', :path => 'chassis' ) end end class Mock def create_chassis(attributes) response = Excon::Response.new response.status = 200 response.headers = { "X-Compute-Request-Id" => "req-fdc6f99e-55a2-4ab1-8904-0892753828cf", "Content-Type" => "application/json", "Content-Length" => "356", "Date" => Date.new } response.body = self.data[:chassis_collection].first response end end # mock end # openstack end # baremetal end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/baremetal/delete_port.rb0000644000175600017570000000103712730051546025275 0ustar pravipravimodule Fog module Baremetal class OpenStack class Real def delete_port(port_uuid) data = { :port_uuid => port_uuid } request( :body => Fog::JSON.encode(data), :expects => [200, 204], :method => 'DELETE', :path => 'ports' ) end end class Mock def delete_port(port_uuid) response = Excon::Response.new response.status = 200 response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/baremetal/create_node.rb0000644000175600017570000000347412730051546025246 0ustar pravipravimodule Fog module Baremetal class OpenStack class Real # Create a new node # # === Attributes === # chassis_uuid = UUID of the chassis that this node belongs to # driver = Driver used to control the node [REQUIRED] # driver_info = Key/value pairs used by the driver, such as out-of-band management credentials. Can be # specified multiple times # extra = Record arbitrary key/value metadata. Can be specified multiple times # uuid = Unique UUID for the node # properties = Key/value pairs describing the physical characteristics of the node. This is exported to # Nova and used by the scheduler. Can be specified multiple times def create_node(attributes) desired_options = [ :chassis_uuid, :driver, :driver_info, :extra, :uuid, :properties ] # Filter only allowed creation attributes data = attributes.select { |key, value| desired_options.include?(key.to_sym) } request( :body => Fog::JSON.encode(data), :expects => [200,201], :method => 'POST', :path => 'nodes' ) end end class Mock def create_node(attributes) response = Excon::Response.new response.status = 200 response.headers = { "X-Compute-Request-Id" => "req-fdc6f99e-55a2-4ab1-8904-0892753828cf", "Content-Type" => "application/json", "Content-Length" => "356", "Date" => Date.new } response.body = self.data[:nodes].first response end end # mock end # openstack end # baremetal end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/baremetal/list_nodes.rb0000644000175600017570000000166212730051546025136 0ustar pravipravimodule Fog module Baremetal class OpenStack class Real def list_nodes(options = {}) request( :expects => [200, 204], :method => 'GET', :path => 'nodes', :query => options ) end end # class Real class Mock def list_nodes(options = {}) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = { "nodes" => [{ "instance_uuid" => Fog::UUID.uuid, "maintenance" => false, "power_state" => "power on", "provision_state" => "active", "uuid" => Fog::UUID.uuid, "links" => [] }] } response end # def list_nodes end # class Mock end # class OpenStack end # module Baremetal end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/baremetal/list_ports_detailed.rb0000644000175600017570000000123512730051546027024 0ustar pravipravimodule Fog module Baremetal class OpenStack class Real def list_ports_detailed(options = {}) request( :expects => [200, 204], :method => 'GET', :path => 'ports/detail', :query => options ) end end # class Real class Mock def list_ports_detailed(options = {}) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = { "ports" => self.data[:ports] } response end # def list_ports end # class Mock end # class OpenStack end # module Baremetal end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/baremetal/get_port.rb0000644000175600017570000000113312730051546024607 0ustar pravipravimodule Fog module Baremetal class OpenStack class Real def get_port(port_id) request( :expects => [200, 204], :method => 'GET', :path => "ports/#{port_id}" ) end end # class Real class Mock def get_port(port_id) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = self.data[:ports].first response end # def get_port end # class Mock end # class OpenStack end # module Baremetal end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/baremetal/list_drivers.rb0000644000175600017570000000122012730051546025472 0ustar pravipravimodule Fog module Baremetal class OpenStack class Real def list_drivers(options = {}) request( :expects => [200, 204], :method => 'GET', :path => 'drivers', :query => options ) end end # class Real class Mock def list_drivers(options = {}) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = { "drivers" => self.data[:drivers] } response end # def list_drivers end # class Mock end # class OpenStack end # module Baremetal end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/baremetal/patch_chassis.rb0000644000175600017570000000242212730051546025602 0ustar pravipravimodule Fog module Baremetal class OpenStack class Real # Patch a chassis # # parameter example: # [{:op=> 'replace', :path => "/extra/placement", :value => "somewhere"}] # # === Patch parameter, list of jsonpatch === # op = Operations: 'add', 'replace' or 'remove' # path = Attributes to add/replace or remove (only PATH is necessary on remove), # e.g. /extra/placement # value = Value to set def patch_chassis(chassis_uuid, patch) request( :body => Fog::JSON.encode(patch), :expects => 200, :method => 'PATCH', :path => "chassis/#{chassis_uuid}" ) end end class Mock def patch_chassis(chassis_uuid, patch) response = Excon::Response.new response.status = 200 response.headers = { "X-Compute-Request-Id" => "req-fdc6f99e-55a2-4ab1-8904-0892753828cf", "Content-Type" => "application/json", "Content-Length" => "356", "Date" => Date.new } response.body = self.data[:chassis_collection].first response end end # mock end # openstack end # baremetal end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/baremetal/list_nodes_detailed.rb0000644000175600017570000000123512730051546026765 0ustar pravipravimodule Fog module Baremetal class OpenStack class Real def list_nodes_detailed(options = {}) request( :expects => [200, 204], :method => 'GET', :path => 'nodes/detail', :query => options ) end end # class Real class Mock def list_nodes_detailed(options = {}) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = { "nodes" => self.data[:nodes] } response end # def list_nodes end # class Mock end # class OpenStack end # module Baremetal end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/baremetal/get_driver_properties.rb0000644000175600017570000000324512730051546027400 0ustar pravipravimodule Fog module Baremetal class OpenStack class Real def get_driver_properties(driver_name) data = { :driver_name => driver_name } request( :body => Fog::JSON.encode(data), :expects => [200, 204], :method => 'GET', :path => "drivers/properties" ) end end # class Real class Mock def get_driver_properties(driver_name) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = { "pxe_deploy_ramdisk" => "UUID (from Glance) of the ramdisk.", "ipmi_transit_address" => "transit address for bridged request.", "ipmi_terminal_port" => "node's UDP port to connect to.", "ipmi_target_channel" => "destination channel for bridged request.", "ipmi_transit_channel" => "transit channel for bridged request.", "ipmi_local_address" => "local IPMB address for bridged requests. ", "ipmi_username" => "username; default is NULL user. Optional.", "ipmi_address" => "IP address or hostname of the node. Required.", "ipmi_target_address" => "destination address for bridged request.", "ipmi_password" => "password. Optional.", "pxe_deploy_kernel" => "UUID (from Glance) of the deployment kernel.", "ipmi_priv_level" => "privilege level; default is ADMINISTRATOR. ", "ipmi_bridging" => "bridging_type." } response end # def get_driver_properties end # class Mock end # class OpenStack end # module Baremetal end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/baremetal/patch_node.rb0000644000175600017570000000235612730051546025100 0ustar pravipravimodule Fog module Baremetal class OpenStack class Real # Patch a node # # parameter example: # [{:op=> 'replace', :path => "/driver", :value => "pxe_ssh"}] # # === Patch parameter, list of jsonpatch === # op = Operations: 'add', 'replace' or 'remove' # path = Attributes to add/replace or remove (only PATH is necessary on remove), # e.g. /driver_info/ipmi_address # value = Value to set def patch_node(node_uuid, patch) request( :body => Fog::JSON.encode(patch), :expects => 200, :method => 'PATCH', :path => "nodes/#{node_uuid}" ) end end class Mock def patch_node(node_uuid, patch) response = Excon::Response.new response.status = 200 response.headers = { "X-Compute-Request-Id" => "req-fdc6f99e-55a2-4ab1-8904-0892753828cf", "Content-Type" => "application/json", "Content-Length" => "356", "Date" => Date.new } response.body = self.data[:nodes].first response end end # mock end # openstack end # baremetal end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/baremetal/set_node_maintenance.rb0000644000175600017570000000150112730051546027125 0ustar pravipravimodule Fog module Baremetal class OpenStack class Real def set_node_maintenance(node_uuid, parameters=nil) request( :expects => [200, 202, 204], :method => 'PUT', :path => "nodes/#{node_uuid}/maintenance", :query => parameters ) end end class Mock def set_node_maintenance(node_uuid, parameters=nil) response = Excon::Response.new response.status = 202 response.headers = { "X-Compute-Request-Id" => "req-fdc6f99e-55a2-4ab1-8904-0892753828cf", "Content-Type" => "application/json", "Content-Length" => "356", "Date" => Date.new } response end end # mock end # openstack end # baremetal end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/baremetal/create_port.rb0000644000175600017570000000247012730051546025300 0ustar pravipravimodule Fog module Baremetal class OpenStack class Real # Create a new port # # === Attributes === # address = MAC Address for this port # extra = Record arbitrary key/value metadata. Can be specified multiple times # node_uuid = UUID of the node that this port belongs to def create_port(attributes) desired_options = [ :address, :extra, :node_uuid ] # Filter only allowed creation attributes data = attributes.select { |key, value| desired_options.include?(key.to_sym) } request( :body => Fog::JSON.encode(data), :expects => [200,201], :method => 'POST', :path => 'ports' ) end end class Mock def create_port(attributes) response = Excon::Response.new response.status = 200 response.headers = { "X-Compute-Request-Id" => "req-fdc6f99e-55a2-4ab1-8904-0892753828cf", "Content-Type" => "application/json", "Content-Length" => "356", "Date" => Date.new } response.body = self.data[:ports].first response end end # mock end # openstack end # baremetal end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/baremetal/set_node_power_state.rb0000644000175600017570000000165212730051546027206 0ustar pravipravimodule Fog module Baremetal class OpenStack class Real def set_node_power_state(node_id, power_state) data = { 'target' => power_state } request( :body => Fog::JSON.encode(data), :expects => 202, :method => 'PUT', :path => "nodes/#{node_id}/states/power" ) end end class Mock def set_node_power_state(node_id, power_state) response = Excon::Response.new response.status = 202 response.headers = { "X-Compute-Request-Id" => "req-fdc6f99e-55a2-4ab1-8904-0892753828cf", "Content-Type" => "application/json", "Content-Length" => "356", "Date" => Date.new } response.body = self.data[:nodes].first response end end # mock end # openstack end # baremetal end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/baremetal/unset_node_maintenance.rb0000644000175600017570000000151012730051546027470 0ustar pravipravimodule Fog module Baremetal class OpenStack class Real def unset_node_maintenance(node_uuid, parameters=nil) request( :expects => [200, 202, 204], :method => 'DELETE', :path => "nodes/#{node_uuid}/maintenance", :query => parameters ) end end class Mock def unset_node_maintenance(node_uuid, parameters=nil) response = Excon::Response.new response.status = 202 response.headers = { "X-Compute-Request-Id" => "req-fdc6f99e-55a2-4ab1-8904-0892753828cf", "Content-Type" => "application/json", "Content-Length" => "356", "Date" => Date.new } response end end # mock end # openstack end # baremetal end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/baremetal/set_node_provision_state.rb0000644000175600017570000000206312730051546030077 0ustar pravipravimodule Fog module Baremetal class OpenStack class Real def set_node_provision_state(node_id, provision_state) data = { 'target' => provision_state } request( :body => Fog::JSON.encode(data), :expects => 202, :method => 'PUT', :path => "nodes/#{node_id}/states/provision", :headers => { :'X-OpenStack-Ironic-API-Version' => 'latest' } ) end end class Mock def set_node_provision_state(node_id, provision_state) response = Excon::Response.new response.status = 202 response.headers = { "X-Compute-Request-Id" => "req-fdc6f99e-55a2-4ab1-8904-0892753828cf", "Content-Type" => "application/json", "Content-Length" => "356", "Date" => Date.new } response.body = self.data[:nodes].first response end end # mock end # openstack end # baremetal end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/baremetal/get_node.rb0000644000175600017570000000113312730051546024550 0ustar pravipravimodule Fog module Baremetal class OpenStack class Real def get_node(node_id) request( :expects => [200, 204], :method => 'GET', :path => "nodes/#{node_id}" ) end end # class Real class Mock def get_node(node_id) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = self.data[:nodes].first response end # def get_node end # class Mock end # class OpenStack end # module Baremetal end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/baremetal/patch_port.rb0000644000175600017570000000240212730051546025127 0ustar pravipravimodule Fog module Baremetal class OpenStack class Real # Patch a port # # parameter example: # [{:op=> 'replace', :path => "/driver_info/ipmi_address", :value => "192.0.2.1"}] # # === Patch parameter, list of jsonpatch === # op = Operations: 'add', 'replace' or 'remove' # path = Attributes to add/replace or remove (only PATH is necessary on remove), # e.g. /driver_info/ipmi_address # value = Value to set def patch_port(port_uuid, patch) request( :body => Fog::JSON.encode(patch), :expects => 200, :method => 'PATCH', :path => "ports/#{port_uuid}" ) end end class Mock def patch_port(port_uuid, patch) response = Excon::Response.new response.status = 200 response.headers = { "X-Compute-Request-Id" => "req-fdc6f99e-55a2-4ab1-8904-0892753828cf", "Content-Type" => "application/json", "Content-Length" => "356", "Date" => Date.new } response.body = self.data[:ports].first response end end # mock end # openstack end # baremetal end # fog fog-openstack-0.1.6/lib/fog/openstack/requests/baremetal/get_driver.rb0000644000175600017570000000116112730051546025117 0ustar pravipravimodule Fog module Baremetal class OpenStack class Real def get_driver(driver_name) request( :expects => [200, 204], :method => 'GET', :path => "drivers/#{driver_name}" ) end end # class Real class Mock def get_driver(driver_name) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = self.data[:drivers].first response end # def get_driver end # class Mock end # class OpenStack end # module Baremetal end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/baremetal/get_chassis.rb0000644000175600017570000000120212730051546025255 0ustar pravipravimodule Fog module Baremetal class OpenStack class Real def get_chassis(chassis_uuid) request( :expects => [200, 204], :method => 'GET', :path => "chassis/#{chassis_uuid}" ) end end # class Real class Mock def get_chassis(chassis_uuid) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = self.data[:chassis_collection].first response end # def get_chassis end # class Mock end # class OpenStack end # module Baremetal end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/baremetal/delete_node.rb0000644000175600017570000000104012730051546025230 0ustar pravipravimodule Fog module Baremetal class OpenStack class Real def delete_node(node_uuid) data = { :node_ident => node_uuid } request( :body => Fog::JSON.encode(data), :expects => [200, 204], :method => 'DELETE', :path => 'nodes' ) end end class Mock def delete_node(node_uuid) response = Excon::Response.new response.status = 200 response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/baremetal/list_ports.rb0000644000175600017570000000224712730051546025175 0ustar pravipravimodule Fog module Baremetal class OpenStack class Real def list_ports(options = {}) request( :expects => [200, 204], :method => 'GET', :path => 'ports', :query => options ) end end # class Real class Mock def list_ports(options = {}) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = { "ports" => [ { "address" => "fe:54:00:77:07:d9", "links" => [ { "href" => "http://localhost:6385/v1/ports/27e3153e-d5bf-4b7e-b517-fb518e17f34c", "rel" => "self" }, { "href" => "http://localhost:6385/ports/27e3153e-d5bf-4b7e-b517-fb518e17f34c", "rel" => "bookmark" } ], "uuid" => Fog::UUID.uuid } ] } response end # def list_ports end # class Mock end # class OpenStack end # module Baremetal end # module Fog fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/0000755000175600017570000000000012730051546022422 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/create_volume_type.rb0000644000175600017570000000015712730051546026645 0ustar pravipravirequire 'fog/openstack/requests/volume/create_volume_type' require 'fog/openstack/requests/volume_v1/real_mock'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/create_snapshot.rb0000644000175600017570000000244612730051546026137 0ustar pravipravirequire 'fog/openstack/requests/volume/create_snapshot' module Fog module Volume class OpenStack class V1 class Real include Fog::Volume::OpenStack::Real def create_snapshot(volume_id, name, description, force = false) data = { 'snapshot' => { 'volume_id' => volume_id, 'display_name' => name, 'display_description' => description, 'force' => force.nil? ? false : force } } _create_snapshot(data) end end class Mock def create_snapshot(volume_id, name, description, _force = false) response = Excon::Response.new response.status = 202 response.body = { "snapshot" => { "status" => "creating", "display_name" => name, "created_at" => Time.now, "display_description" => description, "volume_id" => volume_id, "id" => "5", "size" => 1 } } response end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/get_transfer_details.rb0000644000175600017570000000015412730051546027137 0ustar pravipravirequire 'fog/openstack/requests/volume/get_transfer_details' require 'fog/openstack/requests/volume_v1/real'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/list_transfers_detailed.rb0000644000175600017570000000015712730051546027647 0ustar pravipravirequire 'fog/openstack/requests/volume/list_transfers_detailed' require 'fog/openstack/requests/volume_v1/real'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/update_metadata.rb0000644000175600017570000000015012730051546026065 0ustar pravipravirequire 'fog/openstack/requests/volume/update_metadata' require 'fog/openstack/requests/volume_v1/real' fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/get_quota_defaults.rb0000644000175600017570000000015712730051546026631 0ustar pravipravirequire 'fog/openstack/requests/volume/get_quota_defaults' require 'fog/openstack/requests/volume_v1/real_mock'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/get_volume_type_details.rb0000644000175600017570000000016412730051546027664 0ustar pravipravirequire 'fog/openstack/requests/volume/get_volume_type_details' require 'fog/openstack/requests/volume_v1/real_mock'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/list_zones.rb0000644000175600017570000000014712730051546025142 0ustar pravipravirequire 'fog/openstack/requests/volume/list_zones' require 'fog/openstack/requests/volume_v1/real_mock'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/list_volumes.rb0000644000175600017570000000317512730051546025502 0ustar pravipravirequire 'fog/openstack/requests/volume/list_volumes' module Fog module Volume class OpenStack class V1 class Real include Fog::Volume::OpenStack::Real end class Mock def list_volumes(options = true, options_deprecated = {}) response = Excon::Response.new response.status = 200 self.data[:volumes] ||= [ {"status" => "available", "display_description" => "test 1 desc", "availability_zone" => "nova", "display_name" => "Volume1", "attachments" => [{}], "volume_type" => nil, "snapshot_id" => nil, "size" => 1, "id" => 1, "created_at" => Time.now, "metadata" => {}}, {"status" => "available", "display_description" => "test 2 desc", "availability_zone" => "nova", "display_name" => "Volume2", "attachments" => [{}], "volume_type" => nil, "snapshot_id" => nil, "size" => 1, "id" => 2, "created_at" => Time.now, "metadata" => {}} ] response.body = {'volumes' => self.data[:volumes]} response end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/create_transfer.rb0000644000175600017570000000014712730051546026120 0ustar pravipravirequire 'fog/openstack/requests/volume/create_transfer' require 'fog/openstack/requests/volume_v1/real'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/action.rb0000644000175600017570000000013712730051546024225 0ustar pravipravirequire 'fog/openstack/requests/volume/action' require 'fog/openstack/requests/volume_v1/real' fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/list_volumes_detailed.rb0000644000175600017570000000316412730051546027333 0ustar pravipravirequire 'fog/openstack/requests/volume/list_volumes_detailed' module Fog module Volume class OpenStack class V1 class Real include Fog::Volume::OpenStack::Real end class Mock def list_volumes_detailed(options = {}) response = Excon::Response.new response.status = 200 self.data[:volumes] ||= [ {"status" => "available", "display_description" => "test 1 desc", "availability_zone" => "nova", "display_name" => "Volume1", "attachments" => [{}], "volume_type" => nil, "snapshot_id" => nil, "size" => 1, "id" => 1, "created_at" => Time.now, "metadata" => {}}, {"status" => "available", "display_description" => "test 2 desc", "availability_zone" => "nova", "display_name" => "Volume2", "attachments" => [{}], "volume_type" => nil, "snapshot_id" => nil, "size" => 1, "id" => 2, "created_at" => Time.now, "metadata" => {}} ] response.body = {'volumes' => self.data[:volumes]} response end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/real_mock.rb0000644000175600017570000000036512730051546024707 0ustar pravipravimodule Fog module Volume class OpenStack class V1 class Real include Fog::Volume::OpenStack::Real end class Mock include Fog::Volume::OpenStack::Mock end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/delete_volume.rb0000644000175600017570000000015212730051546025576 0ustar pravipravirequire 'fog/openstack/requests/volume/delete_volume' require 'fog/openstack/requests/volume_v1/real_mock'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/list_snapshots.rb0000644000175600017570000000015312730051546026023 0ustar pravipravirequire 'fog/openstack/requests/volume/list_snapshots' require 'fog/openstack/requests/volume_v1/real_mock'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/update_snapshot.rb0000644000175600017570000000015012730051546026144 0ustar pravipravirequire 'fog/openstack/requests/volume/update_snapshot' require 'fog/openstack/requests/volume_v1/real' fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/update_volume.rb0000644000175600017570000000014612730051546025621 0ustar pravipravirequire 'fog/openstack/requests/volume/update_volume' require 'fog/openstack/requests/volume_v1/real' fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/get_quota_usage.rb0000644000175600017570000000015412730051546026123 0ustar pravipravirequire 'fog/openstack/requests/volume/get_quota_usage' require 'fog/openstack/requests/volume_v1/real_mock'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/set_tenant.rb0000644000175600017570000000014712730051546025115 0ustar pravipravirequire 'fog/openstack/requests/volume/set_tenant' require 'fog/openstack/requests/volume_v1/real_mock'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/delete_volume_type.rb0000644000175600017570000000015712730051546026644 0ustar pravipravirequire 'fog/openstack/requests/volume/delete_volume_type' require 'fog/openstack/requests/volume_v1/real_mock'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/delete_snapshot.rb0000644000175600017570000000015412730051546026130 0ustar pravipravirequire 'fog/openstack/requests/volume/delete_snapshot' require 'fog/openstack/requests/volume_v1/real_mock'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/update_snapshot_metadata.rb0000644000175600017570000000016112730051546030006 0ustar pravipravirequire 'fog/openstack/requests/volume/update_snapshot_metadata' require 'fog/openstack/requests/volume_v1/real' fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/extend_volume.rb0000644000175600017570000000015212730051546025623 0ustar pravipravirequire 'fog/openstack/requests/volume/extend_volume' require 'fog/openstack/requests/volume_v1/real_mock'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/list_snapshots_detailed.rb0000644000175600017570000000016412730051546027660 0ustar pravipravirequire 'fog/openstack/requests/volume/list_snapshots_detailed' require 'fog/openstack/requests/volume_v1/real_mock'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/real.rb0000644000175600017570000000024712730051546023675 0ustar pravipravimodule Fog module Volume class OpenStack class V1 class Real include Fog::Volume::OpenStack::Real end end end end endfog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/get_quota.rb0000644000175600017570000000014612730051546024740 0ustar pravipravirequire 'fog/openstack/requests/volume/get_quota' require 'fog/openstack/requests/volume_v1/real_mock'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/list_volume_types.rb0000644000175600017570000000015612730051546026537 0ustar pravipravirequire 'fog/openstack/requests/volume/list_volume_types' require 'fog/openstack/requests/volume_v1/real_mock'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/accept_transfer.rb0000644000175600017570000000014712730051546026114 0ustar pravipravirequire 'fog/openstack/requests/volume/accept_transfer' require 'fog/openstack/requests/volume_v1/real'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/replace_metadata.rb0000644000175600017570000000015112730051546026217 0ustar pravipravirequire 'fog/openstack/requests/volume/replace_metadata' require 'fog/openstack/requests/volume_v1/real' fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/delete_snapshot_metadata.rb0000644000175600017570000000016112730051546027766 0ustar pravipravirequire 'fog/openstack/requests/volume/delete_snapshot_metadata' require 'fog/openstack/requests/volume_v1/real' fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/get_volume_details.rb0000644000175600017570000000211412730051546026620 0ustar pravipravirequire 'fog/openstack/requests/volume/get_volume_details' module Fog module Volume class OpenStack class V1 class Real include Fog::Volume::OpenStack::Real end class Mock def get_volume_details(detailed=true) response = Excon::Response.new response.status = 200 response.body = { 'volume' => { 'id' => '1', 'display_name' => Fog::Mock.random_letters(rand(8) + 5), 'display_description' => Fog::Mock.random_letters(rand(12) + 10), 'size' => 3, 'volume_type' => nil, 'snapshot_id' => '4', 'status' => 'online', 'availability_zone' => 'nova', 'created_at' => Time.now, 'attachments' => [] } } response end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/delete_transfer.rb0000644000175600017570000000014712730051546026117 0ustar pravipravirequire 'fog/openstack/requests/volume/delete_transfer' require 'fog/openstack/requests/volume_v1/real'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/get_snapshot_details.rb0000644000175600017570000000161612730051546027156 0ustar pravipravirequire 'fog/openstack/requests/volume/get_snapshot_details' module Fog module Volume class OpenStack class V1 class Real include Fog::Volume::OpenStack::Real end class Mock def get_snapshot_details(detailed=true) response = Excon::Response.new response.status = 200 response.body = { 'snapshot' => { 'id' => '1', 'display_name' => 'Snapshot1', 'display_description' => 'Volume1 snapshot', 'size' => 1, 'volume_id' => '1', 'status' => 'available', 'created_at' => Time.now } } response end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/create_volume.rb0000644000175600017570000000311612730051546025602 0ustar pravipravirequire 'fog/openstack/requests/volume/create_volume' module Fog module Volume class OpenStack class V1 class Real def create_volume(name, description, size, options={}) data = { 'volume' => { 'display_name' => name, 'display_description' => description, 'size' => size } } _create_volume(data, options) end include Fog::Volume::OpenStack::Real end class Mock def create_volume(name, description, size, options={}) response = Excon::Response.new response.status = 202 response.body = { 'volume' => { 'id' => Fog::Mock.random_numbers(2), 'display_name' => name, 'display_description' => description, 'metadata' => options['metadata'] || {}, 'size' => size, 'status' => 'creating', 'snapshot_id' => options[:snapshot_id] || nil, 'image_id' => options[:imageRef] || nil, 'volume_type' => nil, 'availability_zone' => 'nova', 'created_at' => Time.now, 'attachments' => [] } } response end end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/update_quota.rb0000644000175600017570000000015112730051546025437 0ustar pravipravirequire 'fog/openstack/requests/volume/update_quota' require 'fog/openstack/requests/volume_v1/real_mock'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/list_transfers.rb0000644000175600017570000000014612730051546026012 0ustar pravipravirequire 'fog/openstack/requests/volume/list_transfers' require 'fog/openstack/requests/volume_v1/real'fog-openstack-0.1.6/lib/fog/openstack/requests/volume_v1/delete_metadata.rb0000644000175600017570000000015012730051546026045 0ustar pravipravirequire 'fog/openstack/requests/volume/delete_metadata' require 'fog/openstack/requests/volume_v1/real' fog-openstack-0.1.6/lib/fog/openstack/requests/storage/0000755000175600017570000000000012730051546022151 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/requests/storage/get_object_https_url.rb0000644000175600017570000000620212730051546026707 0ustar pravipravimodule Fog module Storage class OpenStack class Real # Get an expiring object https url from Cloud Files # # ==== Parameters # * container<~String> - Name of container containing object # * object<~String> - Name of object to get expiring url for # * expires<~Time> - An expiry time for this url # # ==== Returns # * response<~Excon::Response>: # * body<~String> - url for object def get_object_https_url(container, object, expires, options = {}) create_temp_url(container, object, expires, "GET", {:port => 443}.merge(options).merge(:scheme => "https")) end # creates a temporary url # # ==== Parameters # * container<~String> - Name of container containing object # * object<~String> - Name of object to get expiring url for # * expires<~Time> - An expiry time for this url # * method<~String> - The method to use for accessing the object (GET, PUT, HEAD) # * options<~Hash> - An optional options hash # * 'scheme'<~String> - The scheme to use (http, https) # * 'host'<~String> - The host to use # * 'port'<~Integer> - The port to use # # ==== Returns # * response<~Excon::Response>: # * body<~String> - url for object # # ==== See Also # http://docs.rackspace.com/files/api/v1/cf-devguide/content/Create_TempURL-d1a444.html def create_temp_url(container, object, expires, method, options = {}) raise ArgumentError, "Insufficient parameters specified." unless (container && object && expires && method) raise ArgumentError, "Storage must be instantiated with the :openstack_temp_url_key option" if @openstack_temp_url_key.nil? scheme = options[:scheme] || @scheme host = options[:host] || @host port = options[:port] || @port # POST not allowed allowed_methods = %w{GET PUT HEAD} unless allowed_methods.include?(method) raise ArgumentError.new("Invalid method '#{method}' specified. Valid methods are: #{allowed_methods.join(', ')}") end expires = expires.to_i object_path_escaped = "#{@path}/#{Fog::OpenStack.escape(container)}/#{Fog::OpenStack.escape(object,"/")}" object_path_unescaped = "#{@path}/#{Fog::OpenStack.escape(container)}/#{object}" string_to_sign = "#{method}\n#{expires}\n#{object_path_unescaped}" hmac = Fog::HMAC.new('sha1', @openstack_temp_url_key) sig = sig_to_hex(hmac.sign(string_to_sign)) temp_url_options = { :scheme => scheme, :host => host, :port => port, :path => object_path_escaped, :query => "temp_url_sig=#{sig}&temp_url_expires=#{expires}" } URI::Generic.build(temp_url_options).to_s end private def sig_to_hex(str) str.unpack("C*").map { |c| c.to_s(16) }.map { |h| h.size == 1 ? "0#{h}" : h }.join end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/storage/put_dynamic_obj_manifest.rb0000644000175600017570000000423012730051546027531 0ustar pravipravimodule Fog module Storage class OpenStack class Real # Create a new dynamic large object manifest # # Creates an object with a +X-Object-Manifest+ header that specifies the common prefix ("/") # for all uploaded segments. Retrieving the manifest object streams all segments matching this prefix. # Segments must sort in the order they should be concatenated. Note that any future objects stored in the container # along with the segments that match the prefix will be included when retrieving the manifest object. # # All segments must be stored in the same container, but may be in a different container than the manifest object. # The default +X-Object-Manifest+ header is set to "+container+/+object+", but may be overridden in +options+ # to specify the prefix and/or the container where segments were stored. # If overridden, names should be CGI escaped (excluding spaces) if needed (see {Fog::OpenStack.escape}). # # @param container [String] Name for container where +object+ will be stored. Should be < 256 bytes and must not contain '/' # @param object [String] Name for manifest object. # @param options [Hash] Config headers for +object+. # @option options [String] 'X-Object-Manifest' ("container/object") "/" for segment objects. # # @raise [Fog::Storage::OpenStack::NotFound] HTTP 404 # @raise [Excon::Errors::BadRequest] HTTP 400 # @raise [Excon::Errors::Unauthorized] HTTP 401 # @raise [Excon::Errors::HTTPStatusError] # # @see http://docs.openstack.org/api/openstack-object-storage/1.0/content/dynamic-large-object-creation.html def put_dynamic_obj_manifest(container, object, options = {}) path = "#{Fog::OpenStack.escape(container)}/#{Fog::OpenStack.escape(object)}" headers = {'X-Object-Manifest' => path}.merge(options) request( :expects => 201, :headers => headers, :method => 'PUT', :path => path ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/storage/post_set_meta_temp_url_key.rb0000644000175600017570000000210612730051546030122 0ustar pravipravimodule Fog module Storage class OpenStack class Real # Set the account wide Temp URL Key. This is a secret key that's # used to generate signed expiring URLs. # # Once the key has been set with this request you should create new # Storage objects with the :openstack_temp_url_key option then use # the get_object_https_url method to generate expiring URLs. # # *** CAUTION *** changing this secret key will invalidate any expiring # URLS generated with old keys. # # ==== Parameters # * key<~String> - The new Temp URL Key # # ==== Returns # * response<~Excon::Response> # # ==== See Also # http://docs.rackspace.com/files/api/v1/cf-devguide/content/Set_Account_Metadata-d1a4460.html def post_set_meta_temp_url_key(key) request( :expects => [201, 202, 204], :method => 'POST', :headers => {'X-Account-Meta-Temp-Url-Key' => key} ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/storage/get_containers.rb0000644000175600017570000000175012730051546025505 0ustar pravipravimodule Fog module Storage class OpenStack class Real # List existing storage containers # # ==== Parameters # * options<~Hash>: # * 'limit'<~Integer> - Upper limit to number of results returned # * 'marker'<~String> - Only return objects with name greater than this value # # ==== Returns # * response<~Excon::Response>: # * body<~Array>: # * container<~Hash>: # * 'bytes'<~Integer>: - Number of bytes used by container # * 'count'<~Integer>: - Number of items in container # * 'name'<~String>: - Name of container def get_containers(options = {}) options = options.reject {|key, value| value.nil?} request( :expects => [200, 204], :method => 'GET', :path => '', :query => {'format' => 'json'}.merge!(options) ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/storage/head_container.rb0000644000175600017570000000135412730051546025444 0ustar pravipravimodule Fog module Storage class OpenStack class Real # List number of objects and total bytes stored # # ==== Parameters # * container<~String> - Name of container to retrieve info for # # ==== Returns # * response<~Excon::Response>: # * headers<~Hash>: # * 'X-Container-Object-Count'<~String> - Count of containers # * 'X-Container-Bytes-Used'<~String> - Bytes used def head_container(container) request( :expects => 204, :method => 'HEAD', :path => Fog::OpenStack.escape(container), :query => {'format' => 'json'} ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/storage/delete_static_large_object.rb0000644000175600017570000000362412730051546030014 0ustar pravipravimodule Fog module Storage class OpenStack class Real # Delete a static large object. # # Deletes the SLO manifest +object+ and all segments that it references. # The server will respond with +200 OK+ for all requests. # +response.body+ must be inspected for actual results. # # @param container [String] Name of container. # @param object [String] Name of the SLO manifest object. # @param options [Hash] Additional request headers. # # @return [Excon::Response] # * body [Hash] - Results of the operation. # * "Number Not Found" [Integer] - Number of missing segments. # * "Response Status" [String] - Response code for the subrequest of the last failed operation. # * "Errors" [Array] # * object_name [String] - Object that generated an error when the delete was attempted. # * response_status [String] - Response status from the subrequest for object_name. # * "Number Deleted" [Integer] - Number of segments deleted. # * "Response Body" [String] - Response body for Response Status. # # @see http://docs.openstack.org/api/openstack-object-storage/1.0/content/static-large-objects.html def delete_static_large_object(container, object, options = {}) response = request({ :expects => 200, :method => 'DELETE', :headers => options.merge('Content-Type' => 'text/plain', 'Accept' => 'application/json'), :path => "#{Fog::OpenStack.escape(container)}/#{Fog::OpenStack.escape(object)}", :query => { 'multipart-manifest' => 'delete' } }, false) response.body = Fog::JSON.decode(response.body) response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/storage/put_container.rb0000644000175600017570000000127512730051546025355 0ustar pravipravimodule Fog module Storage class OpenStack class Real # Create a new container # # ==== Parameters # * name<~String> - Name for container, should be < 256 bytes and must not contain '/' # def put_container(name, options={}) headers = options[:headers] || {} headers['X-Container-Read'] = '.r:*' if options[:public] headers['X-Remove-Container-Read'] = 'x' if options[:public] == false request( :expects => [201, 202], :method => 'PUT', :path => Fog::OpenStack.escape(name), :headers => headers ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/storage/copy_object.rb0000644000175600017570000000170712730051546025003 0ustar pravipravimodule Fog module Storage class OpenStack class Real # Copy object # # ==== Parameters # * source_container_name<~String> - Name of source bucket # * source_object_name<~String> - Name of source object # * target_container_name<~String> - Name of bucket to create copy in # * target_object_name<~String> - Name for new copy of object # * options<~Hash> - Additional headers def copy_object(source_container_name, source_object_name, target_container_name, target_object_name, options={}) headers = { 'X-Copy-From' => "/#{source_container_name}/#{source_object_name}" }.merge(options) request({ :expects => 201, :headers => headers, :method => 'PUT', :path => "#{Fog::OpenStack.escape(target_container_name)}/#{Fog::OpenStack.escape(target_object_name)}" }) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/storage/delete_object.rb0000644000175600017570000000103412730051546025264 0ustar pravipravimodule Fog module Storage class OpenStack class Real # Delete an existing object # # ==== Parameters # * container<~String> - Name of container to delete # * object<~String> - Name of object to delete # def delete_object(container, object) request( :expects => 204, :method => 'DELETE', :path => "#{Fog::OpenStack.escape(container)}/#{Fog::OpenStack.escape(object)}" ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/storage/put_static_obj_manifest.rb0000644000175600017570000000534312730051546027402 0ustar pravipravimodule Fog module Storage class OpenStack class Real # Create a new static large object manifest. # # A static large object is similar to a dynamic large object. Whereas a GET for a dynamic large object manifest # will stream segments based on the manifest's +X-Object-Manifest+ object name prefix, a static large object # manifest streams segments which are defined by the user within the manifest. Information about each segment is # provided in +segments+ as an Array of Hash objects, ordered in the sequence which the segments should be streamed. # # When the SLO manifest is received, each segment's +etag+ and +size_bytes+ will be verified. # The +etag+ for each segment is returned in the response to {#put_object}, but may also be calculated. # e.g. +Digest::MD5.hexdigest(segment_data)+ # # The maximum number of segments for a static large object is 1000, and all segments (except the last) must be # at least 1 MiB in size. Unlike a dynamic large object, segments are not required to be in the same container. # # @example # segments = [ # { :path => 'segments_container/first_segment', # :etag => 'md5 for first_segment', # :size_bytes => 'byte size of first_segment' }, # { :path => 'segments_container/second_segment', # :etag => 'md5 for second_segment', # :size_bytes => 'byte size of second_segment' } # ] # put_static_obj_manifest('my_container', 'my_large_object', segments) # # @param container [String] Name for container where +object+ will be stored. # Should be < 256 bytes and must not contain '/' # @param object [String] Name for manifest object. # @param segments [Array] Segment data for the object. # @param options [Hash] Config headers for +object+. # # @raise [Fog::Storage::OpenStack::NotFound] HTTP 404 # @raise [Excon::Errors::BadRequest] HTTP 400 # @raise [Excon::Errors::Unauthorized] HTTP 401 # @raise [Excon::Errors::HTTPStatusError] # # @see http://docs.openstack.org/api/openstack-object-storage/1.0/content/static-large-objects.html def put_static_obj_manifest(container, object, segments, options = {}) request( :expects => 201, :method => 'PUT', :headers => options, :body => Fog::JSON.encode(segments), :path => "#{Fog::OpenStack.escape(container)}/#{Fog::OpenStack.escape(object)}", :query => { 'multipart-manifest' => 'put' } ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/storage/delete_container.rb0000644000175600017570000000065612730051546026011 0ustar pravipravimodule Fog module Storage class OpenStack class Real # Delete an existing container # # ==== Parameters # * name<~String> - Name of container to delete # def delete_container(name) request( :expects => 204, :method => 'DELETE', :path => Fog::OpenStack.escape(name) ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/storage/delete_multiple_objects.rb0000644000175600017570000000612412730051546027367 0ustar pravipravimodule Fog module Storage class OpenStack class Real # Deletes multiple objects or containers with a single request. # # To delete objects from a single container, +container+ may be provided # and +object_names+ should be an Array of object names within the container. # # To delete objects from multiple containers or delete containers, # +container+ should be +nil+ and all +object_names+ should be prefixed with a container name. # # Containers must be empty when deleted. +object_names+ are processed in the order given, # so objects within a container should be listed first to empty the container. # # Up to 10,000 objects may be deleted in a single request. # The server will respond with +200 OK+ for all requests. # +response.body+ must be inspected for actual results. # # @example Delete objects from a container # object_names = ['object', 'another/object'] # conn.delete_multiple_objects('my_container', object_names) # # @example Delete objects from multiple containers # object_names = ['container_a/object', 'container_b/object'] # conn.delete_multiple_objects(nil, object_names) # # @example Delete a container and all it's objects # object_names = ['my_container/object_a', 'my_container/object_b', 'my_container'] # conn.delete_multiple_objects(nil, object_names) # # @param container [String,nil] Name of container. # @param object_names [Array] Object names to be deleted. # @param options [Hash] Additional request headers. # # @return [Excon::Response] # * body [Hash] - Results of the operation. # * "Number Not Found" [Integer] - Number of missing objects or containers. # * "Response Status" [String] - Response code for the subrequest of the last failed operation. # * "Errors" [Array] # * object_name [String] - Object that generated an error when the delete was attempted. # * response_status [String] - Response status from the subrequest for object_name. # * "Number Deleted" [Integer] - Number of objects or containers deleted. # * "Response Body" [String] - Response body for "Response Status". def delete_multiple_objects(container, object_names, options = {}) body = object_names.map do |name| object_name = container ? "#{ container }/#{ name }" : name URI.encode(object_name) end.join("\n") response = request({ :expects => 200, :method => 'DELETE', :headers => options.merge('Content-Type' => 'text/plain', 'Accept' => 'application/json'), :body => body, :query => { 'bulk-delete' => true } }, false) response.body = Fog::JSON.decode(response.body) response end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/storage/get_container.rb0000644000175600017570000000326412730051546025324 0ustar pravipravimodule Fog module Storage class OpenStack class Real # Get details for container and total bytes stored # # ==== Parameters # * container<~String> - Name of container to retrieve info for # * options<~String>: # * 'limit'<~String> - Maximum number of objects to return # * 'marker'<~String> - Only return objects whose name is greater than marker # * 'prefix'<~String> - Limits results to those starting with prefix # * 'path'<~String> - Return objects nested in the pseudo path # # ==== Returns # * response<~Excon::Response>: # * headers<~Hash>: # * 'X-Account-Container-Count'<~String> - Count of containers # * 'X-Account-Bytes-Used'<~String> - Bytes used # * body<~Array>: # * 'bytes'<~Integer> - Number of bytes used by container # * 'count'<~Integer> - Number of items in container # * 'name'<~String> - Name of container # * item<~Hash>: # * 'bytes'<~String> - Size of object # * 'content_type'<~String> Content-Type of object # * 'hash'<~String> - Hash of object (etag?) # * 'last_modified'<~String> - Last modified timestamp # * 'name'<~String> - Name of object def get_container(container, options = {}) options = options.reject {|key, value| value.nil?} request( :expects => 200, :method => 'GET', :path => Fog::OpenStack.escape(container), :query => {'format' => 'json'}.merge!(options) ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/storage/public_url.rb0000644000175600017570000000117612730051546024643 0ustar pravipravimodule Fog module Storage class OpenStack class Real # Get public_url for an object # # ==== Parameters # * container<~String> - Name of container to look in # * object<~String> - Name of object to look for # def public_url(container=nil, object=nil) return nil if container.nil? u = "#{url}/#{Fog::OpenStack.escape(container)}" u << "/#{Fog::OpenStack.escape(object)}" unless object.nil? u end private def url "#{@scheme}://#{@host}:#{@port}#{@path}" end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/storage/head_object.rb0000644000175600017570000000104112730051546024721 0ustar pravipravimodule Fog module Storage class OpenStack class Real # Get headers for object # # ==== Parameters # * container<~String> - Name of container to look in # * object<~String> - Name of object to look for # def head_object(container, object) request({ :expects => 200, :method => 'HEAD', :path => "#{Fog::OpenStack.escape(container)}/#{Fog::OpenStack.escape(object)}" }, false) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/storage/put_object_manifest.rb0000644000175600017570000000057712730051546026533 0ustar pravipravimodule Fog module Storage class OpenStack class Real # Create a new dynamic large object manifest # # This is an alias for {#put_dynamic_obj_manifest} for backward compatibility. def put_object_manifest(container, object, options = {}) put_dynamic_obj_manifest(container, object, options) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/storage/put_object.rb0000644000175600017570000000250712730051546024640 0ustar pravipravimodule Fog module Storage class OpenStack class Real # Create a new object # # When passed a block, it will make a chunked request, calling # the block for chunks until it returns an empty string. # In this case the data parameter is ignored. # # ==== Parameters # * container<~String> - Name for container, should be < 256 bytes and must not contain '/' # * object<~String> - Name for object # * data<~String|File> - data to upload # * options<~Hash> - config headers for object. Defaults to {}. # * block<~Proc> - chunker # def put_object(container, object, data, options = {}, &block) if block_given? params = { :request_block => block } headers = options else data = Fog::Storage.parse_data(data) headers = data[:headers].merge!(options) params = { :body => data[:body] } end params.merge!( :expects => 201, :idempotent => !params[:request_block], :headers => headers, :method => 'PUT', :path => "#{Fog::OpenStack.escape(container)}/#{Fog::OpenStack.escape(object)}" ) request(params) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/storage/head_containers.rb0000644000175600017570000000113512730051546025624 0ustar pravipravimodule Fog module Storage class OpenStack class Real # List number of containers and total bytes stored # # ==== Returns # * response<~Excon::Response>: # * headers<~Hash>: # * 'X-Account-Container-Count'<~String> - Count of containers # * 'X-Account-Bytes-Used'<~String> - Bytes used def head_containers request( :expects => 200..299, :method => 'HEAD', :path => '', :query => {'format' => 'json'} ) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/storage/get_object.rb0000644000175600017570000000122712730051546024605 0ustar pravipravimodule Fog module Storage class OpenStack class Real # Get details for object # # ==== Parameters # * container<~String> - Name of container to look in # * object<~String> - Name of object to look for # def get_object(container, object, &block) params = { :expects => 200, :method => 'GET', :path => "#{Fog::OpenStack.escape(container)}/#{Fog::OpenStack.escape(object)}" } if block_given? params[:response_block] = block end request(params, false) end end end end end fog-openstack-0.1.6/lib/fog/openstack/requests/storage/get_object_http_url.rb0000644000175600017570000000125612730051546026530 0ustar pravipravimodule Fog module Storage class OpenStack class Real # Get an expiring object http url # # ==== Parameters # * container<~String> - Name of container containing object # * object<~String> - Name of object to get expiring url for # * expires<~Time> - An expiry time for this url # # ==== Returns # * response<~Excon::Response>: # * body<~String> - url for object def get_object_http_url(container, object, expires, options = {}) create_temp_url(container, object, expires, "GET", {:port => 80}.merge(options).merge(:scheme => "http")) end end end end end fog-openstack-0.1.6/lib/fog/openstack/common.rb0000644000175600017570000000254312730051546020453 0ustar pravipravimodule Fog module OpenStack module Common attr_reader :unscoped_token include Fog::OpenStack::Core def request(params) retried = false begin std_headers = { 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'X-Auth-Token' => @auth_token } param_headers = params.fetch(:headers, {}) response = @connection.request(params.merge({ :headers => std_headers.merge(param_headers), :path => "#{@path}/#{params[:path]}" })) rescue Excon::Errors::Unauthorized => error raise if retried retried = true @openstack_must_reauthenticate = true authenticate retry rescue Excon::Errors::HTTPStatusError => error raise case error when Excon::Errors::NotFound self.class.not_found_class.slurp(error) else error end end unless response.body.empty? response.body = Fog::JSON.decode(response.body) unless params[:raw_body] end response end end end end fog-openstack-0.1.6/lib/fog/openstack/examples/0000755000175600017570000000000012730051546020450 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/examples/compute/0000755000175600017570000000000012730051546022124 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/examples/compute/basics.rb0000644000175600017570000000316112730051546023716 0ustar pravipravi# OpenStack Compute (Nova) Example require 'fog/openstack' auth_url = "https://example.net/v2.0/tokens" username = 'admin@example.net' password = 'secret' tenant = 'My Compute Tenant' # String compute_client ||= ::Fog::Compute.new(:provider => :openstack, :openstack_api_key => password , :openstack_username => username , :openstack_auth_url => auth_url , :openstack_tenant => tenant) # Create VM # Options include metadata, availability zone, etc... begin vm = compute_client.servers.create(:name => 'lucky', :image_ref => 'fcd8f8a9', :flavor_ref => 4) rescue => e puts JSON.parse(e.response.body)['badRequest']['message'] end # Destroy VM vm = compute_client.servers.get(vm.id) # Retrieve previously created vm by UUID floating_ips = vm.all_addresses # fetch and release its floating IPs floating_ips.each do |address| compute_client.disassociate_address(uuid, address['ip']) compute_client.release_address(address['id']) end vm.destroy # Images available at tenant image_names = compute_client.images.map { |image| image['name'] } # Floating IP address pools available at tenant compute_client.addresses.get_address_pools # response.body #=> { 'name' => 'pool1' }, { 'name' => 'pool2' } # VNC console vm.console.body # returns VNC url # "console" => { # "url" => "http://vmvncserver:6080/vnc_auto.html?token=231", # "type" => "novnc" # } fog-openstack-0.1.6/lib/fog/openstack/examples/compute/block_device_mapping_v2.rb0000644000175600017570000000144712730051546027212 0ustar pravipravi# OpenStack Compute (Nova) Example require 'fog/openstack' auth_url = "https://example.net/v2.0/tokens" username = 'admin@example.net' password = 'secret' tenant = 'My Compute Tenant' # String compute_client ||= ::Fog::Compute::OpenStack.new( :openstack_api_key => password, :openstack_username => username, :openstack_auth_url => auth_url, :openstack_tenant => tenant ) _vm = compute_client.servers.create( :name => name, :flavor_ref => flavor, :block_device_mapping_v2 => [ { :boot_index => 0, :device_name => "vda", :source_type => "volume", # Or "snapshot" :destination_type => "volume", :delete_on_termination => false, :uuid => cinder_uddi, } ] ) fog-openstack-0.1.6/lib/fog/openstack/examples/identity/0000755000175600017570000000000012730051546022301 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/examples/identity/basics.rb0000644000175600017570000000333612730051546024077 0ustar pravipravi# OpenStack Identity Service (Keystone) Example require 'fog/openstack' require 'pp' auth_url = "https://example.net/v2.0/tokens" username = 'admin@example.net' password = 'secret' keystone = Fog::Identity::OpenStack.new :openstack_auth_url => auth_url, :openstack_username => username, :openstack_api_key => password # Optional, self-signed certs #:connection_options => { :ssl_verify_peer => false } # # Listing keystone tenants # keystone.tenants.each do |tenant| # pp tenant end # # List users # keystone.users.each do |user| # # ... pp user end # # Create a new tenant # tenant = keystone.tenants.create :name => 'rubiojr@example.net', :description => 'My foo tenant' # # Create a new user # user = keystone.users.create :name => 'rubiojr@example.net', :tenant_id => tenant.id, :password => 'rubiojr@example.net', :email => 'rubiojr@example.net' # Find the recently created tenant tenant = keystone.tenants.find { |t| t.name == 'rubiojr@example.net' } # Destroy the tenant tenant.destroy # Find the recently created user user = keystone.users.find { |u| u.name == 'rubiojr@example.net' } # Destroy the user user.destroy fog-openstack-0.1.6/lib/fog/openstack/examples/planning/0000755000175600017570000000000012730051546022256 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/examples/planning/basics.rb0000644000175600017570000000157712730051546024061 0ustar pravipravi# OpenStack Planning Service (Tuskar) Example require 'fog/openstack' require 'pp' auth_url = "https://example.net/v2.0/tokens" username = 'admin@example.net' password = 'secret' tenant = 'My Compute Tenant' # String planning ||= ::Fog::Openstack.new( :service => :planning, :openstack_api_key => password, :openstack_username => username, :openstack_auth_url => auth_url, :openstack_tenant => tenant ) pp planning # # Listing of Tuskar roles # roles = planning.roles.each do |role| pp role end # # Listing of Tuskar plans # plans = planning.plans.each do |plan| pp plan end # # Creating new Tuskar plan # plan = planning.plans.new({ :name => 'New Plan Name', :description => 'New Plan Description' }) pp plan # # Assign role to plan # role_uuid = roles.first.uuid plan.add_role(role_uuid) # # Output Heat templates for plan # pp plan.templates fog-openstack-0.1.6/lib/fog/openstack/examples/introspection/0000755000175600017570000000000012730051546023350 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/examples/introspection/basics.rb0000644000175600017570000000325512730051546025146 0ustar pravipravi require 'rubygems' require 'fog/openstack' # version >= 1.37 auth_url = "https://example.net:5000/v3/auth/tokens" username = 'admin@example.net' password = 'secret' project = 'admin' @connection_params = { :openstack_auth_url => auth_url, :openstack_username => username, :openstack_api_key => password, :openstack_project_name => project, :openstack_domain_id => "default" } inspector = Fog::Introspection::OpenStack.new(@connection_params) # Introspection of an Ironic node ironic = Fog::Baremetal::OpenStack.new(@connection_params) nodes = ironic.list_nodes node1_uuid = nodes.body["nodes"][0]["uuid"] # Launch introspection inspector.create_introspection(node1_uuid) # Introspection status inspector.get_introspection(node1_uuid) # Abort introspection inspector.abort_introspection(node1_uuid) # Retrieve introspection data # Note: introspection must be finished and ended successfully inspector.get_introspection_details(node1_uuid) ## Introspection Rules # Create a set of rules rules = { "description" => "Successful Rule", "actions" => [ { "action" => "set-attribute", "path" => "/extra/rule_success", "value" => "yes" } ], "conditions" => [ { "field" => "memory_mb", "op" => "ge", "value" => 256 }, { "field" => "local_gb", "op" => "ge", "value" => 1 } ] } inspector.create_rules(rules) # List all rules set rules1 = inspector.list_rules # Show a rules set rules1_uuid = rules1[:body]["rules"][0]['uuid'] inspector.get_rules(rules1_uuid) # Delete a specific rules set inspector.delete_rules(rules1_uuid) # Destroys all rules sets inspector.delete_rules_all fog-openstack-0.1.6/lib/fog/openstack/examples/network/0000755000175600017570000000000012730051546022141 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/examples/network/network_add_port.rb0000644000175600017570000000200012730051546026023 0ustar pravipravirequire 'fog/openstack' # Add additional port to an Openstack node def create_virtual_address_pairing(username, password, auth_url, tenant, device_id, device_ip_address, network_id) network_driver = Fog::Network.new(:provider => :openstack, :openstack_api_key => password, :openstack_username => username, :openstack_auth_url => auth_url, :openstack_tenant => tenant) virtual_ip_address = network_driver.create_port(network_id) server_nics = network_driver.list_ports('device_id' => device_id).data[:body]['ports'] port = (server_nics.select do |network_port| network_port['mac_address'] == server.attributes['macaddress'] end).first network_driver.update_port(port['id'], :allowed_address_pairs => [{:ip_address => device_ip_address}, {:ip_address => virtual_ip_address}]) end fog-openstack-0.1.6/lib/fog/openstack/examples/network/network_subnets_routers.rb0000644000175600017570000000435512730051546027514 0ustar pravipravirequire 'fog/openstack' # # Quantum demo # # Create some routers, networks and subnets for # a couple of tenants. # # Needs Fog >= 1.11.0 # Needs OpenStack credentials in ~/.fog # def create_tenant_network( tenant_name, external_net, router_name = 'router1', subnet_range = '10.0.0.0/21', subnet_gateway = '10.0.0.1', private_network_name = 'private' ) network = Fog::Network[:openstack] id = Fog::Identity[:openstack] tenant = id.tenants.find { |t| t.name == tenant_name } # Create a router for the tenant router = network.routers.create :name => router_name, :tenant_id => tenant.id, :external_gateway_info => { 'network_id' => external_net.id } # Create a private network for the tenant net = network.networks.create :name => private_network_name, :tenant_id => tenant.id # Create a subnet for the previous network and associate it # with the tenant subnet = network.subnets.create :name => 'net_10', :network_id => net.id, :ip_version => 4, :gateway_ip => subnet_gateway, :cidr => subnet_range, :tenant_id => tenant.id, :enable_dhcp => true network.add_router_interface router.id, subnet.id end # Create a public shared network public_net = network.networks.create :name => 'nova', :router_external => true # Create the public subnet public_subnet = network.subnets.create :name => 'floating_ips_net', :network_id => public_net.id, :ip_version => 4, :cidr => '1.2.3.0/24', :enable_dhcp => false # Create tenant networks create_tenant_network 'admin@example.net', public_net create_tenant_network 'demo@example.net', public_net fog-openstack-0.1.6/lib/fog/openstack/examples/network/network_rbac.rb0000644000175600017570000000377312730051546025160 0ustar pravipravirequire 'fog/openstack' require 'pp' # # Creates a private network and shares it with another project via RBAC policy # # Needs to be in an environment where keystone v3 is available # # You will need to source OpenStack credentials since the script # reads the following envionment variables: # # OS_AUTH_URL # OS_PASSWORD # OS_USERNAME # OS_USER_DOMAIN_NAME # OS_PROJECT_NAME # OS_REGION_NAME # # optionally disable SSL verification # SSL_VERIFY=false auth_options = { :openstack_auth_url => "#{ENV['OS_AUTH_URL']}/auth/tokens", :openstack_api_key => ENV['OS_PASSWORD'], :openstack_username => ENV['OS_USERNAME'], :openstack_domain_name => ENV['OS_USER_DOMAIN_NAME'], :openstack_project_name => ENV['OS_PROJECT_NAME'], :openstack_region => ENV['OS_REGION_NAME'], :connection_options => {:ssl_verify_peer => ENV['SSL_VERIFY'] != 'false'} } identity_service = Fog::Identity::OpenStack::V3.new(auth_options) network_service = Fog::Network::OpenStack.new(auth_options) own_project = identity_service.projects.select { |p| p.name == ENV['OS_PROJECT_NAME'] }.first other_project = identity_service.projects.select { |p| p.name != ENV['OS_PROJECT_NAME'] }.first puts "Create network in #{own_project.name}" foonet = network_service.networks.create(:name => 'foo-net23', :tenant_id => own_project.id) puts "Share network with #{other_project.name}" rbac = network_service.rbac_policies.create( :object_type => 'network', :object_id => foonet.id, :tenant_id => own_project.id, :target_tenant => other_project.id, :action => 'access_as_shared' ) puts "Get RBAC policy" rbac = network_service.rbac_policies.find_by_id(rbac.id) pp rbac puts "Change share to own project" rbac.target_tenant = own_project.id rbac.save puts "Get network and see that it is now shared" foonet = network_service.networks.get(foonet.id) pp foonet puts "Remove the share via RBAC" rbac.destroy puts "Get network and see that it is no longer shared" foonet.reload pp foonet foonet.destroy fog-openstack-0.1.6/lib/fog/openstack/examples/storage/0000755000175600017570000000000012730051546022114 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/examples/storage/set-account-quota.rb0000644000175600017570000000422012730051546026013 0ustar pravipravirequire 'fog/openstack' require 'pp' # # This example sets the account quota (in bytes) for the tenant demo@test.lan # using an admin account (admin has the reseller user role). # # Uses the account impersonation feature recently added to the # OpenStack Storage service in Fog (See https://github.com/fog/fog/pull/1632). # # Should be available in Fog 1.10.0+1. # # Setting account quotas is only supported in Swift 1.8.0+ # using the brand new account_quota middleware introduced in # OpenStack Grizzly (currently unreleased as of 2013/04/03). # # https://github.com/openstack/swift/blob/master/swift/common/middleware/account_quotas.py # auth_url = 'https://identity.test.lan/v2.0/tokens' user = 'admin@test.lan' password = 'secret' Excon.defaults[:ssl_verify_peer] = false # # We are going to use the Identity (Keystone) service # to retrieve the list of tenants available and find # the tenant we want to set the quotas for. # id = Fog::Identity::OpenStack.new :openstack_auth_url => auth_url, :openstack_username => user, :openstack_api_key => password # # Storage service (Swift) # st = Fog::Storage::OpenStack.new :openstack_auth_url => auth_url, :openstack_username => user, :openstack_api_key => password id.tenants.each do |t| # We want to set the account quota for tenant demo@test.lan next unless t.name == 'demo@test.lan' # We've found the tenant, impersonate the account # (the account prefix AUTH_ may be different for you, double check it). puts "Changing account to #{t.name}" st.change_account "AUTH_#{t.id}" # Now we're adding the required header to the demo@test.lan # tenant account, limiting the account bytes to 1048576 (1MB) # # Uploading more than 1MB will return 413: Request Entity Too Large st.request :method => 'POST', :headers => { 'X-Account-Meta-Quota-Bytes' => '1048576' } # We can list the account details to verify the new # header has been added pp st.request :method => 'HEAD' end # Restore the account we were using initially (admin@test.lan) st.reset_account_name fog-openstack-0.1.6/lib/fog/openstack/examples/image/0000755000175600017570000000000012730051546021532 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/examples/image/upload-test-image.rb0000755000175600017570000000546412730051546025414 0ustar pravipravirequire 'securerandom' require 'rubygems/package' require 'zlib' require 'fog/openstack' # # Download CirrOS 0.3.0 image from launchpad (~6.5MB) to /tmp # and upload it to Glance (the OpenStack Image Service). # # You will need to source OpenStack credentials since the script # reads the following envionment variables: # # OS_PASSWORD # OS_USERNAME # OS_AUTH_URL # OS_TENANT_NAME # # Should work with Fog >= 1.9, ruby 1.8.7 and 2.0 # image_url = "https://launchpadlibrarian.net/83305869/cirros-0.3.0-x86_64-uec.tar.gz" image_out = File.open("/tmp/cirros-image-#{SecureRandom.hex}", 'wb') extract_path = "/tmp/cirros-#{SecureRandom.hex}-dir" ami = "#{extract_path}/cirros-0.3.0-x86_64-blank.img" aki = "#{extract_path}/cirros-0.3.0-x86_64-vmlinuz" ari = "#{extract_path}/cirros-0.3.0-x86_64-initrd" FileUtils.mkdir_p extract_path # Efficient image write puts "Downloading Cirros image..." streamer = lambda do |chunk, remaining_bytes, total_bytes| image_out.write chunk end Excon.get image_url, :response_block => streamer image_out.close puts "Image downloaded to #{image_out.path}" puts "Extracting image contents to #{extract_path}..." Gem::Package::TarReader.new(Zlib::GzipReader.open(image_out.path)).each do |entry| FileUtils.mkdir_p "#{extract_path}/#{File.dirname(entry.full_name)}" File.open "#{extract_path}/#{entry.full_name}", 'w' do |f| f.write entry.read end end image_service = Fog::Image::OpenStack.new :openstack_api_key => ENV['OS_PASSWORD'], :openstack_username => ENV["OS_USERNAME"], :openstack_auth_url => ENV["OS_AUTH_URL"] + "/tokens", :openstack_tenant => ENV["OS_TENANT_NAME"] puts "Uploading AKI..." aki = image_service.images.create :name => 'cirros-0.3.0-amd64-aki', :size => File.size(aki), :disk_format => 'aki', :container_format => 'aki', :location => aki puts "Uploading ARI..." ari = image_service.images.create :name => 'cirros-0.3.0-amd64-ari', :size => File.size(ari), :disk_format => 'ari', :container_format => 'ari', :location => ari puts "Uploading AMI..." image_service.images.create :name => 'cirros-0.3.0-amd64', :size => File.size(ami), :disk_format => 'ami', :container_format => 'ami', :location => ami, :properties => { 'kernel_id' => aki.id, 'ramdisk_id' => ari.id } fog-openstack-0.1.6/lib/fog/openstack/models/0000755000175600017570000000000012730051546020115 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/models/volume/0000755000175600017570000000000012730051546021424 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/models/volume/volumes.rb0000644000175600017570000000230112730051546023437 0ustar pravipravirequire 'fog/openstack/models/collection' module Fog module Volume class OpenStack module Volumes def all(options = {}) # the parameter has been "detailed = true" before. Make sure we are # backwards compatible detailed = options.is_a?(Hash) ? options.delete(:detailed) : options if detailed.nil? || detailed # This method gives details by default, unless false or {:detailed => false} is passed load_response(service.list_volumes_detailed(options), 'volumes') else Fog::Logger.deprecation('Calling OpenStack[:volume].volumes.all(false) or volumes.all(:detailed => false) '\ ' is deprecated, call .volumes.summary instead') load_response(service.list_volumes(options), 'volumes') end end def summary(options = {}) load_response(service.list_volumes(options), 'volumes') end def get(volume_id) if volume = service.get_volume_details(volume_id).body['volume'] new(volume) end rescue Fog::Volume::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/volume/snapshot.rb0000644000175600017570000000162712730051546023616 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Volume class OpenStack class Snapshot < Fog::OpenStack::Model def update(data) requires :id response = service.update_snapshot(id, data) merge_attributes(response.body['snapshot']) self end def destroy requires :id service.delete_snapshot(id) true end # Existing keys have values updated and new key-value pairs are created, but none are deleted def update_metadata(metadata) requires :id service.update_snapshot_metadata(id, metadata) true end # Delete one specific key-value pair by specifying the key name def delete_metadata(key_name) requires :id service.delete_snapshot_metadata(id, key_name) true end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/volume/availability_zone.rb0000644000175600017570000000024512730051546025457 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Volume class OpenStack class AvailabilityZone < Fog::OpenStack::Model end end end endfog-openstack-0.1.6/lib/fog/openstack/models/volume/volume.rb0000644000175600017570000000341212730051546023260 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Volume class OpenStack class Volume < Fog::OpenStack::Model attribute :metadata attribute :status attribute :size attribute :volume_type, :aliases => %w(volumeType type) attribute :snapshot_id, :aliases => 'snapshotId' attribute :imageRef, :aliases => 'image_id' attribute :availability_zone, :aliases => 'availabilityZone' attribute :created_at, :aliases => 'createdAt' attribute :attachments attribute :source_volid def destroy requires :id service.delete_volume(id) true end def extend(size) requires :id service.extend_volume(id, size) true end def ready? status == 'available' end def reset_status(status) requires :id service.action(id, 'os-reset_status' => {:status => status}) end def create_metadata(metadata) replace_metadata(metadata) end # Existing keys have values updated and new key-value pairs are created, but none are deleted def update_metadata(metadata) requires :id service.update_metadata(id, metadata) true end # All existing key-value pairs are deleted and replaced with the key-value pairs specified here def replace_metadata(metadata) requires :id service.replace_metadata(id, metadata) true end # Delete one specific key-value pair by specifying the key name def delete_metadata(key_name) requires :id service.delete_metadata(id, key_name) true end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/volume/transfer.rb0000644000175600017570000000121212730051546023571 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Volume class OpenStack class Transfer < Fog::OpenStack::Model def save requires :name, :volume_id data = service.create_transfer(volume_id, :name => name) merge_attributes(data.body['transfer']) true end def destroy requires :id service.delete_transfer(id) true end def initialize(attributes) # Old 'connection' is renamed as service and should be used instead prepare_service_value(attributes) super end end end end endfog-openstack-0.1.6/lib/fog/openstack/models/volume/transfers.rb0000644000175600017570000000174212730051546023764 0ustar pravipravirequire 'fog/openstack/models/collection' module Fog module Volume class OpenStack module Transfers def all(options = {}) load_response(service.list_transfers_detailed(options), 'transfers') end def summary(options = {}) load_response(service.list_transfers(options), 'transfers') end def get(transfer_id) if transfer = service.get_transfer_details(transfer_id).body['transfer'] new(transfer) end rescue Fog::Volume::OpenStack::NotFound nil end def accept(transfer_id, auth_key) # NOTE: This is NOT a method on the Transfer object, since the # receiver cannot see the transfer object in the get_transfer_details # or list_transfers(_detailed) requests. if transfer = service.accept_transfer(transfer_id, auth_key).body['transfer'] new(transfer) end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/volume/volume_types.rb0000644000175600017570000000103012730051546024476 0ustar pravipravirequire 'fog/openstack/models/collection' module Fog module Volume class OpenStack module VolumeTypes def all(options = {}) response = service.list_volume_types(options) load_response(response, 'volume_types') end def get(volume_type_id) if volume_type = service.get_volume_type_details(volume_type_id).body['volume_type'] new(volume_type) end rescue Fog::Volume::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/volume/availability_zones.rb0000644000175600017570000000044212730051546025641 0ustar pravipravirequire 'fog/openstack/models/collection' module Fog module Volume class OpenStack module AvailabilityZones def all(options = {}) data = service.list_zones(options) load_response(data, 'availabilityZoneInfo') end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/volume/volume_type.rb0000644000175600017570000000125712730051546024326 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Volume class OpenStack class VolumeType < Fog::OpenStack::Model attribute :extra_specs def create requires :name response = service.create_volume_type(attributes) merge_attributes(response.body['volume_type']) self end def update requires :id response = service.update_volume_type(id, attributes) merge_attributes(response.body['volume_type']) self end def destroy requires :id service.delete_volume_type(id) true end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/volume/snapshots.rb0000644000175600017570000000116312730051546023774 0ustar pravipravirequire 'fog/openstack/models/collection' module Fog module Volume class OpenStack module Snapshots def all(options = {}) load_response(service.list_snapshots_detailed(options), 'snapshots') end def summary(options = {}) load_response(service.list_snapshots(options), 'snapshots') end def get(snapshots_id) snapshot = service.get_snapshot_details(snapshots_id).body['snapshot'] if snapshot new(snapshot) end rescue Fog::Volume::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/compute/0000755000175600017570000000000012730051546021571 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/models/compute/volumes.rb0000644000175600017570000000216312730051546023612 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/compute/volume' module Fog module Compute class OpenStack class Volumes < Fog::OpenStack::Collection model Fog::Compute::OpenStack::Volume def all(options = true) if !options.is_a?(Hash) if options Fog::Logger.deprecation('Calling OpenStack[:compute].volumes.all(true) is deprecated, use .volumes.all') else Fog::Logger.deprecation('Calling OpenStack[:compute].volumes.all(false) is deprecated, use .volumes.summary') end load_response(service.list_volumes(options), 'volumes') else load_response(service.list_volumes_detail(options), 'volumes') end end def summary(options = {}) load_response(service.list_volumes(options), 'volumes') end def get(volume_id) if volume = service.get_volume_details(volume_id).body['volume'] new(volume) end rescue Fog::Compute::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/compute/host.rb0000644000175600017570000000132712730051546023076 0ustar pravipravirequire 'fog/compute/models/server' require 'fog/openstack/models/compute/metadata' module Fog module Compute class OpenStack class Host < Fog::OpenStack::Model attribute :host_name attribute :service_name attribute :details attribute :zone def initialize(attributes) attributes["service_name"] = attributes.delete "service" # Old 'connection' is renamed as service and should be used instead prepare_service_value(attributes) super end def details service.get_host_details(self.host_name).body['host'] rescue Fog::Compute::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/compute/network.rb0000644000175600017570000000045112730051546023607 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Compute class OpenStack class Network < Fog::OpenStack::Model identity :id attribute :name attribute :addresses end # class Network end # class OpenStack end # module Compute end # module Fog fog-openstack-0.1.6/lib/fog/openstack/models/compute/addresses.rb0000644000175600017570000000130412730051546024071 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/compute/address' module Fog module Compute class OpenStack class Addresses < Fog::OpenStack::Collection model Fog::Compute::OpenStack::Address def all(options = {}) load_response(service.list_all_addresses(options), 'floating_ips') end def get(address_id) if address = service.get_address(address_id).body['floating_ip'] new(address) end rescue Fog::Compute::OpenStack::NotFound nil end def get_address_pools service.list_address_pools.body['floating_ip_pools'] end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/compute/snapshot.rb0000644000175600017570000000153512730051546023761 0ustar pravipravirequire 'fog/openstack/models/model' require 'fog/openstack/models/compute/metadata' module Fog module Compute class OpenStack class Snapshot < Fog::OpenStack::Model identity :id attribute :name, :aliases => 'displayName' attribute :description, :aliases => 'displayDescription' attribute :volume_id, :aliases => 'volumeId' attribute :created_at, :aliases => 'createdAt' attribute :status attribute :size def save(force = false) requires :volume_id, :name, :description data = service.create_snapshot(volume_id, name, description, force) merge_attributes(data.body['snapshot']) true end def destroy requires :id service.delete_snapshot(id) true end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/compute/key_pair.rb0000644000175600017570000000257712730051546023734 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Compute class OpenStack class KeyPair < Fog::OpenStack::Model identity :name attribute :fingerprint attribute :public_key attribute :private_key attribute :user_id attribute :id attr_accessor :public_key def destroy requires :name service.delete_key_pair(name) true end def save requires :name data = if public_key service.create_key_pair(name, public_key).body['keypair'] else service.create_key_pair(name).body['keypair'] end new_attributes = data.reject {|key,value| !['fingerprint', 'public_key', 'name', 'private_key', 'user_id'].include?(key)} merge_attributes(new_attributes) true end def write(path="#{ENV['HOME']}/.ssh/fog_#{Fog.credential.to_s}_#{name}.pem") if writable? split_private_key = private_key.split(/\n/) File.open(path, "w") do |f| split_private_key.each {|line| f.puts line} f.chmod 0600 end "Key file built: #{path}" else "Invalid private key" end end def writable? !!(private_key && ENV.key?('HOME')) end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/compute/volume_attachments.rb0000644000175600017570000000076712730051546026032 0ustar pravipravirequire 'fog/core/collection' module Fog module Compute class OpenStack class VolumeAttachments < Fog::Collection model Fog::Compute::OpenStack::VolumeAttachment def get(server_id) if server_id puts service.list_volume_attachments(server_id).body load(service.list_volume_attachments(server_id).body['volumeAttachments']) end rescue Fog::Compute::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/compute/address.rb0000644000175600017570000000317112730051546023545 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Compute class OpenStack class Address < Fog::OpenStack::Model identity :id attribute :ip attribute :pool attribute :fixed_ip attribute :instance_id def initialize(attributes = {}) # assign server first to prevent race condition with persisted? self.server = attributes.delete(:server) super end def destroy requires :id service.release_address(id) true end def server=(new_server) if new_server associate(new_server) else disassociate end end def save raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted? data = service.allocate_address(pool).body['floating_ip'] new_attributes = data.reject {|key,value| !['id', 'instance_id', 'ip', 'fixed_ip'].include?(key)} merge_attributes(new_attributes) if @server self.server = @server end true end private def associate(new_server) unless persisted? @server = new_server else @server = nil self.instance_id = new_server.id service.associate_address(instance_id, ip) end end def disassociate @server = nil if persisted? service.disassociate_address(instance_id, ip) end self.instance_id = nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/compute/availability_zone.rb0000644000175600017570000000050712730051546025625 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Compute class OpenStack class AvailabilityZone < Fog::OpenStack::Model identity :zoneName attribute :hosts attribute :zoneLabel attribute :zoneState def to_s zoneName end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/compute/flavor.rb0000644000175600017570000000336312730051546023414 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Compute class OpenStack class Flavor < Fog::OpenStack::Model identity :id attribute :name attribute :ram attribute :disk attribute :vcpus attribute :links attribute :swap attribute :rxtx_factor attribute :metadata attribute :ephemeral, :aliases => 'OS-FLV-EXT-DATA:ephemeral' attribute :is_public, :aliases => 'os-flavor-access:is_public' attribute :disabled, :aliases => 'OS-FLV-DISABLED:disabled' def save requires :name, :ram, :vcpus, :disk attributes[:ephemeral] = ephemeral || 0 attributes[:is_public] = is_public || false attributes[:disabled] = disabled || false attributes[:swap] = swap || 0 attributes[:rxtx_factor] = rxtx_factor || 1.0 merge_attributes(service.create_flavor(attributes).body['flavor']) self end def destroy requires :id service.delete_flavor(id) true end def metadata service.get_flavor_metadata(id).body['extra_specs'] rescue Fog::Compute::OpenStack::NotFound nil end def create_metadata(metadata) service.create_flavor_metadata(id, metadata) rescue Fog::Compute::OpenStack::NotFound nil end def update_metadata(key, value) service.update_flavor_metadata(id, key, value) rescue Fog::Compute::OpenStack::NotFound nil end def delete_metadata(key) service.delete_flavor_metadata(id, key) rescue Fog::Compute::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/compute/aggregates.rb0000644000175600017570000000116512730051546024232 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/compute/aggregate' module Fog module Compute class OpenStack class Aggregates < Fog::OpenStack::Collection model Fog::Compute::OpenStack::Aggregate def all(options = {}) load_response(service.list_aggregates(options), 'aggregates') end def find_by_id(id) new(service.get_aggregate(id).body['aggregate']) end alias_method :get, :find_by_id def destroy(id) aggregate = self.find_by_id(id) aggregate.destroy end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/compute/volume_attachment.rb0000644000175600017570000000037012730051546025635 0ustar pravipravirequire 'fog/core/model' module Fog module Compute class OpenStack class VolumeAttachment < Fog::Model identity :id attribute :serverId attribute :volumeId attribute :device end end end end fog-openstack-0.1.6/lib/fog/openstack/models/compute/volume.rb0000644000175600017570000000272512730051546023433 0ustar pravipravirequire 'fog/openstack/models/model' require 'fog/openstack/models/compute/metadata' module Fog module Compute class OpenStack class Volume < Fog::OpenStack::Model identity :id attribute :name, :aliases => 'displayName' attribute :description, :aliases => 'displayDescription' attribute :status attribute :size attribute :type, :aliases => 'volumeType' attribute :snapshot_id, :aliases => 'snapshotId' attribute :availability_zone, :aliases => 'availabilityZone' attribute :created_at, :aliases => 'createdAt' attribute :attachments def save requires :name, :description, :size data = service.create_volume(name, description, size, attributes) merge_attributes(data.body['volume']) true end def destroy requires :id service.delete_volume(id) true end def attach(server_id, name) requires :id data = service.attach_volume(id, server_id, name) merge_attributes(:attachments => attachments << data.body['volumeAttachment']) true end def detach(server_id, attachment_id) requires :id service.detach_volume(server_id, attachment_id) true end def ready? self.status == "available" end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/compute/metadata.rb0000644000175600017570000000355112730051546023702 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/meta_parent' require 'fog/openstack/models/compute/metadatum' require 'fog/openstack/models/compute/image' require 'fog/openstack/models/compute/server' module Fog module Compute class OpenStack class Metadata < Fog::OpenStack::Collection model Fog::Compute::OpenStack::Metadatum include Fog::Compute::OpenStack::MetaParent def all requires :parent metadata = service.list_metadata(collection_name, @parent.id).body['metadata'] metas = [] metadata.each_pair {|k,v| metas << {"key" => k, "value" => v} } unless metadata.nil? # TODO convert to load_response? load(metas) end def get(key) requires :parent data = service.get_metadata(collection_name, @parent.id, key).body["meta"] metas = [] data.each_pair {|k,v| metas << {"key" => k, "value" => v} } new(metas[0]) rescue Fog::Compute::OpenStack::NotFound nil end def update(data=nil) requires :parent service.update_metadata(collection_name, @parent.id, to_hash(data)) end def set(data=nil) requires :parent service.set_metadata(collection_name, @parent.id, to_hash(data)) end def new(attributes = {}) requires :parent super({ :parent => @parent }.merge!(attributes)) end def to_hash(data=nil) if data.nil? data={} self.each do |meta| if meta.is_a?(Fog::Compute::OpenStack::Metadatum) then data.store(meta.key, meta.value) else data.store(meta["key"], meta["value"]) end end end data end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/compute/key_pairs.rb0000644000175600017570000000134212730051546024104 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/compute/key_pair' module Fog module Compute class OpenStack class KeyPairs < Fog::OpenStack::Collection model Fog::Compute::OpenStack::KeyPair def all(options = {}) items = Array.new service.list_key_pairs(options).body['keypairs'].each do |kp| items = items + kp.values end # TODO convert to load_response? load(items) end def get(key_pair_name) if key_pair_name self.all.select {|kp| kp.name == key_pair_name}.first end rescue Fog::Compute::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/compute/service.rb0000644000175600017570000000165512730051546023565 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Compute class OpenStack class Service < Fog::OpenStack::Model identity :id attribute :binary attribute :host attribute :state attribute :status attribute :updated_at attribute :zone #detailed attribute :disabled_reason def enable requires :binary, :host service.enable_service(self.host, self.binary) end def disable requires :binary, :host service.disable_service(self.host, self.binary) end def disable_and_log_reason requires :binary, :host, :disabled_reason service.disable_service_log_reason(self.host, self.binary, self.disabled_reason) end def destroy requires :id service.delete_service(self.id) true end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/compute/aggregate.rb0000644000175600017570000000245712730051546024054 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Compute class OpenStack class Aggregate < Fog::OpenStack::Model identity :id attribute :availability_zone attribute :name attribute :metadata attribute :deleted attribute :deleted_at attribute :updated_at attribute :created_at # Detailed attribute :hosts def save requires :name identity ? update : create end def create requires :name merge_attributes(service.create_aggregate(self.name, self.attributes).body['aggregate']) self end def update merge_attributes(service.update_aggregate(self.id, self.attributes).body['aggregate']) self end def add_host(host_uuid) requires :id, service.add_aggregate_host(self.id, host_uuid) end def remove_host(host_uuid) requires :id, service.remove_aggregate_host(self.id, host_uuid) end def update_metadata(metadata) service.update_aggregate_metadata(self.id, metadata) end def destroy requires :id service.delete_aggregate(self.id) true end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/compute/image.rb0000644000175600017570000000214712730051546023204 0ustar pravipravirequire 'fog/openstack/models/model' require 'fog/openstack/models/compute/metadata' module Fog module Compute class OpenStack class Image < Fog::OpenStack::Model identity :id attribute :name attribute :created_at, :aliases => 'created' attribute :updated_at, :aliases => 'updated' attribute :progress attribute :status attribute :minDisk attribute :minRam attribute :server, :aliases => 'server' attribute :metadata attribute :links def metadata @metadata ||= begin Fog::Compute::OpenStack::Metadata.new({ :service => service, :parent => self }) end end def metadata=(new_metadata={}) metas = [] new_metadata.each_pair {|k,v| metas << {"key" => k, "value" => v} } metadata.load(metas) end def destroy requires :id service.delete_image(id) true end def ready? status == 'ACTIVE' end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/compute/security_group_rule.rb0000644000175600017570000000150312730051546026227 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Compute class OpenStack class SecurityGroupRule < Fog::OpenStack::Model identity :id attribute :from_port attribute :group attribute :ip_protocol attribute :to_port attribute :parent_group_id attribute :ip_range def save requires :ip_protocol, :from_port, :to_port, :parent_group_id cidr = ip_range && ip_range["cidr"] if rule = service.create_security_group_rule(parent_group_id, ip_protocol, from_port, to_port, cidr, group).data[:body] merge_attributes(rule["security_group_rule"]) end end def destroy requires :id service.delete_security_group_rule(id) true end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/compute/servers.rb0000644000175600017570000000365212730051546023615 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/compute/server' module Fog module Compute class OpenStack class Servers < Fog::OpenStack::Collection attribute :filters model Fog::Compute::OpenStack::Server def initialize(attributes) self.filters ||= {} super end def all(filters_arg = filters) filters = filters_arg data = service.list_servers_detail(filters) load_response(data, 'servers') end def summary(filters_arg = filters) filters = filters_arg data = service.list_servers(filters) load_response(data, 'servers') end # Creates a new server and populates ssh keys # @return [Fog::Compute::OpenStack::Server] # @raise [Fog::Compute::OpenStack::NotFound] - HTTP 404 # @raise [Fog::Compute::OpenStack::BadRequest] - HTTP 400 # @raise [Fog::Compute::OpenStack::InternalServerError] - HTTP 500 # @raise [Fog::Compute::OpenStack::ServiceError] # @example # service.servers.bootstrap :name => 'bootstrap-server', # :flavor_ref => service.flavors.first.id, # :image_ref => service.images.find {|img| img.name =~ /Ubuntu/}.id, # :public_key_path => '~/.ssh/fog_rsa.pub', # :private_key_path => '~/.ssh/fog_rsa' # def bootstrap(new_attributes = {}) server = create(new_attributes) server.wait_for { ready? } server.setup(:password => server.password) server end def get(server_id) if server = service.get_server_details(server_id).body['server'] new(server) end rescue Fog::Compute::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/compute/hosts.rb0000644000175600017570000000124012730051546023253 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/compute/host' module Fog module Compute class OpenStack class Hosts < Fog::OpenStack::Collection model Fog::Compute::OpenStack::Host def all(options = {}) data = service.list_hosts(options) load_response(data, 'hosts') end def get(host_name) if host = service.get_host_details(host_name).body['host'] new({ 'host_name' => host_name, 'details' => host} ) end rescue Fog::Compute::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/compute/tenants.rb0000644000175600017570000000122112730051546023566 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/compute/tenant' module Fog module Compute class OpenStack class Tenants < Fog::OpenStack::Collection model Fog::Compute::OpenStack::Tenant def all load_response(service.list_tenants, 'tenants') end def usages(start_date = nil, end_date = nil, details = false) service.list_usages(start_date, end_date, details).body['tenant_usages'] end def get(id) self.find {|tenant| tenant.id == id} end end # class Tenants end # class OpenStack end # module Compute end # module Fog fog-openstack-0.1.6/lib/fog/openstack/models/compute/networks.rb0000644000175600017570000000136612730051546024000 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/compute/network' module Fog module Compute class OpenStack class Networks < Fog::OpenStack::Collection model Fog::Compute::OpenStack::Network attribute :server def all requires :server networks = Array.new server.addresses.each_with_index do |address, index| networks << { :id => index + 1, :name => address[0], :addresses => address[1].map {|a| a['addr'] } } end # TODO convert to load_response? load(networks) end end # class Networks end # class OpenStack end # module Compute end # module Fog fog-openstack-0.1.6/lib/fog/openstack/models/compute/images.rb0000644000175600017570000000161512730051546023366 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/compute/image' module Fog module Compute class OpenStack class Images < Fog::OpenStack::Collection attribute :filters model Fog::Compute::OpenStack::Image attribute :server def initialize(attributes) self.filters ||= {} super end def all(filters_arg = filters) filters = filters_arg data = service.list_images_detail(filters) images = load_response(data, 'images') if server self.replace(self.select {|image| image.server_id == server.id}) end images end def get(image_id) data = service.get_image_details(image_id).body['image'] new(data) rescue Fog::Compute::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/compute/services.rb0000644000175600017570000000214612730051546023744 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/compute/service' module Fog module Compute class OpenStack class Services < Fog::OpenStack::Collection model Fog::Compute::OpenStack::Service def all(options = {}) load_response(service.list_services(options), 'services') end alias_method :summary, :all def details(options = {}) Fog::Logger.deprecation('Calling OpenStack[:compute].services.details is deprecated, use .services.all') all(options) end def get(service_id) # OpenStack API currently does not support getting single service from it # There is a blueprint https://blueprints.launchpad.net/nova/+spec/get-service-by-id # with spec proposal patch https://review.openstack.org/#/c/172412/ but this is abandoned. serv = service.list_services.body['services'].detect do |s| s['id'] == service_id end new(serv) if serv rescue Fog::Compute::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/compute/server.rb0000644000175600017570000003056112730051546023431 0ustar pravipravirequire 'fog/compute/models/server' require 'fog/openstack/models/compute/metadata' module Fog module Compute class OpenStack class Server < Fog::Compute::Server identity :id attribute :instance_name, :aliases => 'OS-EXT-SRV-ATTR:instance_name' attribute :addresses attribute :flavor attribute :host_id, :aliases => 'hostId' attribute :image attribute :metadata attribute :links attribute :name # @!attribute [rw] personality # @note This attribute is only used for server creation. This field will be nil on subsequent retrievals. # @return [Hash] Hash containing data to inject into the file system of the cloud server instance during # server creation. # @example To inject fog.txt into file system # :personality => [{ :path => '/root/fog.txt', # :contents => Base64.encode64('Fog was here!') # }] # @see #create # @see http://docs.openstack.org/api/openstack-compute/2/content/Server_Personality-d1e2543.html attribute :personality attribute :progress attribute :accessIPv4 attribute :accessIPv6 attribute :availability_zone, :aliases => 'OS-EXT-AZ:availability_zone' attribute :user_data_encoded attribute :state, :aliases => 'status' attribute :created, :type => :time attribute :updated, :type => :time attribute :tenant_id attribute :user_id attribute :key_name attribute :fault attribute :config_drive attribute :os_dcf_disk_config, :aliases => 'OS-DCF:diskConfig' attribute :os_ext_srv_attr_host, :aliases => 'OS-EXT-SRV-ATTR:host' attribute :os_ext_srv_attr_hypervisor_hostname, :aliases => 'OS-EXT-SRV-ATTR:hypervisor_hostname' attribute :os_ext_srv_attr_instance_name, :aliases => 'OS-EXT-SRV-ATTR:instance_name' attribute :os_ext_sts_power_state, :aliases => 'OS-EXT-STS:power_state' attribute :os_ext_sts_task_state, :aliases => 'OS-EXT-STS:task_state' attribute :os_ext_sts_vm_state, :aliases => 'OS-EXT-STS:vm_state' attr_reader :password attr_writer :image_ref, :flavor_ref, :nics, :os_scheduler_hints attr_accessor :block_device_mapping, :block_device_mapping_v2 # In some cases it's handy to be able to store the project for the record, e.g. swift doesn't contain project # info in the result, so we can track it in this attribute based on what project was used in the request attr_accessor :project def initialize(attributes = {}) # Old 'connection' is renamed as service and should be used instead prepare_service_value(attributes) self.security_groups = attributes.delete(:security_groups) self.min_count = attributes.delete(:min_count) self.max_count = attributes.delete(:max_count) self.nics = attributes.delete(:nics) self.os_scheduler_hints = attributes.delete(:os_scheduler_hints) self.block_device_mapping = attributes.delete(:block_device_mapping) self.block_device_mapping_v2 = attributes.delete(:block_device_mapping_v2) super end def metadata @metadata ||= begin Fog::Compute::OpenStack::Metadata.new(:service => service, :parent => self) end end def metadata=(new_metadata = {}) return unless new_metadata metas = [] new_metadata.each_pair { |k, v| metas << {"key" => k, "value" => v} } @metadata = metadata.load(metas) end def user_data=(ascii_userdata) self.user_data_encoded = [ascii_userdata].pack('m') if ascii_userdata end def destroy requires :id service.delete_server(id) true end def images requires :id service.images(:server => self) end def all_addresses # currently openstack API does not tell us what is a floating ip vs a fixed ip for the vm listing, # we fall back to get all addresses and filter sadly. # Only includes manually-assigned addresses, not auto-assigned @all_addresses ||= service.list_all_addresses.body["floating_ips"].select { |data| data['instance_id'] == id } end def reload @all_addresses = nil super end # returns all ip_addresses for a given instance # this includes both the fixed ip(s) and the floating ip(s) def ip_addresses addresses ? addresses.values.flatten.collect { |x| x['addr'] } : [] end def floating_ip_addresses all_floating = if addresses flattened_values = addresses.values.flatten flattened_values.select { |d| d["OS-EXT-IPS:type"] == "floating" }.collect { |a| a["addr"] } else [] end # Return them all, leading with manually assigned addresses manual = all_addresses.collect { |addr| addr["ip"] } all_floating.sort do |a, b| a_manual = manual.include? a b_manual = manual.include? b if a_manual && !b_manual -1 elsif !a_manual && b_manual 1 else 0 end end all_floating.empty? ? manual : all_floating end def public_ip_addresses if floating_ip_addresses.empty? addresses.select { |s| s[0] =~ /public/i }.collect { |a| a[1][0]['addr'] } else floating_ip_addresses end end def floating_ip_address floating_ip_addresses.first end def public_ip_address public_ip_addresses.first end def private_ip_addresses rfc1918_regexp = /(^10\.|^172\.1[6-9]\.|^172\.2[0-9]\.|^172.3[0-1]\.|^192\.168\.)/ almost_private = ip_addresses - public_ip_addresses - floating_ip_addresses almost_private.select { |ip| rfc1918_regexp.match ip } end def private_ip_address private_ip_addresses.first end attr_reader :image_ref attr_writer :image_ref attr_reader :flavor_ref attr_writer :flavor_ref def ready? state == 'ACTIVE' end def failed? state == 'ERROR' end def change_password(admin_password) requires :id service.change_server_password(id, admin_password) true end def rebuild(image_ref, name, admin_pass = nil, metadata = nil, personality = nil) requires :id service.rebuild_server(id, image_ref, name, admin_pass, metadata, personality) true end def resize(flavor_ref) requires :id service.resize_server(id, flavor_ref) true end def revert_resize requires :id service.revert_resize_server(id) true end def confirm_resize requires :id service.confirm_resize_server(id) true end def security_groups requires :id groups = service.list_security_groups(:server_id => id).body['security_groups'] groups.map do |group| Fog::Compute::OpenStack::SecurityGroup.new group.merge(:service => service) end end attr_writer :security_groups def reboot(type = 'SOFT') requires :id service.reboot_server(id, type) true end def stop requires :id service.stop_server(id) end def pause requires :id service.pause_server(id) end def suspend requires :id service.suspend_server(id) end def start requires :id case state.downcase when 'paused' service.unpause_server(id) when 'suspended' service.resume_server(id) else service.start_server(id) end end def shelve requires :id service.shelve_server(id) end def unshelve requires :id service.unshelve_server(id) end def shelve_offload requires :id service.shelve_offload_server(id) end def create_image(name, metadata = {}) requires :id service.create_image(id, name, metadata) end def console(log_length = nil) requires :id service.get_console_output(id, log_length) end def migrate requires :id service.migrate_server(id) end def live_migrate(host, block_migration, disk_over_commit) requires :id service.live_migrate_server(id, host, block_migration, disk_over_commit) end def evacuate(host = nil, on_shared_storage = nil, admin_password = nil) requires :id service.evacuate_server(id, host, on_shared_storage, admin_password) end def associate_address(floating_ip) requires :id service.associate_address id, floating_ip end def disassociate_address(floating_ip) requires :id service.disassociate_address id, floating_ip end def reset_vm_state(vm_state) requires :id service.reset_server_state id, vm_state end attr_writer :min_count attr_writer :max_count def networks service.networks(:server => self) end def volumes requires :id service.volumes.select do |vol| vol.attachments.find { |attachment| attachment["serverId"] == id } end end def volume_attachments requires :id service.get_server_volumes(id).body['volumeAttachments'] end def attach_volume(volume_id, device_name) requires :id service.attach_volume(volume_id, id, device_name) true end def detach_volume(volume_id) requires :id service.detach_volume(id, volume_id) true end def save raise Fog::Errors::Error, 'Resaving an existing object may create a duplicate' if persisted? requires :flavor_ref, :name requires_one :image_ref, :block_device_mapping, :block_device_mapping_v2 options = { 'personality' => personality, 'accessIPv4' => accessIPv4, 'accessIPv6' => accessIPv6, 'availability_zone' => availability_zone, 'user_data' => user_data_encoded, 'key_name' => key_name, 'config_drive' => config_drive, 'security_groups' => @security_groups, 'min_count' => @min_count, 'max_count' => @max_count, 'nics' => @nics, 'os:scheduler_hints' => @os_scheduler_hints, 'block_device_mapping' => @block_device_mapping, 'block_device_mapping_v2' => @block_device_mapping_v2, } options['metadata'] = metadata.to_hash unless @metadata.nil? options = options.reject { |_key, value| value.nil? } data = service.create_server(name, image_ref, flavor_ref, options) merge_attributes(data.body['server']) true end def setup(credentials = {}) requires :ssh_ip_address, :identity, :public_key, :username ssh = Fog::SSH.new(ssh_ip_address, username, credentials) ssh.run([ %(mkdir .ssh), %(echo "#{public_key}" >> ~/.ssh/authorized_keys), %(passwd -l #{username}), %(echo "#{Fog::JSON.encode(attributes)}" >> ~/attributes.json), %(echo "#{Fog::JSON.encode(metadata)}" >> ~/metadata.json) ]) rescue Errno::ECONNREFUSED sleep(1) retry end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/compute/tenant.rb0000644000175600017570000000102212730051546023402 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Compute class OpenStack class Tenant < Fog::OpenStack::Model identity :id attribute :description attribute :enabled attribute :name def to_s self.name end def usage(start_date, end_date) requires :id service.get_usage(self.id, start_date, end_date).body['tenant_usage'] end end # class Tenant end # class OpenStack end # module Compute end # module Fog fog-openstack-0.1.6/lib/fog/openstack/models/compute/security_group_rules.rb0000644000175600017570000000111212730051546026406 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/compute/security_group_rule' module Fog module Compute class OpenStack class SecurityGroupRules < Fog::OpenStack::Collection model Fog::Compute::OpenStack::SecurityGroupRule def get(security_group_rule_id) if security_group_rule_id body = service.get_security_group_rule(security_group_rule_id).body new(body['security_group_rule']) end rescue Fog::Compute::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/compute/metadatum.rb0000644000175600017570000000112512730051546024076 0ustar pravipravirequire 'fog/openstack/models/model' require 'fog/openstack/models/meta_parent' module Fog module Compute class OpenStack class Metadatum < Fog::OpenStack::Model include Fog::Compute::OpenStack::MetaParent identity :key attribute :value def destroy requires :identity service.delete_meta(collection_name, @parent.id, key) true end def save requires :identity, :value service.update_meta(collection_name, @parent.id, key, value) true end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/compute/security_groups.rb0000644000175600017570000000121112730051546025357 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/compute/security_group' module Fog module Compute class OpenStack class SecurityGroups < Fog::OpenStack::Collection model Fog::Compute::OpenStack::SecurityGroup def all(options = {}) load_response(service.list_security_groups(options), 'security_groups') end def get(security_group_id) if security_group_id new(service.get_security_group(security_group_id).body['security_group']) end rescue Fog::Compute::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/compute/availability_zones.rb0000644000175600017570000000111412730051546026003 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/compute/availability_zone' module Fog module Compute class OpenStack class AvailabilityZones < Fog::OpenStack::Collection model Fog::Compute::OpenStack::AvailabilityZone def all(options = {}) data = service.list_zones_detailed(options) load_response(data, 'availabilityZoneInfo') end def summary(options = {}) data = service.list_zones(options) load_response(data, 'availabilityZoneInfo') end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/compute/security_group.rb0000644000175600017570000000402112730051546025176 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Compute class OpenStack class SecurityGroup < Fog::OpenStack::Model identity :id attribute :name attribute :description attribute :security_group_rules, :aliases => "rules" attribute :tenant_id def security_group_rules Fog::Compute::OpenStack::SecurityGroupRules.new(:service => service).load(attributes[:security_group_rules]) end def rules Fog::Logger.deprecation('#rules is deprecated. Use #security_group_rules instead') attributes[:security_group_rules] end # no one should be calling this because it doesn't do anything # useful but we deprecated the rules attribute and need to maintain the API def rules=(new_rules) Fog::Logger.deprecation('#rules= is deprecated. Use the Fog::Compute::Openstack::SecurityGroupRules collection to create new rules.') attributes[:security_group_rules] = new_rules end def save requires :name, :description data = service.create_security_group(name, description) merge_attributes(data.body['security_group']) true end def destroy requires :id service.delete_security_group(id) true end def create_security_group_rule(min, max, ip_protocol = "tcp", cidr = "0.0.0.0/0", group_id = nil) Fog::Logger.deprecation('#create_security_group_rule is deprecated. Use the Fog::Compute::Openstack::SecurityGroupRules collection to create new rules.') requires :id service.create_security_group_rule(id, ip_protocol, min, max, cidr, group_id) end def delete_security_group_rule(rule_id) Fog::Logger.deprecation('#create_security_group_rule is deprecated. Use the Fog::Compute::Openstack::SecurityGroupRule objects to destroy rules.') service.delete_security_group_rule(rule_id) true end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/compute/flavors.rb0000644000175600017570000000132612730051546023574 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/compute/flavor' module Fog module Compute class OpenStack class Flavors < Fog::OpenStack::Collection model Fog::Compute::OpenStack::Flavor def all(options = {}) data = service.list_flavors_detail(options) load_response(data, 'flavors') end def summary(options = {}) data = service.list_flavors(options) load_response(data, 'flavors') end def get(flavor_id) data = service.get_flavor_details(flavor_id).body['flavor'] new(data) rescue Fog::Compute::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/compute/snapshots.rb0000644000175600017570000000222712730051546024143 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/compute/snapshot' module Fog module Compute class OpenStack class Snapshots < Fog::OpenStack::Collection model Fog::Compute::OpenStack::Snapshot def all(options = {}) if !options.is_a?(Hash) if options Fog::Logger.deprecation('Calling OpenStack[:compute].snapshots.all(true) is deprecated, use .snapshots.all') else Fog::Logger.deprecation('Calling OpenStack[:compute].snapshots.all(false) is deprecated, use .snapshots.summary') end load_response(service.list_snapshots(options), 'snapshots') else load_response(service.list_snapshots_detail(options), 'snapshots') end end def summary(options = {}) load_response(service.list_snapshots(options), 'snapshots') end def get(snapshot_id) if snapshot = service.get_snapshot_details(snapshot_id).body['snapshot'] new(snapshot) end rescue Fog::Compute::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/model.rb0000644000175600017570000000311012730051546021535 0ustar pravipravirequire 'fog/core/model' module Fog module OpenStack class Model < Fog::Model # In some cases it's handy to be able to store the project for the record, e.g. swift doesn't contain project info # in the result, so we can track it in this attribute based on what project was used in the request attr_accessor :project ################################################################################################################## # Abstract base class methods, please keep the consistent naming in all subclasses of the Model class # Initialize a record def initialize(attributes) # Old 'connection' is renamed as service and should be used instead prepare_service_value(attributes) super end # Saves a record, call create or update based on identity, which marks if object was already created def save identity ? update : create end # Updates a record def update # uncomment when exception is defined in another PR # raise Fog::OpenStack::Errors::InterfaceNotImplemented.new('Method :get is not implemented') end # Creates a record def create # uncomment when exception is defined in another PR # raise Fog::OpenStack::Errors::InterfaceNotImplemented.new('Method :get is not implemented') end # Destroys a record def destroy # uncomment when exception is defined in another PR # raise Fog::OpenStack::Errors::InterfaceNotImplemented.new('Method :get is not implemented') end end end end fog-openstack-0.1.6/lib/fog/openstack/models/image_v2/0000755000175600017570000000000012730051546021606 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/models/image_v2/image.rb0000644000175600017570000001076012730051546023221 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Image class OpenStack class V2 class Image < Fog::OpenStack::Model identity :id attribute :name attribute :visibility # public or private attribute :tags attribute :self attribute :size attribute :disk_format attribute :container_format attribute :id attribute :checksum attribute :self attribute :file # detailed attribute :min_disk attribute :created_at attribute :updated_at attribute :protected attribute :status # "queued","saving","active","killed","deleted","pending_delete" attribute :min_ram attribute :owner attribute :properties attribute :metadata attribute :location # from snapshot support attribute :network_allocated attribute :base_image_ref attribute :image_type attribute :instance_uuid attribute :user_id def method_missing(method_sym, *arguments, &block) if attributes.key?(method_sym) attributes[method_sym] elsif attributes.key?(method_sym.to_s) attributes[method_sym.to_s] else super end end def respond_to?(method_sym, include_all = false) if attributes.key?(method_sym) true elsif attributes.key?(method_sym.to_s) true else super end end def create requires :name merge_attributes(service.create_image(attributes).body) self end # This overrides the behaviour of Fog::OpenStack::Model::save() which tries to be clever and # assumes save=update if an ID is present - but Image V2 allows ID to specified on creation def identity nil end # Hash of attributes to update is passed in. Setting value to nil will delete that attribute. # Here we convert that hash into a form suitable for Glance's usage of JSON Patch (RFC6902) def update(attr = {}) requires :id json_patch = [] attr.each do |key, value| op = (@attributes.keys.include? key) ? 'replace' : 'add' op = 'remove' if value.nil? json_patch << {:op => op, :path => "/#{key}", :value => value} end merge_attributes( service.update_image(id, json_patch).body) self end def destroy requires :id service.delete_image(id) true end def upload_data(io_obj) requires :id if io_obj.kind_of? Hash service.upload_image(id, nil, io_obj) else service.upload_image(id, io_obj) end end def download_data(params = {}) requires :id service.download_image(id, params[:content_range], params) end def reactivate requires :id service.reactivate_image(id) end def deactivate requires :id service.deactivate_image(id) end def add_member(member_id) requires :id service.add_member_to_image(id, member_id) end def remove_member(member_id) requires :id service.remove_member_from_image(id, member_id) end def update_member(member) requires :id service.update_image_member(id, member) end def members requires :id service.get_image_members(id).body['members'] end def member(member_id) requires :id service.get_member_details(id, member_id) end def add_tags(tags) requires :id tags.each { |tag| add_tag tag } end def add_tag(tag) requires :id service.add_tag_to_image(id, tag) end def remove_tags(tags) requires :id tags.each { |tag| remove_tag tag } end def remove_tag(tag) requires :id service.remove_tag_from_image(id, tag) end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/image_v2/images.rb0000644000175600017570000000350112730051546023377 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/image_v2/image' module Fog module Image class OpenStack class V2 class Images < Fog::OpenStack::Collection model Fog::Image::OpenStack::V2::Image def all(options = {}) load_response(service.list_images(options), 'images') end def summary(options = {}) load_response(service.list_images(options), 'images') end def find_by_id(id) image_hash = service.get_image_by_id(id).body Fog::Image::OpenStack::V2::Image.new( image_hash.merge(:service => service)) end alias_method :get, :find_by_id def public images = load(service.list_images.body['images']) images.delete_if { |image| image.is_public == false } end def private images = load(service.list_images.body['images']) images.delete_if { |image| image.is_public } end def destroy(id) image = self.find_by_id(id) image.destroy end def method_missing(method_sym, *arguments, &block) if method_sym.to_s =~ /^find_by_(.*)$/ load(service.list_images($1.to_sym => arguments.first).body['images']) else super end end def find_by_size_min(size) find_attribute(__method__, size) end def find_by_size_max(size) find_attribute(__method__, size) end def find_attribute(attribute, value) attribute = attribute.to_s.gsub("find_by_", "") load(service.list_images(attribute.to_sym => value).body['images']) end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/metering/0000755000175600017570000000000012730051546021727 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/models/metering/resources.rb0000644000175600017570000000105612730051546024270 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/metering/resource' module Fog module Metering class OpenStack class Resources < Fog::OpenStack::Collection model Fog::Metering::OpenStack::Resource def all(detailed=true) load_response(service.list_resources) end def find_by_id(resource_id) resource = service.get_resource(resource_id).body new(resource) rescue Fog::Metering::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/metering/meters.rb0000644000175600017570000000000012730051546023541 0ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/models/metering/events.rb0000644000175600017570000000102112730051546023552 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/metering/event' module Fog module Metering class OpenStack class Events < Fog::OpenStack::Collection model Fog::Metering::OpenStack::Event def all(q=[]) load_response(service.list_events(q)) end def find_by_id(message_id) event = service.get_event(message_id).body new(event) rescue Fog::Metering::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/metering/event.rb0000644000175600017570000000044712730051546023402 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Metering class OpenStack class Event < Fog::OpenStack::Model identity :message_id attribute :event_type attribute :generated attribute :raw attribute :traits end end end end fog-openstack-0.1.6/lib/fog/openstack/models/metering/resource.rb0000644000175600017570000000042412730051546024103 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Metering class OpenStack class Resource < Fog::OpenStack::Model identity :resource_id attribute :project_id attribute :user_id attribute :metadata end end end end fog-openstack-0.1.6/lib/fog/openstack/models/metering/meter.rb0000644000175600017570000000000012730051546023356 0ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/models/planning/0000755000175600017570000000000012730051546021723 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/models/planning/plan.rb0000644000175600017570000000305512730051546023205 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Openstack class Planning class Plan < Fog::OpenStack::Model MASTER_TEMPLATE_NAME = 'plan.yaml' ENVIRONMENT_NAME = 'environment.yaml' identity :uuid attribute :description attribute :name attribute :uuid attribute :created_at attribute :updated_at attribute :parameters def templates service.get_plan_templates(uuid).body end def master_template templates[MASTER_TEMPLATE_NAME] end def environment templates[ENVIRONMENT_NAME] end def provider_resource_templates templates.select do |key, template| ![MASTER_TEMPLATE_NAME, ENVIRONMENT_NAME].include?(key) end end def patch(parameters) service.patch_plan(uuid, parameters[:parameters]).body end def add_role(role_uuid) service.add_role_to_plan(uuid, role_uuid) end def remove_role(role_uuid) service.remove_role_from_plan(uuid, role_uuid) end def destroy requires :uuid service.delete_plan(uuid) true end def create requires :name merge_attributes(service.create_plan(self.attributes).body) self end def update(parameters=nil) requires :uuid merge_attributes(service.patch_plan(uuid, parameters).body) self end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/planning/role.rb0000644000175600017570000000072512730051546023215 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Openstack class Planning class Role < Fog::OpenStack::Model identity :uuid attribute :description attribute :name attribute :uuid def add_to_plan(plan_uuid) service.add_role_to_plan(plan_uuid, uuid) end def remove_from_plan(plan_uuid) service.remove_role_from_plan(plan_uuid, uuid) end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/planning/plans.rb0000644000175600017570000000136612730051546023373 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/planning/plan' module Fog module Openstack class Planning class Plans < Fog::OpenStack::Collection model Fog::Openstack::Planning::Plan def all(options = {}) load_response(service.list_plans(options)) end def find_by_uuid(plan_uuid) new(service.get_plan(plan_uuid).body) end alias_method :get, :find_by_uuid def method_missing(method_sym, *arguments, &block) if method_sym.to_s =~ /^find_by_(.*)$/ self.all.find do |plan| plan.send($1) == arguments.first end else super end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/planning/roles.rb0000644000175600017570000000054112730051546023374 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/planning/role' module Fog module Openstack class Planning class Roles < Fog::OpenStack::Collection model Fog::Openstack::Planning::Role def all(options = {}) load_response(service.list_roles(options)) end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/orchestration/0000755000175600017570000000000012730051546023001 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/models/orchestration/resources.rb0000644000175600017570000000207312730051546025342 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/orchestration/resource' module Fog module Orchestration class OpenStack class Resources < Fog::OpenStack::Collection model Fog::Orchestration::OpenStack::Resource def types service.list_resource_types.body['resource_types'].sort end def all(options = {}, deprecated_options = {}) data = service.list_resources(options, deprecated_options) load_response(data, 'resources') end def get(resource_name, stack=nil) stack = self.first.stack if stack.nil? data = service.show_resource_data(stack.stack_name, stack.id, resource_name).body['resource'] new(data) rescue Fog::Compute::OpenStack::NotFound nil end def metadata(stack_name, stack_id, resource_name) service.show_resource_metadata(stack_name, stack_id, resource_name).body['resource'] rescue Fog::Compute::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/orchestration/template.rb0000644000175600017570000000045112730051546025141 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Orchestration class OpenStack class Template < Fog::OpenStack::Model %w{format description template_version parameters resources content}.each do |a| attribute a.to_sym end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/orchestration/templates.rb0000644000175600017570000000256012730051546025327 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/orchestration/template' module Fog module Orchestration class OpenStack class Templates < Fog::OpenStack::Collection model Fog::Orchestration::OpenStack::Template def get(obj) data = if obj.is_a?(Stack) service.get_stack_template(obj).body else service.show_resource_template(obj.resource_name).body end if data.has_key?('AWSTemplateFormatVersion') data['content'] = data.to_json data['format'] = 'CFN' data['template_version'] = data.delete('AWSTemplateFormatVersion') data['description'] = data.delete('Description') data['parameter'] = data.delete('Parameters') data['resources'] = data.delete('Resources') else data['content'] = data.to_yaml data['format'] = 'HOT' data['template_version'] = data.delete('heat_template_version') end new(data) rescue Fog::Compute::OpenStack::NotFound nil end def validate(options={}) data = service.validate_template(options).body temp = new temp.parameters = data['Parameters'] temp.description = data['Description'] temp end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/orchestration/events.rb0000644000175600017570000000166512730051546024642 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/orchestration/event' module Fog module Orchestration class OpenStack class Events < Fog::OpenStack::Collection model Fog::Orchestration::OpenStack::Event def all(options = {}, options_deprecated = {}) data = if options.is_a?(Stack) service.list_stack_events(options, options_deprecated) elsif options.is_a?(Hash) service.list_events(options) else service.list_resource_events(options.stack, options, options_deprecated) end load_response(data, 'events') end def get(stack, resource, event_id) data = service.show_event_details(stack, resource, event_id).body['event'] new(data) rescue Fog::Compute::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/orchestration/stacks.rb0000644000175600017570000000355712730051546024630 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/orchestration/stack' module Fog module Orchestration class OpenStack class Stacks < Fog::OpenStack::Collection model Fog::Orchestration::OpenStack::Stack def all(options = {}) # TODO(lsmola) we can uncomment this when https://bugs.launchpad.net/heat/+bug/1468318 is fixed, till then # we will use non detailed list # data = service.list_stack_data_detailed(options).body['stacks'] data = service.list_stack_data(options) load_response(data, 'stacks') end def summary(options = {}) data = service.list_stack_data(options) load_response(data, 'stacks') end # Deprecated def find_by_id(id) Fog::Logger.deprecation("#find_by_id(id) is deprecated, use #get(name, id) instead [light_black](#{caller.first})[/]") self.find {|stack| stack.id == id} end def get(arg1, arg2 = nil) if arg2.nil? # Deprecated: get(id) Fog::Logger.deprecation("#get(id) is deprecated, use #get(name, id) instead [light_black](#{caller.first})[/]") return find_by_id(arg1) end # Normal use: get(name, id) name = arg1 id = arg2 data = service.show_stack_details(name, id).body['stack'] new(data) rescue Fog::Compute::OpenStack::NotFound nil end def adopt(options={}) service.create_stack(options) end def create(options={}) service.create_stack(options).body['stack'] end def preview(options={}) data = service.preview_stack(options).body['stack'] new(data) end def build_info service.build_info.body end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/orchestration/event.rb0000644000175600017570000000062312730051546024450 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Orchestration class OpenStack class Event < Fog::OpenStack::Model include Reflectable identity :id %w{resource_name event_time links logical_resource_id resource_status resource_status_reason physical_resource_id}.each do |a| attribute a.to_sym end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/orchestration/resource.rb0000644000175600017570000000137512730051546025163 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Orchestration class OpenStack class Resource < Fog::OpenStack::Model include Reflectable identity :id %w{resource_name description links logical_resource_id physical_resource_id resource_status updated_time required_by resource_status_reason resource_type}.each do |a| attribute a.to_sym end def events(options={}) @events ||= service.events.all(self, options) end def metadata @metadata ||= service.show_resource_metadata(stack, self.resource_name).body['metadata'] end def template @template ||= service.templates.get(self) end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/orchestration/stack.rb0000644000175600017570000000737712730051546024451 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Orchestration class OpenStack class Stack < Fog::OpenStack::Model identity :id %w{capabilities description disable_rollback links notification_topics outputs parameters stack_name stack_status stack_status_reason template_description timeout_mins parent creation_time updated_time stack_user_project_id stack_owner}.each do |a| attribute a.to_sym end def save(options={}) if persisted? service.update_stack(self, default_options.merge(options)).body['stack'] else service.stacks.create(default_options.merge(options)) end end # Deprecated def create Fog::Logger.deprecation("#create is deprecated, use #save(options) instead [light_black](#{caller.first})[/]") requires :stack_name service.stacks.create(default_options) end # Deprecated def update Fog::Logger.deprecation("#update is deprecated, use #save(options) instead [light_black](#{caller.first})[/]") requires :stack_name service.update_stack(self, default_options).body['stack'] end def patch(options = {}) requires :stack_name service.patch_stack(self, options).body['stack'] end def delete service.delete_stack(self) end alias_method :destroy, :delete def details @details ||= service.stacks.get(self.stack_name, self.id) end def resources(options={}) @resources ||= service.resources.all({:stack => self}.merge(options)) end def events(options={}) @events ||= service.events.all(self, options) end def template @template ||= service.templates.get(self) end def abandon service.abandon_stack(self) end # Deprecated def template_url Fog::Logger.deprecation("#template_url is deprecated, use it in options for #save(options) instead [light_black](#{caller.first})[/]") @template_url end # Deprecated def template_url=(url) Fog::Logger.deprecation("#template_url= is deprecated, use it in options for #save(options) instead [light_black](#{caller.first})[/]") @template_url = url end # Deprecated def template=(content) Fog::Logger.deprecation("#template=(content) is deprecated, use it in options for #save(options) instead [light_black](#{caller.first})[/]") @template = content end # Deprecated def timeout_in_minutes Fog::Logger.deprecation("#timeout_in_minutes is deprecated, set timeout_mins in options for save(options) instead [light_black](#{caller.first})[/]") timeout_mins end # Deprecated def timeout_in_minutes=(minutes) Fog::Logger.deprecation("#timeout_in_minutes=(minutes) is deprecated, set timeout_mins in options for save(options) instead [light_black](#{caller.first})[/]") timeout_mins = minutes end # build options to create or update stack def default_options template_content = if template && template.is_a?(Fog::Orchestration::OpenStack::Template) template.content else template end { :stack_name => stack_name, :disable_rollback => disable_rollback, :template_url => @template_url, :template => template_content, :timeout_mins => timeout_mins } end private :default_options end end end end fog-openstack-0.1.6/lib/fog/openstack/models/orchestration/resource_schemas.rb0000644000175600017570000000053512730051546026663 0ustar pravipravirequire 'fog/openstack/models/collection' module Fog module Orchestration class OpenStack class ResourceSchemas < Fog::OpenStack::Collection def get(resource_type) service.show_resource_schema(resource_type).body rescue Fog::Compute::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/image_v1/0000755000175600017570000000000012730051546021605 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/models/image_v1/image.rb0000644000175600017570000000355012730051546023217 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Image class OpenStack class V1 class Image < Fog::OpenStack::Model identity :id attribute :name attribute :size attribute :disk_format attribute :container_format attribute :id attribute :checksum #detailed attribute :min_disk attribute :created_at attribute :deleted_at attribute :updated_at attribute :deleted attribute :protected attribute :is_public attribute :status attribute :min_ram attribute :owner attribute :properties attribute :location attribute :copy_from def create requires :name merge_attributes(service.create_image(self.attributes).body['image']) self end def update requires :name merge_attributes(service.update_image(self.attributes).body['image']) self end def destroy requires :id service.delete_image(self.id) true end def add_member(member_id) requires :id service.add_member_to_image(self.id, member_id) end def remove_member(member_id) requires :id service.remove_member_from_image(self.id, member_id) end def update_members(members) requires :id service.update_image_members(self.id, members) end def members requires :id service.get_image_members(self.id).body['members'] end def metadata requires :id service.get_image(self.id).headers end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/image_v1/images.rb0000644000175600017570000000415012730051546023377 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/image_v1/image' module Fog module Image class OpenStack class V1 class Images < Fog::OpenStack::Collection model Fog::Image::OpenStack::V1::Image def all(options = {}) load_response(service.list_public_images_detailed(options), 'images') end def summary(options = {}) load_response(service.list_public_images(options), 'images') end def details(options = {}, deprecated_query = nil) Fog::Logger.deprecation("Calling OpenStack[:glance].images.details will be removed, "\ " call .images.all for detailed list.") load_response(service.list_public_images_detailed(options, deprecated_query), 'images') end def find_by_id(id) all.find {|image| image.id == id} end alias_method :get, :find_by_id def public images = load(service.list_public_images_detailed.body['images']) images.delete_if{|image| image.is_public == false} end def private images = load(service.list_public_images_detailed.body['images']) images.delete_if{|image| image.is_public} end def destroy(id) image = self.find_by_id(id) image.destroy end def method_missing(method_sym, *arguments, &block) if method_sym.to_s =~ /^find_by_(.*)$/ load(service.list_public_images_detailed($1 ,arguments.first).body['images']) else super end end def find_by_size_min(size) find_attribute(__method__, size) end def find_by_size_max(size) find_attribute(__method__, size) end def find_attribute(attribute,value) attribute = attribute.to_s.gsub("find_by_", "") load(service.list_public_images_detailed(attribute , value).body['images']) end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/introspection/0000755000175600017570000000000012730051546023015 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/models/introspection/rules.rb0000644000175600017570000000115212730051546024473 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Introspection class OpenStack class Rules < Fog::OpenStack::Model identity :uuid attribute :description attribute :actions attribute :conditions attribute :links def create requires :actions, :conditions attributes[:description] = description || "" merge_attributes(service.create_rules(attributes).body) self end def destroy requires :uuid service.delete_rules(uuid) true end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/introspection/rules_collection.rb0000644000175600017570000000131212730051546026704 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/introspection/rules' module Fog module Introspection class OpenStack class RulesCollection < Fog::OpenStack::Collection model Fog::Introspection::OpenStack::Rules def all(_options = {}) load_response(service.list_rules, 'rules') end def get(uuid) data = service.get_rules(uuid).body new(data) rescue Fog::Introspection::OpenStack::NotFound nil end def destroy(uuid) rules = get(uuid) rules.destroy end def destroy_all service.delete_rules_all end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/identity_v3/0000755000175600017570000000000012730051546022356 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/models/identity_v3/projects.rb0000644000175600017570000000532612730051546024542 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/identity_v3/project' module Fog module Identity class OpenStack class V3 class Projects < Fog::OpenStack::Collection model Fog::Identity::OpenStack::V3::Project @@cache = {} Fog::Identity::OpenStack::V3::Project.use_cache(@@cache) def all(options = {}) if service.openstack_cache_ttl > 0 cached_project, expires = @@cache[{:token => service.auth_token, :options => options}] return cached_project if cached_project && expires > Time.now end project_to_cache = load_response(service.list_projects(options), 'projects') if service.openstack_cache_ttl > 0 @@cache[{:token => service.auth_token, :options => options}] = [project_to_cache, Time.now + service.openstack_cache_ttl] end return project_to_cache end def create(attributes) @@cache.clear if @@cache super(attributes) end def auth_projects(options = {}) load(service.auth_projects(options).body['projects']) end def find_by_id(id, options=[]) # options can include :subtree_as_ids, :subtree_as_list, :parents_as_ids, :parents_as_list if options.is_a? Symbol # Deal with a single option being passed on its own options = [options] end if service.openstack_cache_ttl > 0 cached_project, expires = @@cache[{:token => service.auth_token, :id => id, :options => options}] return cached_project if cached_project && expires > Time.now end project_hash = service.get_project(id, options).body['project'] top_project = project_from_hash(project_hash, service) if options.include? :subtree_as_list top_project.subtree.map! {|proj_hash| project_from_hash(proj_hash['project'], service)} end if options.include? :parents_as_list top_project.parents.map! {|proj_hash| project_from_hash(proj_hash['project'], service)} end if service.openstack_cache_ttl > 0 @@cache[{:token => service.auth_token, :id => id, :options => options}] = [ top_project, Time.now + service.openstack_cache_ttl] end return top_project end private def project_from_hash(project_hash, service) Fog::Identity::OpenStack::V3::Project.new(project_hash.merge(:service => service)) end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/identity_v3/policy.rb0000644000175600017570000000154512730051546024207 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Identity class OpenStack class V3 class Policy < Fog::OpenStack::Model identity :id attribute :type attribute :blob attribute :links def to_s self.name end def destroy requires :id service.delete_policy(self.id) true end def update(attr = nil) requires :id, :blob, :type merge_attributes( service.update_policy(self.id, attr || attributes).body['policy']) self end def create requires :blob, :type merge_attributes( service.create_policy(attributes).body['policy']) self end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/identity_v3/token.rb0000644000175600017570000000073312730051546024026 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Identity class OpenStack class V3 class Token < Fog::OpenStack::Model attribute :value attribute :catalog attribute :expires_at attribute :issued_at attribute :methods attribute :project attribute :roles attribute :user def to_s self.value end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/identity_v3/tokens.rb0000644000175600017570000000225512730051546024212 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/identity_v3/service' module Fog module Identity class OpenStack class V3 class Tokens < Fog::OpenStack::Collection model Fog::Identity::OpenStack::V3::Token def authenticate(auth) @@cache ||= {} response = service.token_authenticate(auth) token_hash = response.body['token'] Fog::Identity::OpenStack::V3::Token.new( token_hash.merge(:service => service, :value => response.headers['X-Subject-Token'])) end def validate(subject_token) response = service.token_validate(subject_token) token_hash = response.body['token'] Fog::Identity::OpenStack::V3::Token.new( token_hash.merge(:service => service, :value => response.headers['X-Subject-Token'])) end def check(subject_token) service.token_check(subject_token) return true end def revoke(subject_token) service.token_revoke(subject_token) return true end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/identity_v3/group.rb0000644000175600017570000000445412730051546024046 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Identity class OpenStack class V3 class Group < Fog::OpenStack::Model identity :id attribute :description attribute :domain_id attribute :name attribute :links def to_s self.name end def destroy requires :id service.delete_group(self.id) true end def update(attr = nil) requires :id, :name merge_attributes( service.update_group(self.id, attr || attributes).body['group']) self end def create requires :name merge_attributes( service.create_group(attributes).body['group']) self end def add_user user_id requires :id service.add_user_to_group(self.id, user_id) end def remove_user user_id requires :id service.remove_user_from_group(self.id, user_id) end def contains_user? user_id requires :id begin service.group_user_check(self.id, user_id) rescue Fog::Identity::OpenStack::NotFound return false end return true end def roles requires :id, :domain_id service.list_domain_group_roles(self.domain_id, self.id).body['roles'] end def grant_role(role_id) requires :id, :domain_id service.grant_domain_group_role(self.domain_id, self.id, role_id) end def check_role(role_id) requires :id, :domain_id begin service.check_domain_group_role(self.domain_id, self.id, role_id) rescue Fog::Identity::OpenStack::NotFound return false end return true end def revoke_role(role_id) requires :id, :domain_id service.revoke_domain_group_role(self.domain_id, self.id, role_id) end def users(attr = {}) requires :id service.list_group_users(self.id, attr).body['users'] end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/identity_v3/domain.rb0000644000175600017570000000207012730051546024151 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Identity class OpenStack class V3 class Domain < Fog::OpenStack::Model identity :id attribute :description attribute :enabled attribute :name attribute :links def to_s self.name end def destroy @@cache.clear if @@cache requires :id service.delete_domain(self.id) true end def update(attr = nil) @@cache.clear if @@cache requires :id, :name merge_attributes( service.update_domain(self.id, attr || attributes).body['domain']) self end def create @@cache.clear if @@cache requires :name merge_attributes( service.create_domain(attributes).body['domain']) self end def self.use_cache(cache) @@cache = cache end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/identity_v3/role_assignment.rb0000644000175600017570000000062012730051546026072 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Identity class OpenStack class V3 class RoleAssignment < Fog::OpenStack::Model attribute :scope attribute :role attribute :user attribute :group attribute :links def to_s self.links['assignment'] end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/identity_v3/users.rb0000644000175600017570000000171312730051546024046 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/identity_v3/domain' module Fog module Identity class OpenStack class V3 class Users < Fog::OpenStack::Collection model Fog::Identity::OpenStack::V3::User def all(options = {}) load_response(service.list_users(options), 'users') end def find_by_id(id) cached_user = self.find { |user| user.id == id } return cached_user if cached_user user_hash = service.get_user(id).body['user'] Fog::Identity::OpenStack::V3::User.new( user_hash.merge(:service => service)) end def find_by_name(name, options = {}) load(service.list_users(options.merge(:name => name)).body["users"]) end def destroy(id) user = self.find_by_id(id) user.destroy end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/identity_v3/role_assignments.rb0000644000175600017570000000153412730051546026262 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/identity_v3/role' module Fog module Identity class OpenStack class V3 class RoleAssignments < Fog::OpenStack::Collection model Fog::Identity::OpenStack::V3::RoleAssignment def all(options = {}) load_response(service.list_role_assignments(options), 'role_assignments') end def filter_by(options = {}) Fog::Logger.deprecation("Calling OpenStack[:keystone].role_assignments.filter_by(options) method which"\ " is not part of standard interface and is deprecated, call "\ " .role_assignments.all(options) or .role_assignments.summary(options) instead.") all(options) end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/identity_v3/endpoint.rb0000644000175600017570000000173612730051546024532 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Identity class OpenStack class V3 class Endpoint < Fog::OpenStack::Model identity :id attribute :description attribute :interface attribute :service_id attribute :name attribute :region attribute :url attribute :links def to_s self.name end def destroy requires :id service.delete_endpoint(self.id) true end def update(attr = nil) requires :id, :name merge_attributes( service.update_endpoint(self.id, attr || attributes).body['endpoint']) self end def create requires :name merge_attributes( service.create_endpoint(attributes).body['endpoint']) self end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/identity_v3/service.rb0000644000175600017570000000170012730051546024341 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Identity class OpenStack class V3 class Service < Fog::OpenStack::Model identity :id attribute :description attribute :type attribute :name attribute :links def to_s self.name end def destroy requires :id service.delete_service(self.id) true end def update(attr = nil) requires :id merge_attributes( service.update_service(self.id, attr || attributes).body['service']) self end def save requires :name identity ? update : create end def create merge_attributes( service.create_service(attributes).body['service']) self end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/identity_v3/user.rb0000644000175600017570000000373112730051546023665 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Identity class OpenStack class V3 class User < Fog::OpenStack::Model identity :id attribute :default_project_id attribute :description attribute :domain_id attribute :email attribute :enabled attribute :name attribute :links attribute :password def to_s self.name end def groups requires :id service.list_user_groups(self.id).body['groups'] end def projects requires :id service.list_user_projects(self.id).body['projects'] end def roles requires :id, :domain_id service.list_domain_user_roles(self.domain_id, self.id).body['roles'] end def grant_role(role_id) requires :id, :domain_id service.grant_domain_user_role(self.domain_id, self.id, role_id) end def check_role(role_id) requires :id, :domain_id begin service.check_domain_user_role(self.domain_id, self.id, role_id) rescue Fog::Identity::OpenStack::NotFound return false end return true end def revoke_role(role_id) requires :id, :domain_id service.revoke_domain_user_role(self.domain_id, self.id, role_id) end def destroy requires :id service.delete_user(self.id) true end def update(attr = nil) requires :id merge_attributes( service.update_user(self.id, attr || attributes).body['user']) self end def create merge_attributes( service.create_user(attributes).body['user']) self end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/identity_v3/role.rb0000644000175600017570000000141712730051546023647 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Identity class OpenStack class V3 class Role < Fog::OpenStack::Model identity :id attribute :name attribute :links def to_s self.name end def destroy requires :id service.delete_role(self.id) true end def update(attr = nil) requires :id merge_attributes( service.update_role(self.id, attr || attributes).body['role']) self end def create merge_attributes( service.create_role(attributes).body['role']) self end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/identity_v3/endpoints.rb0000644000175600017570000000141412730051546024706 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/identity_v3/service' module Fog module Identity class OpenStack class V3 class Endpoints < Fog::OpenStack::Collection model Fog::Identity::OpenStack::V3::Endpoint def all(options = {}) load_response(service.list_endpoints(options), 'endpoints') end def find_by_id(id) cached_endpoint = self.find { |endpoint| endpoint.id == id } return cached_endpoint if cached_endpoint endpoint_hash = service.get_endpoint(id).body['endpoint'] Fog::Identity::OpenStack::V3::Endpoint.new( endpoint_hash.merge(:service => service)) end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/identity_v3/policies.rb0000644000175600017570000000153712730051546024520 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/identity_v3/policy' module Fog module Identity class OpenStack class V3 class Policies < Fog::OpenStack::Collection model Fog::Identity::OpenStack::V3::Policy def all(options = {}) load_response(service.list_policies(options), 'policies') end def find_by_id(id) cached_policy = self.find { |policy| policy.id == id } return cached_policy if cached_policy policy_hash = service.get_policy(id).body['policy'] Fog::Identity::OpenStack::V3::Policy.new( policy_hash.merge(:service => service)) end def destroy(id) policy = self.find_by_id(id) policy.destroy end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/identity_v3/os_credentials.rb0000644000175600017570000000165512730051546025710 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/identity_v3/os_credential' module Fog module Identity class OpenStack class V3 class OsCredentials < Fog::OpenStack::Collection model Fog::Identity::OpenStack::V3::OsCredential def all(options = {}) load_response(service.list_os_credentials(options), 'credentials') end def find_by_id(id) cached_credential = self.find { |credential| credential.id == id } return cached_credential if cached_credential credential_hash = service.get_os_credential(id).body['credential'] Fog::Identity::OpenStack::V3::Credential.new( credential_hash.merge(:service => service)) end def destroy(id) credential = self.find_by_id(id) credential.destroy end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/identity_v3/services.rb0000644000175600017570000000155512730051546024534 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/identity_v3/service' module Fog module Identity class OpenStack class V3 class Services < Fog::OpenStack::Collection model Fog::Identity::OpenStack::V3::Service def all(options = {}) load_response(service.list_services(options), 'services') end def find_by_id(id) cached_service = self.find { |service| service.id == id } return cached_service if cached_service service_hash = service.get_service(id).body['service'] Fog::Identity::OpenStack::V3::Service.new( service_hash.merge(:service => service)) end def destroy(id) service = self.find_by_id(id) service.destroy end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/identity_v3/os_credential.rb0000644000175600017570000000312012730051546025512 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Identity class OpenStack class V3 class OsCredential < Fog::OpenStack::Model identity :id attribute :project_id attribute :type attribute :blob attribute :user_id attribute :links def to_s self.name end def destroy requires :id service.delete_os_credential(self.id) @parsed_blob = nil true end def update(attr = nil) requires :id merge_attributes( service.update_os_credential(self.id, attr || attributes).body['credential']) @parsed_blob = nil self end def save requires :blob, :type @parsed_blob = nil identity ? update : create end def create merge_attributes( service.create_os_credential(attributes).body['credential']) @parsed_blob = nil self end def parsed_blob @parsed_blob = ::JSON.parse(blob) unless @parsed_blob @parsed_blob end def name parsed_blob['name'] if blob end def public_key parsed_blob['public_key'] if blob end def fingerprint parsed_blob['fingerprint'] if blob end def private_key parsed_blob['private_key'] if blob end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/identity_v3/groups.rb0000644000175600017570000000151312730051546024222 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/identity_v3/group' module Fog module Identity class OpenStack class V3 class Groups < Fog::OpenStack::Collection model Fog::Identity::OpenStack::V3::Group def all(options = {}) load_response(service.list_groups(options), 'groups') end def find_by_id(id) cached_group = self.find { |group| group.id == id } return cached_group if cached_group group_hash = service.get_group(id).body['group'] Fog::Identity::OpenStack::V3::group.new( group_hash.merge(:service => service)) end def destroy(id) group = self.find_by_id(id) group.destroy end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/identity_v3/domains.rb0000644000175600017570000000332712730051546024342 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/identity_v3/domain' module Fog module Identity class OpenStack class V3 class Domains < Fog::OpenStack::Collection model Fog::Identity::OpenStack::V3::Domain @@cache = {} Fog::Identity::OpenStack::V3::Domain.use_cache(@@cache) def all(options = {}) cached_domain, expires = @@cache[{token: service.auth_token, options: options}] return cached_domain if cached_domain && expires > Time.now domain_to_cache = load_response(service.list_domains(options), 'domains') @@cache[{token: service.auth_token, options: options}] = domain_to_cache, Time.now + 30 # 30-second TTL return domain_to_cache end def create(attributes) @@cache.clear if @@cache super(attributes) end def auth_domains(options = {}) load(service.auth_domains(options).body['domains']) end def find_by_id(id) cached_domain, expires = @@cache[{token: service.auth_token, id: id}] return cached_domain if cached_domain && expires > Time.now domain_hash = service.get_domain(id).body['domain'] domain_to_cache = Fog::Identity::OpenStack::V3::Domain.new( domain_hash.merge(:service => service)) @@cache[{token: service.auth_token, id: id}] = domain_to_cache, Time.now + 30 # 30-second TTL return domain_to_cache end def destroy(id) @@cache.clear if @@cache domain = self.find_by_id(id) domain.destroy end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/identity_v3/roles.rb0000644000175600017570000000252612730051546024034 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/identity_v3/role' module Fog module Identity class OpenStack class V3 class Roles < Fog::OpenStack::Collection model Fog::Identity::OpenStack::V3::Role def all(options = {}) load_response(service.list_roles(options), 'roles') end def assignments(options = {}) # TODO(lsmola) this method doesn't make much sense, it should be moved to role.rb and automatically add # role.id filter. Otherwise it's just duplication. Fog::Logger.deprecation("Calling OpenStack[:keystone].roles.assignments(options) method which"\ " deprecated, call OpenStack[:keystone].role_assignments.all(options) instead") load(service.list_role_assignments(options).body['role_assignments']) end def find_by_id(id) cached_role = self.find { |role| role.id == id } return cached_role if cached_role role_hash = service.get_role(id).body['role'] Fog::Identity::OpenStack::V3::role.new( role_hash.merge(:service => service)) end def destroy(id) role = self.find_by_id(id) role.destroy end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/identity_v3/project.rb0000644000175600017570000000551412730051546024356 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Identity class OpenStack class V3 class Project < Fog::OpenStack::Model identity :id attribute :domain_id attribute :description attribute :enabled attribute :name attribute :links attribute :parent_id attribute :subtree attribute :parents def to_s self.name end def destroy @@cache.clear if @@cache requires :id service.delete_project(self.id) true end def update(attr = nil) @@cache.clear if @@cache requires :id merge_attributes( service.update_project(self.id, attr || attributes).body['project']) self end def create @@cache.clear if @@cache merge_attributes( service.create_project(attributes).body['project']) self end def user_roles(user_id) requires :id service.list_project_user_roles(self.id, user_id).body['roles'] end def grant_role_to_user(role_id, user_id) @@cache.clear if @@cache requires :id service.grant_project_user_role(self.id, user_id, role_id) end def check_user_role(user_id, role_id) requires :id begin service.check_project_user_role(self.id, user_id, role_id) rescue Fog::Identity::OpenStack::NotFound return false end return true end def revoke_role_from_user(role_id, user_id) @@cache.clear if @@cache requires :id service.revoke_project_user_role(self.id, user_id, role_id) end def group_roles(group_id) requires :id service.list_project_group_roles(self.id, group_id).body['roles'] end def grant_role_to_group(role_id, group_id) @@cache.clear if @@cache requires :id service.grant_project_group_role(self.id, group_id, role_id) end def check_group_role(group_id, role_id) requires :id begin service.check_project_group_role(self.id, group_id, role_id) rescue Fog::Identity::OpenStack::NotFound return false end return true end def revoke_role_from_group(role_id, group_id) @@cache.clear if @@cache requires :id service.revoke_project_group_role(self.id, group_id, role_id) end def self.use_cache(cache) @@cache = cache end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/nfv/0000755000175600017570000000000012730051546020706 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/models/nfv/vnfds.rb0000644000175600017570000000113312730051546022351 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/nfv/vnfd' module Fog module NFV class OpenStack class Vnfds < Fog::OpenStack::Collection model Fog::NFV::OpenStack::Vnfd def all(options = {}) load_response(service.list_vnfds(options), 'vnfds') end def get(uuid) data = service.get_vnfd(uuid).body['vnfd'] new(data) rescue Fog::NFV::OpenStack::NotFound nil end def destroy(uuid) vnfd = get(uuid) vnfd.destroy end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/nfv/vnfd.rb0000644000175600017570000000222212730051546022166 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module NFV class OpenStack class Vnfd < Fog::OpenStack::Model identity :id attribute :service_types attribute :description attribute :tenant_id attribute :mgmt_driver attribute :infra_driver attribute :name attribute :vnf_attributes # Attributes for create attribute :vnfd attribute :auth def create(options = {}) merge_attributes(service.create_vnfd(default_options.merge(options)).body['vnfd']) self end def update(_options = {}) raise Fog::OpenStack::Errors::InterfaceNotImplemented.new("Method 'update' is not supported") end def save(options = {}) identity ? update(options) : create(options) end def destroy requires :id service.delete_vnfd(id) true end def default_options { :vnfd => vnfd, :auth => auth } end def vnf_attributes attributes['attributes'] end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/nfv/vnf.rb0000644000175600017570000000232412730051546022025 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module NFV class OpenStack class Vnf < Fog::OpenStack::Model identity :id attribute :status attribute :name attribute :tenant_id attribute :instance_id attribute :mgmt_url attribute :description attribute :vnf_attributes # Attributes for create and update attribute :vnf attribute :auth def create(options = {}) merge_attributes(service.create_vnf(default_options.merge(options)).body['vnf']) self end def update(options = {}) merge_attributes(service.update_vnf(identity, default_options.merge(options)).body['vnf']) self end def save(options = {}) identity ? update(options) : create(options) end def destroy requires :id service.delete_vnf(id) true end def default_options { :vnf => vnf, :auth => auth } end def vnf_attributes attributes['attributes'] end def ready? status == 'ACTIVE' end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/nfv/vnfs.rb0000644000175600017570000000112212730051546022203 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/nfv/vnf' module Fog module NFV class OpenStack class Vnfs < Fog::OpenStack::Collection model Fog::NFV::OpenStack::Vnf def all(options = {}) load_response(service.list_vnfs(options), 'vnfs') end def get(uuid) data = service.get_vnf(uuid).body['vnf'] new(data) rescue Fog::NFV::OpenStack::NotFound nil end def destroy(uuid) vnf = get(uuid) vnf.destroy end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/network/0000755000175600017570000000000012730051546021606 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/models/network/network.rb0000644000175600017570000000223312730051546023624 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Network class OpenStack class Network < Fog::OpenStack::Model identity :id attribute :name attribute :subnets attribute :shared attribute :status attribute :admin_state_up attribute :tenant_id attribute :provider_network_type, :aliases => 'provider:network_type' attribute :provider_physical_network, :aliases => 'provider:physical_network' attribute :provider_segmentation_id, :aliases => 'provider:segmentation_id' attribute :router_external, :aliases => 'router:external' def subnets service.subnets.select {|s| s.network_id == self.id } end def create merge_attributes(service.create_network(self.attributes).body['network']) self end def update requires :id merge_attributes(service.update_network(self.id, self.attributes).body['network']) self end def destroy requires :id service.delete_network(self.id) true end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/network/lb_pool.rb0000644000175600017570000000352712730051546023570 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Network class OpenStack class LbPool < Fog::OpenStack::Model identity :id attribute :subnet_id attribute :protocol attribute :lb_method attribute :name attribute :description attribute :health_monitors attribute :members attribute :status attribute :admin_state_up attribute :vip_id attribute :tenant_id attribute :active_connections attribute :bytes_in attribute :bytes_out attribute :total_connections def create requires :subnet_id, :protocol, :lb_method merge_attributes(service.create_lb_pool(self.subnet_id, self.protocol, self.lb_method, self.attributes).body['pool']) self end def update requires :id, :subnet_id, :protocol, :lb_method merge_attributes(service.update_lb_pool(self.id, self.attributes).body['pool']) self end def destroy requires :id service.delete_lb_pool(self.id) true end def stats requires :id merge_attributes(service.get_lb_pool_stats(self.id).body['stats']) self end def associate_health_monitor(health_monitor_id) requires :id service.associate_lb_health_monitor(self.id, health_monitor_id) true end def disassociate_health_monitor(health_monitor_id) requires :id service.disassociate_lb_health_monitor(self.id, health_monitor_id) true end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/network/router.rb0000644000175600017570000000313512730051546023455 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Network class OpenStack # The Layer-3 Networking Extensions (router) # # A logical entity for forwarding packets across internal # subnets and NATting them on external networks through # an appropriate external gateway. # # @see http://docs.openstack.org/api/openstack-network/2.0/content/router_ext.html class Router < Fog::OpenStack::Model identity :id attribute :name attribute :admin_state_up attribute :tenant_id attribute :external_gateway_info attribute :status def create requires :name response = service.create_router(self.name, options) merge_attributes(response.body['router']) self end def update requires :id response = service.update_router(self.id, options) merge_attributes(response.body['router']) self end def destroy requires :id service.delete_router(self.id) true end private def options options = self.attributes.dup if options[:external_gateway_info] if options[:external_gateway_info].is_a?(Fog::Network::OpenStack::Network) options[:external_gateway_info] = { :network_id => options[:external_gateway_info].id } else options[:external_gateway_info] = { :network_id => options[:external_gateway_info]} end end options end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/network/ipsec_policy.rb0000644000175600017570000000233512730051546024620 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Network class OpenStack class IpsecPolicy < Fog::OpenStack::Model identity :id attribute :name attribute :description attribute :status attribute :admin_state_up attribute :tenant_id attribute :auth_algorithm attribute :encryption_algorithm attribute :pfs attribute :transform_protocol attribute :encapsulation_mode attribute :lifetime def create requires :name, :auth_algorithm, :encryption_algorithm, :lifetime, :pfs, :transform_protocol, :encapsulation_mode merge_attributes(service.create_ipsec_policy(attributes).body['ipsecpolicy']) self end def update requires :id, :name, :auth_algorithm, :encryption_algorithm, :lifetime, :pfs, :transform_protocol, :encapsulation_mode merge_attributes(service.update_ipsec_policy(id, attributes).body['ipsecpolicy']) self end def destroy requires :id service.delete_ipsec_policy(id) true end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/network/lb_member.rb0000644000175600017570000000230712730051546024061 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Network class OpenStack class LbMember < Fog::OpenStack::Model identity :id attribute :pool_id attribute :address attribute :protocol_port attribute :weight attribute :status attribute :admin_state_up attribute :tenant_id def create requires :pool_id, :address, :protocol_port, :weight merge_attributes(service.create_lb_member(self.pool_id, self.address, self.protocol_port, self.weight, self.attributes).body['member']) self end def update requires :id, :pool_id, :address, :protocol_port, :weight merge_attributes(service.update_lb_member(self.id, self.attributes).body['member']) self end def destroy requires :id service.delete_lb_member(self.id) true end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/network/ipsec_site_connections.rb0000644000175600017570000000160412730051546026665 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/network/ipsec_site_connection' module Fog module Network class OpenStack class IpsecSiteConnections < Fog::OpenStack::Collection attribute :filters model Fog::Network::OpenStack::IpsecSiteConnection def initialize(attributes) self.filters ||= {} super end def all(filters_arg = filters) filters = filters_arg load_response(service.list_ipsec_site_connections(filters), 'ipsec_site_connections') end def get(ipsec_site_connection_id) connection = service.get_ipsec_site_connection(ipsec_site_connection_id).body['ipsec_site_connection'] if connection new(connection) end rescue Fog::Network::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/network/lb_members.rb0000644000175600017570000000136112730051546024243 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/network/lb_member' module Fog module Network class OpenStack class LbMembers < Fog::OpenStack::Collection attribute :filters model Fog::Network::OpenStack::LbMember def initialize(attributes) self.filters ||= {} super end def all(filters_arg = filters) filters = filters_arg load_response(service.list_lb_members(filters), 'members') end def get(member_id) if member = service.get_lb_member(member_id).body['member'] new(member) end rescue Fog::Network::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/network/lb_health_monitor.rb0000644000175600017570000000323712730051546025631 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Network class OpenStack class LbHealthMonitor < Fog::OpenStack::Model identity :id attribute :type attribute :delay attribute :timeout attribute :max_retries attribute :http_method attribute :url_path attribute :expected_codes attribute :status attribute :admin_state_up attribute :tenant_id def create requires :type, :delay, :timeout, :max_retries merge_attributes(service.create_lb_health_monitor(self.type, self.delay, self.timeout, self.max_retries, self.attributes).body['health_monitor']) self end def update requires :id, :type, :delay, :timeout, :max_retries merge_attributes(service.update_lb_health_monitor(self.id, self.attributes).body['health_monitor']) self end def destroy requires :id service.delete_lb_health_monitor(self.id) true end def associate_to_pool(pool_id) requires :id service.associate_lb_health_monitor(pool_id, self.id) true end def disassociate_from_pool(pool_id) requires :id service.disassociate_lb_health_monitor(pool_id, self.id) true end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/network/lb_vip.rb0000644000175600017570000000255612730051546023416 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Network class OpenStack class LbVip < Fog::OpenStack::Model identity :id attribute :subnet_id attribute :pool_id attribute :protocol attribute :protocol_port attribute :name attribute :description attribute :address attribute :port_id attribute :session_persistence attribute :connection_limit attribute :status attribute :admin_state_up attribute :tenant_id def create requires :subnet_id, :pool_id, :protocol, :protocol_port merge_attributes(service.create_lb_vip(self.subnet_id, self.pool_id, self.protocol, self.protocol_port, self.attributes).body['vip']) self end def update requires :id, :subnet_id, :pool_id, :protocol, :protocol_port merge_attributes(service.update_lb_vip(self.id, self.attributes).body['vip']) self end def destroy requires :id service.delete_lb_vip(self.id) true end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/network/ipsec_site_connection.rb0000644000175600017570000000314212730051546026501 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Network class OpenStack class IpsecSiteConnection < Fog::OpenStack::Model identity :id attribute :name attribute :description attribute :status attribute :admin_state_up attribute :tenant_id attribute :vpnservice_id attribute :ikepolicy_id attribute :ipsecpolicy_id attribute :peer_address attribute :peer_id attribute :peer_cidrs attribute :psk attribute :mtu attribute :dpd attribute :initiator def create requires :name, :vpnservice_id, :ikepolicy_id, :ipsecpolicy_id, :peer_address, :peer_id, :peer_cidrs, :psk merge_attributes(service.create_ipsec_site_connection(vpnservice_id, ikepolicy_id, ipsecpolicy_id, attributes).body['ipsec_site_connection']) self end def update requires :id, :name, :vpnservice_id, :ikepolicy_id, :ipsecpolicy_id, :peer_address, :peer_id, :peer_cidrs, :psk merge_attributes(service.update_ipsec_site_connection(id, attributes).body['ipsec_site_connection']) self end def destroy requires :id service.delete_ipsec_site_connection(id) true end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/network/subnets.rb0000644000175600017570000000134412730051546023620 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/network/subnet' module Fog module Network class OpenStack class Subnets < Fog::OpenStack::Collection attribute :filters model Fog::Network::OpenStack::Subnet def initialize(attributes) self.filters ||= {} super end def all(filters_arg = filters) filters = filters_arg load_response(service.list_subnets(filters), 'subnets') end def get(subnet_id) if subnet = service.get_subnet(subnet_id).body['subnet'] new(subnet) end rescue Fog::Network::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/network/port.rb0000644000175600017570000000200512730051546023114 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Network class OpenStack class Port < Fog::OpenStack::Model identity :id attribute :name attribute :network_id attribute :fixed_ips attribute :mac_address attribute :status attribute :admin_state_up attribute :device_owner attribute :device_id attribute :tenant_id attribute :security_groups def create requires :network_id merge_attributes(service.create_port(self.network_id, self.attributes).body['port']) self end def update requires :id, :network_id merge_attributes(service.update_port(self.id, self.attributes).body['port']) self end def destroy requires :id service.delete_port(self.id) true end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/network/ports.rb0000644000175600017570000000131612730051546023303 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/network/port' module Fog module Network class OpenStack class Ports < Fog::OpenStack::Collection attribute :filters model Fog::Network::OpenStack::Port def initialize(attributes) self.filters ||= {} super end def all(filters_arg = filters) filters = filters_arg load_response(service.list_ports(filters), 'ports') end def get(port_id) if port = service.get_port(port_id).body['port'] new(port) end rescue Fog::Network::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/network/security_group_rule.rb0000644000175600017570000000156612730051546026255 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Network class OpenStack class SecurityGroupRule < Fog::OpenStack::Model identity :id attribute :security_group_id attribute :direction attribute :protocol attribute :port_range_min attribute :port_range_max attribute :remote_ip_prefix attribute :ethertype attribute :remote_group_id attribute :tenant_id def destroy requires :id service.delete_security_group_rule(id) true end def save raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted? merge_attributes(service.create_security_group_rule(security_group_id, direction, attributes).body['security_group_rule']) true end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/network/vpn_service.rb0000644000175600017570000000220412730051546024454 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Network class OpenStack class VpnService < Fog::OpenStack::Model identity :id attribute :subnet_id attribute :router_id attribute :name attribute :description attribute :status attribute :admin_state_up attribute :tenant_id attribute :external_v4_ip attribute :external_v6_ip def create requires :subnet_id, :router_id, :name, :admin_state_up merge_attributes(service.create_vpn_service(subnet_id, router_id, attributes).body['vpnservice']) self end def update requires :id, :subnet_id, :router_id, :name, :admin_state_up merge_attributes(service.update_vpn_service(id, attributes).body['vpnservice']) self end def destroy requires :id service.delete_vpn_service(id) true end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/network/networks.rb0000644000175600017570000000135712730051546024015 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/network/network' module Fog module Network class OpenStack class Networks < Fog::OpenStack::Collection attribute :filters model Fog::Network::OpenStack::Network def initialize(attributes) self.filters ||= {} super end def all(filters_arg = filters) filters = filters_arg load_response(service.list_networks(filters), 'networks') end def get(network_id) if network = service.get_network(network_id).body['network'] new(network) end rescue Fog::Network::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/network/ike_policy.rb0000644000175600017570000000224512730051546024265 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Network class OpenStack class IkePolicy < Fog::OpenStack::Model identity :id attribute :name attribute :description attribute :status attribute :admin_state_up attribute :tenant_id attribute :auth_algorithm attribute :encryption_algorithm attribute :pfs attribute :phase1_negotiation_mode attribute :lifetime attribute :ike_version def create requires :name, :auth_algorithm, :encryption_algorithm, :ike_version, :lifetime, :pfs, :phase1_negotiation_mode merge_attributes(service.create_ike_policy(attributes).body['ikepolicy']) self end def update requires :id, :name, :auth_algorithm, :encryption_algorithm, :ike_version, :lifetime, :pfs, :phase1_negotiation_mode merge_attributes(service.update_ike_policy(id, attributes).body['ikepolicy']) self end def destroy requires :id service.delete_ike_policy(id) true end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/network/floating_ip.rb0000644000175600017570000000274712730051546024440 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Network class OpenStack class FloatingIp < Fog::OpenStack::Model identity :id attribute :floating_network_id attribute :port_id attribute :tenant_id attribute :router_id attribute :fixed_ip_address attribute :floating_ip_address def initialize(attributes) @connection = attributes[:connection] super end def create requires :floating_network_id merge_attributes(service.create_floating_ip(floating_network_id, attributes).body['floatingip']) self end def update self end def destroy requires :id service.delete_floating_ip(id) true end def associate(port_id, fixed_ip_address = nil) requires :id merge_attributes(service.associate_floating_ip( id, port_id, options(fixed_ip_address)).body['floatingip']) end def disassociate(fixed_ip_address = nil) requires :id merge_attributes(service.disassociate_floating_ip( id, options(fixed_ip_address)).body['floatingip']) end private def options(fixed_ip_address) fixed_ip_address ? {'fixed_ip_address' => fixed_ip_address} : {} end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/network/vpn_services.rb0000644000175600017570000000142712730051546024645 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/network/vpn_service' module Fog module Network class OpenStack class VpnServices < Fog::OpenStack::Collection attribute :filters model Fog::Network::OpenStack::VpnService def initialize(attributes) self.filters ||= {} super end def all(filters_arg = filters) filters = filters_arg load_response(service.list_vpn_services(filters), 'vpnservices') end def get(vpn_service_id) if vpn_service = service.get_vpn_service(vpn_service_id).body['vpnservice'] new(vpn_service) end rescue Fog::Network::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/network/lb_pools.rb0000644000175600017570000000133312730051546023744 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/network/lb_pool' module Fog module Network class OpenStack class LbPools < Fog::OpenStack::Collection attribute :filters model Fog::Network::OpenStack::LbPool def initialize(attributes) self.filters ||= {} super end def all(filters_arg = filters) filters = filters_arg load_response(service.list_lb_pools(filters), 'pools') end def get(pool_id) if pool = service.get_lb_pool(pool_id).body['pool'] new(pool) end rescue Fog::Network::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/network/floating_ips.rb0000644000175600017570000000144112730051546024611 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/network/floating_ip' module Fog module Network class OpenStack class FloatingIps < Fog::OpenStack::Collection attribute :filters model Fog::Network::OpenStack::FloatingIp def initialize(attributes) self.filters ||= {} super end def all(filters_arg = filters) filters = filters_arg load_response(service.list_floating_ips(filters), 'floatingips') end def get(floating_network_id) if floating_ip = service.get_floating_ip(floating_network_id).body['floatingip'] new(floating_ip) end rescue Fog::Network::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/network/security_group_rules.rb0000644000175600017570000000153312730051546026432 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/network/security_group_rule' module Fog module Network class OpenStack class SecurityGroupRules < Fog::OpenStack::Collection attribute :filters model Fog::Network::OpenStack::SecurityGroupRule def initialize(attributes) self.filters ||= {} super end def all(filters_arg = filters) filters = filters_arg load_response(service.list_security_group_rules(filters), 'security_group_rules') end def get(sec_group_rule_id) if sec_group_rule = service.get_security_group_rule(sec_group_rule_id).body['security_group_rule'] new(sec_group_rule) end rescue Fog::Network::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/network/lb_vips.rb0000644000175600017570000000132012730051546023565 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/network/lb_vip' module Fog module Network class OpenStack class LbVips < Fog::OpenStack::Collection attribute :filters model Fog::Network::OpenStack::LbVip def initialize(attributes) self.filters ||= {} super end def all(filters_arg = filters) filters = filters_arg load_response(service.list_lb_vips(filters), 'vips') end def get(vip_id) if vip = service.get_lb_vip(vip_id).body['vip'] new(vip) end rescue Fog::Network::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/network/security_groups.rb0000644000175600017570000000147212730051546025405 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/network/security_group' module Fog module Network class OpenStack class SecurityGroups < Fog::OpenStack::Collection attribute :filters model Fog::Network::OpenStack::SecurityGroup def initialize(attributes) self.filters ||= {} super end def all(filters_arg = filters) filters = filters_arg load_response(service.list_security_groups(filters), 'security_groups') end def get(security_group_id) if security_group = service.get_security_group(security_group_id).body['security_group'] new(security_group) end rescue Fog::Network::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/network/rbac_policies.rb0000644000175600017570000000150312730051546024730 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/network/rbac_policy' module Fog module Network class OpenStack class RbacPolicies < Fog::OpenStack::Collection attribute :filters model Fog::Network::OpenStack::RbacPolicy def initialize(attributes) self.filters ||= {} super end def all(filters_arg = filters) filters = filters_arg load_response(service.list_rbac_policies(filters), 'rbac_policies') end def get(rbac_policy_id) if rbac_policy = service.get_rbac_policy(rbac_policy_id).body['rbac_policy'] new(rbac_policy) end rescue Fog::Network::OpenStack::NotFound nil end alias_method :find_by_id, :get end end end end fog-openstack-0.1.6/lib/fog/openstack/models/network/lb_health_monitors.rb0000644000175600017570000000150712730051546026012 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/network/lb_health_monitor' module Fog module Network class OpenStack class LbHealthMonitors < Fog::OpenStack::Collection attribute :filters model Fog::Network::OpenStack::LbHealthMonitor def initialize(attributes) self.filters ||= {} super end def all(filters_arg = filters) filters = filters_arg load_response(service.list_lb_health_monitors(filters), 'health_monitors') end def get(health_monitor_id) if health_monitor = service.get_lb_health_monitor(health_monitor_id).body['health_monitor'] new(health_monitor) end rescue Fog::Network::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/network/security_group.rb0000644000175600017570000000150312730051546025215 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Network class OpenStack class SecurityGroup < Fog::OpenStack::Model identity :id attribute :name attribute :description attribute :security_group_rules attribute :tenant_id def destroy requires :id service.delete_security_group(id) true end def security_group_rules Fog::Network::OpenStack::SecurityGroupRules.new(:service => service).load(attributes[:security_group_rules]) end def save raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted? merge_attributes(service.create_security_group(attributes).body['security_group']) true end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/network/rbac_policy.rb0000644000175600017570000000146712730051546024431 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Network class OpenStack class RbacPolicy < Fog::OpenStack::Model identity :id attribute :object_type attribute :object_id attribute :tenant_id attribute :target_tenant attribute :action def create requires :object_type, :object_id, :target_tenant, :action merge_attributes(service.create_rbac_policy(attributes).body['rbac_policy']) self end def update requires :id, :target_tenant merge_attributes(service.update_rbac_policy(id, attributes).body['rbac_policy']) self end def destroy requires :id service.delete_rbac_policy(id) true end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/network/subnet.rb0000644000175600017570000000224112730051546023432 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Network class OpenStack class Subnet < Fog::OpenStack::Model identity :id attribute :name attribute :network_id attribute :cidr attribute :ip_version attribute :gateway_ip attribute :allocation_pools attribute :dns_nameservers attribute :host_routes attribute :enable_dhcp attribute :tenant_id def create requires :network_id, :cidr, :ip_version merge_attributes(service.create_subnet(self.network_id, self.cidr, self.ip_version, self.attributes).body['subnet']) self end def update requires :id merge_attributes(service.update_subnet(self.id, self.attributes).body['subnet']) self end def destroy requires :id service.delete_subnet(self.id) true end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/network/ipsec_policies.rb0000644000175600017570000000144512730051546025131 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/network/ipsec_policy' module Fog module Network class OpenStack class IpsecPolicies < Fog::OpenStack::Collection attribute :filters model Fog::Network::OpenStack::IpsecPolicy def initialize(attributes) self.filters ||= {} super end def all(filters_arg = filters) filters = filters_arg load_response(service.list_ipsec_policies(filters), 'ipsecpolicies') end def get(ipsec_policy_id) if ipsec_policy = service.get_ipsec_policy(ipsec_policy_id).body['ipsecpolicy'] new(ipsec_policy) end rescue Fog::Network::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/network/ike_policies.rb0000644000175600017570000000141712730051546024575 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/network/ike_policy' module Fog module Network class OpenStack class IkePolicies < Fog::OpenStack::Collection attribute :filters model Fog::Network::OpenStack::IkePolicy def initialize(attributes) self.filters ||= {} super end def all(filters_arg = filters) filters = filters_arg load_response(service.list_ike_policies(filters), 'ikepolicies') end def get(ike_policy_id) if ike_policy = service.get_ike_policy(ike_policy_id).body['ikepolicy'] new(ike_policy) end rescue Fog::Network::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/network/routers.rb0000644000175600017570000000134412730051546023640 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/network/router' module Fog module Network class OpenStack class Routers < Fog::OpenStack::Collection attribute :filters model Fog::Network::OpenStack::Router def initialize(attributes) self.filters ||= {} super end def all(filters_arg = filters) filters = filters_arg load_response(service.list_routers(filters), 'routers') end def get(router_id) if router = service.get_router(router_id).body['router'] new(router) end rescue Fog::Network::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/identity_v2/0000755000175600017570000000000012730051546022355 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/models/identity_v2/users.rb0000644000175600017570000000237612730051546024053 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/identity_v2/user' module Fog module Identity class OpenStack class V2 class Users < Fog::OpenStack::Collection model Fog::Identity::OpenStack::V2::User attribute :tenant_id def all(options = {}) options[:tenant_id] = tenant_id load_response(service.list_users(options), 'users') end def find_by_id(id) self.find { |user| user.id == id } || Fog::Identity::OpenStack::V2::User.new( service.get_user_by_id(id).body['user'].merge( 'service' => service ) ) end def find_by_name(name) self.find { |user| user.name == name } || Fog::Identity::OpenStack::V2::User.new( service.get_user_by_name(name).body['user'].merge( 'service' => service ) ) end def destroy(id) user = self.find_by_id(id) user.destroy end end # class Users end # class V2 end # class OpenStack end # module Identity end # module Fog fog-openstack-0.1.6/lib/fog/openstack/models/identity_v2/user.rb0000644000175600017570000000371612730051546023667 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Identity class OpenStack class V2 class User < Fog::OpenStack::Model identity :id attribute :email attribute :enabled attribute :name attribute :tenant_id, :aliases => 'tenantId' attribute :password attr_accessor :email, :name, :tenant_id, :enabled, :password def ec2_credentials requires :id service.ec2_credentials(:user => self) end def save raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted? requires :name enabled = true if enabled.nil? data = service.create_user(name, password, email, tenant_id, enabled) merge_attributes(data.body['user']) true end def update(options = {}) requires :id options.merge('id' => id) response = service.update_user(id, options) true end def update_password(password) update({'password' => password, 'url' => "/users/#{id}/OS-KSADM/password"}) end def update_tenant(tenant) tenant = tenant.id if tenant.class != String update({:tenantId => tenant, 'url' => "/users/#{id}/OS-KSADM/tenant"}) end def update_enabled(enabled) update({:enabled => enabled, 'url' => "/users/#{id}/OS-KSADM/enabled"}) end def destroy requires :id service.delete_user(id) true end def roles(tenant_id = self.tenant_id) if tenant_id service.list_roles_for_user_on_tenant(tenant_id, self.id).body['roles'] else [] end end end # class User end # class V2 end # class OpenStack end # module Identity end # module Fog fog-openstack-0.1.6/lib/fog/openstack/models/identity_v2/role.rb0000644000175600017570000000244712730051546023652 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Identity class OpenStack class V2 class Role < Fog::OpenStack::Model identity :id attribute :name def save requires :name data = service.create_role(name) merge_attributes(data.body['role']) true end def destroy requires :id service.delete_role(id) true end def add_to_user(user, tenant) add_remove_to_user(user, tenant, :add) end def remove_to_user(user, tenant) add_remove_to_user(user, tenant, :remove) end private def add_remove_to_user(user, tenant, ops) requires :id user_id = get_id(user) tenant_id = get_id(tenant) case ops when :add service.create_user_role(tenant_id, user_id, id).status == 200 when :remove service.delete_user_role(tenant_id, user_id, id).status == 204 end end def get_id(_) _.is_a?(String) ? _ : _.id end end # class Role end # class V2 end # class OpenStack end # module Identity end # module Fog fog-openstack-0.1.6/lib/fog/openstack/models/identity_v2/tenants.rb0000644000175600017570000000164712730051546024366 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/identity_v2/tenant' module Fog module Identity class OpenStack class V2 class Tenants < Fog::OpenStack::Collection model Fog::Identity::OpenStack::V2::Tenant def all(options = {}) load_response(service.list_tenants(options), 'tenants') end def find_by_id(id) cached_tenant = self.find { |tenant| tenant.id == id } return cached_tenant if cached_tenant tenant_hash = service.get_tenant(id).body['tenant'] Fog::Identity::OpenStack::V2::Tenant.new( tenant_hash.merge(:service => service)) end def destroy(id) tenant = self.find_by_id(id) tenant.destroy end end # class Tenants end # class V2 end # class OpenStack end # module Compute end # module Fog fog-openstack-0.1.6/lib/fog/openstack/models/identity_v2/ec2_credentials.rb0000644000175600017570000000301112730051546025723 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/identity_v2/ec2_credential' module Fog module Identity class OpenStack class V2 class Ec2Credentials < Fog::OpenStack::Collection model Fog::Identity::OpenStack::V2::Ec2Credential attribute :user def all(options = {}) user_id = user ? user.id : nil options[:user_id] = user_id ec2_credentials = service.list_ec2_credentials(options) load_response(ec2_credentials, 'credentials') end def create(attributes = {}) if user then attributes[:user_id] ||= user.id attributes[:tenant_id] ||= user.tenant_id end super attributes end def destroy(access_key) ec2_credential = self.find_by_access_key(access_key) ec2_credential.destroy end def find_by_access_key(access_key) user_id = user ? user.id : nil ec2_credential = self.find { |ec2_credential| ec2_credential.access == access_key } unless ec2_credential then response = service.get_ec2_credential(user_id, access_key) body = response.body['credential'] body = body.merge 'service' => service ec2_credential = Fog::Identity::OpenStack::V2::EC2Credential.new(body) end ec2_credential end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/identity_v2/tenant.rb0000644000175600017570000000264712730051546024204 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Identity class OpenStack class V2 class Tenant < Fog::OpenStack::Model identity :id attribute :description attribute :enabled attribute :name def to_s self.name end def roles_for(user) service.roles( :tenant => self, :user => user) end def users requires :id service.users(:tenant_id => self.id) end def destroy requires :id service.delete_tenant(self.id) true end def update(attr = nil) requires :id, :name merge_attributes( service.update_tenant(self.id, attr || attributes).body['tenant']) self end def create requires :name merge_attributes( service.create_tenant(attributes).body['tenant']) self end def grant_user_role(user_id, role_id) service.add_user_to_tenant(self.id, user_id, role_id) end def revoke_user_role(user_id, role_id) service.remove_user_from_tenant(self.id, user_id, role_id) end end # class Tenant end # class V2 end # class OpenStack end # module Identity end # module Fog fog-openstack-0.1.6/lib/fog/openstack/models/identity_v2/roles.rb0000644000175600017570000000103012730051546024020 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/identity_v2/role' module Fog module Identity class OpenStack class V2 class Roles < Fog::OpenStack::Collection model Fog::Identity::OpenStack::V2::Role def all(options = {}) load_response(service.list_roles(options), 'roles') end def get(id) service.get_role(id) end end end # class V2 end # class OpenStack end # module Identity end # module Fog fog-openstack-0.1.6/lib/fog/openstack/models/identity_v2/ec2_credential.rb0000644000175600017570000000163512730051546025552 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Identity class OpenStack class V2 class Ec2Credential < Fog::OpenStack::Model identity :access, :aliases => 'access_key' attribute :secret, :aliases => 'secret_key' attribute :tenant_id attribute :user_id def destroy requires :access requires :user_id service.delete_ec2_credential user_id, access true end def save raise Fog::Errors::Error, 'Existing credentials cannot be altered' if access self.user_id ||= user.id self.tenant_id ||= user.tenant_id requires :user_id, :tenant_id data = service.create_ec2_credential user_id, tenant_id merge_attributes(data.body['credential']) true end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/volume_v2/0000755000175600017570000000000012730051546022033 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/models/volume_v2/volumes.rb0000644000175600017570000000060712730051546024055 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/volume_v2/volume' require 'fog/openstack/models/volume/volumes' module Fog module Volume class OpenStack class V2 class Volumes < Fog::OpenStack::Collection model Fog::Volume::OpenStack::V2::Volume include Fog::Volume::OpenStack::Volumes end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/volume_v2/snapshot.rb0000644000175600017570000000232612730051546024222 0ustar pravipravirequire 'fog/openstack/models/volume/snapshot' module Fog module Volume class OpenStack class V2 class Snapshot < Fog::Volume::OpenStack::Snapshot identity :id attribute :name attribute :status attribute :description attribute :metadata attribute :force def save requires :name data = if id.nil? service.create_snapshot(attributes[:volume_id], name, description, force) else service.update_snapshot(id, attributes.reject { |k, _v| k == :id }) end merge_attributes(data.body['snapshot']) true end def create requires :name # volume_id, name, description, force=false response = service.create_snapshot(attributes[:volume_id], attributes[:name], attributes[:description], attributes[:force]) merge_attributes(response.body['snapshot']) self end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/volume_v2/availability_zone.rb0000644000175600017570000000044612730051546026071 0ustar pravipravirequire 'fog/openstack/models/volume/availability_zone' module Fog module Volume class OpenStack class V2 class AvailabilityZone < Fog::Volume::OpenStack::AvailabilityZone identity :zoneName attribute :zoneState end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/volume_v2/volume.rb0000644000175600017570000000175212730051546023674 0ustar pravipravirequire 'fog/openstack/models/volume/volume' module Fog module Volume class OpenStack class V2 class Volume < Fog::Volume::OpenStack::Volume identity :id superclass.attributes.each { |attrib| attribute attrib } attribute :name attribute :description attribute :tenant_id, :aliases => 'os-vol-tenant-attr:tenant_id' def save requires :name, :size data = if id.nil? service.create_volume(name, description, size, attributes) else service.update_volume(id, attributes.reject { |k, _v| k == :id }) end merge_attributes(data.body['volume']) true end def update(attr = nil) requires :id merge_attributes( service.update_volume(id, attr || attributes).body['volume']) self end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/volume_v2/transfer.rb0000644000175600017570000000065012730051546024205 0ustar pravipravirequire 'fog/openstack/models/volume/transfer' module Fog module Volume class OpenStack class V2 class Transfer < Fog::Volume::OpenStack::Transfer identity :id attribute :auth_key, :aliases => 'authKey' attribute :created_at, :aliases => 'createdAt' attribute :name attribute :volume_id, :aliases => 'volumeId' end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/volume_v2/transfers.rb0000644000175600017570000000062112730051546024366 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/volume_v2/transfer' require 'fog/openstack/models/volume/transfers' module Fog module Volume class OpenStack class V2 class Transfers < Fog::OpenStack::Collection model Fog::Volume::OpenStack::V2::Transfer include Fog::Volume::OpenStack::Transfers end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/volume_v2/volume_types.rb0000644000175600017570000000063512730051546025117 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/volume_v2/volume_type' require 'fog/openstack/models/volume/volume_types' module Fog module Volume class OpenStack class V2 class VolumeTypes < Fog::OpenStack::Collection model Fog::Volume::OpenStack::V2::VolumeType include Fog::Volume::OpenStack::VolumeTypes end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/volume_v2/availability_zones.rb0000644000175600017570000000067312730051546026256 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/volume_v2/availability_zone' require 'fog/openstack/models/volume/availability_zones' module Fog module Volume class OpenStack class V2 class AvailabilityZones < Fog::OpenStack::Collection model Fog::Volume::OpenStack::V2::AvailabilityZone include Fog::Volume::OpenStack::AvailabilityZones end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/volume_v2/volume_type.rb0000644000175600017570000000046212730051546024732 0ustar pravipravirequire 'fog/openstack/models/volume/volume_type' module Fog module Volume class OpenStack class V2 class VolumeType < Fog::Volume::OpenStack::VolumeType identity :id attribute :name attribute :volume_backend_name end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/volume_v2/snapshots.rb0000644000175600017570000000062112730051546024401 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/volume_v2/snapshot' require 'fog/openstack/models/volume/snapshots' module Fog module Volume class OpenStack class V2 class Snapshots < Fog::OpenStack::Collection model Fog::Volume::OpenStack::V2::Snapshot include Fog::Volume::OpenStack::Snapshots end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/collection.rb0000644000175600017570000000331512730051546022577 0ustar pravipravirequire 'fog/core/collection' module Fog module OpenStack class Collection < Fog::Collection # It's important to store the whole response, it contains e.g. important info about whether there is another # page of data. attr_accessor :response def load_response(response, index = nil) # Delete it index if it's there, so we don't store response with data twice, but we store only metadata objects = index ? response.body.delete(index) : response.body clear && objects.each { |object| self << new(object) } self.response = response self end ################################################################################################################## # Abstract base class methods, please keep the consistent naming in all subclasses of the Collection class # Returns detailed list of records def all(options = {}) raise Fog::OpenStack::Errors::InterfaceNotImplemented.new('Method :all is not implemented') end # Returns non detailed list of records, usually just subset of attributes, which makes this call more effective. # Not all openstack services support non detailed list, so it delegates to :all by default. def summary(options = {}) all(options) end # Gets record given record's UUID def get(uuid) raise Fog::OpenStack::Errors::InterfaceNotImplemented.new('Method :get is not implemented') end def find_by_id(uuid) get(uuid) end # Destroys record given record's UUID def destroy(uuid) raise Fog::OpenStack::Errors::InterfaceNotImplemented.new('Method :destroy is not implemented') end end end end fog-openstack-0.1.6/lib/fog/openstack/models/baremetal/0000755000175600017570000000000012730051546022051 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/models/baremetal/chassis_collection.rb0000644000175600017570000000237012730051546026250 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/baremetal/chassis' module Fog module Baremetal class OpenStack class ChassisCollection < Fog::OpenStack::Collection model Fog::Baremetal::OpenStack::Chassis def all(options = {}) load_response(service.list_chassis_detailed(options), 'chassis') end def summary(options = {}) load_response(service.list_chassis(options), 'chassis') end def details(options = {}) Fog::Logger.deprecation("Calling OpenStack[:baremetal].chassis_collection.details will be removed, "\ " call .chassis_collection.all for detailed list.") all(options) end def find_by_uuid(uuid) new(service.get_chassis(uuid).body) end alias_method :get, :find_by_uuid def destroy(uuid) chassis = self.find_by_id(uuid) chassis.destroy end def method_missing(method_sym, *arguments, &block) if method_sym.to_s =~ /^find_by_(.*)$/ load(service.list_chassis_detailed({$1 => arguments.first}).body['chassis']) else super end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/baremetal/node.rb0000644000175600017570000000503412730051546023325 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Baremetal class OpenStack class Node < Fog::OpenStack::Model identity :uuid attribute :instance_uuid attribute :maintenance attribute :power_state attribute :provision_state attribute :uuid #detailed attribute :created_at attribute :updated_at attribute :chassis_uuid attribute :console_enabled attribute :driver attribute :driver_info attribute :extra attribute :instance_info attribute :last_error attribute :maintenance_reason attribute :properties attribute :provision_updated_at attribute :reservation attribute :target_power_state attribute :target_provision_state def create requires :driver merge_attributes(service.create_node(self.attributes).body) self end def update(patch=nil) requires :uuid, :driver if patch merge_attributes(service.patch_node(uuid, patch).body) else # TODO implement update_node method using PUT method and self.attributes # once it is supported by Ironic raise ArgumentError, ('You need to provide patch attribute. Ironic does ' 'not support update by hash yet, only by jsonpatch.') end self end def destroy requires :uuid service.delete_node(self.uuid) true end def chassis requires :uuid service.get_chassis(self.chassis_uuid).body end def ports requires :uuid service.list_ports_detailed({:node_uuid => self.uuid}).body['ports'] end def set_node_maintenance(parameters=nil) requires :uuid service.set_node_maintenance(uuid, parameters) true end def unset_node_maintenance(parameters=nil) requires :uuid service.unset_node_maintenance(uuid, parameters) true end def metadata requires :uuid service.get_node(self.uuid).headers end def set_power_state(power_state) requires :uuid service.set_node_power_state(self.uuid, power_state) end def set_provision_state(provision_state) requires :uuid service.set_node_provision_state(self.uuid, provision_state) end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/baremetal/chassis.rb0000644000175600017570000000232712730051546024037 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Baremetal class OpenStack class Chassis < Fog::OpenStack::Model identity :uuid attribute :description attribute :uuid #detailed attribute :created_at attribute :updated_at attribute :extra def create requires :description merge_attributes(service.create_chassis(self.attributes).body) self end def update(patch=nil) requires :uuid, :description if patch merge_attributes(service.patch_chassis(uuid, patch).body) else # TODO implement update_node method using PUT method and self.attributes # once it is supported by Ironic raise ArgumentError, ('You need to provide patch attribute. Ironic does ' 'not support update by hash yet, only by jsonpatch.') end self end def destroy requires :uuid service.delete_chassis(self.uuid) true end def metadata requires :uuid service.get_chassis(self.uuid).headers end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/baremetal/nodes.rb0000644000175600017570000000234512730051546023512 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/baremetal/node' module Fog module Baremetal class OpenStack class Nodes < Fog::OpenStack::Collection model Fog::Baremetal::OpenStack::Node def all(options = {}) load_response(service.list_nodes_detailed(options), 'nodes') end def summary(options = {}) load_response(service.list_nodes(options), 'nodes') end def details(options = {}) Fog::Logger.deprecation("Calling OpenStack[:baremetal].nodes.details will be removed, "\ " call .nodes.all for detailed list.") load(service.list_nodes_detailed(options).body['nodes']) end def find_by_uuid(uuid) new(service.get_node(uuid).body) end alias_method :get, :find_by_uuid def destroy(uuid) node = self.find_by_uuid(uuid) node.destroy end def method_missing(method_sym, *arguments, &block) if method_sym.to_s =~ /^find_by_(.*)$/ load(service.list_nodes_detailed({$1 => arguments.first}).body['nodes']) else super end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/baremetal/drivers.rb0000644000175600017570000000077112730051546024061 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/baremetal/driver' module Fog module Baremetal class OpenStack class Drivers < Fog::OpenStack::Collection model Fog::Baremetal::OpenStack::Driver def all(options = {}) load_response(service.list_drivers(options), 'drivers') end def find_by_name(name) new(service.get_driver(name).body) end alias_method :get, :find_by_name end end end end fog-openstack-0.1.6/lib/fog/openstack/models/baremetal/port.rb0000644000175600017570000000236112730051546023364 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Baremetal class OpenStack class Port < Fog::OpenStack::Model identity :uuid attribute :address attribute :uuid #detailed attribute :created_at attribute :updated_at attribute :extra attribute :node_uuid def create requires :address, :node_uuid merge_attributes(service.create_port(self.attributes).body) self end def update(patch=nil) requires :uuid, :address, :node_uuid if patch merge_attributes(service.patch_port(uuid, patch).body) else # TODO implement update_node method using PUT method and self.attributes # once it is supported by Ironic raise ArgumentError, ('You need to provide patch attribute. Ironic does ' 'not support update by hash yet, only by jsonpatch.') end self end def destroy requires :uuid service.delete_port(self.uuid) true end def metadata requires :uuid service.get_port(self.uuid).headers end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/baremetal/ports.rb0000644000175600017570000000234312730051546023547 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/baremetal/port' module Fog module Baremetal class OpenStack class Ports < Fog::OpenStack::Collection model Fog::Baremetal::OpenStack::Port def all(options = {}) load_response(service.list_ports_detailed(options), 'ports') end def summary(options = {}) load_response(service.list_ports(options), 'ports') end def details(options = {}) Fog::Logger.deprecation("Calling OpenStack[:baremetal].ports.details will be removed, "\ " call .ports.all for detailed list.") load(service.list_ports_detailed(options).body['ports']) end def find_by_uuid(uuid) new(service.get_port(uuid).body) end alias_method :get, :find_by_uuid def destroy(uuid) port = self.find_by_id(uuid) port.destroy end def method_missing(method_sym, *arguments, &block) if method_sym.to_s =~ /^find_by_(.*)$/ load(service.list_ports_detailed({$1 => arguments.first}).body['ports']) else super end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/baremetal/driver.rb0000644000175600017570000000071012730051546023667 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Baremetal class OpenStack class Driver < Fog::OpenStack::Model identity :name attribute :name attribute :hosts def properties requires :name service.get_driver_properties(self.name).body end def metadata requires :name service.get_driver(self.name).headers end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/volume_v1/0000755000175600017570000000000012730051546022032 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/models/volume_v1/volumes.rb0000644000175600017570000000060712730051546024054 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/volume_v1/volume' require 'fog/openstack/models/volume/volumes' module Fog module Volume class OpenStack class V1 class Volumes < Fog::OpenStack::Collection model Fog::Volume::OpenStack::V1::Volume include Fog::Volume::OpenStack::Volumes end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/volume_v1/snapshot.rb0000644000175600017570000000242612730051546024222 0ustar pravipravirequire 'fog/openstack/models/volume/snapshot' module Fog module Volume class OpenStack class V1 class Snapshot < Fog::Volume::OpenStack::Snapshot identity :id attribute :display_name attribute :status attribute :display_description attribute :metadata attribute :force def save requires :display_name data = if id.nil? service.create_snapshot(attributes[:volume_id], display_name, display_description, force) else service.update_snapshot(id, attributes.reject { |k, _v| k == :id }) end merge_attributes(data.body['snapshot']) true end def create requires :display_name # volume_id, name, description, force=false response = service.create_snapshot(attributes[:volume_id], attributes[:display_name], attributes[:display_description], attributes[:force]) merge_attributes(response.body['snapshot']) self end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/volume_v1/availability_zone.rb0000644000175600017570000000044612730051546026070 0ustar pravipravirequire 'fog/openstack/models/volume/availability_zone' module Fog module Volume class OpenStack class V1 class AvailabilityZone < Fog::Volume::OpenStack::AvailabilityZone identity :zoneName attribute :zoneState end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/volume_v1/volume.rb0000644000175600017570000000211712730051546023667 0ustar pravipravirequire 'fog/openstack/models/volume/volume' module Fog module Volume class OpenStack class V1 class Volume < Fog::Volume::OpenStack::Volume identity :id superclass.attributes.each { |attrib| attribute attrib } attribute :display_name, :aliases => 'displayName' attribute :display_description, :aliases => 'displayDescription' attribute :tenant_id, :aliases => 'os-vol-tenant-attr:tenant_id' def save requires :display_name, :size data = if id.nil? service.create_volume(display_name, display_description, size, attributes) else service.update_volume(id, attributes.reject { |k, _v| k == :id }) end merge_attributes(data.body['volume']) true end def update(attr = nil) requires :id merge_attributes( service.update_volume(id, attr || attributes).body['volume']) self end end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/volume_v1/transfer.rb0000644000175600017570000000064712730051546024212 0ustar pravipravirequire 'fog/openstack/models/volume/transfer' module Fog module Volume class OpenStack class V1 class Transfer < Fog::Volume::OpenStack::Transfer identity :id attribute :auth_key, :aliases => 'authKey' attribute :created_at, :aliases => 'createdAt' attribute :name attribute :volume_id, :aliases => 'volumeId' end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/volume_v1/transfers.rb0000644000175600017570000000062112730051546024365 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/volume_v1/transfer' require 'fog/openstack/models/volume/transfers' module Fog module Volume class OpenStack class V1 class Transfers < Fog::OpenStack::Collection model Fog::Volume::OpenStack::V1::Transfer include Fog::Volume::OpenStack::Transfers end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/volume_v1/volume_types.rb0000644000175600017570000000063512730051546025116 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/volume_v1/volume_type' require 'fog/openstack/models/volume/volume_types' module Fog module Volume class OpenStack class V1 class VolumeTypes < Fog::OpenStack::Collection model Fog::Volume::OpenStack::V1::VolumeType include Fog::Volume::OpenStack::VolumeTypes end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/volume_v1/availability_zones.rb0000644000175600017570000000067312730051546026255 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/volume_v1/availability_zone' require 'fog/openstack/models/volume/availability_zones' module Fog module Volume class OpenStack class V1 class AvailabilityZones < Fog::OpenStack::Collection model Fog::Volume::OpenStack::V1::AvailabilityZone include Fog::Volume::OpenStack::AvailabilityZones end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/volume_v1/volume_type.rb0000644000175600017570000000046212730051546024731 0ustar pravipravirequire 'fog/openstack/models/volume/volume_type' module Fog module Volume class OpenStack class V1 class VolumeType < Fog::Volume::OpenStack::VolumeType identity :id attribute :name attribute :volume_backend_name end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/volume_v1/snapshots.rb0000644000175600017570000000062112730051546024400 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/volume_v1/snapshot' require 'fog/openstack/models/volume/snapshots' module Fog module Volume class OpenStack class V1 class Snapshots < Fog::OpenStack::Collection model Fog::Volume::OpenStack::V1::Snapshot include Fog::Volume::OpenStack::Snapshots end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/meta_parent.rb0000644000175600017570000000126312730051546022743 0ustar pravipravimodule Fog module Compute class OpenStack module MetaParent def parent @parent end def parent=(new_parent) @parent = new_parent end def collection_name if @parent.class == Fog::Compute::OpenStack::Image return "images" elsif @parent.class == Fog::Compute::OpenStack::Server return "servers" else raise "Metadata is not supported for this model type." end end def metas_to_hash(metas) hash = {} metas.each { |meta| hash.store(meta.key, meta.value) } hash end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/storage/0000755000175600017570000000000012730051546021561 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/models/storage/files.rb0000644000175600017570000000523012730051546023210 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/storage/file' module Fog module Storage class OpenStack class Files < Fog::OpenStack::Collection attribute :directory attribute :limit attribute :marker attribute :path attribute :prefix model Fog::Storage::OpenStack::File def all(options = {}) requires :directory options = { 'limit' => limit, 'marker' => marker, 'path' => path, 'prefix' => prefix }.merge!(options) merge_attributes(options) parent = directory.collection.get( directory.key, options ) if parent # TODO change to load_response? load(parent.files.map {|file| file.attributes}) else nil end end alias_method :each_file_this_page, :each def each if !block_given? self else subset = dup.all subset.each_file_this_page {|f| yield f} while subset.length == (subset.limit || 10000) subset = subset.all(:marker => subset.last.key) subset.each_file_this_page {|f| yield f} end self end end def get(key, &block) requires :directory data = service.get_object(directory.key, key, &block) file_data = data.headers.merge({ :body => data.body, :key => key }) new(file_data) rescue Fog::Storage::OpenStack::NotFound nil end def get_url(key) requires :directory if self.directory.public_url "#{self.directory.public_url}/#{Fog::OpenStack.escape(key, '/')}" end end def get_http_url(key, expires, options = {}) requires :directory service.get_object_http_url(directory.key, key, expires, options) end def get_https_url(key, expires, options = {}) requires :directory service.get_object_https_url(directory.key, key, expires, options) end def head(key, options = {}) requires :directory data = service.head_object(directory.key, key) file_data = data.headers.merge({ :key => key }) new(file_data) rescue Fog::Storage::OpenStack::NotFound nil end def new(attributes = {}) requires :directory super({ :directory => directory }.merge!(attributes)) end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/storage/directories.rb0000644000175600017570000000203012730051546024415 0ustar pravipravirequire 'fog/openstack/models/collection' require 'fog/openstack/models/storage/directory' module Fog module Storage class OpenStack class Directories < Fog::OpenStack::Collection model Fog::Storage::OpenStack::Directory def all(options = {}) data = service.get_containers(options) load_response(data) end def get(key, options = {}) data = service.get_container(key, options) directory = new(:key => key) for key, value in data.headers if ['X-Container-Bytes-Used', 'X-Container-Object-Count'].include?(key) directory.merge_attributes(key => value) end end directory.files.merge_attributes(options) directory.files.instance_variable_set(:@loaded, true) data.body.each do |file| directory.files << directory.files.new(file) end directory rescue Fog::Storage::OpenStack::NotFound nil end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/storage/file.rb0000644000175600017570000001516612730051546023036 0ustar pravipravirequire 'fog/openstack/models/model' module Fog module Storage class OpenStack class File < Fog::OpenStack::Model identity :key, :aliases => 'name' attribute :access_control_allow_origin, :aliases => ['Access-Control-Allow-Origin'] attribute :content_length, :aliases => ['bytes', 'Content-Length'], :type => :integer attribute :content_type, :aliases => ['content_type', 'Content-Type'] attribute :content_disposition, :aliases => ['content_disposition', 'Content-Disposition'] attribute :etag, :aliases => ['hash', 'Etag'] attribute :last_modified, :aliases => ['last_modified', 'Last-Modified'], :type => :time attribute :metadata attribute :origin, :aliases => ['Origin'] # @!attribute [rw] delete_at # A Unix Epoch Timestamp, in integer form, representing the time when this object will be automatically deleted. # @return [Integer] the unix epoch timestamp of when this object will be automatically deleted # @see http://docs.openstack.org/developer/swift/overview_expiring_objects.html attribute :delete_at, :aliases => ['X-Delete-At'] # @!attribute [rw] delete_after # A number of seconds representing how long from now this object will be automatically deleted. # @return [Integer] the number of seconds until this object will be automatically deleted # @see http://docs.openstack.org/developer/swift/overview_expiring_objects.html attribute :delete_after, :aliases => ['X-Delete-After'] # @!attribute [rw] content_encoding # When you create an object or update its metadata, you can optionally set the Content-Encoding metadata. # This metadata enables you to indicate that the object content is compressed without losing the identity of the # underlying media type (Content-Type) of the file, such as a video. # @see http://docs.openstack.org/developer/swift/api/use_content-encoding_metadata.html#use-content-encoding-metadata attribute :content_encoding, :aliases => 'Content-Encoding' def body attributes[:body] ||= if last_modified collection.get(identity).body else '' end end def body=(new_body) attributes[:body] = new_body end def directory @directory end def copy(target_directory_key, target_file_key, options={}) requires :directory, :key options['Content-Type'] ||= content_type if content_type options['Access-Control-Allow-Origin'] ||= access_control_allow_origin if access_control_allow_origin options['Origin'] ||= origin if origin options['Content-Encoding'] ||= content_encoding if content_encoding service.copy_object(directory.key, key, target_directory_key, target_file_key, options) target_directory = service.directories.new(:key => target_directory_key) target_directory.files.get(target_file_key) end def destroy requires :directory, :key service.delete_object(directory.key, key) true end def metadata attributes[:metadata] ||= headers_to_metadata end def owner=(new_owner) if new_owner attributes[:owner] = { :display_name => new_owner['DisplayName'], :id => new_owner['ID'] } end end def public=(new_public) new_public end # Get a url for file. # # required attributes: key # # @param expires [String] number of seconds (since 1970-01-01 00:00) before url expires # @param options [Hash] # @return [String] url # def url(expires, options = {}) requires :directory, :key self.service.create_temp_url(directory.key, key, expires, "GET", options) end def public_url requires :key self.collection.get_url(self.key) end def save(options = {}) requires :body, :directory, :key options['Content-Type'] = content_type if content_type options['Content-Disposition'] = content_disposition if content_disposition options['Access-Control-Allow-Origin'] = access_control_allow_origin if access_control_allow_origin options['Origin'] = origin if origin options['X-Delete-At'] = delete_at if delete_at options['X-Delete-After'] = delete_after if delete_after options['Content-Encoding'] = content_encoding if content_encoding options.merge!(metadata_to_headers) data = service.put_object(directory.key, key, body, options) update_attributes_from(data) refresh_metadata self.content_length = Fog::Storage.get_body_size(body) self.content_type ||= Fog::Storage.get_content_type(body) true end private def directory=(new_directory) @directory = new_directory end def refresh_metadata metadata.reject! {|k, v| v.nil? } end def headers_to_metadata key_map = key_mapping Hash[metadata_attributes.map {|k, v| [key_map[k], v] }] end def key_mapping key_map = metadata_attributes key_map.each_pair {|k, v| key_map[k] = header_to_key(k)} end def header_to_key(opt) opt.gsub(metadata_prefix, '').split('-').map {|k| k[0, 1].downcase + k[1..-1]}.join('_').to_sym end def metadata_to_headers header_map = header_mapping Hash[metadata.map {|k, v| [header_map[k], v] }] end def header_mapping header_map = metadata.dup header_map.each_pair {|k, v| header_map[k] = key_to_header(k)} end def key_to_header(key) metadata_prefix + key.to_s.split(/[-_]/).map(&:capitalize).join('-') end def metadata_attributes if last_modified headers = service.head_object(directory.key, self.key).headers headers.reject! {|k, v| !metadata_attribute?(k)} else {} end end def metadata_attribute?(key) key.to_s =~ /^#{metadata_prefix}/ end def metadata_prefix "X-Object-Meta-" end def update_attributes_from(data) merge_attributes(data.headers.reject {|key, value| ['Content-Length', 'Content-Type'].include?(key)}) end end end end end fog-openstack-0.1.6/lib/fog/openstack/models/storage/directory.rb0000644000175600017570000000214312730051546024112 0ustar pravipravirequire 'fog/openstack/models/model' require 'fog/openstack/models/storage/files' module Fog module Storage class OpenStack class Directory < Fog::OpenStack::Model identity :key, :aliases => 'name' attribute :bytes, :aliases => 'X-Container-Bytes-Used' attribute :count, :aliases => 'X-Container-Object-Count' attr_writer :public def destroy requires :key service.delete_container(key) true rescue Excon::Errors::NotFound false end def files @files ||= begin Fog::Storage::OpenStack::Files.new( :directory => self, :service => service ) end end def public_url requires :key @public_url ||= begin service.public_url(key) rescue Fog::Storage::OpenStack::NotFound => err nil end end def save requires :key service.put_container(key, :public => @public) true end end end end end fog-openstack-0.1.6/lib/fog/openstack/metering.rb0000644000175600017570000001163512730051546020777 0ustar pravipravi module Fog module Metering class OpenStack < Fog::Service requires :openstack_auth_url recognizes :openstack_auth_token, :openstack_management_url, :persistent, :openstack_service_type, :openstack_service_name, :openstack_tenant, :openstack_tenant_id, :openstack_api_key, :openstack_username, :openstack_identity_endpoint, :current_user, :current_tenant, :openstack_region, :openstack_endpoint_type, :openstack_cache_ttl, :openstack_project_name, :openstack_project_id, :openstack_project_domain, :openstack_user_domain, :openstack_domain_name, :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id, :openstack_identity_prefix model_path 'fog/openstack/models/metering' model :resource collection :resources model :event collection :events request_path 'fog/openstack/requests/metering' # Metering request :get_event request :get_resource request :get_samples request :get_statistics request :list_events request :list_meters request :list_resources class Mock def self.data @data ||= Hash.new do |hash, key| hash[key] = { :users => {}, :tenants => {} } end end def self.reset @data = nil end def initialize(options={}) @openstack_username = options[:openstack_username] @openstack_tenant = options[:openstack_tenant] @openstack_auth_uri = URI.parse(options[:openstack_auth_url]) @auth_token = Fog::Mock.random_base64(64) @auth_token_expiration = (Time.now.utc + 86400).iso8601 management_url = URI.parse(options[:openstack_auth_url]) management_url.port = 8776 management_url.path = '/v1' @openstack_management_url = management_url.to_s @data ||= { :users => {} } unless @data[:users].find {|u| u['name'] == options[:openstack_username]} id = Fog::Mock.random_numbers(6).to_s @data[:users][id] = { 'id' => id, 'name' => options[:openstack_username], 'email' => "#{options[:openstack_username]}@mock.com", 'tenantId' => Fog::Mock.random_numbers(6).to_s, 'enabled' => true } end end def data self.class.data[@openstack_username] end def reset_data self.class.data.delete(@openstack_username) end def credentials { :provider => 'openstack', :openstack_auth_url => @openstack_auth_uri.to_s, :openstack_auth_token => @auth_token, :openstack_management_url => @openstack_management_url } end end class Real include Fog::OpenStack::Core def initialize(options={}) initialize_identity options @openstack_service_type = options[:openstack_service_type] || ['metering'] @openstack_service_name = options[:openstack_service_name] @openstack_endpoint_type = options[:openstack_endpoint_type] || 'adminURL' @connection_options = options[:connection_options] || {} authenticate @persistent = options[:persistent] || false @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end def request(params) begin response = @connection.request(params.merge({ :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'X-Auth-Token' => @auth_token }.merge!(params[:headers] || {}), :path => "#{@path}/v2/#{params[:path]}"#, # Causes errors for some requests like tenants?limit=1 # :query => ('ignore_awful_caching' << Time.now.to_i.to_s) })) rescue Excon::Errors::Unauthorized => error if error.response.body != 'Bad username or password' # token expiration @openstack_must_reauthenticate = true authenticate retry else # bad credentials raise error end rescue Excon::Errors::HTTPStatusError => error raise case error when Excon::Errors::NotFound Fog::Metering::OpenStack::NotFound.slurp(error) else error end end unless response.body.empty? response.body = Fog::JSON.decode(response.body) end response end private end end end end fog-openstack-0.1.6/lib/fog/openstack/volume_v2.rb0000644000175600017570000001223712730051546021102 0ustar pravipravirequire 'fog/openstack/core' require 'fog/openstack/common' require 'fog/openstack/volume' module Fog module Volume class OpenStack class V2 < Fog::Volume::OpenStack SUPPORTED_VERSIONS = /v2(\.(0-9))*/ requires :openstack_auth_url recognizes *@@recognizes model_path 'fog/openstack/models/volume_v2' model :volume collection :volumes model :availability_zone collection :availability_zones model :volume_type collection :volume_types model :snapshot collection :snapshots model :transfer collection :transfers request_path 'fog/openstack/requests/volume_v2' # Volume request :list_volumes request :list_volumes_detailed request :create_volume request :update_volume request :get_volume_details request :extend_volume request :delete_volume request :list_zones request :list_volume_types request :create_volume_type request :update_volume_type request :delete_volume_type request :get_volume_type_details request :create_snapshot request :update_snapshot request :list_snapshots request :list_snapshots_detailed request :get_snapshot_details request :delete_snapshot request :update_snapshot_metadata request :delete_snapshot_metadata request :list_transfers request :list_transfers_detailed request :create_transfer request :get_transfer_details request :accept_transfer request :delete_transfer request :update_quota request :get_quota request :get_quota_defaults request :get_quota_usage request :update_metadata request :replace_metadata request :delete_metadata request :set_tenant request :action class Mock def self.data @data ||= Hash.new do |hash, key| hash[key] = { :users => {}, :tenants => {}, :quota => { 'gigabytes' => 1000, 'volumes' => 10, 'snapshots' => 10 } } end end def self.reset @data = nil end def initialize(options = {}) @openstack_username = options[:openstack_username] @openstack_tenant = options[:openstack_tenant] @openstack_auth_uri = URI.parse(options[:openstack_auth_url]) @auth_token = Fog::Mock.random_base64(64) @auth_token_expiration = (Time.now.utc + 86400).iso8601 management_url = URI.parse(options[:openstack_auth_url]) management_url.port = 8776 management_url.path = '/v1' @openstack_management_url = management_url.to_s @data ||= {:users => {}} unless @data[:users].find { |u| u['name'] == options[:openstack_username] } id = Fog::Mock.random_numbers(6).to_s @data[:users][id] = { 'id' => id, 'name' => options[:openstack_username], 'email' => "#{options[:openstack_username]}@mock.com", 'tenantId' => Fog::Mock.random_numbers(6).to_s, 'enabled' => true } end end def data self.class.data[@openstack_username] end def reset_data self.class.data.delete(@openstack_username) end def credentials {:provider => 'openstack', :openstack_auth_url => @openstack_auth_uri.to_s, :openstack_auth_token => @auth_token, :openstack_management_url => @openstack_management_url} end end class Real include Fog::OpenStack::Core def self.not_found_class Fog::Volume::OpenStack::NotFound end include Fog::OpenStack::Common def initialize(options = {}) initialize_identity options @openstack_service_type = options[:openstack_service_type] || ['volumev2'] @openstack_service_name = options[:openstack_service_name] @openstack_endpoint_type = options[:openstack_endpoint_type] || 'adminURL' @connection_options = options[:connection_options] || {} authenticate unless @path.match(SUPPORTED_VERSIONS) @path = Fog::OpenStack.get_supported_version_path(SUPPORTED_VERSIONS, @openstack_management_uri, @auth_token, @connection_options) end @persistent = options[:persistent] || false @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end end end end end end fog-openstack-0.1.6/lib/fog/openstack/storage.rb0000644000175600017570000001370212730051546020626 0ustar pravipravi module Fog module Storage class OpenStack < Fog::Service requires :openstack_auth_url recognizes :openstack_auth_token, :openstack_management_url, :persistent, :openstack_service_type, :openstack_service_name, :openstack_tenant, :openstack_tenant_id, :openstack_userid, :openstack_api_key, :openstack_username, :openstack_identity_endpoint, :current_user, :current_tenant, :openstack_region, :openstack_endpoint_type, :openstack_auth_omit_default_port, :openstack_project_name, :openstack_project_id, :openstack_cache_ttl, :openstack_project_domain, :openstack_user_domain, :openstack_domain_name, :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id, :openstack_identity_prefix, :openstack_temp_url_key model_path 'fog/openstack/models/storage' model :directory collection :directories model :file collection :files request_path 'fog/openstack/requests/storage' request :copy_object request :delete_container request :delete_object request :delete_multiple_objects request :delete_static_large_object request :get_container request :get_containers request :get_object request :get_object_http_url request :get_object_https_url request :head_container request :head_containers request :head_object request :put_container request :put_object request :put_object_manifest request :put_dynamic_obj_manifest request :put_static_obj_manifest request :post_set_meta_temp_url_key request :public_url class Mock def self.data @data ||= Hash.new do |hash, key| hash[key] = {} end end def self.reset @data = nil end def initialize(options={}) @openstack_api_key = options[:openstack_api_key] @openstack_username = options[:openstack_username] @path = '/v1/AUTH_1234' end def data self.class.data[@openstack_username] end def reset_data self.class.data.delete(@openstack_username) end def change_account(account) @original_path ||= @path version_string = @original_path.split('/')[1] @path = "/#{version_string}/#{account}" end def reset_account_name @path = @original_path end end class Real include Fog::OpenStack::Core def initialize(options={}) initialize_identity options @openstack_service_type = options[:openstack_service_type] || ['object-store'] @openstack_service_name = options[:openstack_service_name] @connection_options = options[:connection_options] || {} authenticate @persistent = options[:persistent] || false @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end # Change the current account while re-using the auth token. # # This is usefull when you have an admin role and you're able # to HEAD other user accounts, set quotas, list files, etc. # # For example: # # # List current user account details # service = Fog::Storage[:openstack] # service.request :method => 'HEAD' # # Would return something like: # # Account: AUTH_1234 # Date: Tue, 05 Mar 2013 16:50:52 GMT # X-Account-Bytes-Used: 0 (0.00 Bytes) # X-Account-Container-Count: 0 # X-Account-Object-Count: 0 # # Now let's change the account # # service.change_account('AUTH_3333') # service.request :method => 'HEAD' # # Would return something like: # # Account: AUTH_3333 # Date: Tue, 05 Mar 2013 16:51:53 GMT # X-Account-Bytes-Used: 23423433 # X-Account-Container-Count: 2 # X-Account-Object-Count: 10 # # If we wan't to go back to our original admin account: # # service.reset_account_name # def change_account(account) @original_path ||= @path version_string = @path.split('/')[1] @path = "/#{version_string}/#{account}" end def reset_account_name @path = @original_path end def request(params, parse_json = true) begin response = @connection.request(params.merge({ :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'X-Auth-Token' => @auth_token }.merge!(params[:headers] || {}), :path => "#{@path}/#{params[:path]}", })) rescue Excon::Errors::Unauthorized => error if error.response.body != 'Bad username or password' # token expiration @openstack_must_reauthenticate = true authenticate retry else # bad credentials raise error end rescue Excon::Errors::HTTPStatusError => error raise case error when Excon::Errors::NotFound Fog::Storage::OpenStack::NotFound.slurp(error) else error end end if !response.body.empty? && parse_json && response.get_header('Content-Type') =~ %r{application/json} response.body = Fog::JSON.decode(response.body) end response end private end end end end fog-openstack-0.1.6/lib/fog/openstack/baremetal.rb0000644000175600017570000002466312730051546021126 0ustar pravipravi module Fog module Baremetal class OpenStack < Fog::Service SUPPORTED_VERSIONS = /(.)*/ requires :openstack_auth_url recognizes :openstack_auth_token, :openstack_management_url, :persistent, :openstack_service_type, :openstack_service_name, :openstack_tenant, :openstack_tenant_id, :openstack_api_key, :openstack_username, :openstack_identity_endpoint, :current_user, :current_tenant, :openstack_region, :openstack_endpoint_type, :openstack_cache_ttl, :openstack_project_name, :openstack_project_id, :openstack_project_domain, :openstack_user_domain, :openstack_domain_name, :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id ## MODELS # model_path 'fog/openstack/models/baremetal' model :chassis collection :chassis_collection model :driver collection :drivers model :node collection :nodes model :port collection :ports ## REQUESTS # request_path 'fog/openstack/requests/baremetal' # Node requests request :create_node request :delete_node request :get_node request :list_nodes request :list_nodes_detailed request :patch_node request :set_node_power_state request :set_node_provision_state request :set_node_maintenance request :unset_node_maintenance # Chassis requests request :create_chassis request :delete_chassis request :get_chassis request :list_chassis request :list_chassis_detailed request :patch_chassis # Driver requests request :get_driver request :get_driver_properties request :list_drivers # Port requests request :create_port request :delete_port request :get_port request :list_ports request :list_ports_detailed request :patch_port ## TODO not implemented API requests: ## Chassis # request :list_chassis_nodes # request :list_chassis_nodes_details ## Node requests # request :validate_node # request :get_boot_device # request :set_boot_device # request :list_supported_boot_devices # request :list_node_states # request :get_console_info # request :change_console_state # request :get_vendor_passthru_methods ## Driver requests # request :get_vendor_passthru_methods class Mock def self.data @data ||= Hash.new do |hash, key| chassis_uuid = Fog::UUID.uuid instance_uuid = Fog::UUID.uuid node_uuid = Fog::UUID.uuid hash[key] = { :chassis_collection => [ { "created_at" => "2000-01-01T12:00:00", "description" => "Sample chassis", "extra" => {}, "links" => [ { "href" => "http://localhost:6385/v1/chassis/eaaca217-e7d8-47b4-bb41-3f99f20eed89", "rel" => "self" }, { "href" => "http://localhost:6385/chassis/eaaca217-e7d8-47b4-bb41-3f99f20eed89", "rel" => "bookmark" } ], "nodes" => [ { "href" => "http://localhost:6385/v1/chassis/eaaca217-e7d8-47b4-bb41-3f99f20eed89/nodes", "rel" => "self" }, { "href" => "http://localhost:6385/chassis/eaaca217-e7d8-47b4-bb41-3f99f20eed89/nodes", "rel" => "bookmark" } ], "updated_at" => "2000-01-01T12:00:00", "uuid" => chassis_uuid } ], :drivers => [ { "hosts" => [ "fake-host" ], "name" => "sample-driver" } ], :nodes => [{ "chassis_uuid" => chassis_uuid, "console_enabled" => false, "created_at" => "2000-01-01T12:00:00", "driver" => "sample-driver", "driver_info" => {}, "extra" => {}, "instance_info" => {}, "instance_uuid" => instance_uuid, "last_error" => nil, "links" => [ { "href" => "http://localhost:6385/v1/nodes/1be26c0b-03f2-4d2e-ae87-c02d7f33c123", "rel" => "self" }, { "href" => "http://localhost:6385/nodes/1be26c0b-03f2-4d2e-ae87-c02d7f33c123", "rel" => "bookmark" } ], "maintenance" => false, "maintenance_reason" => nil, "ports" => [ { "href" => "http://localhost:6385/v1/nodes/1be26c0b-03f2-4d2e-ae87-c02d7f33c123/ports", "rel" => "self" }, { "href" => "http://localhost:6385/nodes/1be26c0b-03f2-4d2e-ae87-c02d7f33c123/ports", "rel" => "bookmark" } ], "power_state" => "power on", "properties" => { "cpus" => "1", "local_gb" => "10", "memory_mb" => "1024" }, "provision_state" => "active", "provision_updated_at" => "2000-01-01T12:00:00", "reservation" => nil, "target_power_state" => nil, "target_provision_state" => nil, "updated_at" => "2000-01-01T12:00:00", "uuid" => node_uuid }], :ports => [{ "address" => "fe:54:00:77:07:d9", "created_at" => "2014-12-23T19:35:30.734116", "extra" => { "foo" => "bar" }, "links" => [ { "href" => "http://localhost:6385/v1/ports/27e3153e-d5bf-4b7e-b517-fb518e17f34c", "rel" => "self" }, { "href" => "http://localhost:6385/ports/27e3153e-d5bf-4b7e-b517-fb518e17f34c", "rel" => "bookmark" } ], "node_uuid" => "7ae81bb3-dec3-4289-8d6c-da80bd8001ae", "updated_at" => "2014-12-23T19:35:30.734119", "uuid" => "27e3153e-d5bf-4b7e-b517-fb518e17f34c" }] } end end def self.reset @data = nil end def initialize(options={}) @openstack_username = options[:openstack_username] @openstack_tenant = options[:openstack_tenant] @openstack_auth_uri = URI.parse(options[:openstack_auth_url]) @auth_token = Fog::Mock.random_base64(64) @auth_token_expiration = (Time.now.utc + 86400).iso8601 management_url = URI.parse(options[:openstack_auth_url]) management_url.port = 9292 management_url.path = '/v1' @openstack_management_url = management_url.to_s @data ||= { :users => {} } unless @data[:users].find {|u| u['name'] == options[:openstack_username]} id = Fog::Mock.random_numbers(6).to_s @data[:users][id] = { 'id' => id, 'name' => options[:openstack_username], 'email' => "#{options[:openstack_username]}@mock.com", 'tenantId' => Fog::Mock.random_numbers(6).to_s, 'enabled' => true } end end def data self.class.data[@openstack_username] end def reset_data self.class.data.delete(@openstack_username) end def credentials { :provider => 'openstack', :openstack_auth_url => @openstack_auth_uri.to_s, :openstack_auth_token => @auth_token, :openstack_region => @openstack_region, :openstack_management_url => @openstack_management_url } end end class Real include Fog::OpenStack::Core def initialize(options={}) initialize_identity options @openstack_service_type = options[:openstack_service_type] || ['baremetal'] @openstack_service_name = options[:openstack_service_name] @connection_options = options[:connection_options] || {} authenticate unless @path.match(SUPPORTED_VERSIONS) @path = "/" + Fog::OpenStack.get_supported_version(SUPPORTED_VERSIONS, @openstack_management_uri, @auth_token, @connection_options) end @persistent = options[:persistent] || false @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end def request(params) begin response = @connection.request(params.merge({ :headers => { 'Content-Type' => 'application/json', 'X-Auth-Token' => @auth_token }.merge!(params[:headers] || {}), :path => "#{@path}/#{params[:path]}"#, })) rescue Excon::Errors::Unauthorized => error if error.response.body != 'Bad username or password' # token expiration @openstack_must_reauthenticate = true authenticate retry else # bad credentials raise error end rescue Excon::Errors::HTTPStatusError => error raise case error when Excon::Errors::NotFound Fog::Compute::OpenStack::NotFound.slurp(error) else error end end unless response.body.empty? response.body = Fog::JSON.decode(response.body) end response end private end end end end fog-openstack-0.1.6/lib/fog/openstack/image_v2.rb0000644000175600017570000001164712730051546020661 0ustar pravipravirequire 'fog/openstack/common' require 'fog/openstack/image' module Fog module Image class OpenStack class V2 < Fog::Service SUPPORTED_VERSIONS = /v2(\.(0|1|2|3))*/ requires :openstack_auth_url recognizes :openstack_auth_token, :openstack_management_url, :persistent, :openstack_service_type, :openstack_service_name, :openstack_tenant, :openstack_tenant_id, :openstack_api_key, :openstack_username, :openstack_identity_endpoint, :current_user, :current_tenant, :openstack_region, :openstack_endpoint_type, :openstack_cache_ttl, :openstack_project_name, :openstack_project_id, :openstack_project_domain, :openstack_user_domain, :openstack_domain_name, :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id, :openstack_identity_prefix model_path 'fog/openstack/models/image_v2' model :image collection :images request_path 'fog/openstack/requests/image_v2' request :list_images request :get_image request :create_image request :update_image request :upload_image request :download_image request :reactivate_image request :deactivate_image request :add_tag_to_image request :remove_tag_from_image request :get_image_members request :get_member_details request :update_image_member request :get_shared_images request :add_member_to_image request :remove_member_from_image request :delete_image request :get_image_by_id request :set_tenant class Mock def self.data @data ||= Hash.new do |hash, key| hash[key] = { :images => {} } end end def self.reset @data = nil end def initialize(options = {}) @openstack_username = options[:openstack_username] @openstack_tenant = options[:openstack_tenant] @openstack_auth_uri = URI.parse(options[:openstack_auth_url]) @auth_token = Fog::Mock.random_base64(64) @auth_token_expiration = (Time.now.utc + 86400).iso8601 management_url = URI.parse(options[:openstack_auth_url]) management_url.port = 9292 management_url.path = '/v2' @openstack_management_url = management_url.to_s @data ||= {:users => {}} unless @data[:users].detect { |u| u['name'] == options[:openstack_username] } id = Fog::Mock.random_numbers(6).to_s @data[:users][id] = { 'id' => id, 'name' => options[:openstack_username], 'email' => "#{options[:openstack_username]}@mock.com", 'tenantId' => Fog::Mock.random_numbers(6).to_s, 'enabled' => true } end end def data self.class.data[@openstack_username] end def reset_data self.class.data.delete(@openstack_username) end def credentials {:provider => 'openstack', :openstack_auth_url => @openstack_auth_uri.to_s, :openstack_auth_token => @auth_token, :openstack_region => @openstack_region, :openstack_management_url => @openstack_management_url} end end class Upload # Exists for image_v2_upload_spec "describe" end class Real include Fog::OpenStack::Core def self.not_found_class Fog::Image::OpenStack::NotFound end include Fog::OpenStack::Common def initialize(options = {}) initialize_identity options @openstack_service_type = options[:openstack_service_type] || ['image'] @openstack_service_name = options[:openstack_service_name] @openstack_endpoint_type = options[:openstack_endpoint_type] || 'adminURL' @connection_options = options[:connection_options] || {} authenticate unless @path.match(SUPPORTED_VERSIONS) @path = Fog::OpenStack.get_supported_version_path(SUPPORTED_VERSIONS, @openstack_management_uri, @auth_token, @connection_options) end @persistent = options[:persistent] || false @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end end end end end end fog-openstack-0.1.6/lib/fog/openstack/image_v1.rb0000644000175600017570000001123412730051546020650 0ustar pravipravirequire 'fog/openstack/common' require 'fog/openstack/image' module Fog module Image class OpenStack class V1 < Fog::Service SUPPORTED_VERSIONS = /v1(\.(0|1))*/ requires :openstack_auth_url recognizes :openstack_auth_token, :openstack_management_url, :persistent, :openstack_service_type, :openstack_service_name, :openstack_tenant, :openstack_tenant_id, :openstack_api_key, :openstack_username, :openstack_identity_endpoint, :current_user, :current_tenant, :openstack_region, :openstack_endpoint_type, :openstack_cache_ttl, :openstack_project_name, :openstack_project_id, :openstack_project_domain, :openstack_user_domain, :openstack_domain_name, :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id, :openstack_identity_prefix model_path 'fog/openstack/models/image_v1' model :image collection :images request_path 'fog/openstack/requests/image_v1' request :list_public_images request :list_public_images_detailed request :get_image request :create_image request :update_image request :get_image_members request :update_image_members request :get_shared_images request :add_member_to_image request :remove_member_from_image request :delete_image request :get_image_by_id request :set_tenant class Mock def self.data @data ||= Hash.new do |hash, key| hash[key] = { :images => {} } end end def self.reset @data = nil end def initialize(options = {}) @openstack_username = options[:openstack_username] @openstack_tenant = options[:openstack_tenant] @openstack_auth_uri = URI.parse(options[:openstack_auth_url]) @auth_token = Fog::Mock.random_base64(64) @auth_token_expiration = (Time.now.utc + 86400).iso8601 management_url = URI.parse(options[:openstack_auth_url]) management_url.port = 9292 management_url.path = '/v1' @openstack_management_url = management_url.to_s @data ||= {:users => {}} unless @data[:users].detect { |u| u['name'] == options[:openstack_username] } id = Fog::Mock.random_numbers(6).to_s @data[:users][id] = { 'id' => id, 'name' => options[:openstack_username], 'email' => "#{options[:openstack_username]}@mock.com", 'tenantId' => Fog::Mock.random_numbers(6).to_s, 'enabled' => true } end end def data self.class.data[@openstack_username] end def reset_data self.class.data.delete(@openstack_username) end def credentials {:provider => 'openstack', :openstack_auth_url => @openstack_auth_uri.to_s, :openstack_auth_token => @auth_token, :openstack_region => @openstack_region, :openstack_management_url => @openstack_management_url} end end class Real include Fog::OpenStack::Core def self.not_found_class Fog::Image::OpenStack::NotFound end include Fog::OpenStack::Common def initialize(options = {}) initialize_identity options @openstack_service_type = options[:openstack_service_type] || ['image'] @openstack_service_name = options[:openstack_service_name] @openstack_endpoint_type = options[:openstack_endpoint_type] || 'adminURL' @connection_options = options[:connection_options] || {} authenticate unless @path.match(SUPPORTED_VERSIONS) @path = Fog::OpenStack.get_supported_version_path(SUPPORTED_VERSIONS, @openstack_management_uri, @auth_token, @connection_options) end @persistent = options[:persistent] || false @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end end end end end end fog-openstack-0.1.6/lib/fog/openstack/docs/0000755000175600017570000000000012730051546017562 5ustar pravipravifog-openstack-0.1.6/lib/fog/openstack/docs/planning.md0000644000175600017570000001415212730051546021715 0ustar pravipravi# Planning This document explains how to get started using OpenStack Tuskar with Fog. ## Starting irb console Start by executing the following command: ```bash irb ``` Once `irb` has launched you need to require the Fog library. If using Ruby 1.8.x execute: ```ruby require 'rubygems' require 'fog/openstack' ``` If using Ruby 1.9.x execute: ```ruby require 'fog/openstack' ``` ## Create Service Next, create a connection to Tuskar: ```ruby service = Fog::Openstack.new({ :service => :planning, # OpenStack Fog service :openstack_username => USERNAME, # Your OpenStack Username :openstack_api_key => PASSWORD, # Your OpenStack Password :openstack_auth_url => 'http://YOUR_OPENSTACK_ENDPOINT:PORT/v2.0/tokens' :connection_options => {} # Optional }) ``` ### Optional Connection Parameters Fog supports passing additional connection parameters to its underlying HTTP library (Excon) using the `:connection_options` parameter.
Key Description
:connect_timeout Connection timeout (default: 60 seconds)
:read_timeout Read timeout for connection (default: 60 seconds)
:write_timeout Write timeout for connection (default: 60 seconds)
:proxy Proxy for HTTP and HTTPS connections
:ssl_ca_path Path to SSL certificate authorities
:ssl_ca_file SSL certificate authority file
:ssl_verify_peer SSL verify peer (default: true)
## Fog Abstractions Fog provides both a **model** and **request** abstraction. The request abstraction provides the most efficient interface and the model abstraction wraps the request abstraction to provide a convenient `ActiveModel` like interface. ### Request Layer The `Fog::Openstack[:planning]` object supports a number of methods that wrap individual HTTP requests to the Tuskar API. To see a list of requests supported by the planning service: ```ruby service.requests ``` This returns: ```ruby [ :list_roles, :list_plans, :get_plan_templates, :get_plan, :patch_plan, :create_plan, :delete_plan, :add_role_to_plan, :remove_role_from_plan ] ``` #### Example Request To request a list of plans: ```ruby response = service.list_plans ``` This returns in the following `Excon::Response`: ```ruby # [ { "created_at"=>"2014-09-26T20:23:14.222815", "description"=>"Development testing cloud", "name"=>"dev-cloud", "parameters"=> [ { "default"=>"guest", "description"=>"The password for RabbitMQ", "hidden"=>true, "label"=>nil, "name"=>"compute-1 => =>RabbitPassword", "value"=>"secret-password" }, { "default"=>"default", "description"=>"description", "hidden"=>true, "label"=>nil, "name"=>"name", "value"=>"value" } ], "roles"=> [ { "description"=>"OpenStack hypervisor node. Can be wrapped in a ResourceGroup for scaling.\n", "name"=>"compute", "uuid"=>"b7b1583c-5c80-481f-a25b-708ed4a39734", "version"=>1 } ], "updated_at"=>nil, "uuid"=>"53268a27-afc8-4b21-839f-90227dd7a001" } ], :headers=>{}, :status=>200 }, @body="", @headers={}, @status=nil, @remote_ip=nil, @local_port=nil, @local_address=nil > ``` To view the status of the response: ```ruby response.status ``` **Note**: Fog is aware of the valid HTTP response statuses for each request type. If an unexpected HTTP response status occurs, Fog will raise an exception. To view response headers: ```ruby response.headers ``` This will return hash similar to: ```ruby { "X-Account-Bytes-Used"=>"2563554", "Date"=>"Thu, 21 Feb 2013 21:57:02 GMT", "X-Account-Meta-Temp-Url-Key"=>"super_secret_key", "X-Timestamp"=>"1354552916.82056", "Content-Length"=>"0", "Content-Type"=>"application/json; charset=utf-8", "X-Trans-Id"=>"txe934924374a744c8a6c40dd8f29ab94a", "Accept-Ranges"=>"bytes", "X-Account-Container-Count"=>"7", "X-Account-Object-Count"=>"5" } ``` [//]: # (TODO: Specify URL to rubydoc.info when OpenStack Planning service is part of release and pages are built) To learn more about `Fog::Openstack[:planning]` request methods refer to [rdoc](http://rubydoc.info/gems/fog/Fog). To learn more about Excon refer to [Excon GitHub repo](https://github.com/geemus/excon). ### Model Layer Fog models behave in a manner similar to `ActiveModel`. Models will generally respond to `create`, `save`, `destroy`, `reload` and `attributes` methods. Additionally, fog will automatically create attribute accessors. Here is a summary of common model methods:
Method Description
create Accepts hash of attributes and creates object.
Note: creation is a non-blocking call and you will be required to wait for a valid state before using resulting object.
save Saves object.
Note: not all objects support updating object.
destroy Destroys object.
Note: this is a non-blocking call and object deletion might not be instantaneous.
reload Updates object with latest state from service.
attributes Returns a hash containing the list of model attributes and values.
identity Returns the identity of the object.
Note: This might not always be equal to object.id.
The remainder of this document details the model abstraction. ## Additional Resources * [fog.io](http://fog.io/) * [Fog rdoc](http://rubydoc.info/gems/fog/) * [Fog Github repo](https://github.com/fog/fog) * [Fog Github Issues](https://github.com/fog/fog/issues) * [Excon Github repo](https://github.com/geemus/excon) * [Tuskar API](http://docs.openstack.org/developer/tuskar/) ## Support and Feedback Your feedback is appreciated! If you have specific issues with the **fog** SDK, you should file an [issue via Github](https://github.com/fog/fog/issues). fog-openstack-0.1.6/lib/fog/openstack/docs/getting_started.md0000644000175600017570000000464212730051546023301 0ustar pravipravi# Getting Started with Fog and OpenStack This document explains how to get started using Fog with [OpenStack](http://openstack.org) ## Requirements ### Ruby Fog officially supports Ruby 2.0.0, 1.9.3, 1.9.2, and 1.8.7 (also known as Matz Ruby Interpreter or MRI). While not officially supported, fog has been known to work with Rubinus and JRuby. Ruby 2.0.0 is suggested for new projects. For information on installing Ruby please refer to the [Ruby download page](http://www.ruby-lang.org/en/downloads/). ### RubyGems RubyGems is required to access the Fog gem. For information on installing RubyGems, please refer to [RubyGems download page](http://rubygems.org/pages/download). ### Bundler (optional) Bundler helps manage gem dependencies and is recommended for new projects. For more information about bundler, please refer to the [bundler documentation](http://gembundler.com/). ## Installation To install Fog-Openstack via RubyGems run the following command: $ gem install fog-openstack To install Fog via Bundler add `gem 'fog'` to your `Gemfile`. This is a sample `Gemfile` to install Fog: ```ruby source 'https://rubygems.org' gem 'fog-openstack' ``` After creating your `Gemfile` execute the following command to install the libraries: bundle install ## Next Steps Now that you have installed Fog and obtained your credentials, you are ready to begin exploring the capabilities of the Rackspace Open Cloud and Fog using `irb`. Start by executing the following command: irb Once `irb` has launched you will need to require the Fog library. If using Ruby 1.8.x execute the following command: ```ruby require 'rubygems' require 'fog/openstack' ``` If using Ruby 1.9.x execute the following command: ```ruby require 'fog/openstack' ``` You should now be able to execute the following command to see a list of services Fog provides for the Rackspace Open Cloud: ```ruby Fog::OpenStack.services ``` These services can be explored in further depth in the following documents: * [Compute](compute.md) * [Storage (Swift)](storage.md) ## Additional Resources * [fog.io](http://fog.io) * [Fog rdoc](http://rubydoc.info/gems/fog) * [Fog Github repo](https://github.com/fog/fog) * [Release Notes](https://github.com/fog/fog/blob/master/changelog.txt) ## Support and Feedback Your feedback is appreciated! If you have specific issues with the **fog** SDK, you should file an [issue via Github](https://github.com/fog/fog/issues). fog-openstack-0.1.6/lib/fog/openstack/docs/nfv.md0000644000175600017570000001056212730051546020701 0ustar pravipravi# NFV This document explains how to get started using NFV with fog-openstack. Please also refer to the [Getting Started with Fog and the OpenStack](getting_started.md) document. Tacker is an OpenStack service for NFV Orchestration with a general purpose VNF Manager to deploy and operate Virtual Network Functions (VNFs) and Network Services on an NFV Platform. It is based on ETSI MANO Architectural Framework. # OpenStack setup ## The catalog For the fog-openstack's introspection service to work, the corresponding service must be defined in the OpenStack catalog. ```bash openstack catalog show servicevm +-----------+-----------------------------------------+ | Field | Value | +-----------+-----------------------------------------+ | endpoints | regionOne | | | publicURL: http://172.16.0.21:8888/ | | | internalURL: http://172.16.0.21:8888/ | | | adminURL: http://172.16.0.21:8888/ | | | | | name | tacker | | type | servicevm | +-----------+-----------------------------------------+ ``` Depending on the OpenStack release, the NFV service might be installed but not defined yet in the catalog. In such case, you must add the service and corresponding endpoints to create the catalog entry: ```bash source ./stackrc openstack service create --name tacker --description "Tacker Project" servicevm openstack endpoint create --region regionOne tacker --publicurl http://example.com:8888 --internalurl http://example.com:8888 --adminurl http://example.com:8888 ``` # Work flow A usual work-flow might consist of: * Create vnfd * Deploy vnf using vnfd * Retrieve vnf and vnfd data For more details please refer to http://docs.openstack.org/developer/tacker/ Using 'irb', we start with authentication: ```ruby @user = "admin" @project = "admin" @password = "secret" @base_url = "http://keystone.example.com:5000/v3/auth/tokens" require 'rubygems' require 'fog/openstack' @connection_params = { :openstack_auth_url => @base_url, :openstack_username => @user, :openstack_api_key => @password, :openstack_project_name => @project, :openstack_domain_id => "default" } ``` ## Vnfd management ### Create vnfd ```ruby vnfd_data = {:attributes => {:vnfd => "template_name: sample-vnfd\ndescription: demo-example\n\nservice_properties:\n Id: sample-vnfd\n vendor: tacker\n version: 1\n\nvdus:\n vdu1:\n id: vdu1\n vm_image: cirros\n instance_type: m1.tiny\n\n network_interfaces:\n management:\n network: net_mgmt\n management: true\n pkt_in:\n network: net0\n pkt_out:\n network: net1\n\n placement_policy:\n availability_zone: nova\n\n auto-scaling: noop\n\n config:\n param0: key0\n param1: key1\n"}, :service_types => [{:service_type => "vnfd"}], :mgmt_driver => "noop", :infra_driver => "heat"} auth = {"tenantName" => "admin", "passwordCredentials" => {"username" => "admin","password" => "password"}} vnfd = Fog::NFV[:openstack].vnfds.create(:vnfd => vnfd_data, :auth => auth) ``` ### List vnfds ```ruby vnfds = Fog::NFV[:openstack].vnfds ``` ### Get vnfd ```ruby vnfd = Fog::NFV[:openstack].vnfds.last vnfd = Fog::NFV[:openstack].vnfds.get(vnfd.id) ``` ### Destroy vnfd ```ruby vnfd = Fog::NFV[:openstack].vnfds.last vnfd.destroy ``` ## Vnf management ### Create vnf using vnfd ```ruby vnfd = Fog::NFV[:openstack].vnfds.last vnf_data = {:vnfd_id => vnfd.id, :name => 'Test'} auth = {"tenantName" => "admin", "passwordCredentials" => {"username" => "admin","password" => "password"}} vnf = Fog::NFV[:openstack].vnfs.create(:vnf => vnf_data, :auth => auth) ``` ### List vnfs ```ruby vnfs = Fog::NFV[:openstack].vnfs ``` ### Get vnf ```ruby vnf = Fog::NFV[:openstack].vnfs.last vnf = Fog::NFV[:openstack].vnfs.get(vnf.id) ``` ### Update vnf ```ruby vnf = Fog::NFV[:openstack].vnfs.last vnf_data = {"attributes": {"config": "vdus:\n vdu1: \n\n"}} auth = {"tenantName" => "admin", "passwordCredentials" => {"username" => "admin","password" => "password"}} vnf = vnf.update(:vnf => vnf_data, :auth => auth) ``` ### Destroy vnf ```ruby vnf = Fog::NFV[:openstack].vnfs.last vnf.destroy ``` fog-openstack-0.1.6/lib/fog/openstack/docs/storage.md0000644000175600017570000002550412730051546021556 0ustar pravipravi# Storage This document explains how to get started using OpenStack Swift with Fog. ## Starting irb console Start by executing the following command: irb Once `irb` has launched you need to require the Fog library. If using Ruby 1.8.x execute: ```ruby require 'rubygems' require 'fog/openstack' ``` If using Ruby 1.9.x execute: ```ruby require 'fog/openstack' ``` ## Create Service Next, create a connection to Swift: ```ruby service = Fog::Storage::OpenStack.new({ :openstack_username => USERNAME, # Your OpenStack Username :openstack_api_key => PASSWORD, # Your OpenStack Password :openstack_auth_url => 'http://YOUR_OPENSTACK_ENDPOINT:PORT/v2.0/tokens' }) ``` Alternative regions are specified using the key `:openstack_region `. A list of regions available for Swift can be found by executing the following: ### Optional Service Parameters The Storage service supports the following additional parameters:
Key Description
:persistent If set to true, the service will use a persistent connection.
:openstack_service_name
:openstack_service_type
:openstack_tenant
:openstack_region
:openstack_temp_url_key
### Optional Connection Parameters Fog supports passing additional connection parameters to its underlying HTTP library (Excon) using the `:connection_options` parameter.
Key Description
:connect_timeout Connection timeout (default: 60 seconds)
:write_timeout Write timeout for connection (default: 60 seconds)
:proxy Proxy for HTTP and HTTPS connections
:ssl_ca_path Path to SSL certificate authorities
:ssl_ca_file SSL certificate authority file
:ssl_verify_peer SSL verify peer (default: true)
## Fog Abstractions Fog provides both a **model** and **request** abstraction. The request abstraction provides the most efficient interface and the model abstraction wraps the request abstraction to provide a convenient `ActiveModel` like interface. ### Request Layer The Fog::Storage object supports a number of methods that wrap individual HTTP requests to the Swift API. To see a list of requests supported by the storage service: service.requests This returns: [:copy_object, :delete_container, :delete_object, :delete_multiple_objects, :delete_static_large_object, :get_container, :get_containers, :get_object, :get_object_http_url, :get_object_https_url, :head_container, :head_containers, :head_object, :put_container, :put_object, :put_object_manifest, :put_dynamic_obj_manifest, :put_static_obj_manifest, :post_set_meta_temp_url_key] #### Example Request To request a view account details: ```ruby response = service.head_containers ``` This returns in the following `Excon::Response`: ``` #"2563554", "Date"=>"Thu, 21 Feb 2013 21:57:02 GMT", "X-Account-Meta-Temp-Url-Key"=>"super_secret_key", "X-Timestamp"=>"1354552916.82056", "Content-Length"=>"0", "Content-Type"=>"application/json; charset=utf-8", "X-Trans-Id"=>"txe934924374a744c8a6c40dd8f29ab94a", "Accept-Ranges"=>"bytes", "X-Account-Container-Count"=>"7", "X-Account-Object-Count"=>"5"}, @status=204, @body=""> ``` To view the status of the response: ```ruby response.status ``` **Note**: Fog is aware of the valid HTTP response statuses for each request type. If an unexpected HTTP response status occurs, Fog will raise an exception. To view response headers: ```ruby response.headers ``` This will return: ``` {"X-Account-Bytes-Used"=>"2563554", "Date"=>"Thu, 21 Feb 2013 21:57:02 GMT", "X-Account-Meta-Temp-Url-Key"=>"super_secret_key", "X-Timestamp"=>"1354552916.82056", "Content-Length"=>"0", "Content-Type"=>"application/json; charset=utf-8", "X-Trans-Id"=>"txe934924374a744c8a6c40dd8f29ab94a", "Accept-Ranges"=>"bytes", "X-Account-Container-Count"=>"7", "X-Account-Object-Count"=>"5"} ``` To learn more about `Fog::Storage` request methods refer to [rdoc](http://rubydoc.info/gems/fog/Fog/Storage/OpenStack/Real). To learn more about Excon refer to [Excon GitHub repo](https://github.com/geemus/excon). ### Model Layer Fog models behave in a manner similar to `ActiveModel`. Models will generally respond to `create`, `save`, `destroy`, `reload` and `attributes` methods. Additionally, fog will automatically create attribute accessors. Here is a summary of common model methods:
Method Description
create Accepts hash of attributes and creates object.
Note: creation is a non-blocking call and you will be required to wait for a valid state before using resulting object.
save Saves object.
Note: not all objects support updating object.
destroy Destroys object.
Note: this is a non-blocking call and object deletion might not be instantaneous.
reload Updates object with latest state from service.
attributes Returns a hash containing the list of model attributes and values.
identity Returns the identity of the object.
Note: This might not always be equal to object.id.
The remainder of this document details the model abstraction. **Note:** Fog sometimes refers to Swift containers as directories. ## List Directories To retrieve a list of directories: ```ruby service.directories ``` This returns a collection of `Fog::Storage::OpenStack::Directory` models: ## Get Directory To retrieve a specific directory: ```ruby service.directories.get "blue" ``` This returns a `Fog::Storage::OpenStack::Directory` instance: ## Create Directory To create a directory: ```ruby service.directories.create :key => 'backups' ``` ### Additional Parameters The `create` method also supports the following key values:
Key Description
:metadata Hash containing directory metadata.
## Delete Directory To delete a directory: ```ruby directory.destroy ``` **Note**: Directory must be empty before it can be deleted. ## Directory URL To get a directory's URL: ```ruby directory.public_url ``` ## List Files To list files in a directory: ```ruby directory.files ``` **Note**: File contents is not downloaded until `body` attribute is called. ## Upload Files To upload a file into a directory: ```ruby file = directory.files.create :key => 'space.jpg', :body => File.open "space.jpg" ``` **Note**: For files larger than 5 GB please refer to the [Upload Large Files](#upload_large_files) section. ### Additional Parameters The `create` method also supports the following key values:
Key Description
:content_type The content type of the object. Cloud Files will attempt to auto detect this value if omitted.
:access_control_allow_origin URLs can make Cross Origin Requests. Format is http://www.example.com. Separate URLs with a space. An asterisk (*) allows all. Please refer to CORS Container Headers for more information.
:origin The origin is the URI of the object's host.
:etag The MD5 checksum of your object's data. If specified, Cloud Files will validate the integrity of the uploaded object.
:metadata Hash containing file metadata.
## Upload Large Files Swift requires files larger than 5 GB (the Swift default limit) to be uploaded into segments along with an accompanying manifest file. All of the segments must be uploaded to the same container. ```ruby SEGMENT_LIMIT = 5368709119.0 # 5GB -1 BUFFER_SIZE = 1024 * 1024 # 1MB File.open(file_name) do |file| segment = 0 until file.eof? segment += 1 offset = 0 # upload segment to cloud files segment_suffix = segment.to_s.rjust(10, '0') service.put_object("my_container", "large_file/#{segment_suffix}", nil) do if offset <= SEGMENT_LIMIT - BUFFER_SIZE buf = file.read(BUFFER_SIZE).to_s offset += buf.size buf else '' end end end end # write manifest file service.put_object_manifest("my_container", "large_file", 'X-Object-Manifest' => "my_container/large_file/") ``` Segmented files are downloaded like ordinary files. See [Download Files](#download-files) section for more information. ## Download Files The most efficient way to download files from a private or public directory is as follows: ```ruby File.open('downloaded-file.jpg', 'w') do | f | directory.files.get("my_big_file.jpg") do | data, remaining, content_length | f.syswrite data end end ``` This will download and save the file in 1 MB chunks. The chunk size can be changed by passing the parameter `:chunk_size` into the `:connection_options` hash in the service constructor. **Note**: The `body` attribute of file will be empty if a file has been downloaded using this method. If a file object has already been loaded into memory, you can save it as follows: ```ruby File.open('germany.jpg', 'w') {|f| f.write(file_object.body) } ``` **Note**: This method is more memory intensive as the entire object is loaded into memory before saving the file as in the example above. ## File URL To get a file's URL: ```ruby file.public_url ``` ## Metadata You can access metadata as an attribute on `Fog::Storage::Rackspace::File`. ```ruby file.metadata[:environment] ``` File metadata is set when the file is saved: ```ruby file.save ``` Metadata is reloaded when directory or file is reloaded: ```ruby file.reload ``` ## Copy File Cloud Files supports copying files. To copy files into a container named "trip" with a name of "europe.jpg" do the following: ```ruby file.copy("trip", "europe.jpg") ``` To move or rename a file, perform a copy operation and then delete the old file: ```ruby file.copy("trip", "germany.jpg") file.destroy ``` ## Delete File To delete a file: ```ruby file.destroy ``` ## Additional Resources * [fog.io](http://fog.io/) * [Fog rdoc](http://rubydoc.info/gems/fog/) * [Fog Github repo](https://github.com/fog/fog) * [Fog Github Issues](https://github.com/fog/fog/issues) * [Excon Github repo](https://github.com/geemus/excon) * [Swift API](http://docs.openstack.org/api/openstack-object-storage/1.0/content/index.html) ## Support and Feedback Your feedback is appreciated! If you have specific issues with the **fog** SDK, you should file an [issue via Github](https://github.com/fog/fog/issues). fog-openstack-0.1.6/lib/fog/openstack/docs/compute.md0000644000175600017570000007503612730051546021573 0ustar pravipravi#Compute (Nova) This document explains how to get started using OpenStack Compute (Nova) with Fog. It assumes you have read the [Getting Started with Fog and the OpenStack](getting_started.md) document. ## Starting irb console Start by executing the following command: irb Once `irb` has launched you need to require the Fog library by executing: require 'fog/openstack' ## Create Service Next, create a connection to the Compute Service: service = Fog::Compute::OpenStack.new({ :openstack_auth_url => 'http://KEYSTONE_HOST:KEYSTONE_PORT/v2.0/tokens', # OpenStack Keystone endpoint :openstack_username => OPEN_STACK_USER, # Your OpenStack Username :openstack_tenant => OPEN_STACK_TENANT, # Your tenant id :openstack_api_key => OPEN_STACK_PASSWORD, # Your OpenStack Password :connection_options => {} # Optional }) **Note** `openstack_username` and `openstack_tenant` default to `admin` if omitted. ### Optional Connection Parameters Fog supports passing additional connection parameters to its underlying HTTP library (Excon) using the `:connection_options` parameter.
Key Description
:connect_timeout Connection timeout (default: 60 seconds)
:read_timeout Read timeout for connection (default: 60 seconds)
:write_timeout Write timeout for connection (default: 60 seconds)
:proxy Proxy for HTTP and HTTPS connections
:ssl_ca_path Path to SSL certificate authorities
:ssl_ca_file SSL certificate authority file
:ssl_verify_peer SSL verify peer (default: true)
## Fog Abstractions Fog provides both a **model** and **request** abstraction. The request abstraction provides the most efficient interface and the model abstraction wraps the request abstraction to provide a convenient `ActiveModel` like interface. ### Request Layer The request abstraction maps directly to the [OpenStack Compute API](http://docs.openstack.org/api/openstack-compute/2/content/). It provides the most efficient interface to the OpenStack Compute service. To see a list of requests supported by the service: service.requests This returns: :list_servers, :list_servers_detail, :create_server, :get_server_details, :update_server, :delete_server, :server_actions, :server_action, :reboot_server, :rebuild_server, :resize_server, :confirm_resize_server, :revert_resize_server, :pause_server, :unpause_server, :suspend_server, :resume_server, :rescue_server, :change_server_password, :add_fixed_ip, :remove_fixed_ip, :server_diagnostics, :boot_from_snapshot, :reset_server_state, :get_console_output, :get_vnc_console, :live_migrate_server, :migrate_server, :list_images, :list_images_detail, :create_image, :get_image_details, :delete_image, :list_flavors, :list_flavors_detail, :get_flavor_details, :create_flavor, :delete_flavor, :add_flavor_access, :remove_flavor_access, :list_tenants_with_flavor_access, :list_metadata, :get_metadata, :set_metadata, :update_metadata, :delete_metadata, :delete_meta, :update_meta, :list_addresses, :list_address_pools, :list_all_addresses, :list_private_addresses, :list_public_addresses, :get_address, :allocate_address, :associate_address, :release_address, :disassociate_address, :list_security_groups, :get_security_group, :create_security_group, :create_security_group_rule, :delete_security_group, :delete_security_group_rule, :get_security_group_rule, :list_key_pairs, :create_key_pair, :delete_key_pair, :list_tenants, :set_tenant, :get_limits, :list_volumes, :create_volume, :get_volume_details, :delete_volume, :attach_volume, :detach_volume, :get_server_volumes, :create_snapshot, :list_snapshots, :get_snapshot_details, :delete_snapshot, :list_usages, :get_usage, :get_quota, :get_quota_defaults, :update_quota, :list_hosts, :get_host_details #### Example Request To request a list of flavors: response = service.list_flavors This returns in the following `Excon::Response`: #{"flavors"=>[{"id"=>"1", "links"=>[{"href"=>"http://localhost:8774/v2/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/1", "rel"=>"self"}, {"href"=>"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/1", "rel"=>"bookmark"}], "name"=>"m1.tiny"}, {"id"=>"2", "links"=>[{"href"=>"http://localhost:8774/v2/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/2", "rel"=>"self"}, {"href"=>"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/2", "rel"=>"bookmark"}], "name"=>"m1.small"}, {"id"=>"3", "links"=>[{"href"=>"http://localhost:8774/v2/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/3", "rel"=>"self"}, {"href"=>"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/3", "rel"=>"bookmark"}], "name"=>"m1.medium"}, {"id"=>"4", "links"=>[{"href"=>"http://localhost:8774/v2/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/4", "rel"=>"self"}, {"href"=>"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/4", "rel"=>"bookmark"}], "name"=>"m1.large"}, {"id"=>"42", "links"=>[{"href"=>"http://localhost:8774/v2/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/42", "rel"=>"self"}, {"href"=>"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/42", "rel"=>"bookmark"}], "name"=>"m1.nano"}, {"id"=>"5", "links"=>[{"href"=>"http://localhost:8774/v2/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/5", "rel"=>"self"}, {"href"=>"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/5", "rel"=>"bookmark"}], "name"=>"m1.xlarge"}, {"id"=>"84", "links"=>[{"href"=>"http://localhost:8774/v2/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/84", "rel"=>"self"}, {"href"=>"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/84", "rel"=>"bookmark"}], "name"=>"m1.micro"}]}, :headers=>{"Content-Type"=>"application/json", "Content-Length"=>"1748", "X-Compute-Request-Id"=>"req-ae3bcf11-deab-493b-a2d8-1432dead3f7a", "Date"=>"Thu, 09 Jan 2014 17:01:15 GMT"}, :status=>200, :remote_ip=>"localhost"}, @body="{\"flavors\": [{\"id\": \"1\", \"links\": [{\"href\": \"http://localhost:8774/v2/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/1\", \"rel\": \"self\"}, {\"href\": \"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/1\", \"rel\": \"bookmark\"}], \"name\": \"m1.tiny\"}, {\"id\": \"2\", \"links\": [{\"href\": \"http://localhost:8774/v2/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/2\", \"rel\": \"self\"}, {\"href\": \"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/2\", \"rel\": \"bookmark\"}], \"name\": \"m1.small\"}, {\"id\": \"3\", \"links\": [{\"href\": \"http://localhost:8774/v2/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/3\", \"rel\": \"self\"}, {\"href\": \"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/3\", \"rel\": \"bookmark\"}], \"name\": \"m1.medium\"}, {\"id\": \"4\", \"links\": [{\"href\": \"http://localhost:8774/v2/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/4\", \"rel\": \"self\"}, {\"href\": \"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/4\", \"rel\": \"bookmark\"}], \"name\": \"m1.large\"}, {\"id\": \"42\", \"links\": [{\"href\": \"http://localhost:8774/v2/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/42\", \"rel\": \"self\"}, {\"href\": \"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/42\", \"rel\": \"bookmark\"}], \"name\": \"m1.nano\"}, {\"id\": \"5\", \"links\": [{\"href\": \"http://localhost:8774/v2/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/5\", \"rel\": \"self\"}, {\"href\": \"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/5\", \"rel\": \"bookmark\"}], \"name\": \"m1.xlarge\"}, {\"id\": \"84\", \"links\": [{\"href\": \"http://localhost:8774/v2/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/84\", \"rel\": \"self\"}, {\"href\": \"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/84\", \"rel\": \"bookmark\"}], \"name\": \"m1.micro\"}]}", @headers={"Content-Type"=>"application/json", "Content-Length"=>"1748", "X-Compute-Request-Id"=>"req-ae3bcf11-deab-493b-a2d8-1432dead3f7a", "Date"=>"Thu, 09 Jan 2014 17:01:15 GMT"}, @status=200, @remote_ip="localhost"> To view the status of the response: response.status **Note**: Fog is aware of valid HTTP response statuses for each request type. If an unexpected HTTP response status occurs, Fog will raise an exception. To view response body: response.body This will return: {"flavors"=>[{"id"=>"1", "links"=>[{"href"=>"http://localhost:8774/v2/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/1", "rel"=>"self"}, {"href"=>"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/1", "rel"=>"bookmark"}], "name"=>"m1.tiny"}, {"id"=>"2", "links"=>[{"href"=>"http://localhost:8774/v2/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/2", "rel"=>"self"}, {"href"=>"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/2", "rel"=>"bookmark"}], "name"=>"m1.small"}, {"id"=>"3", "links"=>[{"href"=>"http://localhost:8774/v2/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/3", "rel"=>"self"}, {"href"=>"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/3", "rel"=>"bookmark"}], "name"=>"m1.medium"}, {"id"=>"4", "links"=>[{"href"=>"http://localhost:8774/v2/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/4", "rel"=>"self"}, {"href"=>"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/4", "rel"=>"bookmark"}], "name"=>"m1.large"}, {"id"=>"42", "links"=>[{"href"=>"http://localhost:8774/v2/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/42", "rel"=>"self"}, {"href"=>"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/42", "rel"=>"bookmark"}], "name"=>"m1.nano"}, {"id"=>"5", "links"=>[{"href"=>"http://localhost:8774/v2/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/5", "rel"=>"self"}, {"href"=>"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/5", "rel"=>"bookmark"}], "name"=>"m1.xlarge"}, {"id"=>"84", "links"=>[{"href"=>"http://localhost:8774/v2/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/84", "rel"=>"self"}, {"href"=>"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/84", "rel"=>"bookmark"}], "name"=>"m1.micro"}]} To learn more about Compute request methods refer to [rdoc](http://rubydoc.info/gems/fog/Fog/Compute/Openstack/Real). To learn more about Excon refer to [Excon GitHub repo](https://github.com/geemus/excon). ### Model Layer Fog models behave in a manner similar to `ActiveModel`. Models will generally respond to `create`, `save`, `persisted?`, `destroy`, `reload` and `attributes` methods. Additionally, fog will automatically create attribute accessors. Here is a summary of common model methods:
Method Description
create Accepts hash of attributes and creates object.
Note: creation is a non-blocking call and you will be required to wait for a valid state before using resulting object.
save Saves object.
Note: not all objects support updating object.
persisted? Returns true if the object has been persisted.
destroy Destroys object.
Note: this is a non-blocking call and object deletion might not be instantaneous.
reload Updates object with latest state from service.
ready? Returns true if object is in a ready state and able to perform actions. This method will raise an exception if object is in an error state.
attributes Returns a hash containing the list of model attributes and values.
identity Returns the identity of the object.
Note: This might not always be equal to object.id.
wait_for This method periodically reloads model and then yields to specified block until block returns true or a timeout occurs.
The remainder of this document details the model abstraction. ## List Images To retrieve a list of available images: service.images This returns a collection of `Fog::Compute::OpenStack::Image` models: , ] >, links=[{"href"=>"http://localhost:8774/v2/b5bf8e689bc64844b1d08094a2f2bdd5/images/821e2b73-5aed-4f9d-aaa7-2f4f297779f3", "rel"=>"self"}, {"href"=>"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/images/821e2b73-5aed-4f9d-aaa7-2f4f297779f3", "rel"=>"bookmark"}, {"href"=>"http://localhost:9292/b5bf8e689bc64844b1d08094a2f2bdd5/images/821e2b73-5aed-4f9d-aaa7-2f4f297779f3", "type"=>"application/vnd.openstack.image", "rel"=>"alternate"}] >, , links=[{"href"=>"http://localhost:8774/v2/b5bf8e689bc64844b1d08094a2f2bdd5/images/e21af7e2-a181-403a-84a4-fd9df36cb963", "rel"=>"self"}, {"href"=>"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/images/e21af7e2-a181-403a-84a4-fd9df36cb963", "rel"=>"bookmark"}, {"href"=>"http://localhost:9292/b5bf8e689bc64844b1d08094a2f2bdd5/images/e21af7e2-a181-403a-84a4-fd9df36cb963", "type"=>"application/vnd.openstack.image", "rel"=>"alternate"}] >, … ## Get Image To retrieve individual image: service.images.get "821e2b73-5aed-4f9d-aaa7-2f4f297779f3" This returns an `Fog::Compute::OpenStack::Image` instance: , ] >, links=[{"href"=>"http://localhost:8774/v2/b5bf8e689bc64844b1d08094a2f2bdd5/images/821e2b73-5aed-4f9d-aaa7-2f4f297779f3", "rel"=>"self"}, {"href"=>"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/images/821e2b73-5aed-4f9d-aaa7-2f4f297779f3", "rel"=>"bookmark"}, {"href"=>"http://localhost:9292/b5bf8e689bc64844b1d08094a2f2bdd5/images/821e2b73-5aed-4f9d-aaa7-2f4f297779f3", "type"=>"application/vnd.openstack.image", "rel"=>"alternate"}] > ## List Flavors To retrieve a list of available flavors: service.flavors This returns a collection of `Fog::Compute::OpenStack::Flavor` models: "http://localhost:8774/v2/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/1", "rel"=>"self"}, {"href"=>"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/1", "rel"=>"bookmark"}], swap="", rxtx_factor=1.0, ephemeral=0, is_public=true, disabled=false >, "http://localhost:8774/v2/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/2", "rel"=>"self"}, {"href"=>"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/2", "rel"=>"bookmark"}], swap="", rxtx_factor=1.0, ephemeral=0, is_public=true, disabled=false >, … ## Get Flavor To retrieve individual flavor: service.flavors.get 1 This returns a `Fog::Compute::OpenStack::Flavor` instance: "http://localhost:8774/v2/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/1", "rel"=>"self"}, {"href"=>"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/1", "rel"=>"bookmark"}], swap="", rxtx_factor=1.0, ephemeral=0, is_public=true, disabled=false > ## List Servers To retrieve a list of available servers: service.servers This returns a collection of `Fog::Compute::OpenStack::Servers` models: [{"OS-EXT-IPS-MAC:mac_addr"=>"fa:16:3e:14:34:b8", "version"=>4, "addr"=>"10.0.0.5", "OS-EXT-IPS:type"=>"fixed"}]}, flavor={"id"=>"1", "links"=>[{"href"=>"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/1", "rel"=>"bookmark"}]}, host_id="bb705edc279c520d97ad6fbd0b8e75a5c716388616f58e527d0ff633", image={"id"=>"821e2b73-5aed-4f9d-aaa7-2f4f297779f3", "links"=>[{"href"=>"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/images/821e2b73-5aed-4f9d-aaa7-2f4f297779f3", "rel"=>"bookmark"}]}, metadata= , links=[{"href"=>"http://localhost:8774/v2/b5bf8e689bc64844b1d08094a2f2bdd5/servers/4572529c-0cfc-433e-8dbf-7cc383ed5b7c", "rel"=>"self"}, {"href"=>"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/servers/4572529c-0cfc-433e-8dbf-7cc383ed5b7c", "rel"=>"bookmark"}], name="doc-test", personality=nil, progress=0, accessIPv4="", accessIPv6="", availability_zone="nova", user_data_encoded=nil, state="ACTIVE", created=2013-10-10 18:17:46 UTC, updated=2013-10-10 18:17:56 UTC, tenant_id="b5bf8e689bc64844b1d08094a2f2bdd5", user_id="dbee88bc901b4593867c105b2b1ad15b", key_name=nil, fault=nil, config_drive="", os_dcf_disk_config="MANUAL", os_ext_srv_attr_host="devstack", os_ext_srv_attr_hypervisor_hostname="devstack", os_ext_srv_attr_instance_name="instance-00000016", os_ext_sts_power_state=1, os_ext_sts_task_state=nil, os_ext_sts_vm_state="active" >, … ## Get Server To return an individual server: service.servers.get "4572529c-0cfc-433e-8dbf-7cc383ed5b7c" This returns a `Fog::Compute::OpenStack::Server` instance: [{"OS-EXT-IPS-MAC:mac_addr"=>"fa:16:3e:14:34:b8", "version"=>4, "addr"=>"10.0.0.5", "OS-EXT-IPS:type"=>"fixed"}]}, flavor={"id"=>"1", "links"=>[{"href"=>"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/1", "rel"=>"bookmark"}]}, host_id="bb705edc279c520d97ad6fbd0b8e75a5c716388616f58e527d0ff633", image={"id"=>"821e2b73-5aed-4f9d-aaa7-2f4f297779f3", "links"=>[{"href"=>"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/images/821e2b73-5aed-4f9d-aaa7-2f4f297779f3", "rel"=>"bookmark"}]}, metadata= , links=[{"href"=>"http://localhost:8774/v2/b5bf8e689bc64844b1d08094a2f2bdd5/servers/4572529c-0cfc-433e-8dbf-7cc383ed5b7c", "rel"=>"self"}, {"href"=>"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/servers/4572529c-0cfc-433e-8dbf-7cc383ed5b7c", "rel"=>"bookmark"}], name="doc-test", personality=nil, progress=0, accessIPv4="", accessIPv6="", availability_zone="nova", user_data_encoded=nil, state="ACTIVE", created=2013-10-10 18:17:46 UTC, updated=2013-10-10 18:17:56 UTC, tenant_id="b5bf8e689bc64844b1d08094a2f2bdd5", user_id="dbee88bc901b4593867c105b2b1ad15b", key_name=nil, fault=nil, config_drive="", os_dcf_disk_config="MANUAL", os_ext_srv_attr_host="devstack", os_ext_srv_attr_hypervisor_hostname="devstack", os_ext_srv_attr_instance_name="instance-00000016", os_ext_sts_power_state=1, os_ext_sts_task_state=nil, os_ext_sts_vm_state="active" > ## Create Server If you are interested in creating a server utilizing ssh key authentication, you are recommended to use [bootstrap](#bootstrap) method. To create a server: flavor = service.flavors.first image = service.images.first server = service.servers.create(:name => 'fog-doc', :flavor_ref => flavor.id, :image_ref => image.id) **Note**: The `:name`, `:flavor_ref`, and `image_ref` attributes are required for server creation. This will return a `Fog::Compute::OpenStack::Server` instance: , links=[{"href"=>"http://localhost:8774/v2/b5bf8e689bc64844b1d08094a2f2bdd5/servers/81746324-94ab-44fb-9aa9-ee0b4d95fa34", "rel"=>"self"}, {"href"=>"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/servers/81746324-94ab-44fb-9aa9-ee0b4d95fa34", "rel"=>"bookmark"}], name="fog-doc", personality=nil, progress=nil, accessIPv4=nil, accessIPv6=nil, availability_zone=nil, user_data_encoded=nil, state=nil, created=nil, updated=nil, tenant_id=nil, user_id=nil, key_name=nil, fault=nil, config_drive=nil, os_dcf_disk_config="MANUAL", os_ext_srv_attr_host=nil, os_ext_srv_attr_hypervisor_hostname=nil, os_ext_srv_attr_instance_name=nil, os_ext_sts_power_state=nil, os_ext_sts_task_state=nil, os_ext_sts_vm_state=nil > Notice that your server contains several `nil` attributes. To see the latest status, reload the instance as follows: server.reload You can see that the server is currently being built: [{"OS-EXT-IPS-MAC:mac_addr"=>"fa:16:3e:71:0d:c4", "version"=>4, "addr"=>"10.0.0.2", "OS-EXT-IPS:type"=>"fixed"}]}, flavor={"id"=>"1", "links"=>[{"href"=>"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/flavors/1", "rel"=>"bookmark"}]}, host_id="bb705edc279c520d97ad6fbd0b8e75a5c716388616f58e527d0ff633", image={"id"=>"821e2b73-5aed-4f9d-aaa7-2f4f297779f3", "links"=>[{"href"=>"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/images/821e2b73-5aed-4f9d-aaa7-2f4f297779f3", "rel"=>"bookmark"}]}, metadata= , links=[{"href"=>"http://localhost:8774/v2/b5bf8e689bc64844b1d08094a2f2bdd5/servers/5f50aeff-a745-4cbc-9f8b-0356142e6f95", "rel"=>"self"}, {"href"=>"http://localhost:8774/b5bf8e689bc64844b1d08094a2f2bdd5/servers/5f50aeff-a745-4cbc-9f8b-0356142e6f95", "rel"=>"bookmark"}], name="fog-doc", personality=nil, progress=0, accessIPv4="", accessIPv6="", availability_zone="nova", user_data_encoded=nil, state="BUILD", created=2014-01-09 19:43:52 UTC, updated=2014-01-09 19:43:58 UTC, tenant_id="b5bf8e689bc64844b1d08094a2f2bdd5", user_id="dbee88bc901b4593867c105b2b1ad15b", key_name=nil, fault=nil, config_drive="", os_dcf_disk_config="MANUAL", os_ext_srv_attr_host="devstack", os_ext_srv_attr_hypervisor_hostname="devstack", os_ext_srv_attr_instance_name="instance-00000018", os_ext_sts_power_state=0, os_ext_sts_task_state="spawning", os_ext_sts_vm_state="building" > You will be unable to perform any actions to this server until it reaches an `ACTIVE` state. Since this is true for most server actions, Fog provides the convenience method `wait_for`. Fog can wait for the server to become ready as follows: server.wait_for { ready? } **Note**: The `Fog::Compute::OpenStack::Server` instance returned from the create method contains a `password` attribute. The `password` attribute will NOT be present in subsequent retrievals either through `service.servers` or `service.servers.get my_server_id`. ### Additional Parameters The `create` method also supports the following key values:
Key Description
:metadata Hash containing server metadata.
:personality Array of files to be injected onto the server. Please refer to the Fog personality API documentation for further information.
## Bootstrap In addition to the `create` method, Fog provides a `bootstrap` method which creates a server and then performs the following actions via ssh: 1. Create `ROOT_USER/.ssh/authorized_keys` file using the ssh key specified in `:public_key_path`. 2. Lock password for root user using `passwd -l root`. 3. Create `ROOT_USER/attributes.json` file with the contents of `server.attributes`. 4. Create `ROOT_USER/metadata.json` file with the contents of `server.metadata`. **Note**: Unlike the `create` method, `bootstrap` is blocking method call. If non-blocking behavior is desired, developers should use the `:personality` parameter on the `create` method. The following example demonstrates bootstraping a server: service.servers.bootstrap :name => 'bootstrap-server', :flavor_id => service.flavors.first.id, :image_id => service.images.find {|img| img.name =~ /Ubuntu/}.id, :public_key_path => '~/.ssh/fog_rsa.pub', :private_key_path => '~/.ssh/fog_rsa' **Note**: The `:name`, `:flavor_ref`, `:image_ref`, `:public_key_path`, `:private_key_path` are required for the `bootstrap` method. The `bootstrap` method uses the same additional parameters as the `create` method. Refer to the [Additional Parameters](#additional-parameters) section for more information. ## SSH Once a server has been created and set up for ssh key authentication, fog can execute remote commands as follows: result = server.ssh ['pwd'] This will return the following: [#] **Note**: SSH key authentication can be set up using `bootstrap` method or by using the `:personality` attribute on the `:create` method. See [Bootstrap](#bootstrap) or [Create Server](#create-server) for more information. ## Delete Server To delete a server: server.destroy **Note**: The server is not immediately destroyed, but it does occur shortly there after. ## Change Admin Password To change the administrator password: server.change_password "superSecure" ## Reboot To perform a soft reboot: server.reboot To perform a hard reboot: server.reboot 'HARD' ## Rebuild Rebuild removes all data on the server and replaces it with the specified image. The id and all IP addresses remain the same. The rebuild method has the following method signature: def rebuild(image_ref, name, admin_pass=nil, metadata=nil, personality=nil) A basic server build is as follows: image = service.images.first server.rebuild(image.id, name) ## Resize Resizing a server allows you to change the resources dedicated to the server. To resize a server: flavor = service.flavor[2] server.resize flavor.id During the resize process the server will have a state of `RESIZE`. Once a server has completed resizing it will be in a `VERIFY_RESIZE` state. You can use Fog's `wait_for` method to wait for this state as follows: server.wait_for { server.status == 'VERIFY_RESIZE' } In this case, `wait_for` is waiting for the server to become `VERIFY_READY` and will raise an exception if we enter an `ACTIVE` or `ERROR` state. Once a server enters the `VERIFY_RESIZE` we will need to call `confirm_resize` to confirm the server was properly resized or `revert_resize` to rollback to the old size/flavor. **Note:** A server will automatically confirm resize after 24 hours. To confirm resize: server.confirm_resize To revert to previous size/flavor: server.revert_resize ## Create Image To create an image of your server: response = server.create_image "back-image-#{server.name}", :metadata => { :environment => 'development' } You can use the second parameter to specify image metadata. This is an optional parameter.` During the imaging process, the image state will be `SAVING`. The image is ready for use when when state `ACTIVE` is reached. Fog can use `wait_for` to wait for an active state as follows: image_id = response.body["image"]["id"] image = service.images.get image_id image.wait_for { ready? } ## List Attached Volumes To list Cloud Block Volumes attached to server: server.volume_attachments ## Attach Volume To attach volume using the volume id: server.attach_volume "0e7a706c-340d-48b3-802d-192850387f93", "/dev/xvdb" If the volume id is unknown you can look it up as follows: volume = service.volumes.first server.attach_volume volume.id, "/dev/xvdb" **Note** Valid device names are `/dev/xvd[a-p]`. ## Detach Volume To detach a volume: server.detach_volume volume.id ## Examples Example code using Compute can be found [here](https://github.com/fog/fog/tree/master/lib/fog/openstack/examples/compute). ## Additional Resources * [fog.io](http://fog.io/) * [Fog rdoc](http://rubydoc.info/gems/fog/) * [Fog Github repo](https://github.com/fog/fog) * [Fog Github Issues](https://github.com/fog/fog/issues) * [Excon Github repo](https://github.com/geemus/excon) * [OpenStack Compute API](http://docs.openstack.org/api/openstack-compute/2/content/) ## Support and Feedback Your feedback is appreciated! If you have specific issues with the **fog** SDK, you should file an [issue via Github](https://github.com/fog/fog/issues). fog-openstack-0.1.6/lib/fog/openstack/docs/introspection.md0000644000175600017570000001553512730051546023015 0ustar pravipravi# Introspection This document explains how to get started using introspection with fog-openstack. Please also refer to the [Getting Started with Fog and the OpenStack](getting_started.md) document. Introspection service is implemented by the OpenStack ironic-inspector project. Introspection is strongly related to the Baremetal service (Ironic project). Effectively, Instrospection communicates and operates on nodes defined by the Baremetal layer (Ironic). # OpenStack setup ## The catalog For the fog-openstack's introspection service to work, the corresponding service must be defined in the OpenStack catalog. ```bash openstack catalog show inspector +-----------+-----------------------------------------+ | Field | Value | +-----------+-----------------------------------------+ | endpoints | regionOne | | | publicURL: http://192.0.2.1:5050/v1 | | | internalURL: http://192.0.2.1:5050/v1 | | | adminURL: http://192.0.2.1:5050/v1 | | | | | name | inspector | | type | introspection | +-----------+-----------------------------------------+ ``` Depending on the OpenStack release, the introspection service might be installed but not defined yet in the catalog. In such case, you must add the service and corresponding endpoints to create the catalog entry: ```bash source ./stackrc openstack service create --name inspector --description "OpenStack Introspection" introspection openstack endpoint create --region regionOne inspector --publicurl http://example.com:5050/v1 --internalurl http://example.com:5050/v1 --adminurl http://example.com:5050/v1 ``` ## The introspection timeout The default timeout value after which introspection is considered failed is set by an 1 hour (3600 s) default. Although in production environment, baremetal introspection requires time, testing in virtual environment doesn't, this is why if you are in the latter case the timeout value can be reduced for speeding results: ```bash sudo openstack-config --set /etc/ironic-inspector/inspector.conf DEFAULT timeout 300 ``` # Work flow Assuming Baremetal nodes have been defined (imported), a usual work-flow might consist of: * Start introspection * Check introspection status or abort introspection * Retrieve introspection data * optionally, pre-defined DSL based rules can be defined and applied during introspection. For more details about this process please refer to http://docs.openstack.org/developer/ironic-inspector/workflow.html Using 'irb', we start with authentication: ```ruby @user = "admin" @project = "admin" @password = "secret" @base_url = "http://keystone.example.com:5000/v3/auth/tokens" require 'rubygems' require 'fog/openstack' @connection_params = { :openstack_auth_url => @base_url, :openstack_username => @user, :openstack_api_key => @password, :openstack_project_name => @project, :openstack_domain_id => "default" } ``` ## Baremetal node introspection ### Baremetal nodes Find the available Baremetal nodes. ```ruby iron = Fog::Baremetal::OpenStack.new(@connection_params) nodes = iron.node_list ``` ### Start introspection Let's start introspection using the first available node. Note: To be introspected, a node must be in "manage" state. If needed, use Baremetal Service to change the state with set_node_provision_state. For more information, please refer to http://docs.openstack.org/developer/ironic/deploy/install-guide.html#hardware-inspection ```ruby node_id = nodes.body["nodes"][0]["uuid"] inspector = Fog::Introspection::OpenStack.new(@connection_params) introspection1 = inspector.create_introspection(node_id) ``` If everything went well the status returned by the request must be 202 which means accepted: ```ruby introspection1.status => 202 ``` ### Check introspection status To check the status of the introspection: ```ruby inspector.get_introspection(node_id) ``` The body returned has 2 fields: * finished: A boolean, set to true if introspection process is finished * error: A null string unless an error occurred or the process was canceled by the operator (in case introspection was aborted) ### Abort an ongoing introspection To abort a node introspection: ```ruby inspector.abort_introspection(node_id) ``` ### Retrieve introspected data ```ruby inspector.get_introspection_details(node_id) ``` The response body will provide a *very* long list of information about the node. ## DSL rules ### Create rules ```ruby rule_set1 = { "description" => "Successful Rule", "actions" => [ { "action" => "set-attribute", "path" => "/extra/rule_success", "value" => "yes" } ], "conditions" => [ { "field" => "memory_mb", "op" => "ge", "value" => 256 }, { "field" => "local_gb", "op" => "ge", "value" => 1 } ] } rule_set2 = { "description" => "Failing Rule", "actions" => [ { "action" => "set-attribute", "path" => "/extra/rule_success", "value" => "no" }, { "action" => "fail", "message" => "This rule should not have run" } ], "conditions" => [ { "field" => "memory_mb", "op" => "lt", "value" => 42 }, { "field" => "local_gb", "op" => "eq", "value" => 0 } ], } inspector.create_rules(rule_set1) inspector.create_rules(rule_set2) ``` ### List all rules ```ruby inspector.list_rules.body => {"rules"=> [{"description"=>"Successful Rule", "links"=>[{"href"=>"/v1/rules/4bf1bf40-d30f-4f31-a970-f0290d7e751b", "rel"=>"self"}], "uuid"=>"4bf1bf40-d30f-4f31-a970-f0290d7e751b"}, {"description"=>"Failing Rule", "links"=>[{"href"=>"/v1/rules/0d6e6687-3f69-4c14-8cab-ea6ada78036f", "rel"=>"self"}], "uuid"=>"0d6e6687-3f69-4c14-8cab-ea6ada78036f"}]} ``` ### Show rules details ```ruby inspector.get_rules('0d6e6687-3f69-4c14-8cab-ea6ada78036f').body => {"actions"=> [{"action"=>"set-attribute", "path"=>"/extra/rule_success", "value"=>"no"}, {"action"=>"fail", "message"=>"This rule should not have run"}], "conditions"=>[{"field"=>"memory_mb", "op"=>"lt", "value"=>42}, {"field"=>"local_gb", "op"=>"eq", "value"=>0}], "description"=>"Failing Rule", "links"=>[{"href"=>"/v1/rules/0d6e6687-3f69-4c14-8cab-ea6ada78036f", "rel"=>"self"}], "uuid"=>"0d6e6687-3f69-4c14-8cab-ea6ada78036f"} ``` ### Delete a specific rules set ```ruby inspector.delete_rules'0d6e6687-3f69-4c14-8cab-ea6ada78036f') inspector.list_rules.body => {"rules"=> [{"description"=>"Successful Rule", "links"=>[{"href"=>"/v1/rules/4bf1bf40-d30f-4f31-a970-f0290d7e751b", "rel"=>"self"}], "uuid"=>"4bf1bf40-d30f-4f31-a970-f0290d7e751b"}]} ``` ### Destroys all rules ```ruby inspector.delete_rules_all inspector.list_rules.body => {"rules"=>[]} ``` fog-openstack-0.1.6/lib/fog/openstack/docs/metering.md0000644000175600017570000000302712730051546021720 0ustar pravipravi# OpenStack Metering (Ceilometer) This document explains how to get started using OpenStack Metering (Ceilometer) with Fog. It assumes you have read the [Getting Started with Fog and the OpenStack](getting_started.md) document. Fog uses the [OpenStack Metering API](http://docs.openstack.org/developer/ceilometer/webapi/v2.html). ## Metering Service Get a handle on the Metering service: ```ruby service = Fog::Metering::OpenStack.new({ :openstack_auth_url => 'http://KEYSTONE_HOST:KEYSTONE_PORT/v2.0/tokens', # OpenStack Keystone endpoint :openstack_username => OPEN_STACK_USER, # Your OpenStack Username :openstack_tenant => OPEN_STACK_TENANT, # Your tenant id :openstack_api_key => OPEN_STACK_PASSWORD, # Your OpenStack Password :connection_options => {} # Optional }) ``` ## Events * `service.events([])`: Return a list of events. * `service.events.find_by_id()`: Return the event matching message_id, or nil if no such event exists. ### Filter events example Return events newer than 2016-03-17T09:59:44.606000. ```ruby query_filter = [{ 'field' => 'start_timestamp', 'op' => 'gt', 'value' => '2016-03-17T09:59:44.606000' }] service.events(query_filter) ``` ## Resources * `service.resources`: Return a list of resources. * `service.resources.find_by_id()`: Return the resource matching resource_id, or nil if no such resource exists. fog-openstack-0.1.6/lib/fog/openstack/docs/network.md0000644000175600017570000002500412730051546021576 0ustar pravipravi# Network (Neutron) This document explains how to get started using OpenStack Network (Neutron) with Fog. It assumes you have read the [Getting Started with Fog and OpenStack](getting_started.md) document. ## Starting irb console Start by executing the following command: ``` irb ``` Once `irb` has launched you need to require the Fog library by executing: ``` require 'fog/openstack' ``` ## Create Service Next, create a connection to the Network Service: ``` service = Fog::Network::OpenStack.new( :openstack_auth_url => 'http://KEYSTONE_HOST:KEYSTONE_PORT/v3/auth/tokens', # OpenStack Keystone v3 endpoint :openstack_username => OPEN_STACK_USER, # Your OpenStack Username :openstack_domain_name => OPEN_STACK_DOMAIN, # Your OpenStack Domain name :openstack_project_name => OPEN_STACK_PROJECT, # Your OpenStack Project name :openstack_api_key => OPEN_STACK_PASSWORD, # Your OpenStack Password :connection_options => {} # Optional ) ``` ### Optional Connection Parameters Fog supports passing additional connection parameters to its underlying HTTP library (Excon) using the `:connection_options` parameter.
Key Description
:connect_timeout Connection timeout (default: 60 seconds)
:read_timeout Read timeout for connection (default: 60 seconds)
:write_timeout Write timeout for connection (default: 60 seconds)
:proxy Proxy for HTTP and HTTPS connections
:ssl_ca_path Path to SSL certificate authorities
:ssl_ca_file SSL certificate authority file
:ssl_verify_peer SSL verify peer (default: true)
## Fog Abstractions Fog provides both a **model** and **request** abstraction. The request abstraction provides the most efficient interface and the model abstraction wraps the request abstraction to provide a convenient `ActiveModel` like interface. ### Request Layer The request abstraction maps directly to the [OpenStack Network API](http://developer.openstack.org/api-ref-networking-v2.html). It provides the most efficient interface to the OpenStack Network service. To see a list of requests supported by the service: ``` service.requests ``` This returns: ``` :list_networks, :create_network, :delete_network, :get_network, :update_network, :list_ports, :create_port, :delete_port, :get_port, :update_port, :list_subnets, :create_subnet, :delete_subnet, :get_subnet, :update_subnet, :list_floating_ips, :create_floating_ip, :delete_floating_ip, :get_floating_ip, :associate_floating_ip, :disassociate_floating_ip, :list_routers, :create_router, :delete_router, :get_router, :update_router, :add_router_interface, :remove_router_interface, :list_lb_pools, :create_lb_pool, :delete_lb_pool, :get_lb_pool, :get_lb_pool_stats, :update_lb_pool, :list_lb_members, :create_lb_member, :delete_lb_member, :get_lb_member, :update_lb_member, :list_lb_health_monitors, :create_lb_health_monitor, :delete_lb_health_monitor, :get_lb_health_monitor, :update_lb_health_monitor, :associate_lb_health_monitor, :disassociate_lb_health_monitor, :list_lb_vips, :create_lb_vip, :delete_lb_vip, :get_lb_vip, :update_lb_vip, :list_vpn_services, :create_vpn_service, :delete_vpn_service, :get_vpn_service, :update_vpn_service, :list_ike_policies, :create_ike_policy, :delete_ike_policy, :get_ike_policy, :update_ike_policy, :list_ipsec_policies, :create_ipsec_policy, :delete_ipsec_policy, :get_ipsec_policy, :update_ipsec_policy, :list_ipsec_site_connections, :create_ipsec_site_connection, :delete_ipsec_site_connection, :get_ipsec_site_connection, :update_ipsec_site_connection, :list_rbac_policies, :create_rbac_policy, :delete_rbac_policy, :get_rbac_policy, :update_rbac_policy, :create_security_group, :delete_security_group, :get_security_group, :list_security_groups, :create_security_group_rule, :delete_security_group_rule, :get_security_group_rule, :list_security_group_rules, :set_tenant, :get_quotas, :get_quota, :update_quota, :delete_quota ``` #### Example Request To request a list of networks: ``` response = service.list_networks ``` This returns in the following `Excon::Response`: ``` #{"networks"=>[ {"id"=>"f9c54735-a230-443e-9379-b87f741cc1b1", "name"=>"Public", "subnets"=>["db50da7f-1248-43d2-aa30-1c10da0d380d"], "shared"=>true, "status"=>"ACTIVE", "tenant_id"=>"a51fd915", "provider_network_type"=>"vlan", "router:external"=>false, "admin_state_up"=>true}, {"id"=>"e624a36d-762b-481f-9b50-4154ceb78bbb", "name"=>"network_1", "subnets"=>["2e4ec6a4-0150-47f5-8523-e899ac03026e"], "shared"=>false, "status"=>"ACTIVE", "admin_state_up"=>true, "tenant_id"=>"f8b26a6032bc47718a7702233ac708b9"}]}, :status=>200, :headers=>{}}, @body={"networks"=>[ {"id"=>"f9c54735-a230-443e-9379-b87f741cc1b1", "name"=>"Public", "subnets"=>["db50da7f-1248-43d2-aa30-1c10da0d380d"], "shared"=>true, "status"=>"ACTIVE", "tenant_id"=>"a51fd915", "provider_network_type"=>"vlan", "router:external"=>false, "admin_state_up"=>true}, {"id"=>"e624a36d-762b-481f-9b50-4154ceb78bbb", "name"=>"network_1", "subnets"=>["2e4ec6a4-0150-47f5-8523-e899ac03026e"], "shared"=>false, "status"=>"ACTIVE", "admin_state_up"=>true, "tenant_id"=>"f8b26a6032bc47718a7702233ac708b9"}]}, @headers={}, @status=200, @remote_ip=nil, @local_port=nil, @local_address=nil > ``` To view the status of the response: ``` response.status ``` **Note**: Fog is aware of valid HTTP response statuses for each request type. If an unexpected HTTP response status occurs, Fog will raise an exception. To view response body: ``` response.body ``` This will return: ``` {"networks"=>[ {"id"=>"f9c54735-a230-443e-9379-b87f741cc1b1", "name"=>"Public", "subnets"=>["db50da7f-1248-43d2-aa30-1c10da0d380d"], "shared"=>true, "status"=>"ACTIVE", "tenant_id"=>"a51fd915", "provider_network_type"=>"vlan", "router:external"=>false, "admin_state_up"=>true}, {"id"=>"e624a36d-762b-481f-9b50-4154ceb78bbb", "name"=>"network_1", "subnets"=>["2e4ec6a4-0150-47f5-8523-e899ac03026e"], "shared"=>false, "status"=>"ACTIVE", "admin_state_up"=>true, "tenant_id"=>"f8b26a6032bc47718a7702233ac708b9"}] } ``` To learn more about Network request methods refer to [rdoc](http://www.rubydoc.info/gems/fog-openstack/Fog/Network/OpenStack/Real). To learn more about Excon refer to [Excon GitHub repo](https://github.com/geemus/excon). ### Model Layer Fog models behave in a manner similar to `ActiveModel`. Models will generally respond to `create`, `save`, `persisted?`, `destroy`, `reload` and `attributes` methods. Additionally, fog will automatically create attribute accessors. Here is a summary of common model methods:
Method Description
create Accepts hash of attributes and creates object.
Note: creation is a non-blocking call and you will be required to wait for a valid state before using resulting object.
save Saves object.
Note: not all objects support updating object.
persisted? Returns true if the object has been persisted.
destroy Destroys object.
Note: this is a non-blocking call and object deletion might not be instantaneous.
reload Updates object with latest state from service.
ready? Returns true if object is in a ready state and able to perform actions. This method will raise an exception if object is in an error state.
attributes Returns a hash containing the list of model attributes and values.
identity Returns the identity of the object.
Note: This might not always be equal to object.id.
wait_for This method periodically reloads model and then yields to specified block until block returns true or a timeout occurs.
To see a list of collections supported by the service: ``` service.collections ``` This returns: ``` :networks, :ports, :subnets, :floating_ips, :routers, :lb_pools, :lb_members, :lb_health_monitors, :lb_vips, :vpn_services, :ike_policies, :ipsec_policies, :ipsec_site_connections, :rbac_policies, :security_groups, :security_group_rules ``` #### Example Request To request a collection of networks: ``` networks = service.networks ``` This returns in the following `Fog::OpenStack::Model`: ``` ] >, shared=true, status="ACTIVE", admin_state_up=true, tenant_id="a51fd915", provider_network_type="vlan", provider_physical_network=nil, provider_segmentation_id=nil, router_external=false >, , shared=false, status="ACTIVE", admin_state_up=true, tenant_id="f8b26a6032bc47718a7702233ac708b9", provider_network_type=nil, provider_physical_network=nil, provider_segmentation_id=nil, router_external=nil > ] > ``` To access the name of the first network: ``` networks.first.name ``` This will return: ``` "Public" ``` ## Examples Example code using Network can be found [here](https://github.com/fog/fog-openstack/tree/master/lib/fog/openstack/examples/network). ## Additional Resources * [fog.io](http://fog.io/) * [fog-openstack rdoc](http://rubydoc.info/gems/fog-openstack) * [fog-openstack Github repo](https://github.com/fog/fog-openstack) * [fog-openstack Github Issues](https://github.com/fog/fog-openstack/issues) * [Excon Github repo](https://github.com/geemus/excon) * [OpenStack Network API](http://developer.openstack.org/api-ref-networking-v2.html) ## Support and Feedback Your feedback is appreciated! If you have specific issues with the **fog-openstack** SDK, you should file an [issue via Github](https://github.com/fog/fog-openstack/issues). fog-openstack-0.1.6/lib/fog/openstack/docs/orchestration.md0000644000175600017570000003300212730051546022766 0ustar pravipravi# OpenStack Orchestration The mission of the OpenStack Orchestration program is to create a human- and machine-accessible service for managing the entire lifecycle of infrastructure and applications within OpenStack clouds. ## Heat Heat is the main project in the OpenStack Orchestration program. It implements an orchestration engine to launch multiple composite cloud applications based on templates in the form of text files that can be treated like code. A native Heat template format is evolving, but Heat also endeavours to provide compatibility with the AWS CloudFormation template format, so that many existing CloudFormation templates can be launched on OpenStack. Heat provides both an OpenStack-native ReST API and a CloudFormation-compatible Query API. *Why ‘Heat’? It makes the clouds rise!* **How it works** * A Heat template describes the infrastructure for a cloud application in a text file that is readable and writable by humans, and can be checked into version control, diffed, &c. * Infrastructure resources that can be described include: servers, floating ips, volumes, security groups, users, etc. * Heat also provides an autoscaling service that integrates with Ceilometer, so you can include a scaling group as a resource in a template. * Templates can also specify the relationships between resources (e.g. this volume is connected to this server). This enables Heat to call out to the OpenStack APIs to create all of your infrastructure in the correct order to completely launch your application. * Heat manages the whole lifecycle of the application - when you need to change your infrastructure, simply modify the template and use it to update your existing stack. Heat knows how to make the necessary changes. It will delete all of the resources when you are finished with the application, too. * Heat primarily manages infrastructure, but the templates integrate well with software configuration management tools such as Puppet and Chef. The Heat team is working on providing even better integration between infrastructure and software. _Source: [OpenStack Wiki](https://wiki.openstack.org/wiki/Heat)_ # OpenStack Orchestration (Heat) Client [Full OpenStack Orchestration/Heat API Docs](http://developer.openstack.org/api-ref-orchestration-v1.html) ## Orchestration Service Get a handle on the Orchestration service: ```ruby service = Fog::Orchestration::OpenStack.new({ :openstack_auth_url => 'http://KEYSTONE_HOST:KEYSTONE_PORT/v2.0/tokens', # OpenStack Keystone endpoint :openstack_username => OPEN_STACK_USER, # Your OpenStack Username :openstack_tenant => OPEN_STACK_TENANT, # Your tenant id :openstack_api_key => OPEN_STACK_PASSWORD, # Your OpenStack Password :connection_options => {} # Optional }) ``` We will use this `service` to interact with the Orchestration resources, `stack`, `event`, `resource`, and `template` ## Stacks Get a list of stacks you own: ```ruby service.stacks ``` This returns a list of stacks with minimum attributes, leaving other attributes empty ```ruby => "http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/stack4/0b8e4060-419b-416b-a927-097d4afbf26d", "rel"=>"self"}], notification_topics=nil, outputs=nil, parameters=nil, stack_name="stack4", stack_status="UPDATE_COMPLETE", stack_status_reason="Stack successfully updated", template_description=nil, timeout_mins=nil, creation_time="2014-08-27T21:25:56Z", updated_time="2015-01-30T20:10:43Z" >, ... ``` Create a new `stack` with a [Heat Template (HOT)](http://docs.openstack.org/developer/heat/template_guide/hot_guide.html) or an AWS CloudFormation Template (CFN): ```ruby raw_template = File.read(TEMPLATE_FILE) service.stacks.new.save({ :stack_name => "a_name_for_stack", :template => raw_template, :parameters => {"flavor" => "m1.small", "image" => "cirror"} }) ``` This returns a JSON blob filled with information about our new stack: ```ruby {"id"=>"53b35fbe-34f7-4837-b0f8-8863b7263b7d", "links"=>[{"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/a_name_for_stack/53b35fbe-34f7-4837-b0f8-8863b7263b7d", "rel"=>"self"}]} ``` We can get a reference to the stack using its `stack_name` and `id`: ```ruby stack = service.stacks.get("stack4", "0b8e4060-419b-416b-a927-097d4afbf26d") ``` This returns a stack with all attributes filled ```ruby => "http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/stack4/0b8e4060-419b-416b-a927-097d4afbf26d", "rel"=>"self"}], notification_topics=[], outputs=[], parameters={"AWS::StackId"=>"arn:openstack:heat::5d139d95546240748508b2a518aa5bef:stacks/stack4/0b8e4060-419b-416b-a927-097d4afbf26d", "AWS::Region"=>"ap-southeast-1", "AWS::StackName"=>"stack4"}, stack_name="stack4", stack_status="UPDATE_COMPLETE", stack_status_reason="Stack successfully updated", template_description="Simple template to deploy a single compute instance", timeout_mins=60, creation_time="2014-08-27T21:25:56Z", updated_time="2015-01-30T20:10:43Z" > ``` It can be also obtained through the details method of a simple stack object ```ruby stack.details ``` A stack knows about related `events`: ```ruby stack.events => "http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/a_name_for_stack/53b35fbe-34f7-4837-b0f8-8863b7263b7d/resources/my_instance/events/251", "rel"=>"self"}, {"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/a_name_for_stack/53b35fbe-34f7-4837-b0f8-8863b7263b7d/resources/my_instance", "rel"=>"resource"}, {"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/a_name_for_stack/53b35fbe-34f7-4837-b0f8-8863b7263b7d", "rel"=>"stack"}], logical_resource_id="my_instance", resource_status="CREATE_IN_PROGRESS", resource_status_reason="state changed", physical_resource_id=nil >, ``` A stack knows about related `resources`: ```ruby stack.resources => "http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9/resources/my_instance", "rel"=>"self"}, {"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9", "rel"=>"stack"}], logical_resource_id="my_instance", resource_status="CREATE_COMPLETE", updated_time="2014-09-12T20:44:06Z", required_by=[], resource_status_reason="state changed", resource_type="OS::Nova::Server" > ] > ``` You can get a stack's `template` ```ruby stack.template => #"", :headers=>{"Content-Type"=>"text/html; charset=UTF-8", "Content-Length"=>"0", "Date"=>"Wed, 21 Jan 2015 20:38:00 GMT"}, :status=>204, :reason_phrase=>"No Content", :remote_ip=>"10.8.96.4", :local_port=>59628, :local_address=>"10.17.68.186"}, @body="", @headers={"Content-Type"=>"text/html; charset=UTF-8", "Content-Length"=>"0", "Date"=>"Wed, 21 Jan 2015 20:38:00 GMT"}, @status=204, @remote_ip="10.8.96.4", @local_port=59628, @local_address="10.17.68.186"> ``` Reload any object by calling `reload` on it: ```ruby stacks.reload => ``` ## Events You can list `Events` of a `stack`: ```ruby stack.events => "http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9/resources/my_instance/events/15", "rel"=>"self"}, {"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9/resources/my_instance", "rel"=>"resource"}, {"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9", "rel"=>"stack"}], logical_resource_id="my_instance", resource_status="CREATE_IN_PROGRESS", resource_status_reason="state changed", physical_resource_id=nil >, ``` `Event` can be got through corresponding `resource` ```ruby event = service.events.get(stack, resource, event_id) => "http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9/resources/my_instance/events/15", "rel"=>"self"}, {"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9/resources/my_instance", "rel"=>"resource"}, {"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9", "rel"=>"stack"}], logical_resource_id="my_instance", resource_status="CREATE_IN_PROGRESS", resource_status_reason="state changed", physical_resource_id=nil > ``` An `event` knows about its associated `stack`: ```ruby event.stack => "http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9", "rel"=>"self"}], stack_status_reason="Stack create completed successfully", stack_name="progenerated", creation_time="2014-09-12T20:43:58Z", updated_time="2014-09-12T20:44:06Z" > ``` An `event` has an associated `resource`: ```ruby resource = event.resource => "http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9/resources/my_instance", "rel"=>"self"}, {"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9", "rel"=>"stack"}], logical_resource_id="my_instance", resource_status="CREATE_COMPLETE", updated_time="2014-09-12T20:44:06Z", required_by=[], resource_status_reason="state changed", resource_type="OS::Nova::Server" > ``` ## Resource `resources` might be nested: ```ruby service.resources.all(stack, {:nested_depth => 1}) => "http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9/resources/my_instance", "rel"=>"self"}, {"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9", "rel"=>"stack"}], logical_resource_id="my_instance", resource_status="CREATE_COMPLETE", updated_time="2014-09-12T20:44:06Z", required_by=[], resource_status_reason="state changed", resource_type="OS::Nova::Server" > ] > ``` A `resource` knows about its associated `stack`: ```ruby resource.stack => "http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9", "rel"=>"self"}], stack_status_reason="Stack create completed successfully", stack_name="progenerated", creation_time="2014-09-12T20:43:58Z", updated_time="2014-09-12T20:44:06Z" > ``` Resource metadata is visible: ```ruby irb: resource.metadata => {} ``` A `resource's` template is visible (if one exists) ```ruby irb: resource.template => nil ``` ## Validation You can validate a template (either HOT or CFN) before using it: ```ruby service.templates.validate(:template => content) => ``` fog-openstack-0.1.6/lib/fog/openstack/nfv.rb0000644000175600017570000001173712730051546017761 0ustar pravipravirequire 'yaml' module Fog module NFV class OpenStack < Fog::Service SUPPORTED_VERSIONS = /v1.0/ requires :openstack_auth_url recognizes :openstack_auth_token, :openstack_management_url, :persistent, :openstack_service_type, :openstack_service_name, :openstack_tenant, :openstack_tenant_id, :openstack_api_key, :openstack_username, :openstack_identity_endpoint, :current_user, :current_tenant, :openstack_region, :openstack_endpoint_type, :openstack_project_name, :openstack_project_id, :openstack_project_domain, :openstack_user_domain, :openstack_domain_name, :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id ## REQUESTS # request_path 'fog/openstack/requests/nfv' # vnfds requests request :list_vnfds request :get_vnfd request :create_vnfd request :delete_vnfd # vfns requests request :list_vnfs request :get_vnf request :create_vnf request :update_vnf request :delete_vnf ## MODELS # model_path 'fog/openstack/models/nfv' model :vnfd collection :vnfds model :vnf collection :vnfs class Mock def self.data @data ||= Hash.new do |hash, key| hash[key] = { :vnfs => [ { "status" => "ACTIVE", "description" => "demo-example", "tenant_id" => "943b6ff8229a4ec2bed0a306f869a0ea", "instance_id" => "5a9a7d3b-24f5-4226-8d43-262972a1776e", "mgmt_url" => "{\"vdu1\": \"192.168.0.8\"}", "attributes" => {"monitoring_policy" => "{\"vdus\": {}}"}, "id" => "cb4cdbd8-cf1a-4758-8d36-40db788a37a1", "name" => "LadasTest" } ], :vnfds => [ { "service_types" => [{"service_type" => "vnfd", "id" => "f9211d81-b58a-4849-8d38-e25376c421bd"}], "description" => "demo-example", "tenant_id" => "943b6ff8229a4ec2bed0a306f869a0ea", "mgmt_driver" => "noop", "infra_driver" => "heat", "attributes" => {"vnfd" => "template_name: sample-vnfd"}, "id" => "1f8f33cf-8c94-427e-a040-f3e393b773b7", "name" => "sample-vnfd" } ] } end end def self.reset @data = nil end include Fog::OpenStack::Core def initialize(options = {}) @auth_token = Fog::Mock.random_base64(64) @auth_token_expiration = (Time.now.utc + 86_400).iso8601 initialize_identity options end def data self.class.data[@openstack_username] end def reset_data self.class.data.delete(@openstack_username) end end class Real include Fog::OpenStack::Core def initialize(options = {}) initialize_identity options @openstack_service_type = options[:openstack_service_type] || ['servicevm'] @openstack_service_name = options[:openstack_service_name] @connection_options = options[:connection_options] || {} authenticate unless @path.match(SUPPORTED_VERSIONS) @path = "/" + Fog::OpenStack.get_supported_version( SUPPORTED_VERSIONS, @openstack_management_uri, @auth_token, @connection_options ) end @persistent = options[:persistent] || false @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end def request(params) response = @connection.request( params.merge( :headers => { 'Content-Type' => 'application/json', 'X-Auth-Token' => @auth_token }.merge!(params[:headers] || {}), :path => "#{@path}/#{params[:path]}" ) ) rescue Excon::Errors::Unauthorized => error if error.response.body != "Bad username or password" # token expiration @openstack_must_reauthenticate = true authenticate retry else # bad credentials raise error end rescue Excon::Errors::HTTPStatusError => error raise case error when Excon::Errors::NotFound Fog::NFV::OpenStack::NotFound.slurp(error) else error end else unless response.body.empty? response.body = Fog::JSON.decode(response.body) end response end end end end end fog-openstack-0.1.6/lib/fog/openstack/introspection.rb0000644000175600017570000001007112730051546022056 0ustar pravipravirequire 'yaml' module Fog module Introspection class OpenStack < Fog::Service SUPPORTED_VERSIONS = /v1/ requires :openstack_auth_url recognizes :openstack_auth_token, :openstack_management_url, :persistent, :openstack_service_type, :openstack_service_name, :openstack_tenant, :openstack_tenant_id, :openstack_api_key, :openstack_username, :openstack_identity_endpoint, :current_user, :current_tenant, :openstack_region, :openstack_endpoint_type, :openstack_cache_ttl, :openstack_project_name, :openstack_project_id, :openstack_project_domain, :openstack_user_domain, :openstack_domain_name, :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id ## REQUESTS # request_path 'fog/openstack/requests/introspection' # Introspection requests request :create_introspection request :get_introspection request :abort_introspection request :get_introspection_details # Rules requests request :create_rules request :list_rules request :delete_rules_all request :get_rules request :delete_rules ## MODELS # model_path 'fog/openstack/models/introspection' model :rules collection :rules_collection class Mock def self.data @data ||= Hash.new do |hash, key| # Introspection data is *huge* we load it from a yaml file file = "../../../../tests/fixtures/introspection.yaml" hash[key] = YAML.load(File.read(File.expand_path(file, __FILE__))) end end def self.reset @data = nil end include Fog::OpenStack::Core def initialize(options = {}) @auth_token = Fog::Mock.random_base64(64) @auth_token_expiration = (Time.now.utc + 86_400).iso8601 initialize_identity options end def data self.class.data[@openstack_username] end def reset_data self.class.data.delete(@openstack_username) end end class Real include Fog::OpenStack::Core def initialize(options = {}) initialize_identity options @openstack_service_type = options[:openstack_service_type] || ['introspection'] @openstack_service_name = options[:openstack_service_name] @connection_options = options[:connection_options] || {} authenticate unless @path.match(SUPPORTED_VERSIONS) @path = "/" + Fog::OpenStack.get_supported_version( SUPPORTED_VERSIONS, @openstack_management_uri, @auth_token, @connection_options ) end @persistent = options[:persistent] || false @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end def request(params) response = @connection.request( params.merge( :headers => { 'Content-Type' => 'application/json', 'X-Auth-Token' => @auth_token }.merge!(params[:headers] || {}), :path => "#{@path}/#{params[:path]}" ) ) rescue Excon::Errors::Unauthorized => error if error.response.body != "Bad username or password" # token expiration @openstack_must_reauthenticate = true authenticate retry else # bad credentials raise error end rescue Excon::Errors::HTTPStatusError => error raise case error when Excon::Errors::NotFound Fog::Introspection::OpenStack::NotFound.slurp(error) else error end else unless response.body.empty? response.body = Fog::JSON.decode(response.body) end response end end end end end fog-openstack-0.1.6/lib/fog/openstack/orchestration.rb0000644000175600017570000001377712730051546022062 0ustar pravipravi module Fog module Orchestration class OpenStack < Fog::Service requires :openstack_auth_url recognizes :openstack_auth_token, :openstack_management_url, :persistent, :openstack_service_type, :openstack_service_name, :openstack_tenant, :openstack_tenant_id, :openstack_api_key, :openstack_username, :openstack_identity_endpoint, :current_user, :current_tenant, :openstack_region, :openstack_endpoint_type, :openstack_cache_ttl, :openstack_project_name, :openstack_project_id, :openstack_project_domain, :openstack_user_domain, :openstack_domain_name, :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id, :openstack_identity_prefix model_path 'fog/openstack/models/orchestration' model :stack collection :stacks model :resource collection :resources collection :resource_schemas model :event collection :events model :template collection :templates request_path 'fog/openstack/requests/orchestration' request :abandon_stack request :build_info request :create_stack request :delete_stack request :get_stack_template request :list_events request :list_resource_events request :list_resource_types request :list_resources request :list_stack_data request :list_stack_data_detailed request :list_stack_events request :preview_stack request :show_event_details request :show_resource_data request :show_resource_metadata request :show_resource_schema request :show_resource_template request :show_stack_details request :update_stack request :patch_stack request :validate_template module Reflectable REFLECTION_REGEX = /\/stacks\/(\w+)\/([\w|-]+)\/resources\/(\w+)/ def resource @resource ||= service.resources.get(r[3], stack) end def stack @stack ||= service.stacks.get(r[1], r[2]) end private def reflection @reflection ||= REFLECTION_REGEX.match(self.links[0]['href']) end alias :r :reflection end class Mock attr_reader :auth_token attr_reader :auth_token_expiration attr_reader :current_user attr_reader :current_tenant def self.data @data ||= Hash.new do |hash, key| hash[key] = { :stacks => {} } end end def self.reset @data = nil end def initialize(options={}) @openstack_username = options[:openstack_username] @openstack_auth_uri = URI.parse(options[:openstack_auth_url]) @current_tenant = options[:openstack_tenant] @auth_token = Fog::Mock.random_base64(64) @auth_token_expiration = (Time.now.utc + 86400).iso8601 management_url = URI.parse(options[:openstack_auth_url]) management_url.port = 8774 management_url.path = '/v1' @openstack_management_url = management_url.to_s identity_public_endpoint = URI.parse(options[:openstack_auth_url]) identity_public_endpoint.port = 5000 @openstack_identity_public_endpoint = identity_public_endpoint.to_s end def data self.class.data["#{@openstack_username}-#{@current_tenant}"] end def reset_data self.class.data.delete("#{@openstack_username}-#{@current_tenant}") end def credentials { :provider => 'openstack', :openstack_auth_url => @openstack_auth_uri.to_s, :openstack_auth_token => @auth_token, :openstack_management_url => @openstack_management_url, :openstack_identity_endpoint => @openstack_identity_public_endpoint } end end class Real include Fog::OpenStack::Core def initialize(options={}) initialize_identity options @openstack_identity_service_type = options[:openstack_identity_service_type] || 'identity' @openstack_service_type = options[:openstack_service_type] || ['orchestration'] @openstack_service_name = options[:openstack_service_name] @connection_options = options[:connection_options] || {} authenticate @persistent = options[:persistent] || false @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end def request(params) begin response = @connection.request(params.merge({ :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'X-Auth-Token' => @auth_token, 'X-Auth-User' => @openstack_username, 'X-Auth-Key' => @openstack_api_key }.merge!(params[:headers] || {}), :path => "#{@path}/#{params[:path]}", :query => params[:query] })) rescue Excon::Errors::Unauthorized => error if error.response.body != 'Bad username or password' # token expiration @openstack_must_reauthenticate = true authenticate retry else # Bad Credentials raise error end rescue Excon::Errors::HTTPStatusError => error raise case error when Excon::Errors::NotFound Fog::Compute::OpenStack::NotFound.slurp(error) else error end end if !response.body.empty? and response.get_header('Content-Type') =~ /application\/json/ then response.body = Fog::JSON.decode(response.body) end response end private end end end end fog-openstack-0.1.6/lib/fog/openstack/identity_v2.rb0000644000175600017570000001361212730051546021422 0ustar pravipravi require 'fog/openstack/common' require 'fog/openstack/identity' module Fog module Identity class OpenStack class V2 < Fog::Service requires :openstack_auth_url recognizes :openstack_auth_token, :openstack_management_url, :persistent, :openstack_service_type, :openstack_service_name, :openstack_tenant, :openstack_tenant_id, :openstack_api_key, :openstack_username, :openstack_identity_endpoint, :current_user, :current_tenant, :openstack_region, :openstack_endpoint_type, :openstack_cache_ttl, :openstack_project_name, :openstack_project_id, :openstack_project_domain, :openstack_user_domain, :openstack_domain_name, :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id, :openstack_identity_prefix, :openstack_endpoint_path_matches model_path 'fog/openstack/models/identity_v2' model :tenant collection :tenants model :user collection :users model :role collection :roles model :ec2_credential collection :ec2_credentials request_path 'fog/openstack/requests/identity_v2' request :check_token request :validate_token request :list_tenants request :create_tenant request :get_tenant request :get_tenants_by_id request :get_tenants_by_name request :update_tenant request :delete_tenant request :list_users request :create_user request :update_user request :delete_user request :get_user_by_id request :get_user_by_name request :add_user_to_tenant request :remove_user_from_tenant request :list_endpoints_for_token request :list_roles_for_user_on_tenant request :list_user_global_roles request :create_role request :delete_role request :delete_user_role request :create_user_role request :get_role request :list_roles request :set_tenant request :create_ec2_credential request :delete_ec2_credential request :get_ec2_credential request :list_ec2_credentials class Mock attr_reader :auth_token attr_reader :auth_token_expiration attr_reader :current_user attr_reader :current_tenant attr_reader :unscoped_token def self.data @users ||= {} @roles ||= {} @tenants ||= {} @ec2_credentials ||= Hash.new { |hash, key| hash[key] = {} } @user_tenant_membership ||= {} @data ||= Hash.new do |hash, key| hash[key] = { :users => @users, :roles => @roles, :tenants => @tenants, :ec2_credentials => @ec2_credentials, :user_tenant_membership => @user_tenant_membership } end end def self.reset! @data = nil @users = nil @roles = nil @tenants = nil @ec2_credentials = nil end def initialize(options={}) @openstack_username = options[:openstack_username] || 'admin' @openstack_tenant = options[:openstack_tenant] || 'admin' @openstack_auth_uri = URI.parse(options[:openstack_auth_url]) @openstack_management_url = @openstack_auth_uri.to_s @auth_token = Fog::Mock.random_base64(64) @auth_token_expiration = (Time.now.utc + 86400).iso8601 @admin_tenant = self.data[:tenants].values.find do |u| u['name'] == 'admin' end if @openstack_tenant @current_tenant = self.data[:tenants].values.find do |u| u['name'] == @openstack_tenant end unless @current_tenant @current_tenant_id = Fog::Mock.random_hex(32) @current_tenant = self.data[:tenants][@current_tenant_id] = { 'id' => @current_tenant_id, 'name' => @openstack_tenant } else @current_tenant_id = @current_tenant['id'] end else @current_tenant = @admin_tenant end @current_user = self.data[:users].values.find do |u| u['name'] == @openstack_username end @current_tenant_id = Fog::Mock.random_hex(32) unless @current_user @current_user_id = Fog::Mock.random_hex(32) @current_user = self.data[:users][@current_user_id] = { 'id' => @current_user_id, 'name' => @openstack_username, 'email' => "#{@openstack_username}@mock.com", 'tenantId' => Fog::Mock.random_numbers(6).to_s, 'enabled' => true } else @current_user_id = @current_user['id'] end end def data self.class.data[@openstack_username] end def reset_data self.class.data.delete(@openstack_username) end def credentials {:provider => 'openstack', :openstack_auth_url => @openstack_auth_uri.to_s, :openstack_auth_token => @auth_token, :openstack_management_url => @openstack_management_url, :openstack_current_user_id => @openstack_current_user_id, :current_user => @current_user, :current_tenant => @current_tenant} end end class Real < Fog::Identity::OpenStack::Real private def default_service_type(_) DEFAULT_SERVICE_TYPE end end end end end end fog-openstack-0.1.6/lib/fog/openstack/core.rb0000644000175600017570000001064712730051546020117 0ustar pravipravimodule Fog module OpenStack module Core attr_accessor :auth_token attr_reader :openstack_cache_ttl attr_reader :auth_token_expiration attr_reader :current_user attr_reader :current_user_id attr_reader :current_tenant attr_reader :openstack_domain_name attr_reader :openstack_user_domain attr_reader :openstack_project_domain attr_reader :openstack_domain_id attr_reader :openstack_user_domain_id attr_reader :openstack_project_id attr_reader :openstack_project_domain_id attr_reader :openstack_identity_prefix def initialize_identity options # Create @openstack_* instance variables from all :openstack_* options options.select{|x|x.to_s.start_with? 'openstack'}.each do |openstack_param, value| instance_variable_set "@#{openstack_param}".to_sym, value end @auth_token ||= options[:openstack_auth_token] @openstack_identity_public_endpoint = options[:openstack_identity_endpoint] @openstack_auth_uri = URI.parse(options[:openstack_auth_url]) @openstack_must_reauthenticate = false @openstack_endpoint_type = options[:openstack_endpoint_type] || 'publicURL' @openstack_cache_ttl = options[:openstack_cache_ttl] || 0 unless @auth_token missing_credentials = Array.new missing_credentials << :openstack_api_key unless @openstack_api_key unless @openstack_username || @openstack_userid missing_credentials << 'openstack_username or openstack_userid' end raise ArgumentError, "Missing required arguments: #{missing_credentials.join(', ')}" unless missing_credentials.empty? end @current_user = options[:current_user] @current_user_id = options[:current_user_id] @current_tenant = options[:current_tenant] end def credentials options = { :provider => 'openstack', :openstack_auth_url => @openstack_auth_uri.to_s, :openstack_auth_token => @auth_token, :openstack_identity_endpoint => @openstack_identity_public_endpoint, :current_user => @current_user, :current_user_id => @current_user_id, :current_tenant => @current_tenant, :unscoped_token => @unscoped_token} openstack_options.merge options end def reload @connection.reset end private def openstack_options options={} # Create a hash of (:openstack_*, value) of all the @openstack_* instance variables self.instance_variables.select{|x|x.to_s.start_with? '@openstack'}.each do |openstack_param| option_name = openstack_param.to_s[1..-1] options[option_name.to_sym] = instance_variable_get openstack_param end options end def authenticate if !@openstack_management_url || @openstack_must_reauthenticate options = openstack_options options[:openstack_auth_token] = @openstack_must_reauthenticate ? nil : @openstack_auth_token credentials = Fog::OpenStack.authenticate(options, @connection_options) @current_user = credentials[:user] @current_user_id = credentials[:current_user_id] @current_tenant = credentials[:tenant] @openstack_must_reauthenticate = false @auth_token = credentials[:token] @openstack_management_url = credentials[:server_management_url] @unscoped_token = credentials[:unscoped_token] else @auth_token = @openstack_auth_token end @openstack_management_uri = URI.parse(@openstack_management_url) @host = @openstack_management_uri.host @path = @openstack_management_uri.path @path.sub!(/\/$/, '') @port = @openstack_management_uri.port @scheme = @openstack_management_uri.scheme # Not all implementations have identity service in the catalog if @openstack_identity_public_endpoint || @openstack_management_url @identity_connection = Fog::Core::Connection.new( @openstack_identity_public_endpoint || @openstack_management_url, false, @connection_options) end true end end end end fog-openstack-0.1.6/gemfiles/0000755000175600017570000000000012730051546015115 5ustar pravipravifog-openstack-0.1.6/gemfiles/Gemfile-1.90000644000175600017570000000075012730051546016717 0ustar pravipravisource "https://rubygems.org" gem "coveralls", require: false group :development, :test do gem "fog-core", ">= 1.35" gem "fog-json", ">= 1.0" gem "fog-xml", ">= 0.1" gem "ipaddress", ">= 0.8" gem "bundler", "~> 1.6" gem "mime-types", "2.6.2" gem "rake", "~> 10.0" gem "rubocop" gem "rubyzip", "~> 0.9.9" gem "shindo", "~> 0.3" gem "minitest" gem "vcr" gem "webmock", "~> 1.24.6" end fog-openstack-0.1.6/Rakefile0000644000175600017570000000137312730051546014773 0ustar pravipravirequire 'bundler/gem_tasks' require 'rubocop/rake_task' require 'rake/testtask' RuboCop::RakeTask.new task :default => :test desc 'Run fog-openstack unit tests' task :test do mock = ENV['FOG_MOCK'] || 'true' sh("export FOG_MOCK=#{mock} && bundle exec shindont") end # The following is transition period until all shindo tests in /tests have been # migrated over minitest /test desc "Run fog-openstack unit tests for /test" Rake::TestTask.new do |t| t.name = 'minitest' t.libs.push [ "lib", "test" ] t.test_files = FileList['test/openstack/*.rb'] t.verbose = true end desc "Run fog-openstack unit tests for /spec" Rake::TestTask.new do |t| t.name = 'spec' t.libs.push [ "lib", "spec" ] t.pattern = 'spec/**/*_spec.rb' t.verbose = true end fog-openstack-0.1.6/fog-openstack.gemspec0000644000175600017570000000264312730051546017434 0ustar pravipravi# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'fog/openstack/version' Gem::Specification.new do |spec| spec.name = "fog-openstack" spec.version = Fog::Openstack::VERSION spec.authors = ["Matt Darby"] spec.email = ["matt.darby@rackspace.com"] spec.summary = %q{OpenStack fog provider gem} spec.description = %q{OpenStack fog provider gem.} spec.homepage = "https://github.com/fog/fog-openstack" spec.license = "MIT" spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } spec.bindir = "exe" spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] spec.add_dependency 'fog-core', '>= 1.39' spec.add_dependency 'fog-json', '>= 1.0' spec.add_dependency 'ipaddress', '>= 0.8' spec.add_development_dependency 'bundler', '~> 1.6' spec.add_development_dependency "mime-types" spec.add_development_dependency "mime-types-data" spec.add_development_dependency 'rake', '~> 10.0' spec.add_development_dependency 'rubocop' spec.add_development_dependency 'rubyzip', '~> 0.9.9' spec.add_development_dependency 'shindo', '~> 0.3' spec.add_development_dependency 'minitest' spec.add_development_dependency 'vcr' spec.add_development_dependency 'webmock', '~> 1.24.6' end fog-openstack-0.1.6/.gitignore0000644000175600017570000000016012730051546015307 0ustar pravipravi/.bundle/ /.yardoc /Gemfile.lock /_yardoc/ /coverage/ /doc/ /pkg/ /spec/reports/ /tmp/ gemfiles/Gemfile-1.9.lock