fog-openstack-1.0.8/0000755000004100000410000000000013423370527014316 5ustar www-datawww-datafog-openstack-1.0.8/docs/0000755000004100000410000000000013423370527015246 5ustar www-datawww-datafog-openstack-1.0.8/docs/metering.md0000644000004100000410000000302713423370527017404 0ustar www-datawww-data# 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::OpenStack::Metering.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-1.0.8/docs/getting_started.md0000644000004100000410000000451113423370527020760 0ustar www-datawww-data# 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) * [Introspection](introspection.md) * [Metering](metering.md) * [Network](network.md) * [NFV](nfv.md) * [Orchestration](orchestration.md) * [Planning](planning.md) * [Shared File System](shared_file_system.md) * [Storage (Swift)](storage.md) * [Workflow](workflow.md) ## Additional Resources [resources and feedback](common/resources.md) fog-openstack-1.0.8/docs/network.md0000644000004100000410000002250513423370527017265 0ustar www-datawww-data# 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::OpenStack::Network.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 ) ``` Read more about the [Optional Connection Parameters](common/connection_params.md) ## 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/openstack/network/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 * [OpenStack Network API](http://developer.openstack.org/api-ref-networking-v2.html) * [more resources and feedback](common/resources.md) fog-openstack-1.0.8/docs/storage.md0000644000004100000410000002356513423370527017247 0ustar www-datawww-data# 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::OpenStack::Storage.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', :connection_options => {} }) ``` Read more about the [Optional Connection Parameters](common/connection_params.md) 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
## 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/openstack/storage/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::OpenStack::Storage::Directory` models: ## Get Directory To retrieve a specific directory: ```ruby service.directories.get "blue" ``` This returns a `Fog::OpenStack::Storage::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 * [Swift API](http://docs.openstack.org/api/openstack-object-storage/1.0/content/index.html) * [more resources and feedback](common/resources.md) fog-openstack-1.0.8/docs/planning.md0000644000004100000410000001200013423370527017367 0ustar www-datawww-data# 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 }) ``` Read more about the [Optional Connection Parameters](common/connection_params.md) ## 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.new` 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.new` 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 * [Tuskar API](http://docs.openstack.org/developer/tuskar/) * [more resources and feedback](common/resources.md) fog-openstack-1.0.8/docs/compute.md0000644000004100000410000007265713423370527017265 0ustar www-datawww-data#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::OpenStack::Compute.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. Read more about the [Optional Connection Parameters](common/connection_params.md) ## 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/openstack/compute/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::OpenStack::Compute::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::OpenStack::Compute::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::OpenStack::Compute::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::OpenStack::Compute::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::OpenStack::Compute::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::OpenStack::Compute::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::OpenStack::Compute::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::OpenStack::Compute::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 * [OpenStack Compute API](http://docs.openstack.org/api/openstack-compute/2/content/) * [more resources and feedback](common/resources.md) fog-openstack-1.0.8/docs/shared_file_system.md0000644000004100000410000000555313423370527021451 0ustar www-datawww-data# Shared File System (Manila) This document explains how to get started using OpenStack Shared File System (Manila) 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 ``` or if you use bundler for managing your gems: ``` bundle exec 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 Shared File System Service: ``` service = Fog::OpenStack::SharedFileSystem.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 ) ``` Read more about the [Optional Connection Parameters](common/connection_params.md) ## 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 Shared File System API](http://developer.openstack.org/api-ref/shared-file-systems). It provides the most efficient interface to the OpenStack Shared File System service. To see a list of requests supported by the service: ``` service.requests ``` #### Example Request To request a list of networks: ``` response = service.list_shares ``` To learn more about Shared File System request methods refer to [rdoc](http://www.rubydoc.info/gems/fog-openstack/Fog/SharedFileSystem/OpenStack/Real). ### 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. To see a list of collections supported by the service: ``` service.collections ``` #### Example Request To request a collection of share networks: ``` networks = service.networks ``` ## Examples Example code using Shared File System can be found [here](https://github.com/fog/fog-openstack/tree/master/examples/share). ## Additional Resources * [OpenStack Shared File System API](http://developer.openstack.org/api-ref/shared-file-systems/) * [more resources and feedback](common/resources.md) fog-openstack-1.0.8/docs/nfv.md0000644000004100000410000001056213423370527016365 0ustar www-datawww-data# 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-1.0.8/docs/introspection.md0000644000004100000410000001553513423370527020501 0ustar www-datawww-data# 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::OpenStack::Baremetal.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::OpenStack::Introspection.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-1.0.8/docs/workflow.md0000644000004100000410000000660313423370527017447 0ustar www-datawww-data# OpenStack Workflow (Mistral) This document explains how to get started using OpenStack Workflow (Mistral) with Fog. It assumes you have read the [Getting Started with Fog and the OpenStack](getting_started.md) document. Fog uses the [OpenStack Mistral API](http://docs.openstack.org/developer/mistral/developer/webapi/v2.html). ## Workflow Service Get a handle for the Workflow service: ```ruby service = Fog::OpenStack::Workflow.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 }) ``` Read more about the [Optional Connection Parameters](common/connection_params.md) ## Executions A Workflow is a composition of one or more actions. To execute a workflow, we create an execution: ```ruby workflow = "tripleo.plan_management.v1.create_default_deployment_plan" input = { :container => 'default' } response = service.create_execution(workflow, input) ``` Execution status and result can be checked by: ```ruby workflow_execution_id = response.body["id"] response = mistral.get_execution(workflow_execution_id) state = response.body["state"] ``` To execute an individual action, we create an action execution: ```ruby input = { :container => 'default' } service.create_action_execution("tripleo.get_capabilities", input) ``` For actions, the result is returned when create_action_execution completes. ## Workflows ### Create a workflow ```ruby workflow_def = { :version => "2.0", :myworkflow => { :type => "direct", :description => "description1", :tasks => { :create_vm => { :description => "create vm" } } } } response = service.create_workflow(workflow_def) workflow_id = response.body["workflows"][0]["id"] ``` ### Validate a workflow before creating it ```ruby service.validate_workflow(workflow_def) ``` ### Update a workflow ```ruby workflow_def_new = { :version => "2.0", :myworkflow => { :type => "direct", :description => "description2", :tasks => { :create_vm => { :description => "create vm" } } } } service.update_workflow(workflow_def_new) ``` ### List workflow ```ruby service.list_workflows ``` ### Delete workflow ```ruby service.delete_workflow(workflow_id) ``` ## Other Mistral resources In addition to workflows, the following Mistral resources are also supported: * Workbooks * Actions * Executions * Tasks * Action Executions * Cron Triggers * Environments * Validations For examples on how to interact with these resources, please refer to https://github.com/fog/fog-openstack/tree/master/examples/workflow/workflow-examples.rb ## Additional Resources * [Mistral Wiki](https://wiki.openstack.org/wiki/Mistral) * [Mistral DSL v2](http://docs.openstack.org/developer/mistral/dsl/dsl_v2.html) * [Mistral API v2](http://docs.openstack.org/developer/mistral/developer/webapi/v2.html) * [Mistral python client](https://github.com/openstack/python-mistralclient) Can be useful to see how to interact with the API. * [more resources and feedback](common/resources.md) fog-openstack-1.0.8/docs/common/0000755000004100000410000000000013423370527016536 5ustar www-datawww-datafog-openstack-1.0.8/docs/common/resources.md0000644000004100000410000000065413423370527021077 0ustar www-datawww-data## 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) * [Excon Github repo](https://github.com/geemus/excon) ## 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-1.0.8/docs/common/connection_params.md0000644000004100000410000000202713423370527022563 0ustar www-datawww-data### 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)
:debug_request debug print request (default: false)
:debug_response debug print response (default: false)
fog-openstack-1.0.8/docs/orchestration.md0000644000004100000410000003513313423370527020461 0ustar www-datawww-data# 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::OpenStack::Orchestration.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` Read more about the [Optional Connection Parameters](common/connection_params.md) ## 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 ``` To update a stack while manipulating a Stack object from the Stack Collection: ```ruby heat_template = { "template": { "description": "Updated description" } } stack.save(heat_template) ``` `save` uses the `update_stack` request method, although it expects a Stack object as well: ```ruby heat_template = { "template": { "description": "Updated description" } } service.update_stack(stack, heat_template) ``` Alternatively a request only approach can be used, providing a stack id and name: ```ruby id = "49b83314-d341-468a-aef4-44bbccce251e" name = "stack_name" heat_template = { "template": { "description": "Other update description" } } service.update_stack(id, name, heat_template) ``` 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) => ``` ## Cancel Update When the stack is updating, you can cancel the update: ```ruby # stack.stack_status == 'UPDATE_IN_PROGRESS' stack.cancel_update => nil ``` Then you can see the status changed to ROLLBACK_IN_PROGRESS: ```ruby stack = service.stacks.get(stack.stack_name, stack.id) stack.stack_status => "ROLLBACK_IN_PROGRESS" ``` fog-openstack-1.0.8/playbooks/0000755000004100000410000000000013423370527016321 5ustar www-datawww-datafog-openstack-1.0.8/playbooks/fog-openstack-unittest-test/0000755000004100000410000000000013423370527023713 5ustar www-datawww-datafog-openstack-1.0.8/playbooks/fog-openstack-unittest-test/run.yaml0000644000004100000410000000421613423370527025406 0ustar www-datawww-data- hosts: all become: yes tasks: - name: Run unittest tests shell: cmd: | set -e set -o pipefail set -x apt-get install ruby ruby-dev -y for key in 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB; do gpg --keyserver keys.gnupg.net --keyserver-options timeout=5 --recv-keys "$key" || \ gpg --keyserver pgp.mit.edu --keyserver-options timeout=5 --recv-keys "$key" || \ gpg --keyserver keyserver.pgp.com --keyserver-options timeout=5 --recv-keys "$key" || \ gpg --keyserver ha.pool.sks-keyservers.net --keyserver-options timeout=5 --recv-keys "$key" done curl -L https://get.rvm.io | bash -s stable source /usr/local/rvm/scripts/rvm > /dev/null 2>&1 for version in {{ rvm }}; do if [ "$version" == "jruby-head" ]; then continue fi rvm install ${version} --disable-binary > /dev/null 2>&1 rvm use ${version} > /dev/null 2>&1 echo "Running tests based on Ruby ${version}..." ruby --version gem install bundler --version '~> 1' bundle install --jobs=3 --retry=3 bundle exec rake test TESTOPTS="--verbose" done executable: /bin/bash chdir: '{{ zuul.project.src_dir }}' environment: JRUBY_OPTS: '--debug' ANSIBLE_PYTHON_INTERPRETER: /usr/bin/python3 - name: Run unittest tests for jruby-head shell: cmd: | set -e set -o pipefail set -x rvm install jruby-head --disable-binary rvm use jruby-head echo "Running tests based on Ruby jruby-head... ruby --version gem install bundler gem update bundler bundle install --jobs=3 --retry=3 bundle exec rake test TESTOPTS="--verbose" executable: /bin/bash chdir: '{{ zuul.project.src_dir }}' environment: JRUBY_OPTS: '--debug' ANSIBLE_PYTHON_INTERPRETER: /usr/bin/python3 ignore_errors: true fog-openstack-1.0.8/playbooks/fog-openstack-unittest-spec/0000755000004100000410000000000013423370527023666 5ustar www-datawww-datafog-openstack-1.0.8/playbooks/fog-openstack-unittest-spec/run.yaml0000644000004100000410000000423013423370527025355 0ustar www-datawww-data- hosts: all become: yes tasks: - name: Run unittest spec tests shell: cmd: | set -e set -o pipefail set -x apt-get install ruby ruby-dev -y for key in 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB; do gpg --keyserver keys.gnupg.net --keyserver-options timeout=5 --recv-keys "$key" || \ gpg --keyserver pgp.mit.edu --keyserver-options timeout=5 --recv-keys "$key" || \ gpg --keyserver keyserver.pgp.com --keyserver-options timeout=5 --recv-keys "$key" || \ gpg --keyserver ha.pool.sks-keyservers.net --keyserver-options timeout=5 --recv-keys "$key" done curl -L https://get.rvm.io | bash -s stable source /usr/local/rvm/scripts/rvm > /dev/null 2>&1 for version in {{ rvm }}; do if [ "$version" == "jruby-head" ]; then continue fi rvm install ${version} --disable-binary > /dev/null 2>&1 rvm use ${version} > /dev/null 2>&1 echo "Running tests based on Ruby ${version}..." ruby --version gem install bundler --version '~> 1' bundle install --jobs=3 --retry=3 bundle exec rake spec TESTOPTS="--verbose" done executable: /bin/bash chdir: '{{ zuul.project.src_dir }}' environment: JRUBY_OPTS: '--debug' ANSIBLE_PYTHON_INTERPRETER: /usr/bin/python3 - name: Run unittest spec tests for jruby-head shell: cmd: | set -e set -o pipefail set -x rvm install jruby-head --disable-binary rvm use jruby-head echo "Running tests based on Ruby jruby-head... ruby --version gem install bundler gem update bundler bundle install --jobs=3 --retry=3 bundle exec rake spec TESTOPTS="--verbose" executable: /bin/bash chdir: '{{ zuul.project.src_dir }}' environment: JRUBY_OPTS: '--debug' ANSIBLE_PYTHON_INTERPRETER: /usr/bin/python3 ignore_errors: true fog-openstack-1.0.8/playbooks/.gitkeep0000644000004100000410000000000013423370527017740 0ustar www-datawww-datafog-openstack-1.0.8/.travis.yml0000644000004100000410000000116513423370527016432 0ustar www-datawww-datalanguage: ruby sudo: false before_install: - gem install bundler --version '~> 1' script: - bundle exec rake test TESTOPTS="--verbose" - bundle exec rake spec env: - JRUBY_OPTS=--debug matrix: fast_finish: true include: - rvm: 2.3.8 gemfile: Gemfile - rvm: 2.4.5 gemfile: Gemfile - rvm: 2.5.3 gemfile: Gemfile - rvm: 2.6.0 gemfile: Gemfile - 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-1.0.8/README.md0000644000004100000410000004227213423370527015604 0ustar www-datawww-data# 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.svg)](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. * Keystone endpoints are version less. Version 3 is the default as v2.0 is deprecated. Meanwhile Keystone V3 still supports v2.0 for backward compatibility. Therefore passing a tenant instead of a project (along with a domain) makes Keystone provide v2.0 token. Connection parameters: ```ruby @connection_params = { openstack_auth_url: "http://devstack.test:5000", 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 to either provide a tenant name (`openstack_tenant`) or a tenant id (`openstack_tenant_id`). Alternatively you can use `:openstack_identity_api_version` parameter with 'v2.0'. ```ruby @connection_params = { openstack_auth_url: "http://devstack.test:5000", openstack_username: "admin", openstack_api_key: "password", openstack_tenant: "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::OpenStack::Compute.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::OpenStack::Compute.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) Download Glance image: ```ruby image = Fog::OpenStack::Image.new(@connection_params) image_out = File.open("/tmp/cirros-image-download", 'wb') streamer = lambda do |chunk, _, _| image_out.write chunk end image.download_image(image.images.first.id, response_block: streamer) ``` Create Glance image from file or URL: ```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_handle = image.images.create name: "cirros", disk_format: "qcow2", container_format: "bare" # => image_handle.upload_data File.binread(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::OpenStack::Identity.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::OpenStack::Identity.new(@connection_params) tenants = identity.projects.select do |project| project.name == @connection_params[:openstack_project_name] end tenant_id = tenants[0].id neutron = Fog::OpenStack::Network.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 ``` $ git clone https://github.com/fog/fog-openstack.git # Clone repository $ cd fog-openstack; bin/setup # Install dependencies from project directory $ bundle exec rake test # Run tests $ bundle exec rake spec # Run tests $ bin/console # Run interactive prompt that allows you to experiment (optional) $ bundle exec rake install # Install gem to your local machine (optional) ``` You can also use a docker image for development and running tests. Once you have cloned the repository, it can be run with: ``` $ docker-compose up test $ docker-compose up ruby # Start a container with the ruby environment ``` In order to release a new version, perform the following steps: 1. Update version number in `version.rb`. 2. Run `bundle exec rake release`, which will create a git tag for the version. 3. Push git commits and tags. 4. Push the `.gem` file to [rubygems.org](https://rubygems.org). ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/fog/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-1.0.8/bin/0000755000004100000410000000000013423370527015066 5ustar www-datawww-datafog-openstack-1.0.8/bin/console0000755000004100000410000000052213423370527016455 0ustar www-datawww-data#!/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-1.0.8/bin/setup0000755000004100000410000000020313423370527016147 0ustar www-datawww-data#!/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-1.0.8/LICENSE.md0000644000004100000410000000220313423370527015717 0ustar www-datawww-dataThe 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-1.0.8/CHANGELOG.md0000644000004100000410000000251313423370527016130 0ustar www-datawww-data# 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-1.0.8/.rubocop.yml0000644000004100000410000000407413423370527016575 0ustar www-datawww-data# # Overrides # AbcSize: Severity: refactor AlignHash: EnforcedHashRocketStyle: table EnforcedColonStyle: table BlockNesting: Severity: refactor ClassLength: Max: 150 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 # Exclude test methods from BlockLength. Metrics/BlockLength: ExcludedMethods: - after - before - context - describe - it - model_tests - namespace - draw ParameterLists: Severity: refactor PerceivedComplexity: Severity: refactor RedundantReturn: AllowMultipleReturnValues: true SignalException: EnforcedStyle: only_raise SingleLineMethods: AllowIfMethodIsEmpty: false SpaceInsideHashLiteralBraces: EnforcedStyle: no_space Style/RegexpLiteral: EnforcedStyle: slashes AllowInnerSlashes: true 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 Style/FrozenStringLiteralComment: Enabled: false StringLiterals: Enabled: false StringLiteralsInInterpolation: Enabled: false TrailingCommaInArrayLiteral: Enabled: false TrailingCommaInHashLiteral: Enabled: false WhileUntilModifier: Enabled: false WordArray: AutoCorrect: false fog-openstack-1.0.8/.gitignore0000644000004100000410000000024013423370527016302 0ustar www-datawww-data/.bundle/ /.yardoc /Gemfile.lock /_yardoc/ /coverage/ /doc/ /pkg/ /spec/reports/ /tmp/ gemfiles/Gemfile-1.9.lock .DS_Store .idea/ vendor/bundle test/.lorem.txt fog-openstack-1.0.8/CODE_OF_CONDUCT.md0000644000004100000410000000453113423370527017120 0ustar www-datawww-data# 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-1.0.8/examples/0000755000004100000410000000000013423370527016134 5ustar www-datawww-datafog-openstack-1.0.8/examples/volume/0000755000004100000410000000000013423370527017443 5ustar www-datawww-datafog-openstack-1.0.8/examples/volume/backups.rb0000644000004100000410000000200313423370527021413 0ustar www-datawww-datarequire 'fog/openstack' require 'fog/openstack/workflow/v2' auth_url = "http://192.0.2.1:5000/v3/auth/tokens" username = "admin" password = "1b1d81f7e25b53e497246b168971823c5754f395" project = "admin" @connection_params = { :openstack_auth_url => auth_url, :openstack_username => username, :openstack_api_key => password, :openstack_project_name => project, :openstack_domain_id => "default", } cinder = Fog::OpenStack::Volume.new(@connection_params) puts "INFO: create backup of existing volume named test" response = cinder.create_backup({:name => 'test-backup', :volume_id => '82fe2ad5-43a3-4c2b-8464-e57b138ea81c'}) puts response.body puts "INFO: list backups" backups = cinder.backups puts "INFO: get details of existing backup" backup_id = backups[0].id backup = cinder.backups.get(backup_id) puts "INFO: restore backup" response = backup.restore('82fe2ad5-43a3-4c2b-8464-e57b138ea81c') puts response.body puts "INFO: delete backup" backup.destroy fog-openstack-1.0.8/examples/planning/0000755000004100000410000000000013423370527017742 5ustar www-datawww-datafog-openstack-1.0.8/examples/planning/basics.rb0000644000004100000410000000157713423370527021545 0ustar www-datawww-data# 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-1.0.8/examples/metric/0000755000004100000410000000000013423370527017417 5ustar www-datawww-datafog-openstack-1.0.8/examples/metric/basics.rb0000644000004100000410000000207213423370527021211 0ustar www-datawww-datarequire 'fog/openstack' require 'time' auth_url = "http://10.0.0.13:5000/v3/auth/tokens" username = 'admin' password = 'njXDF8bKr68RQsfbANvURzkmT' project = 'admin' @connection_params = { :openstack_auth_url => auth_url, :openstack_username => username, :openstack_api_key => password, :openstack_project_name => project, :openstack_domain_id => "default" } puts "### SERVICE CONNECTION ###" metric = Fog::OpenStack::Metric.new(@connection_params) p metric puts "### RESOURCES ###" p metric.list_resources p metric.resources.all(details: true) p metric.resources.find_by_id("3c6c53c9-25c1-4aca-984d-a20c1926b499") p metric.get_resource_metric_measures("d1f84147-d4ef-465e-a679-265df36918ed", "disk.ephemeral.size", start: 0, stop: Time.now.iso8601, granularity: 300).body puts "### METRICS ###" p metric.metrics.all p metric.metrics.find_by_id("7feff2ca-2edd-4ea5-96d7-2cc5262bb504") p metric.get_metric_measures("d8e5e557-e3cc-41bd-9d87-dac3eedd0df7", start: 0, stop: Time.now.iso8601, granularity: 300).body puts "### END ###" fog-openstack-1.0.8/examples/workflow/0000755000004100000410000000000013423370527020006 5ustar www-datawww-datafog-openstack-1.0.8/examples/workflow/workflow-examples.rb0000644000004100000410000001717013423370527024027 0ustar www-datawww-datarequire 'fog/openstack' require 'fog/openstack/workflow/v2' auth_url = "http://192.0.2.1:5000/v3/auth/tokens" username = "admin" password = "1b1d81f7e25b53e497246b168971823c5754f395" project = "admin" @connection_params = { :openstack_auth_url => auth_url, :openstack_username => username, :openstack_api_key => password, :openstack_project_name => project, :openstack_domain_id => "default", } mistral = Fog::OpenStack::Workflow.new(@connection_params) puts "INFO: create_execution" workflow = "tripleo.plan_management.v1.create_default_deployment_plan" input = { :container => 'default' } response = mistral.create_execution(workflow, input) puts response.body state = response.body["state"] workflow_execution_id = response.body["id"] puts "INFO: state #{state} execution_id #{workflow_execution_id}" while state == "RUNNING" sleep 5 response = mistral.get_execution(workflow_execution_id) state = response.body["state"] workflow_execution_id = response.body["id"] puts "INFO: state #{state} execution_id #{workflow_execution_id}" end puts response.body puts "INFO: list_executions" response = mistral.list_executions puts response.body puts "INFO: update_execution" response = mistral.update_execution(workflow_execution_id, "description", "changed description") puts response.body puts "INFO: list_tasks #{workflow_execution_id}" response = mistral.list_tasks(workflow_execution_id) task_ex_id = response.body["tasks"][0]["id"] puts response.body puts "INFO: get_task #{task_ex_id}" response = mistral.get_task(task_ex_id) puts response.body puts "INFO: rerun_task #{task_ex_id}" response = mistral.rerun_task(task_ex_id) puts response.body puts "INFO: delete_execution" response = mistral.delete_execution(workflow_execution_id) puts response.body puts "INFO: create_action_execution" input = { :container => 'default' } response = mistral.create_action_execution("tripleo.get_capabilities", input) puts response.body puts "INFO: list_action_executions" response = mistral.list_action_executions puts response.body puts "INFO: get_action_execution" execution_id = response.body["id"] response = mistral.get_action_execution(execution_id) puts response.body puts "INFO: create_workbook" workbook_def = { :version => "2.0", :name => "workbook name", :description => "workbook description", } response = mistral.create_workbook(workbook_def) workbook_name = response.body["name"] puts response.body puts "INFO: get_workbook" response = mistral.get_workbook(workbook_name) puts response.body puts "INFO: list_workbooks" response = mistral.list_workbooks puts response.body puts "INFO: update_workbook" workbook_def = { :version => "2.0", :name => "workbook name", :description => "workbook description2", } response = mistral.update_workbook(workbook_def) puts response.body puts "INFO: get_workbook2" response = mistral.get_workbook(workbook_name) puts response.body puts "INFO: validate_workbook" response = mistral.validate_workbook(workbook_def) puts response.body puts "INFO: delete_workbook" response = mistral.delete_workbook(workbook_name) puts response.body puts "INFO: create_workflow" workflow_def = { :version => "2.0", :myworkflow => { :type => "direct", :description => "description1", :tasks => { :create_vm => { :description => "create vm" } } } } response = mistral.create_workflow(workflow_def) workflow_id = response.body["workflows"][0]["id"] puts response.body puts "INFO: get_workflow #{workflow_id}" response = mistral.get_workflow(workflow_id) puts response.body puts "INFO: list_workflows" response = mistral.list_workflows puts response.body puts "INFO: list_workflows with params" params = { :limit => 1 } response = mistral.list_workflows(params) perm_workflow_id = response.body["workflows"][0]["id"] puts response.body puts "INFO: update_workflow" workflow_def = { :version => "2.0", :myworkflow => { :type => "direct", :description => "description2", :tasks => { :create_vm => { :description => "create vm" } } } } response = mistral.update_workflow(workflow_def) puts response.body puts "INFO: get_workflow2" response = mistral.get_workflow(workflow_id) puts response.body puts "INFO: validate_workflow" response = mistral.validate_workflow(workflow_def) puts response.body puts "INFO: delete_workflow #{workflow_id}" response = mistral.delete_workflow(workflow_id) puts response.body puts "INFO: create_action" action_def = { :version => "2.0", :myaction => { :input => ['execution_id'], :base => "std.email", "base-input" => { :to_addrs => ['admin@mywebsite.org'], :subject => "subject1", :body => "body1", :from_addr => "mistral@openstack.org", :smtp_server => "smtp.test.com", :smtp_password => "secret" } } } response = mistral.create_action(action_def) puts response.body puts "INFO: get_action" action_name = "myaction" response = mistral.get_action(action_name) puts response.body puts "INFO: list_actions" response = mistral.list_actions puts response.body puts "INFO: list_actions with params" params = { :limit => 1 } response = mistral.list_actions(params) puts response.body puts "INFO: update_action" action_def = { :version => "2.0", :myaction => { :input => ['execution_id'], :base => "std.email", "base-input" => { :to_addrs => ['admin@mywebsite.org'], :subject => "subject updated", :body => "body1", :from_addr => "mistral@openstack.org", :smtp_server => "smtp.test.com", :smtp_password => "secret" } } } response = mistral.update_action(action_def) puts response.body puts "INFO: get_action2" response = mistral.get_action(action_name) puts response.body puts "INFO: validate_action" response = mistral.validate_action(action_def) puts response.body puts "INFO: delete_action" response = mistral.delete_action(action_name) puts response.body puts "INFO: create_cron_trigger #{perm_workflow_id}" cron_name = "mycron" workflow_input = { "container" => "test1" } response = mistral.create_cron_trigger(cron_name, perm_workflow_id, workflow_input) puts response.body puts "INFO: get_cron_trigger" response = mistral.get_cron_trigger(cron_name) puts response.body puts "INFO: list_cron_triggers" response = mistral.list_cron_triggers puts response.body puts "INFO: delete_cron_trigger" response = mistral.delete_cron_trigger(cron_name) puts response.body puts "INFO: create_environment" environment_def = { "name" => "environment-1", "variables" => { "var1" => "value1", "var2" => "value2" } } response = mistral.create_environment(environment_def) puts response.body puts "INFO: get_environment" environment_name = environment_def["name"] response = mistral.get_environment(environment_name) puts response.body puts "INFO: list_environments" response = mistral.list_environments puts response.body puts "INFO: update_environment" environment_def = { "name" => "environment-1", "variables" => { "var1" => "value3", "var2" => "value4" } } response = mistral.update_environment(environment_def) puts response.body puts "INFO: get_environment2" response = mistral.get_environment(environment_name) puts response.body puts "INFO: delete_environment" response = mistral.delete_environment(environment_name) puts response.body # # Services api is unsupported atm. Next call will fail. # puts "INFO: list_services" response = mistral.list_services puts response.body fog-openstack-1.0.8/examples/image/0000755000004100000410000000000013423370527017216 5ustar www-datawww-datafog-openstack-1.0.8/examples/image/upload-test-image.rb0000755000004100000410000000565413423370527023101 0ustar www-datawww-datarequire '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::OpenStack::Image.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-1.0.8/examples/identity/0000755000004100000410000000000013423370527017765 5ustar www-datawww-datafog-openstack-1.0.8/examples/identity/basics_v3.rb0000644000004100000410000000443113423370527022170 0ustar www-datawww-data# OpenStack Identity Service (Keystone) Example require 'fog/openstack' require 'pp' auth_url = "https://example.net:35357" username = 'admin@example.net' password = 'secret' project = 'admin' domain = 'Default' keystone = Fog::OpenStack::Identity.new :openstack_auth_url => auth_url, :openstack_username => username, :openstack_api_key => password, :openstack_project_name => project, :openstack_domain_name => domain # Optional, self-signed certs #:connection_options => { :ssl_verify_peer => false } # # List keystone projects # keystone.projects.each do |project| # "http://example.net:35357/..."}, # parent_id=nil, # subtree=nil, # parents=nil # > # ... pp project end # # List users # keystone.users.each do |user| # "http://example.net:35357/..."}, # password=nil # > # ... pp user end # # Create a new tenant # project = keystone.projects.create :name => 'rubiojr@example.net', :description => 'My foo tenant' # # Create a new user # user = keystone.users.create :name => 'rubiojr@example.net', :default_project_id => project.id, :password => 'rubiojr@example.net', :email => 'rubiojr@example.net', :domain_id => 'Default' # Find the recently created tenant project = keystone.projects.find { |t| t.name == 'rubiojr@example.net' } # Destroy the tenant project.destroy # Find the recently created user user = keystone.users.find { |u| u.name == 'rubiojr@example.net' } # Destroy the user user.destroy fog-openstack-1.0.8/examples/identity/basics.rb0000644000004100000410000000345413423370527021564 0ustar www-datawww-data# OpenStack Identity Service (Keystone) Example require 'fog/openstack' require 'pp' auth_url = "https://example.net" username = 'admin@example.net' password = 'secret' tenant = 'admin' keystone = Fog::OpenStack::Identity.new :openstack_auth_url => auth_url, :openstack_username => username, :openstack_api_key => password, :openstack_tenant => tenant # 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-1.0.8/examples/event/0000755000004100000410000000000013423370527017255 5ustar www-datawww-datafog-openstack-1.0.8/examples/event/basics.rb0000644000004100000410000000072213423370527021047 0ustar www-datawww-datarequire 'fog/openstack' require 'time' auth_url = "http://10.0.0.101:5000/v2.0/tokens" username = 'admin' password = 'D78JVyRnzJG8j7Mb6fgpeUMp7' @connection_params = { :openstack_auth_url => auth_url, :openstack_username => username, :openstack_api_key => password, } puts "### SERVICE CONNECTION ###" event_service = Fog::OpenStack::Event.new(@connection_params) p event_service puts "### LIST EVENTS ###" p event_service.events.all fog-openstack-1.0.8/examples/compute/0000755000004100000410000000000013423370527017610 5ustar www-datawww-datafog-openstack-1.0.8/examples/compute/block_device_mapping_v2.rb0000644000004100000410000000144713423370527024676 0ustar www-datawww-data# 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::OpenStack::Compute.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-1.0.8/examples/compute/basics.rb0000644000004100000410000000316113423370527021402 0ustar www-datawww-data# 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-1.0.8/examples/storage/0000755000004100000410000000000013423370527017600 5ustar www-datawww-datafog-openstack-1.0.8/examples/storage/set-account-quota.rb0000644000004100000410000000422013423370527023477 0ustar www-datawww-datarequire '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::OpenStack::Identity.new :openstack_auth_url => auth_url, :openstack_username => user, :openstack_api_key => password # # Storage service (Swift) # st = Fog::OpenStack::Storage.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-1.0.8/examples/network/0000755000004100000410000000000013423370527017625 5ustar www-datawww-datafog-openstack-1.0.8/examples/network/network_rbac.rb0000644000004100000410000000377313423370527022644 0ustar www-datawww-datarequire '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::OpenStack::Identity::V3.new(auth_options) network_service = Fog::OpenStack::Network.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-1.0.8/examples/network/network_subnets_routers.rb0000644000004100000410000000436013423370527025174 0ustar www-datawww-datarequire '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::OpenStack::Network.new 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-1.0.8/examples/network/network_add_port.rb0000644000004100000410000000200013423370527023507 0ustar www-datawww-datarequire '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-1.0.8/examples/container_infra/0000755000004100000410000000000013423370527021275 5ustar www-datawww-datafog-openstack-1.0.8/examples/container_infra/basics.rb0000644000004100000410000000423013423370527023065 0ustar www-datawww-data# OpenStack Container Infra (Magnum) Example require 'fog/openstack' # Initialize a connection to the Magnum API params = { openstack_auth_url: 'https://example.net/v3/auth/tokens', openstack_username: 'username', openstack_api_key: 'password', openstack_project_name: 'magnum' } container_infra = Fog::ContainerInfra::OpenStack.new(params) # Get the Fedora Atomic image image = Fog::OpenStack::Image.new(params) unless image.images.map(&:name).include?("fedora-atomic-latest") puts "Couldn't find Fedora Atomic. Uploading to Glance..." fedora = image.images.create name: "fedora-atomic-latest", disk_format: "qcow2", visibility: 'public', container_format: 'bare', copy_from: 'https://fedorapeople.org/groups/magnum/fedora-atomic-latest.qcow2', properties: {'os_distro' => 'fedora-atomic'}.to_json fedora.wait_for { status == "active" } end # Create a cluster template for using Docker Swarm and Fedora Atomic params = { name: 'swarm-cluster-template', image_id: 'fedora-atomic-latest', keypair_id: 'YOUR_KEYPAIR_NAME', external_network_id: 'public', master_flavor_id: 'm1.small', flavor_id: 'm1.small', coe: 'swarm', docker_volume_size: 3, dns_nameserver: '8.8.8.8', tls_disabled: true } cluster_template = container_infra.cluster_templates.create(params) puts "Created cluster template #{cluster_template.name} (#{cluster_template.uuid})" # Create a swarm cluster and wait for it to build params = { name: 'swarm-cluster', cluster_template_id: 'swarm-cluster-template', master_count: 1, node_count: 1 } cluster = container_infra.clusters.create(params) start = Time.now puts "Building cluster #{cluster.name} (#{cluster.uuid})" cluster.wait_for { status != 'CREATE_IN_PROGRESS' } puts "Finished building #{cluster.name} in #{(Time.now - start).round} seconds. Status: #{cluster.status}." puts "More info: #{cluster.status_reason}" if cluster.status == 'CREATE_FAILED' fog-openstack-1.0.8/examples/shared_file_system/0000755000004100000410000000000013423370527022005 5ustar www-datawww-datafog-openstack-1.0.8/examples/shared_file_system/basics.rb0000644000004100000410000000336013423370527023600 0ustar www-datawww-datarequire 'fog/openstack' require 'pp' # # Creates a share network and a share # # 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'} } network_service = Fog::OpenStack::Network.new(auth_options) share_service = Fog::OpenStack::SharedFileSystem.new(auth_options) net = network_service.networks.first raise 'no network exists' if net.nil? puts "Create share network in #{net.name}" share_network = share_service.networks.create( :neutron_net_id => net.id, :neutron_subnet_id => net.subnets.first.id, :name => 'fog_share_net' ) pp share_network puts 'Create share' example_share = share_service.shares.create( :share_proto => 'NFS', :size => 1, :name => 'fog_share', :share_network_id => share_network.id ) pp example_share puts 'Create snapshot' example_snap = share_service.snapshots.create( :share_id => example_share.id, :name => 'fog_share_snapshot' ) pp example_snap puts 'Removing snapshot, share and share network' example_snap.destroy example_share.destroy share_network.destroy fog-openstack-1.0.8/examples/introspection/0000755000004100000410000000000013423370527021034 5ustar www-datawww-datafog-openstack-1.0.8/examples/introspection/basics.rb0000644000004100000410000000325513423370527022632 0ustar www-datawww-data 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::OpenStack::Introspection.new(@connection_params) # Introspection of an Ironic node ironic = Fog::OpenStack::Baremetal.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-1.0.8/docker-compose.yml0000644000004100000410000000164113423370527017755 0ustar www-datawww-data# # This file allows to: # - create a ruby docker environment for development # - run a testsuite from scratch like .travis.yml # # Run all tests with # # $ docker-compose up test # # Create the develompent environment with # # $ docker-compose up -d ruby # $ docker exec -ti fogopenstack_ruby_1 /bin/bash # version: '2' services: ruby: image: ruby:2.4-stretch cap_add: - SYS_PTRACE volumes: - .:/code:z - .:/home/travis/build/fog/fog-openstack:z entrypoint: tail -f /etc/hosts test: image: ruby:2.4-stretch cap_add: - SYS_PTRACE volumes: - .:/code:z - .:/home/travis/build/fog/fog-openstack:z environment: - JRUBY_OPTS=--debug working_dir: /home/travis/build/fog/fog-openstack entrypoint: | bash -c ' gem update bundler --verbose bundle install --verbose bundle exec rake test bundle exec rake spec ' fog-openstack-1.0.8/.hound.yml0000644000004100000410000000004213423370527016230 0ustar www-datawww-dataruby: config_file: .rubocop.yml fog-openstack-1.0.8/Rakefile0000644000004100000410000000163713423370527015772 0ustar www-datawww-datarequire 'bundler/gem_tasks' require 'rubocop/rake_task' require 'rake/testtask' RuboCop::RakeTask.new task :default => ['tests:mock', 'tests:spec', 'tests:unit'] task :mock => 'tests:mock' task :spec => "tests:spec" task :unit => 'tests:unit' namespace :tests do desc 'Run fog-openstack tests with Mock class' Rake::TestTask.new do |t| ENV['FOG_MOCK']= ENV['FOG_MOCK'].nil? ? 'true' : ENV['FOG_MOCK'] t.name = 'mock' t.libs.push [ "lib", "test" ] t.test_files = FileList['test/**/*.rb'] t.verbose = true end desc 'Run fog-openstack tests with RSpec and VCR' Rake::TestTask.new do |t| t.name = 'spec' t.libs.push [ "lib", "spec" ] t.pattern = 'spec/**/*_spec.rb' t.verbose = true end desc 'Run fog-openstack unit tests' Rake::TestTask.new do |t| t.name = 'unit' t.libs.push [ "lib", "unit" ] t.pattern = 'unit/**/*_test.rb' t.verbose = true end end fog-openstack-1.0.8/lib/0000755000004100000410000000000013423370527015064 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/0000755000004100000410000000000013423370527015637 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack.rb0000644000004100000410000001317113423370527020156 0ustar www-datawww-datarequire 'fog/core' require 'fog/json' module Fog module OpenStack require 'fog/openstack/auth/token' autoload :VERSION, 'fog/openstack/version' autoload :Core, 'fog/openstack/core' autoload :Errors, 'fog/openstack/errors' autoload :Baremetal, 'fog/openstack/baremetal' autoload :Compute, 'fog/openstack/compute' autoload :ContainerInfra, 'fog/openstack/container_infra' autoload :DNS, 'fog/openstack/dns' autoload :Event, 'fog/openstack/event' autoload :Identity, 'fog/openstack/identity' autoload :Image, 'fog/openstack/image' autoload :Introspection, 'fog/openstack/introspection' autoload :KeyManager, 'fog/openstack/key_manager' autoload :Metering, 'fog/openstack/metering' autoload :Metric, 'fog/openstack/metric' autoload :Monitoring, 'fog/openstack/monitoring' autoload :Network, 'fog/openstack/network' autoload :NFV, 'fog/openstack/nfv' autoload :Orchestration, 'fog/openstack/orchestration' autoload :OrchestrationUtil, 'fog/openstack/orchestration/util/recursive_hot_file_loader' autoload :Planning, 'fog/openstack/planning' autoload :SharedFileSystem, 'fog/openstack/shared_file_system' autoload :Storage, 'fog/openstack/storage' autoload :Workflow, 'fog/openstack/workflow' autoload :Volume, 'fog/openstack/volume' extend Fog::Provider service(:baremetal, 'Baremetal') service(:compute, 'Compute') service(:container_infra, 'ContainerInfra') service(:dns, 'DNS') service(:event, 'Event') service(:identity, 'Identity') service(:image, 'Image') service(:introspection, 'Introspection') service(:key, 'KeyManager') service(:metering, 'Metering') service(:metric, 'Metric') service(:monitoring, 'Monitoring') service(:network, 'Network') service(:nfv, 'NFV') service(:orchestration, 'Orchestration') service(:planning, 'Planning') service(:shared_file_system, 'SharedFileSystem') service(:storage, 'Storage') service(:volume, 'Volume') service(:workflow, 'Workflow') @token_cache = {} class << self attr_accessor :token_cache end def self.clear_token_cache Fog::OpenStack.token_cache = {} end def self.endpoint_region?(endpoint, region) region.nil? || endpoint['region'] == region end def self.get_supported_version(supported_versions, uri, auth_token, connection_options = {}) supported_version = get_version(supported_versions, uri, auth_token, connection_options) version = supported_version['id'] if supported_version version_raise(supported_versions) if version.nil? version end def self.get_supported_version_path(supported_versions, uri, auth_token, connection_options = {}) supported_version = get_version(supported_versions, uri, auth_token, connection_options) link = supported_version['links'].find { |l| l['rel'] == 'self' } if supported_version path = URI.parse(link['href']).path if link version_raise(supported_versions) if path.nil? path.chomp '/' end def self.get_supported_microversion(supported_versions, uri, auth_token, connection_options = {}) supported_version = get_version(supported_versions, uri, auth_token, connection_options) supported_version['version'] if supported_version 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.get_version(supported_versions, uri, auth_token, connection_options = {}) version_cache = "#{uri}#{supported_versions}" return @version[version_cache] if @version && @version[version_cache] # To allow version discovery we need a "version less" endpoint path = uri.path.gsub(/\/v([1-9]+\d*)(\.[1-9]+\d*)*.*$/, '/') url = "#{uri.scheme}://#{uri.host}:#{uri.port}#{path}" connection = Fog::Core::Connection.new(url, 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 = {} unless @version @version[version_cache] = extract_version_from_body(body, supported_versions) end def self.extract_version_from_body(body, supported_versions) versions = [] unless body['versions'].nil? || body['versions'].empty? versions = body['versions'].kind_of?(Array) ? body['versions'] : body['versions']['values'] end # Some version API would return single endpoint rather than endpoints list, try to get it via 'version'. unless body['version'].nil? or versions.length != 0 versions = [body['version']] end version = nil # order is important, preferred status should be first %w(CURRENT stable SUPPORTED DEPRECATED).each do |status| version = versions.find { |x| x['id'].match(supported_versions) && (x['status'] == status) } break if version end version end def self.version_raise(supported_versions) raise Fog::OpenStack::Errors::ServiceUnavailable, "OpenStack service only supports API versions #{supported_versions.inspect}" end end end fog-openstack-1.0.8/lib/fog/openstack/0000755000004100000410000000000013423370527017626 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/volume/0000755000004100000410000000000013423370527021135 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/volume/requests/0000755000004100000410000000000013423370527023010 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/volume/requests/snapshot_action.rb0000644000004100000410000000052313423370527026531 0ustar www-datawww-datamodule Fog module OpenStack class Volume module Real def snapshot_action(id, data) request( :body => Fog::JSON.encode(data), :expects => [200, 202], :method => 'POST', :path => "snapshots/#{id}/action" ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/requests/get_backup_details.rb0000644000004100000410000000142513423370527027150 0ustar www-datawww-datamodule Fog module OpenStack class Volume module Real def get_backup_details(backup_id) request( :expects => 200, :method => 'GET', :path => "backups/#{backup_id}" ) end end module Mock def get_backup_details(_backup_id) response = Excon::Response.new response.status = 200 response.body = { "backup" => { "id" => "1", "volume_id" => "2", "name" => "backup 1", "status" => "available", "size" => 1, "object_count" => 16, "container" => "testcontainer", } } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/requests/get_volume_type_details.rb0000644000004100000410000000136613423370527030257 0ustar www-datawww-datamodule Fog module OpenStack class Volume 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-1.0.8/lib/fog/openstack/volume/requests/update_snapshot_metadata.rb0000644000004100000410000000066713423370527030407 0ustar www-datawww-datamodule Fog module OpenStack class Volume 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-1.0.8/lib/fog/openstack/volume/requests/delete_volume_type.rb0000644000004100000410000000073513423370527027234 0ustar www-datawww-datamodule Fog module OpenStack class Volume 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-1.0.8/lib/fog/openstack/volume/requests/list_transfers_detailed.rb0000644000004100000410000000057313423370527030237 0ustar www-datawww-datamodule Fog module OpenStack class Volume # 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-1.0.8/lib/fog/openstack/volume/requests/list_zones.rb0000644000004100000410000000127113423370527025527 0ustar www-datawww-datamodule Fog module OpenStack class Volume 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-1.0.8/lib/fog/openstack/volume/requests/update_volume.rb0000644000004100000410000000050413423370527026205 0ustar www-datawww-datamodule Fog module OpenStack class Volume 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-1.0.8/lib/fog/openstack/volume/requests/replace_metadata.rb0000644000004100000410000000065013423370527026611 0ustar www-datawww-datamodule Fog module OpenStack class Volume 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-1.0.8/lib/fog/openstack/volume/requests/set_tenant.rb0000644000004100000410000000052113423370527025477 0ustar www-datawww-datamodule Fog module OpenStack class Volume 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 end end fog-openstack-1.0.8/lib/fog/openstack/volume/requests/delete_snapshot.rb0000644000004100000410000000072213423370527026517 0ustar www-datawww-datamodule Fog module OpenStack class Volume 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-1.0.8/lib/fog/openstack/volume/requests/get_quota_usage.rb0000644000004100000410000000201513423370527026507 0ustar www-datawww-datamodule Fog module OpenStack class Volume 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-1.0.8/lib/fog/openstack/volume/requests/create_backup.rb0000644000004100000410000000223213423370527026124 0ustar www-datawww-datamodule Fog module OpenStack class Volume module Real def create_backup(attributes) desired_options = [ :container, :name, :description, :volume_id, :incremental, :force, ] # Filter only allowed creation attributes data = { :backup => attributes.select { |key, _value| desired_options.include?(key.to_sym) } } request( :body => Fog::JSON.encode(data), :expects => [200, 202], :method => 'POST', :path => 'backups' ) end end module Mock def create_backup(_options = {}) response = Excon::Response.new response.status = 202 response.body = { "backup" => { "id" => "1", "volume_id" => "2", "name" => "backup 1", "status" => "available", "size" => 1, "object_count" => 16, "container" => "testcontainer", } } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/requests/create_volume_type.rb0000644000004100000410000000202613423370527027230 0ustar www-datawww-datamodule Fog module OpenStack class Volume 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-1.0.8/lib/fog/openstack/volume/requests/get_volume_details.rb0000644000004100000410000000043513423370527027212 0ustar www-datawww-datamodule Fog module OpenStack class Volume module Real def get_volume_details(volume_id) request( :expects => 200, :method => 'GET', :path => "volumes/#{volume_id}" ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/requests/delete_backup.rb0000644000004100000410000000070613423370527026127 0ustar www-datawww-datamodule Fog module OpenStack class Volume module Real def delete_backup(backup_id) request( :expects => 202, :method => 'DELETE', :path => "backups/#{backup_id}" ) end end module Mock def delete_backup(_backup_id) response = Excon::Response.new response.status = 204 response end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/requests/create_snapshot.rb0000644000004100000410000000052413423370527026520 0ustar www-datawww-datamodule Fog module OpenStack class Volume 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-1.0.8/lib/fog/openstack/volume/requests/create_volume.rb0000644000004100000410000000115413423370527026170 0ustar www-datawww-datamodule Fog module OpenStack class Volume 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-1.0.8/lib/fog/openstack/volume/requests/list_volumes.rb0000644000004100000410000000170313423370527026063 0ustar www-datawww-datamodule Fog module OpenStack class Volume module Real def list_volumes(options = true, options_deprecated = {}) if options.kind_of?(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-1.0.8/lib/fog/openstack/volume/requests/list_backups.rb0000644000004100000410000000045613423370527026025 0ustar www-datawww-datamodule Fog module OpenStack class Volume module Real def list_backups(options = {}) request( :expects => 200, :method => 'GET', :path => 'backups', :query => options ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/requests/update_quota.rb0000644000004100000410000000124313423370527026030 0ustar www-datawww-datamodule Fog module OpenStack class Volume module Real def update_quota(tenant_id, options = {}) 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 = {}) data[:quota_updated] = data[:quota].merge options response = Excon::Response.new response.status = 200 response.body = {'quota_set' => data[:quota_updated]} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/requests/get_quota_defaults.rb0000644000004100000410000000110513423370527027211 0ustar www-datawww-datamodule Fog module OpenStack class Volume 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' => data[:quota].merge('id' => tenant_id) } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/requests/delete_metadata.rb0000644000004100000410000000047613423370527026446 0ustar www-datawww-datamodule Fog module OpenStack class Volume 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-1.0.8/lib/fog/openstack/volume/requests/list_volume_types.rb0000644000004100000410000000201013423370527027114 0ustar www-datawww-datamodule Fog module OpenStack class Volume 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 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' => data[:volume_types]} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/requests/delete_snapshot_metadata.rb0000644000004100000410000000051513423370527030357 0ustar www-datawww-datamodule Fog module OpenStack class Volume 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-1.0.8/lib/fog/openstack/volume/requests/update_volume_type.rb0000644000004100000410000000211013423370527027241 0ustar www-datawww-datamodule Fog module OpenStack class Volume 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-1.0.8/lib/fog/openstack/volume/requests/list_volumes_detailed.rb0000644000004100000410000000047613423370527027724 0ustar www-datawww-datamodule Fog module OpenStack class Volume module Real def list_volumes_detailed(options = {}) request( :expects => 200, :method => 'GET', :path => 'volumes/detail', :query => options ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/requests/list_snapshots.rb0000644000004100000410000000237713423370527026423 0ustar www-datawww-datamodule Fog module OpenStack class Volume module Real def list_snapshots(options = true, options_deprecated = {}) if options.kind_of?(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-1.0.8/lib/fog/openstack/volume/requests/list_snapshots_detailed.rb0000644000004100000410000000114513423370527030246 0ustar www-datawww-datamodule Fog module OpenStack class Volume 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-1.0.8/lib/fog/openstack/volume/requests/update_metadata.rb0000644000004100000410000000065413423370527026464 0ustar www-datawww-datamodule Fog module OpenStack class Volume module Real def update_metadata(volume_id, metadata = {}) data = { 'metadata' => metadata } request( :body => Fog::JSON.encode(data), :expects => [200,202], :method => 'POST', :path => "volumes/#{volume_id}/metadata" ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/requests/restore_backup.rb0000644000004100000410000000067613423370527026356 0ustar www-datawww-datamodule Fog module OpenStack class Volume module Real def restore_backup(backup_id, volume_id = nil, name = nil) data = {'restore' => {'volume_id' => volume_id, 'name' => name}} request( :expects => 202, :method => 'POST', :path => "backups/#{backup_id}/restore", :body => Fog::JSON.encode(data) ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/requests/delete_volume.rb0000644000004100000410000000070613423370527026171 0ustar www-datawww-datamodule Fog module OpenStack class Volume 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-1.0.8/lib/fog/openstack/volume/requests/get_quota.rb0000644000004100000410000000110413423370527025321 0ustar www-datawww-datamodule Fog module OpenStack class Volume 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' => (data[:quota_updated] || data[:quota]).merge('id' => tenant_id) } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/requests/get_snapshot_details.rb0000644000004100000410000000044513423370527027543 0ustar www-datawww-datamodule Fog module OpenStack class Volume module Real def get_snapshot_details(snapshot_id) request( :expects => 200, :method => 'GET', :path => "snapshots/#{snapshot_id}" ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/requests/list_backups_detailed.rb0000644000004100000410000000220013423370527027645 0ustar www-datawww-datamodule Fog module OpenStack class Volume module Real def list_backups_detailed(options = {}) request( :expects => 200, :method => 'GET', :path => 'backups/detail', :query => options ) end end module Mock def list_backups_detailed(_options = {}) response = Excon::Response.new response.status = 200 data[:backups] ||= [ { "id" => "1", "volume_id" => "2", "name" => "backup 1", "status" => "available", "size" => 1, "object_count" => 16, "container" => "testcontainer", }, { "id" => "2", "volume_id" => "2", "name" => "backup 2", "status" => "available", "size" => 1, "object_count" => 16, "container" => "testcontainer", } ] response.body = { 'backups' => data[:backups] } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/requests/extend_volume.rb0000644000004100000410000000107713423370527026220 0ustar www-datawww-datamodule Fog module OpenStack class Volume 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-1.0.8/lib/fog/openstack/volume/requests/update_snapshot.rb0000644000004100000410000000250613423370527026541 0ustar www-datawww-datamodule Fog module OpenStack class Volume 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-1.0.8/lib/fog/openstack/volume/requests/action.rb0000644000004100000410000000051013423370527024606 0ustar www-datawww-datamodule Fog module OpenStack class Volume 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-1.0.8/lib/fog/openstack/volume/requests/create_transfer.rb0000644000004100000410000000105713423370527026507 0ustar www-datawww-datamodule Fog module OpenStack class Volume 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-1.0.8/lib/fog/openstack/volume/requests/accept_transfer.rb0000644000004100000410000000073713423370527026507 0ustar www-datawww-datamodule Fog module OpenStack class Volume 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-1.0.8/lib/fog/openstack/volume/requests/get_transfer_details.rb0000644000004100000410000000053613423370527027531 0ustar www-datawww-datamodule Fog module OpenStack class Volume # 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-1.0.8/lib/fog/openstack/volume/requests/delete_transfer.rb0000644000004100000410000000045413423370527026506 0ustar www-datawww-datamodule Fog module OpenStack class Volume 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-1.0.8/lib/fog/openstack/volume/requests/list_transfers.rb0000644000004100000410000000055313423370527026402 0ustar www-datawww-datamodule Fog module OpenStack class Volume # 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-1.0.8/lib/fog/openstack/volume/models/0000755000004100000410000000000013423370527022420 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/volume/models/availability_zones.rb0000644000004100000410000000044213423370527026635 0ustar www-datawww-datarequire 'fog/openstack/models/collection' module Fog module OpenStack class Volume module AvailabilityZones def all(options = {}) data = service.list_zones(options) load_response(data, 'availabilityZoneInfo') end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/models/backup.rb0000644000004100000410000000207613423370527024217 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Volume class Backup < Fog::OpenStack::Model attribute :availability_zone attribute :container attribute :created_at attribute :description attribute :fail_reason attribute :name attribute :object_count attribute :size attribute :status attribute :volume_id attribute :is_incremental attribute :has_dependent_backups def create requires :name, :volume_id data = service.create_backup(attributes) merge_attributes(data.body['backup']) true end def destroy requires :id service.delete_backup(id) true end def restore(volume_id = nil, name = nil) requires :id service.restore_backup(id, volume_id, name) true end def volume requires :id service.get_volume_details(volume_id).body['volume'] end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/models/snapshot.rb0000644000004100000410000000162713423370527024612 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Volume 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-1.0.8/lib/fog/openstack/volume/models/availability_zone.rb0000644000004100000410000000024613423370527026454 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Volume class AvailabilityZone < Fog::OpenStack::Model end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/models/volumes.rb0000644000004100000410000000230413423370527024436 0ustar www-datawww-datarequire 'fog/openstack/models/collection' module Fog module OpenStack class Volume module Volumes def all(options = {}) # the parameter has been "detailed = true" before. Make sure we are # backwards compatible detailed = options.kind_of?(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::OpenStack::Volume::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/models/volume_type.rb0000644000004100000410000000125713423370527025322 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Volume 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-1.0.8/lib/fog/openstack/volume/models/backups.rb0000644000004100000410000000113113423370527024371 0ustar www-datawww-datarequire 'fog/openstack/models/collection' module Fog module OpenStack class Volume module Backups def all(options = {}) load_response(service.list_backups_detailed(options), 'backups') end def summary(options = {}) load_response(service.list_backups(options), 'backups') end def get(backup_id) backup = service.get_backup_details(backup_id).body['backup'] if backup new(backup) end rescue Fog::OpenStack::Volume::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/models/volume_types.rb0000644000004100000410000000103013423370527025472 0ustar www-datawww-datarequire 'fog/openstack/models/collection' module Fog module OpenStack class Volume 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::OpenStack::Volume::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/models/transfers.rb0000644000004100000410000000174113423370527024757 0ustar www-datawww-datarequire 'fog/openstack/models/collection' module Fog module OpenStack class Volume 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::OpenStack::Volume::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-1.0.8/lib/fog/openstack/volume/models/transfer.rb0000644000004100000410000000121313423370527024566 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Volume 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 end fog-openstack-1.0.8/lib/fog/openstack/volume/models/snapshots.rb0000644000004100000410000000116313423370527024770 0ustar www-datawww-datarequire 'fog/openstack/models/collection' module Fog module OpenStack class Volume 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::OpenStack::Volume::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/models/volume.rb0000644000004100000410000000341213423370527024254 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Volume 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-1.0.8/lib/fog/openstack/volume/v2/0000755000004100000410000000000013423370527021464 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/0000755000004100000410000000000013423370527023337 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/snapshot_action.rb0000644000004100000410000000015013423370527027054 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/snapshot_action' require 'fog/openstack/volume/v2/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/get_backup_details.rb0000644000004100000410000000015313423370527027474 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/get_backup_details' require 'fog/openstack/volume/v2/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/get_volume_type_details.rb0000644000004100000410000000016513423370527030602 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/get_volume_type_details' require 'fog/openstack/volume/v2/requests/real_mock' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/update_snapshot_metadata.rb0000644000004100000410000000016113423370527030723 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/update_snapshot_metadata' require 'fog/openstack/volume/v2/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/delete_volume_type.rb0000644000004100000410000000016013423370527027553 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/delete_volume_type' require 'fog/openstack/volume/v2/requests/real_mock' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/list_transfers_detailed.rb0000644000004100000410000000016013423370527030556 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/list_transfers_detailed' require 'fog/openstack/volume/v2/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/list_zones.rb0000644000004100000410000000015013423370527026051 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/list_zones' require 'fog/openstack/volume/v2/requests/real_mock' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/update_volume.rb0000644000004100000410000000104513423370527026535 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/update_volume' require 'fog/openstack/volume/v2/requests/real' module Fog module OpenStack class Volume module Real def update_volume(volume_id, data = {}) data = data.select { |key| key == :name || key == :description || key == :metadata } request( :body => Fog::JSON.encode('volume' => data), :expects => 200, :method => 'PUT', :path => "volumes/#{volume_id}" ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/replace_metadata.rb0000644000004100000410000000015113423370527027134 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/replace_metadata' require 'fog/openstack/volume/v2/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/set_tenant.rb0000644000004100000410000000015013423370527026024 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/set_tenant' require 'fog/openstack/volume/v2/requests/real_mock' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/delete_snapshot.rb0000644000004100000410000000015513423370527027046 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/delete_snapshot' require 'fog/openstack/volume/v2/requests/real_mock' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/get_quota_usage.rb0000644000004100000410000000015513423370527027041 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/get_quota_usage' require 'fog/openstack/volume/v2/requests/real_mock' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/create_backup.rb0000644000004100000410000000014613423370527026455 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/create_backup' require 'fog/openstack/volume/v2/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/create_volume_type.rb0000644000004100000410000000016013423370527027554 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/create_volume_type' require 'fog/openstack/volume/v2/requests/real_mock' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/get_volume_details.rb0000644000004100000410000000201713423370527027537 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/get_volume_details' module Fog module OpenStack class Volume class V2 class Real include Fog::OpenStack::Volume::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-1.0.8/lib/fog/openstack/volume/v2/requests/delete_backup.rb0000644000004100000410000000014613423370527026454 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/delete_backup' require 'fog/openstack/volume/v2/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/create_snapshot.rb0000644000004100000410000000231613423370527027050 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/create_snapshot' module Fog module OpenStack class Volume class V2 class Real include Fog::OpenStack::Volume::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-1.0.8/lib/fog/openstack/volume/v2/requests/create_volume.rb0000644000004100000410000000273613423370527026526 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/create_volume' module Fog module OpenStack class Volume 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::OpenStack::Volume::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-1.0.8/lib/fog/openstack/volume/v2/requests/list_volumes.rb0000644000004100000410000000302713423370527026413 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/list_volumes' module Fog module OpenStack class Volume class V2 class Real include Fog::OpenStack::Volume::Real end class Mock def list_volumes(_options = true, _options_deprecated = {}) response = Excon::Response.new response.status = 200 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' => data[:volumes]} response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/list_backups.rb0000644000004100000410000000014513423370527026347 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/list_backups' require 'fog/openstack/volume/v2/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/update_quota.rb0000644000004100000410000000015213423370527026355 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/update_quota' require 'fog/openstack/volume/v1/requests/real_mock' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/get_quota_defaults.rb0000644000004100000410000000016013423370527027540 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/get_quota_defaults' require 'fog/openstack/volume/v2/requests/real_mock' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/delete_metadata.rb0000644000004100000410000000015013423370527026762 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/delete_metadata' require 'fog/openstack/volume/v2/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/list_volume_types.rb0000644000004100000410000000015713423370527027455 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/list_volume_types' require 'fog/openstack/volume/v2/requests/real_mock' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/delete_snapshot_metadata.rb0000644000004100000410000000016113423370527030703 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/delete_snapshot_metadata' require 'fog/openstack/volume/v2/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/update_volume_type.rb0000644000004100000410000000016013423370527027573 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/update_volume_type' require 'fog/openstack/volume/v2/requests/real_mock' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/list_volumes_detailed.rb0000644000004100000410000000301513423370527030243 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/list_volumes_detailed' module Fog module OpenStack class Volume class V2 class Real include Fog::OpenStack::Volume::Real end class Mock def list_volumes_detailed(_options = {}) response = Excon::Response.new response.status = 200 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' => data[:volumes]} response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/list_snapshots.rb0000644000004100000410000000015413423370527026741 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/list_snapshots' require 'fog/openstack/volume/v2/requests/real_mock' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/list_snapshots_detailed.rb0000644000004100000410000000016513423370527030576 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/list_snapshots_detailed' require 'fog/openstack/volume/v2/requests/real_mock' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/update_metadata.rb0000644000004100000410000000015013423370527027002 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/update_metadata' require 'fog/openstack/volume/v2/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/real_mock.rb0000644000004100000410000000036613423370527025625 0ustar www-datawww-datamodule Fog module OpenStack class Volume class V2 class Real include Fog::OpenStack::Volume::Real end class Mock include Fog::OpenStack::Volume::Mock end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/restore_backup.rb0000644000004100000410000000014713423370527026676 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/restore_backup' require 'fog/openstack/volume/v2/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/delete_volume.rb0000644000004100000410000000015313423370527026514 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/delete_volume' require 'fog/openstack/volume/v2/requests/real_mock' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/get_quota.rb0000644000004100000410000000014713423370527025656 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/get_quota' require 'fog/openstack/volume/v2/requests/real_mock' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/get_snapshot_details.rb0000644000004100000410000000147113423370527030072 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/get_snapshot_details' module Fog module OpenStack class Volume class V2 class Real include Fog::OpenStack::Volume::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-1.0.8/lib/fog/openstack/volume/v2/requests/list_backups_detailed.rb0000644000004100000410000000015613423370527030204 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/list_backups_detailed' require 'fog/openstack/volume/v2/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/extend_volume.rb0000644000004100000410000000015313423370527026541 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/extend_volume' require 'fog/openstack/volume/v2/requests/real_mock' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/update_snapshot.rb0000644000004100000410000000015013423370527027061 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/update_snapshot' require 'fog/openstack/volume/v2/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/action.rb0000644000004100000410000000013713423370527025142 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/action' require 'fog/openstack/volume/v2/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/create_transfer.rb0000644000004100000410000000015013423370527027027 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/create_transfer' require 'fog/openstack/volume/v2/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/real.rb0000644000004100000410000000025013423370527024604 0ustar www-datawww-datamodule Fog module OpenStack class Volume class V2 class Real include Fog::OpenStack::Volume::Real end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/accept_transfer.rb0000644000004100000410000000015013423370527027023 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/accept_transfer' require 'fog/openstack/volume/v2/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/get_transfer_details.rb0000644000004100000410000000015513423370527030055 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/get_transfer_details' require 'fog/openstack/volume/v2/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/delete_transfer.rb0000644000004100000410000000015013423370527027026 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/delete_transfer' require 'fog/openstack/volume/v2/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/requests/list_transfers.rb0000644000004100000410000000014713423370527026730 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/list_transfers' require 'fog/openstack/volume/v2/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v2/models/0000755000004100000410000000000013423370527022747 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/volume/v2/models/availability_zones.rb0000644000004100000410000000067313423370527027172 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/volume/v2/models/availability_zone' require 'fog/openstack/volume/models/availability_zones' module Fog module OpenStack class Volume class V2 class AvailabilityZones < Fog::OpenStack::Collection model Fog::OpenStack::Volume::V2::AvailabilityZone include Fog::OpenStack::Volume::AvailabilityZones end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/v2/models/backup.rb0000644000004100000410000000044513423370527024544 0ustar www-datawww-datarequire 'fog/openstack/volume/models/backup' module Fog module OpenStack class Volume class V2 class Backup < Fog::OpenStack::Volume::Backup identity :id superclass.attributes.each { |attrib| attribute attrib } end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/v2/models/snapshot.rb0000644000004100000410000000236013423370527025134 0ustar www-datawww-datarequire 'fog/openstack/volume/models/snapshot' module Fog module OpenStack class Volume class V2 class Snapshot < Fog::OpenStack::Volume::Snapshot identity :id attribute :name attribute :status attribute :description attribute :metadata attribute :force attribute :size 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-1.0.8/lib/fog/openstack/volume/v2/models/availability_zone.rb0000644000004100000410000000044613423370527027005 0ustar www-datawww-datarequire 'fog/openstack/volume/models/availability_zone' module Fog module OpenStack class Volume class V2 class AvailabilityZone < Fog::OpenStack::Volume::AvailabilityZone identity :zoneName attribute :zoneState end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/v2/models/volumes.rb0000644000004100000410000000060713423370527024771 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/volume/v2/models/volume' require 'fog/openstack/volume/models/volumes' module Fog module OpenStack class Volume class V2 class Volumes < Fog::OpenStack::Collection model Fog::OpenStack::Volume::V2::Volume include Fog::OpenStack::Volume::Volumes end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/v2/models/volume_type.rb0000644000004100000410000000046213423370527025646 0ustar www-datawww-datarequire 'fog/openstack/volume/models/volume_type' module Fog module OpenStack class Volume class V2 class VolumeType < Fog::OpenStack::Volume::VolumeType identity :id attribute :name attribute :volume_backend_name end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/v2/models/backups.rb0000644000004100000410000000060713423370527024727 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/volume/v2/models/backup' require 'fog/openstack/volume/models/backups' module Fog module OpenStack class Volume class V2 class Backups < Fog::OpenStack::Collection model Fog::OpenStack::Volume::V2::Backup include Fog::OpenStack::Volume::Backups end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/v2/models/volume_types.rb0000644000004100000410000000063513423370527026033 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/volume/v2/models/volume_type' require 'fog/openstack/volume/models/volume_types' module Fog module OpenStack class Volume class V2 class VolumeTypes < Fog::OpenStack::Collection model Fog::OpenStack::Volume::V2::VolumeType include Fog::OpenStack::Volume::VolumeTypes end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/v2/models/transfers.rb0000644000004100000410000000062113423370527025302 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/volume/v2/models/transfer' require 'fog/openstack/volume/models/transfers' module Fog module OpenStack class Volume class V2 class Transfers < Fog::OpenStack::Collection model Fog::OpenStack::Volume::V2::Transfer include Fog::OpenStack::Volume::Transfers end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/v2/models/transfer.rb0000644000004100000410000000064713423370527025127 0ustar www-datawww-datarequire 'fog/openstack/volume/models/transfer' module Fog module OpenStack class Volume class V2 class Transfer < Fog::OpenStack::Volume::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-1.0.8/lib/fog/openstack/volume/v2/models/snapshots.rb0000644000004100000410000000062113423370527025315 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/volume/v2/models/snapshot' require 'fog/openstack/volume/models/snapshots' module Fog module OpenStack class Volume class V2 class Snapshots < Fog::OpenStack::Collection model Fog::OpenStack::Volume::V2::Snapshot include Fog::OpenStack::Volume::Snapshots end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/v2/models/volume.rb0000644000004100000410000000203013423370527024576 0ustar www-datawww-datarequire 'fog/openstack/volume/models/volume' module Fog module OpenStack class Volume class V2 class Volume < Fog::OpenStack::Volume::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.select { |key| %i(name description metadata).include?(key) }) 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-1.0.8/lib/fog/openstack/volume/v1/0000755000004100000410000000000013423370527021463 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/0000755000004100000410000000000013423370527023336 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/get_backup_details.rb0000644000004100000410000000015313423370527027473 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/get_backup_details' require 'fog/openstack/volume/v1/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/get_volume_type_details.rb0000644000004100000410000000016513423370527030601 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/get_volume_type_details' require 'fog/openstack/volume/v1/requests/real_mock' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/update_snapshot_metadata.rb0000644000004100000410000000016113423370527030722 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/update_snapshot_metadata' require 'fog/openstack/volume/v1/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/delete_volume_type.rb0000644000004100000410000000016013423370527027552 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/delete_volume_type' require 'fog/openstack/volume/v1/requests/real_mock' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/list_transfers_detailed.rb0000644000004100000410000000016013423370527030555 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/list_transfers_detailed' require 'fog/openstack/volume/v1/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/list_zones.rb0000644000004100000410000000015013423370527026050 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/list_zones' require 'fog/openstack/volume/v1/requests/real_mock' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/update_volume.rb0000644000004100000410000000070613423370527026537 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/update_volume' require 'fog/openstack/volume/v1/requests/real' module Fog module OpenStack class Volume 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 end end end fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/replace_metadata.rb0000644000004100000410000000015113423370527027133 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/replace_metadata' require 'fog/openstack/volume/v1/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/set_tenant.rb0000644000004100000410000000015013423370527026023 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/set_tenant' require 'fog/openstack/volume/v1/requests/real_mock' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/delete_snapshot.rb0000644000004100000410000000015513423370527027045 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/delete_snapshot' require 'fog/openstack/volume/v1/requests/real_mock' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/get_quota_usage.rb0000644000004100000410000000015513423370527027040 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/get_quota_usage' require 'fog/openstack/volume/v1/requests/real_mock' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/create_backup.rb0000644000004100000410000000014613423370527026454 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/create_backup' require 'fog/openstack/volume/v1/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/create_volume_type.rb0000644000004100000410000000016013423370527027553 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/create_volume_type' require 'fog/openstack/volume/v1/requests/real_mock' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/get_volume_details.rb0000644000004100000410000000204313423370527027535 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/get_volume_details' module Fog module OpenStack class Volume class V1 class Real include Fog::OpenStack::Volume::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-1.0.8/lib/fog/openstack/volume/v1/requests/delete_backup.rb0000644000004100000410000000014613423370527026453 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/delete_backup' require 'fog/openstack/volume/v1/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/create_snapshot.rb0000644000004100000410000000244613423370527027053 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/create_snapshot' module Fog module OpenStack class Volume class V1 class Real include Fog::OpenStack::Volume::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-1.0.8/lib/fog/openstack/volume/v1/requests/create_volume.rb0000644000004100000410000000301613423370527026515 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/create_volume' module Fog module OpenStack class Volume 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::OpenStack::Volume::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-1.0.8/lib/fog/openstack/volume/v1/requests/list_volumes.rb0000644000004100000410000000310313423370527026405 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/list_volumes' module Fog module OpenStack class Volume class V1 class Real include Fog::OpenStack::Volume::Real end class Mock def list_volumes(_options = true, _options_deprecated = {}) response = Excon::Response.new response.status = 200 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' => data[:volumes]} response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/list_backups.rb0000644000004100000410000000014513423370527026346 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/list_backups' require 'fog/openstack/volume/v1/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/update_quota.rb0000644000004100000410000000015213423370527026354 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/update_quota' require 'fog/openstack/volume/v1/requests/real_mock' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/get_quota_defaults.rb0000644000004100000410000000016013423370527027537 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/get_quota_defaults' require 'fog/openstack/volume/v1/requests/real_mock' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/delete_metadata.rb0000644000004100000410000000015013423370527026761 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/delete_metadata' require 'fog/openstack/volume/v1/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/list_volume_types.rb0000644000004100000410000000015713423370527027454 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/list_volume_types' require 'fog/openstack/volume/v1/requests/real_mock' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/delete_snapshot_metadata.rb0000644000004100000410000000016113423370527030702 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/delete_snapshot_metadata' require 'fog/openstack/volume/v1/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/list_volumes_detailed.rb0000644000004100000410000000307113423370527030244 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/list_volumes_detailed' module Fog module OpenStack class Volume class V1 class Real include Fog::OpenStack::Volume::Real end class Mock def list_volumes_detailed(_options = {}) response = Excon::Response.new response.status = 200 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' => data[:volumes]} response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/list_snapshots.rb0000644000004100000410000000015413423370527026740 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/list_snapshots' require 'fog/openstack/volume/v1/requests/real_mock' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/list_snapshots_detailed.rb0000644000004100000410000000016513423370527030575 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/list_snapshots_detailed' require 'fog/openstack/volume/v1/requests/real_mock' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/update_metadata.rb0000644000004100000410000000015013423370527027001 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/update_metadata' require 'fog/openstack/volume/v1/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/real_mock.rb0000644000004100000410000000036613423370527025624 0ustar www-datawww-datamodule Fog module OpenStack class Volume class V1 class Real include Fog::OpenStack::Volume::Real end class Mock include Fog::OpenStack::Volume::Mock end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/restore_backup.rb0000644000004100000410000000014713423370527026675 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/restore_backup' require 'fog/openstack/volume/v1/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/delete_volume.rb0000644000004100000410000000015313423370527026513 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/delete_volume' require 'fog/openstack/volume/v1/requests/real_mock' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/get_quota.rb0000644000004100000410000000014713423370527025655 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/get_quota' require 'fog/openstack/volume/v1/requests/real_mock' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/get_snapshot_details.rb0000644000004100000410000000156113423370527030071 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/get_snapshot_details' module Fog module OpenStack class Volume class V1 class Real include Fog::OpenStack::Volume::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-1.0.8/lib/fog/openstack/volume/v1/requests/list_backups_detailed.rb0000644000004100000410000000015613423370527030203 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/list_backups_detailed' require 'fog/openstack/volume/v1/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/extend_volume.rb0000644000004100000410000000015313423370527026540 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/extend_volume' require 'fog/openstack/volume/v1/requests/real_mock' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/update_snapshot.rb0000644000004100000410000000015013423370527027060 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/update_snapshot' require 'fog/openstack/volume/v1/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/action.rb0000644000004100000410000000013713423370527025141 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/action' require 'fog/openstack/volume/v1/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/create_transfer.rb0000644000004100000410000000015013423370527027026 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/create_transfer' require 'fog/openstack/volume/v1/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/real.rb0000644000004100000410000000025013423370527024603 0ustar www-datawww-datamodule Fog module OpenStack class Volume class V1 class Real include Fog::OpenStack::Volume::Real end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/accept_transfer.rb0000644000004100000410000000015013423370527027022 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/accept_transfer' require 'fog/openstack/volume/v1/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/get_transfer_details.rb0000644000004100000410000000015513423370527030054 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/get_transfer_details' require 'fog/openstack/volume/v1/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/delete_transfer.rb0000644000004100000410000000015013423370527027025 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/delete_transfer' require 'fog/openstack/volume/v1/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/requests/list_transfers.rb0000644000004100000410000000014713423370527026727 0ustar www-datawww-datarequire 'fog/openstack/volume/requests/list_transfers' require 'fog/openstack/volume/v1/requests/real' fog-openstack-1.0.8/lib/fog/openstack/volume/v1/models/0000755000004100000410000000000013423370527022746 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/volume/v1/models/availability_zones.rb0000644000004100000410000000067313423370527027171 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/volume/v1/models/availability_zone' require 'fog/openstack/volume/models/availability_zones' module Fog module OpenStack class Volume class V1 class AvailabilityZones < Fog::OpenStack::Collection model Fog::OpenStack::Volume::V1::AvailabilityZone include Fog::OpenStack::Volume::AvailabilityZones end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/v1/models/backup.rb0000644000004100000410000000044513423370527024543 0ustar www-datawww-datarequire 'fog/openstack/volume/models/backup' module Fog module OpenStack class Volume class V1 class Backup < Fog::OpenStack::Volume::Backup identity :id superclass.attributes.each { |attrib| attribute attrib } end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/v1/models/snapshot.rb0000644000004100000410000000246013423370527025134 0ustar www-datawww-datarequire 'fog/openstack/volume/models/snapshot' module Fog module OpenStack class Volume class V1 class Snapshot < Fog::OpenStack::Volume::Snapshot identity :id attribute :display_name attribute :status attribute :display_description attribute :metadata attribute :force attribute :size 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-1.0.8/lib/fog/openstack/volume/v1/models/availability_zone.rb0000644000004100000410000000044613423370527027004 0ustar www-datawww-datarequire 'fog/openstack/volume/models/availability_zone' module Fog module OpenStack class Volume class V1 class AvailabilityZone < Fog::OpenStack::Volume::AvailabilityZone identity :zoneName attribute :zoneState end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/v1/models/volumes.rb0000644000004100000410000000060713423370527024770 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/volume/v1/models/volume' require 'fog/openstack/volume/models/volumes' module Fog module OpenStack class Volume class V1 class Volumes < Fog::OpenStack::Collection model Fog::OpenStack::Volume::V1::Volume include Fog::OpenStack::Volume::Volumes end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/v1/models/volume_type.rb0000644000004100000410000000046213423370527025645 0ustar www-datawww-datarequire 'fog/openstack/volume/models/volume_type' module Fog module OpenStack class Volume class V1 class VolumeType < Fog::OpenStack::Volume::VolumeType identity :id attribute :name attribute :volume_backend_name end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/v1/models/backups.rb0000644000004100000410000000060713423370527024726 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/volume/v1/models/backup' require 'fog/openstack/volume/models/backups' module Fog module OpenStack class Volume class V1 class Backups < Fog::OpenStack::Collection model Fog::OpenStack::Volume::V1::Backup include Fog::OpenStack::Volume::Backups end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/v1/models/volume_types.rb0000644000004100000410000000063513423370527026032 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/volume/v1/models/volume_type' require 'fog/openstack/volume/models/volume_types' module Fog module OpenStack class Volume class V1 class VolumeTypes < Fog::OpenStack::Collection model Fog::OpenStack::Volume::V1::VolumeType include Fog::OpenStack::Volume::VolumeTypes end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/v1/models/transfers.rb0000644000004100000410000000062113423370527025301 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/volume/v1/models/transfer' require 'fog/openstack/volume/models/transfers' module Fog module OpenStack class Volume class V1 class Transfers < Fog::OpenStack::Collection model Fog::OpenStack::Volume::V1::Transfer include Fog::OpenStack::Volume::Transfers end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/v1/models/transfer.rb0000644000004100000410000000064713423370527025126 0ustar www-datawww-datarequire 'fog/openstack/volume/models/transfer' module Fog module OpenStack class Volume class V1 class Transfer < Fog::OpenStack::Volume::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-1.0.8/lib/fog/openstack/volume/v1/models/snapshots.rb0000644000004100000410000000062113423370527025314 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/volume/v1/models/snapshot' require 'fog/openstack/volume/models/snapshots' module Fog module OpenStack class Volume class V1 class Snapshots < Fog::OpenStack::Collection model Fog::OpenStack::Volume::V1::Snapshot include Fog::OpenStack::Volume::Snapshots end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/v1/models/volume.rb0000644000004100000410000000226213423370527024604 0ustar www-datawww-datarequire 'fog/openstack/volume/models/volume' module Fog module OpenStack class Volume class V1 class Volume < Fog::OpenStack::Volume::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 attrib = attributes.select { |key| %i(display_name display_description metadata).include?(key) } service.update_volume(id, attrib) 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-1.0.8/lib/fog/openstack/volume/v1.rb0000644000004100000410000001070413423370527022012 0ustar www-datawww-datarequire 'fog/openstack/core' require 'fog/openstack/volume' module Fog module OpenStack class Volume class V1 < Fog::OpenStack::Volume SUPPORTED_VERSIONS = /v1(\.(0-9))*/ requires :openstack_auth_url recognizes *@@recognizes model_path 'fog/openstack/volume/v1/models' model :volume collection :volumes model :availability_zone collection :availability_zones model :volume_type collection :volume_types model :snapshot collection :snapshots model :transfer collection :transfers model :backup collection :backups request_path 'fog/openstack/volume/v1/requests' # 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 :list_backups request :list_backups_detailed request :create_backup request :get_backup_details request :restore_backup request :delete_backup 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::OpenStack::Volume::NotFound end def default_endtpoint_type 'admin' end def default_service_type %w[volume] end end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume/v2.rb0000644000004100000410000001101313423370527022005 0ustar www-datawww-datarequire 'fog/openstack/core' require 'fog/openstack/volume' module Fog module OpenStack class Volume class V2 < Fog::OpenStack::Volume SUPPORTED_VERSIONS = /v2(\.(0-9))*/ requires :openstack_auth_url recognizes *@@recognizes model_path 'fog/openstack/volume/v2/models' model :volume collection :volumes model :availability_zone collection :availability_zones model :volume_type collection :volume_types model :snapshot collection :snapshots model :transfer collection :transfers model :backup collection :backups request_path 'fog/openstack/volume/v2/requests' # 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 :list_backups request :list_backups_detailed request :create_backup request :get_backup_details request :restore_backup request :delete_backup 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 request :snapshot_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::OpenStack::Volume::NotFound end def default_endtpoint_type 'admin' end def default_service_type %w[volumev2] end end end end end end fog-openstack-1.0.8/lib/fog/openstack/planning/0000755000004100000410000000000013423370527021434 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/planning/requests/0000755000004100000410000000000013423370527023307 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/planning/requests/get_plan.rb0000644000004100000410000000427713423370527025437 0ustar www-datawww-datamodule 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 Mock def get_plan(_parameters = nil) response = Excon::Response.new response.status = [200, 204][rand(2)] 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 end end end end fog-openstack-1.0.8/lib/fog/openstack/planning/requests/list_roles.rb0000644000004100000410000000146013423370527026014 0ustar www-datawww-datamodule Fog module OpenStack class Planning class Real def list_roles(options = {}) request( :expects => [200, 204], :method => 'GET', :path => 'roles', :query => options ) end end class Mock def list_roles(_options = {}) response = Excon::Response.new response.status = [200, 204][rand(2)] 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 end end end end fog-openstack-1.0.8/lib/fog/openstack/planning/requests/create_plan.rb0000644000004100000410000000153213423370527026112 0ustar www-datawww-datamodule 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 Mock def create_plan(_parameters) response = Excon::Response.new response.status = 201 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 end end end end fog-openstack-1.0.8/lib/fog/openstack/planning/requests/patch_plan.rb0000644000004100000410000000351713423370527025753 0ustar www-datawww-datamodule 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 Mock def patch_plan(_plan_uuid, _parameters) response = Excon::Response.new response.status = 201 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 end end end end fog-openstack-1.0.8/lib/fog/openstack/planning/requests/list_plans.rb0000644000004100000410000000446413423370527026014 0ustar www-datawww-datamodule Fog module OpenStack class Planning class Real def list_plans(options = {}) request( :expects => [200, 204], :method => 'GET', :path => 'plans', :query => options ) end end class Mock def list_plans(_options = {}) response = Excon::Response.new response.status = [200, 204][rand(2)] 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 end end end end fog-openstack-1.0.8/lib/fog/openstack/planning/requests/remove_role_from_plan.rb0000644000004100000410000000155713423370527030217 0ustar www-datawww-datamodule 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 Mock def remove_role_from_plan(_plan_uuid, _role_uuid) response = Excon::Response.new response.status = 200 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 end end end end fog-openstack-1.0.8/lib/fog/openstack/planning/requests/add_role_to_plan.rb0000644000004100000410000000231213423370527027117 0ustar www-datawww-datamodule 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 Mock def add_role_to_plan(_plan_uuid, _role_uuid) response = Excon::Response.new response.status = 201 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 end end end end fog-openstack-1.0.8/lib/fog/openstack/planning/requests/delete_plan.rb0000644000004100000410000000070213423370527026107 0ustar www-datawww-datamodule Fog module OpenStack class Planning class Real def delete_plan(plan_uuid) request( :expects => [204], :method => 'DELETE', :path => "plans/#{plan_uuid}" ) end end class Mock def delete_plan(_plan_uuid) response = Excon::Response.new response.status = 204 response end end end end end fog-openstack-1.0.8/lib/fog/openstack/planning/requests/get_plan_templates.rb0000644000004100000410000000137213423370527027506 0ustar www-datawww-datamodule 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 Mock def get_plan_templates(_plan_uuid) response = Excon::Response.new response.status = [200, 204][rand(2)] response.body = { "environment.yaml" => "... content of template file ...", "plan.yaml" => "... content of template file ...", "provider-compute-1.yaml" => "... content of template file ..." } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/planning/models/0000755000004100000410000000000013423370527022717 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/planning/models/plans.rb0000644000004100000410000000134713423370527024366 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/planning/models/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 get find_by_uuid def method_missing(method_sym, *arguments, &block) if method_sym.to_s =~ /^find_by_(.*)$/ all.find do |plan| plan.send($1) == arguments.first end else super end end end end end end fog-openstack-1.0.8/lib/fog/openstack/planning/models/plan.rb0000644000004100000410000000307013423370527024176 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Planning class Plan < Fog::OpenStack::Model MASTER_TEMPLATE_NAME = 'plan.yaml'.freeze ENVIRONMENT_NAME = 'environment.yaml'.freeze 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(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-1.0.8/lib/fog/openstack/planning/models/roles.rb0000644000004100000410000000054113423370527024370 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/planning/models/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-1.0.8/lib/fog/openstack/planning/models/role.rb0000644000004100000410000000072513423370527024211 0ustar www-datawww-datarequire '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-1.0.8/lib/fog/openstack/metric/0000755000004100000410000000000013423370527021111 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/metric/requests/0000755000004100000410000000000013423370527022764 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/metric/requests/get_resource.rb0000644000004100000410000000246213423370527026003 0ustar www-datawww-datamodule Fog module OpenStack class Metric class Real def get_resource(resource_id) request( :expects => 200, :method => 'GET', :path => "resource/generic/#{resource_id}" ) end end class Mock def get_resource(_resource_id) response = Excon::Response.new response.status = 200 response.body = { "created_by_project_id" => "384a902b-6856-424c-9d30-6b5325ac20a5", "created_by_user_id" => "d040def9-fd68-45f0-a19f-253014f397c3", "ended_at" => nil, "id" => "75c44741-cc60-4033-804e-2d3098c7d2e9", "metrics" => {}, "original_resource_id" => "75C44741-CC60-4033-804E-2D3098C7D2E9", "project_id" => "BD3A1E52-1C62-44CB-BF04-660BD88CD74D", "revision_end" => nil, "revision_start" => "2016-11-08T11:23:45.989977+00:00", "started_at" => "2016-11-08T11:23:45.989960+00:00", "type" => "generic", "user_id" => "BD3A1E52-1C62-44CB-BF04-660BD88CD74D" } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/metric/requests/get_resource_metric_measures.rb0000644000004100000410000000222013423370527031242 0ustar www-datawww-datamodule Fog module OpenStack class Metric class Real def get_resource_metric_measures(resource_id, metric_name, options = {}) request( :expects => 200, :method => 'GET', :path => "resource/generic/#{resource_id}/metric/#{metric_name}/measures", :query => options ) end end class Mock def get_resource_metric_measures(_resource_id, _metric_name, _options = {}) response = Excon::Response.new response.status = 200 response.body = [ [ "2014-10-06T14:00:00+00:00", 3600.0, 24.7 ], [ "2014-10-06T14:34:00+00:00", 60.0, 15.5 ], [ "2014-10-06T14:34:12+00:00", 1.0, 6.0 ], [ "2014-10-06T14:34:20+00:00", 1.0, 25.0 ] ] response end end end end end fog-openstack-1.0.8/lib/fog/openstack/metric/requests/get_metric_measures.rb0000644000004100000410000000167413423370527027347 0ustar www-datawww-datamodule Fog module OpenStack class Metric class Real def get_metric_measures(metric_id, options = {}) request( :expects => 200, :method => 'GET', :path => "metric/#{metric_id}/measures", :query => options, ) end end class Mock def get_metric_measures(_metric_id, _options = {}) response = Excon::Response.new response.status = 200 response.body = [ { "timestamp" => "2014-10-06T14:33:57", "value" => 43.1 }, { "timestamp" => "2014-10-06T14:34:12", "value" => 12 }, { "timestamp" => "2014-10-06T14:34:20", "value" => 2 } ] response end end end end end fog-openstack-1.0.8/lib/fog/openstack/metric/requests/list_resources.rb0000644000004100000410000000651613423370527026366 0ustar www-datawww-datamodule Fog module OpenStack class Metric class Real def list_resources(type = "generic", options = {}) request( :expects => 200, :method => 'GET', :path => "resource/#{Fog::OpenStack.escape(type)}", :query => options ) end end class Mock def list_resources(_type = "generic", _options = {}) response = Excon::Response.new response.status = 200 response.body = [ { "created_by_project_id" => "384a902b-6856-424c-9d30-6b5325ac20a5", "created_by_user_id" => "d040def9-fd68-45f0-a19f-253014f397c3", "ended_at" => nil, "id" => "75c44741-cc60-4033-804e-2d3098c7d2e9", "metrics" => {}, "original_resource_id" => "75C44741-CC60-4033-804E-2D3098C7D2E9", "project_id" => "BD3A1E52-1C62-44CB-BF04-660BD88CD74D", "revision_end" => nil, "revision_start" => "2016-11-08T11:23:45.989977+00:00", "started_at" => "2016-11-08T11:23:45.989960+00:00", "type" => "generic", "user_id" => "BD3A1E52-1C62-44CB-BF04-660BD88CD74D" }, { "created_by_project_id" => "384a902b-6856-424c-9d30-6b5325ac20a5", "created_by_user_id" => "d040def9-fd68-45f0-a19f-253014f397c3", "ended_at" => nil, "id" => "ab68da77-fa82-4e67-aba9-270c5a98cbcb", "metrics" => { "temperature" => "ed51c966-8890-4f4e-96c4-f0a753dbad42" }, "original_resource_id" => "AB68DA77-FA82-4E67-ABA9-270C5A98CBCB", "project_id" => "BD3A1E52-1C62-44CB-BF04-660BD88CD74D", "revision_end" => nil, "revision_start" => "2016-11-08T11:23:46.177259+00:00", "started_at" => "2016-11-08T11:23:46.177236+00:00", "type" => "generic", "user_id" => "BD3A1E52-1C62-44CB-BF04-660BD88CD74D" }, { "created_by_project_id" => "384a902b-6856-424c-9d30-6b5325ac20a5", "created_by_user_id" => "d040def9-fd68-45f0-a19f-253014f397c3", "ended_at" => "2014-01-04T10:00:12+00:00", "id" => "6868da77-fa82-4e67-aba9-270c5ae8cbca", "metrics" => {}, "original_resource_id" => "6868DA77-FA82-4E67-ABA9-270C5AE8CBCA", "project_id" => "BD3A1E52-1C62-44CB-BF04-660BD88CD74D", "revision_end" => nil, "revision_start" => "2016-11-08T11:23:46.781604+00:00", "started_at" => "2014-01-02T23:23:34+00:00", "type" => "instance", "user_id" => "BD3A1E52-1C62-44CB-BF04-660BD88CD74D" } ] response end end end end end fog-openstack-1.0.8/lib/fog/openstack/metric/requests/list_metrics.rb0000644000004100000410000000745113423370527026021 0ustar www-datawww-datamodule Fog module OpenStack class Metric class Real def list_metrics(options = {}) request( :expects => 200, :method => 'GET', :path => 'metric', :query => options ) end end class Mock def list_metrics(_options = {}) response = Excon::Response.new response.status = 200 response.body = [ { "archive_policy" => { "aggregation_methods" => [ "95pct", "median", "max", "count", "std", "sum", "min", "mean" ], "back_window" => 0, "definition" => [ { "granularity" => "0:00:01", "points" => 3600, "timespan" => "1:00:00" }, { "granularity" => "0:01:00", "points" => 10080, "timespan" => "7 days, 0:00:00" }, { "granularity" => "1:00:00", "points" => 8760, "timespan" => "365 days, 0:00:00" } ], "name" => "high" }, "created_by_project_id" => "384a902b-6856-424c-9d30-6b5325ac20a5", "created_by_user_id" => "d040def9-fd68-45f0-a19f-253014f397c3", "id" => "8bbb5f02-b654-4861-b19e-d372fcdca124", "name" => nil, "resource_id" => nil, "unit" => nil }, { "archive_policy" => { "aggregation_methods" => [ "95pct", "median", "max", "count", "std", "sum", "min", "mean" ], "back_window" => 0, "definition" => [ { "granularity" => "0:05:00", "points" => 12, "timespan" => "1:00:00" }, { "granularity" => "1:00:00", "points" => 24, "timespan" => "1 day, 0:00:00" }, { "granularity" => "1 day, 0:00:00", "points" => 30, "timespan" => "30 days, 0:00:00" } ], "name" => "low" }, "created_by_project_id" => "384a902b-6856-424c-9d30-6b5325ac20a5", "created_by_user_id" => "d040def9-fd68-45f0-a19f-253014f397c3", "id" => "af3446dc-e20f-4ecf-aaaa-1240c05ff19b", "name" => nil, "resource_id" => nil, "unit" => nil } ] response end end end end end fog-openstack-1.0.8/lib/fog/openstack/metric/requests/get_metric.rb0000644000004100000410000000363713423370527025444 0ustar www-datawww-datamodule Fog module OpenStack class Metric class Real def get_metric(metric_id) request( :expects => 200, :method => 'GET', :path => "metric/#{metric_id}" ) end end class Mock def get_metric(_metric_id) response = Excon::Response.new response.status = 200 response.body = { "archive_policy" => { "aggregation_methods" => [ "95pct", "median", "max", "count", "std", "sum", "min", "mean" ], "back_window" => 0, "definition" => [ { "granularity" => "0:00:01", "points" => 3600, "timespan" => "1:00:00" }, { "granularity" => "0:01:00", "points" => 10080, "timespan" => "7 days, 0:00:00" }, { "granularity" => "1:00:00", "points" => 8760, "timespan" => "365 days, 0:00:00" } ], "name" => "high" }, "created_by_project_id" => "384a902b-6856-424c-9d30-6b5325ac20a5", "created_by_user_id" => "d040def9-fd68-45f0-a19f-253014f397c3", "id" => "8bbb5f02-b654-4861-b19e-d372fcdca124", "name" => nil, "resource" => nil, "unit" => nil } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/metric/models/0000755000004100000410000000000013423370527022374 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/metric/models/resources.rb0000644000004100000410000000105713423370527024736 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/metric/models/resource' module Fog module OpenStack class Metric class Resources < Fog::OpenStack::Collection model Fog::OpenStack::Metric::Resource def all(options = {}) load_response(service.list_resources(options)) end def find_by_id(resource_id) resource = service.get_resource(resource_id).body new(resource) rescue Fog::OpenStack::Metric::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/metric/models/metric.rb0000644000004100000410000000055613423370527024212 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Metric class Metric < Fog::OpenStack::Model identity :id attribute :name attribute :resource_id attribute :unit attribute :created_by_project_id attribute :created_by_user_id attribute :definition end end end end fog-openstack-1.0.8/lib/fog/openstack/metric/models/metrics.rb0000644000004100000410000000140713423370527024371 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/metric/models/metric' module Fog module OpenStack class Metric class Metrics < Fog::OpenStack::Collection model Fog::OpenStack::Metric::Metric def all(options = {}) load_response(service.list_metrics(options)) end def find_by_id(metric_id) resource = service.get_metric(metric_id).body new(resource) rescue Fog::OpenStack::Metric::NotFound nil end def find_measures_by_id(metric_id, options = {}) resource = service.get_metric_measures(metric_id, options).body new(resource) rescue Fog::OpenStack::Metric::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/metric/models/resource.rb0000644000004100000410000000046013423370527024550 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Metric class Resource < Fog::OpenStack::Model identity :id attribute :original_resource_id attribute :project_id attribute :user_id attribute :metrics end end end end fog-openstack-1.0.8/lib/fog/openstack/version.rb0000644000004100000410000000010513423370527021634 0ustar www-datawww-datamodule Fog module OpenStack VERSION = '1.0.8'.freeze end end fog-openstack-1.0.8/lib/fog/openstack/workflow/0000755000004100000410000000000013423370527021500 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/workflow/v2/0000755000004100000410000000000013423370527022027 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/0000755000004100000410000000000013423370527023702 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/list_workflows.rb0000644000004100000410000000145213423370527027321 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def list_workflows(params = {}) body = Fog::JSON.encode(params) request( :body => body, :expects => 200, :method => "GET", :path => "workflows" ) end end class Mock def list_workflows(_params = {}) response = Excon::Response.new response.status = 200 response.body = {"workflows" => [{"name" => "workflow1", "description" => "d1"}, {"name" => "workflow2", "description" => "d2"}]} response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/create_action_execution.rb0000644000004100000410000000153313423370527031114 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def create_action_execution(action, input = {}, params = {}) data = {:name => action} data[:input] = Fog::JSON.encode(input) unless input.empty? data[:params] = Fog::JSON.encode(params) unless params.empty? body = Fog::JSON.encode(data) request( :body => body, :expects => 201, :method => "POST", :path => "action_executions" ) end end class Mock def create_action_execution(_action, _input = {}, _params = {}) response = Excon::Response.new response.status = 201 response.body = "" response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/get_action_execution.rb0000644000004100000410000000114013423370527030422 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def get_action_execution(execution_id) request( :expects => 200, :method => "GET", :path => "action_executions/#{execution_id}" ) end end class Mock def get_action_execution(_execution_id) response = Excon::Response.new response.status = 200 response.body = {"state" => "running", "id" => "1111"} response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/update_workbook.rb0000644000004100000410000000114613423370527027430 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def update_workbook(definition) body = Fog::JSON.encode(definition) request( :body => body, :expects => 200, :method => "PUT", :path => "workbooks" ) end end class Mock def update_workbook(_definition) response = Excon::Response.new response.status = 200 response.body = "" response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/delete_workflow.rb0000644000004100000410000000101013423370527027413 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def delete_workflow(identifier) request( :expects => 204, :method => "DELETE", :path => "workflows/#{identifier}" ) end end class Mock def delete_workflow(_identifier) response = Excon::Response.new response.status = 204 response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/delete_execution.rb0000644000004100000410000000076313423370527027562 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def delete_execution(id) request( :expects => 204, :method => "DELETE", :path => "executions/#{id}" ) end end class Mock def delete_execution(_id) response = Excon::Response.new response.status = 204 response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/list_services.rb0000644000004100000410000000127313423370527027110 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def list_services request( :expects => 200, :method => "GET", :path => "services" ) end end class Mock def list_services response = Excon::Response.new response.status = 200 response.body = {"services" => [{"name" => "service1", "description" => "d1"}, {"name" => "service2", "description" => "d2"}]} response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/create_environment.rb0000644000004100000410000000140213423370527030113 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def create_environment(definition) unless definition["variables"].nil? definition["variables"] = Fog::JSON.encode(definition["variables"]) end body = Fog::JSON.encode(definition) request( :body => body, :expects => 201, :method => "POST", :path => "environments" ) end end class Mock def create_environment(_definition) response = Excon::Response.new response.status = 201 response.body = "" response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/delete_workbook.rb0000644000004100000410000000100213423370527027377 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def delete_workbook(name) request( :expects => 204, :method => "DELETE", :path => "workbooks/#{URI.encode(name)}" ) end end class Mock def delete_workbook(_name) response = Excon::Response.new response.status = 204 response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/list_environments.rb0000644000004100000410000000133313423370527030011 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def list_environments request( :expects => 200, :method => "GET", :path => "environments" ) end end class Mock def list_environments response = Excon::Response.new response.status = 200 response.body = {"environments" => [{"name" => "environment1", "description" => "d1"}, {"name" => "environment2", "description" => "d2"}]} response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/list_executions.rb0000644000004100000410000000126713423370527027456 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def list_executions request( :expects => 200, :method => "GET", :path => "executions" ) end end class Mock def list_executions response = Excon::Response.new response.status = 200 response.body = {"executions" => [{"state" => "ERROR", "id" => "1111"}, {"state" => "RUNNING", "id" => "2222"}]} response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/list_cron_triggers.rb0000644000004100000410000000134313423370527030132 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def list_cron_triggers request( :expects => 200, :method => "GET", :path => "cron_triggers" ) end end class Mock def list_cron_triggers response = Excon::Response.new response.status = 200 response.body = {"cron_triggers" => [{"name" => "cron_trigger1", "description" => "d1"}, {"name" => "cron_trigger2", "description" => "d2"}]} response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/validate_workflow.rb0000644000004100000410000000120513423370527027750 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def validate_workflow(definition) body = Fog::JSON.encode(definition) request( :body => body, :expects => 200, :method => "POST", :path => "workflows/validate" ) end end class Mock def validate_workflow(_definition) response = Excon::Response.new response.status = 200 response.body = "{\"valid\": true}" response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/delete_action.rb0000644000004100000410000000077413423370527027036 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def delete_action(name) request( :expects => 204, :method => "DELETE", :path => "actions/#{URI.encode(name)}" ) end end class Mock def delete_action(_name) response = Excon::Response.new response.status = 204 response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/get_action.rb0000644000004100000410000000115013423370527026340 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def get_action(name) request( :expects => 200, :method => "GET", :path => "actions/#{URI.encode(name)}" ) end end class Mock def get_action(_name) response = Excon::Response.new response.status = 200 response.body = {"version" => "2.0", "action1" => {"input" => ['test_id']}} response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/get_task.rb0000644000004100000410000000111513423370527026026 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def get_task(id) request( :expects => 200, :method => "GET", :path => "tasks/#{id}" ) end end class Mock def get_task(_id) response = Excon::Response.new response.status = 200 response.body = {"version" => "2.0", "task1" => {"id" => ['test_id']}} response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/get_workflow.rb0000644000004100000410000000124313423370527026740 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def get_workflow(identifier) request( :expects => 200, :method => "GET", :path => "workflows/#{identifier}" ) end end class Mock def get_workflow(_identifier) response = Excon::Response.new response.status = 200 response.body = {"version" => "2.0", "name" => "workflow1", "description" => "d1"} response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/create_workflow.rb0000644000004100000410000000114713423370527027427 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def create_workflow(definition) body = Fog::JSON.encode(definition) request( :body => body, :expects => 201, :method => "POST", :path => "workflows" ) end end class Mock def create_workflow(_definition) response = Excon::Response.new response.status = 201 response.body = "" response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/rerun_task.rb0000644000004100000410000000137413423370527026411 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def rerun_task(task_ex_id) rerun_payload = { :id => task_ex_id, :state => 'RUNNING', :reset => true } body = Fog::JSON.encode(rerun_payload) request( :body => body, :expects => 200, :method => "PUT", :path => "tasks/#{task_ex_id}" ) end end class Mock def update_action(_task_ex_id) response = Excon::Response.new response.status = 200 response.body = "" response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/list_action_executions.rb0000644000004100000410000000134113423370527031004 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def list_action_executions request( :expects => 200, :method => "GET", :path => "action_executions" ) end end class Mock def list_action_executions response = Excon::Response.new response.status = 200 response.body = {"action_executions" => [{"state" => "ERROR", "id" => "1111"}, {"state" => "RUNNING", "id" => "2222"}]} response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/update_action.rb0000644000004100000410000000114013423370527027042 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def update_action(definition) body = Fog::JSON.encode(definition) request( :body => body, :expects => 200, :method => "PUT", :path => "actions" ) end end class Mock def update_action(_definition) response = Excon::Response.new response.status = 200 response.body = "" response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/get_execution.rb0000644000004100000410000000111313423370527027065 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def get_execution(execution_id) request( :expects => 200, :method => "GET", :path => "executions/#{execution_id}" ) end end class Mock def get_execution(_execution_id) response = Excon::Response.new response.status = 200 response.body = {"state" => "running", "id" => "1111"} response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/create_action.rb0000644000004100000410000000114113423370527027024 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def create_action(definition) body = Fog::JSON.encode(definition) request( :body => body, :expects => 201, :method => "POST", :path => "actions" ) end end class Mock def create_action(_definition) response = Excon::Response.new response.status = 201 response.body = "" response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/get_environment.rb0000644000004100000410000000130113423370527027425 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def get_environment(name) request( :expects => 200, :method => "GET", :path => "environments/#{URI.encode(name)}" ) end end class Mock def get_environment(_name) response = Excon::Response.new response.status = 200 response.body = {"name" => "environment1", "variables" => {"var1" => "value1", "var2" => "value2"}} response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/create_workbook.rb0000644000004100000410000000114713423370527027412 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def create_workbook(definition) body = Fog::JSON.encode(definition) request( :body => body, :expects => 201, :method => "POST", :path => "workbooks" ) end end class Mock def create_workbook(_definition) response = Excon::Response.new response.status = 201 response.body = "" response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/get_workbook.rb0000644000004100000410000000123513423370527026724 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def get_workbook(name) request( :expects => 200, :method => "GET", :path => "workbooks/#{URI.encode(name)}" ) end end class Mock def get_workbook(_name) response = Excon::Response.new response.status = 200 response.body = {"version" => "2.0", "name" => "workbook1", "description" => "d1"} response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/update_workflow.rb0000644000004100000410000000114613423370527027445 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def update_workflow(definition) body = Fog::JSON.encode(definition) request( :body => body, :expects => 200, :method => "PUT", :path => "workflows" ) end end class Mock def update_workflow(_definition) response = Excon::Response.new response.status = 200 response.body = "" response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/delete_action_execution.rb0000644000004100000410000000101013423370527031101 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def delete_action_execution(id) request( :expects => 204, :method => "DELETE", :path => "action_executions/#{id}" ) end end class Mock def delete_action_execution(_id) response = Excon::Response.new response.status = 204 response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/create_cron_trigger.rb0000644000004100000410000000343613423370527030244 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def create_cron_trigger(name, workflow_identifier, workflow_input = nil, workflow_params = nil, pattern = "* * * * *", first_time = nil, count = nil) data = { :name => name, :pattern => pattern, :first_execution_time => first_time, :remaining_executions => count } if workflow_identifier data[:workflow_id] = workflow_identifier end if workflow_input data[:workflow_input] = Fog::JSON.encode(workflow_input) end if workflow_params data[:workflow_params] = Fog::JSON.encode(workflow_params) end body = Fog::JSON.encode(data) request( :body => body, :expects => 201, :method => "POST", :path => "cron_triggers" ) end end class Mock def create_cron_trigger(_name, _workflow_identifier, _workflow_input = nil, _workflow_params = nil, _pattern = nil, _first_time = nil, _count = nil) response = Excon::Response.new response.status = 201 response.body = "" response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/create_execution.rb0000644000004100000410000000136013423370527027555 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def create_execution(workflow, input = {}) data = {:workflow_name => workflow} data[:input] = Fog::JSON.encode(input) unless input.empty? body = Fog::JSON.encode(data) request( :body => body, :expects => 201, :method => "POST", :path => "executions" ) end end class Mock def create_execution(_workflow, _input = {}) response = Excon::Response.new response.status = 201 response.body = "" response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/list_tasks.rb0000644000004100000410000000136613423370527026415 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def list_tasks(workflow_execution_id) request( :expects => 200, :method => "GET", :path => "executions/#{workflow_execution_id}/tasks" ) end end class Mock def list_tasks(_workflow_execution_id) response = Excon::Response.new response.status = 200 response.body = {"tasks" => [{"name" => "task1", "description" => "d1"}, {"name" => "task2", "description" => "d2"}]} response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/list_workbooks.rb0000644000004100000410000000130313423370527027277 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def list_workbooks request( :expects => 200, :method => "GET", :path => "workbooks" ) end end class Mock def list_workbooks response = Excon::Response.new response.status = 200 response.body = {"workbooks" => [{"name" => "workbook1", "description" => "d1"}, {"name" => "workbook2", "description" => "d2"}]} response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/update_action_execution.rb0000644000004100000410000000162413423370527031134 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def update_action_execution(id, name, value) # valid values for name are: # state, output # https://github.com/openstack/python-mistralclient/blob/master/mistralclient/commands/v2/action_executions.py data = {:id => id} data[name] = Fog::JSON.encode(value) body = Fog::JSON.encode(data) request( :body => body, :expects => 200, :method => "PUT", :path => "action_executions" ) end end class Mock def update_action_execution(_id, _name, _value) response = Excon::Response.new response.status = 200 response.body = "" response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/get_cron_trigger.rb0000644000004100000410000000125513423370527027555 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def get_cron_trigger(name) request( :expects => 200, :method => "GET", :path => "cron_triggers/#{URI.encode(name)}" ) end end class Mock def get_cron_trigger(_name) response = Excon::Response.new response.status = 200 response.body = {"version" => "2.0", "name" => "cron_trigger1", "description" => "d1"} response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/validate_action.rb0000644000004100000410000000117713423370527027363 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def validate_action(definition) body = Fog::JSON.encode(definition) request( :body => body, :expects => 200, :method => "POST", :path => "actions/validate" ) end end class Mock def validate_action(_definition) response = Excon::Response.new response.status = 200 response.body = "{\"valid\": true}" response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/update_execution.rb0000644000004100000410000000160213423370527027573 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def update_execution(id, name, value) # valid values for name are: # state, description, env # https://github.com/openstack/python-mistralclient/blob/master/mistralclient/commands/v2/executions.py data = {:id => id} data[name] = Fog::JSON.encode(value) body = Fog::JSON.encode(data) request( :body => body, :expects => 200, :method => "PUT", :path => "executions" ) end end class Mock def update_execution(_id, _name, _value) response = Excon::Response.new response.status = 200 response.body = "" response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/list_actions.rb0000644000004100000410000000143213423370527026722 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def list_actions(params = {}) body = Fog::JSON.encode(params) request( :body => body, :expects => 200, :method => "GET", :path => "actions" ) end end class Mock def list_actions(_params = {}) response = Excon::Response.new response.status = 200 response.body = {"actions" => [{"name" => "action1", "description" => "d1"}, {"name" => "action2", "description" => "d2"}]} response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/validate_workbook.rb0000644000004100000410000000120513423370527027733 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def validate_workbook(definition) body = Fog::JSON.encode(definition) request( :body => body, :expects => 200, :method => "POST", :path => "workbooks/validate" ) end end class Mock def validate_workbook(_definition) response = Excon::Response.new response.status = 200 response.body = "{\"valid\": true}" response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/update_environment.rb0000644000004100000410000000140113423370527030131 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def update_environment(definition) unless definition["variables"].nil? definition["variables"] = Fog::JSON.encode(definition["variables"]) end body = Fog::JSON.encode(definition) request( :body => body, :expects => 200, :method => "PUT", :path => "environments" ) end end class Mock def update_environment(_definition) response = Excon::Response.new response.status = 200 response.body = "" response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/delete_environment.rb0000644000004100000410000000101313423370527030110 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def delete_environment(name) request( :expects => 204, :method => "DELETE", :path => "environments/#{URI.encode(name)}" ) end end class Mock def delete_environment(_name) response = Excon::Response.new response.status = 204 response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2/requests/delete_cron_trigger.rb0000644000004100000410000000101613423370527030233 0ustar www-datawww-datamodule Fog module OpenStack class Workflow class V2 class Real def delete_cron_trigger(name) request( :expects => 204, :method => "DELETE", :path => "cron_triggers/#{URI.encode(name)}" ) end end class Mock def delete_cron_trigger(_name) response = Excon::Response.new response.status = 204 response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow/v2.rb0000644000004100000410000000741513423370527022363 0ustar www-datawww-datarequire 'fog/openstack/workflow' module Fog module OpenStack class Workflow class V2 < Fog::Service SUPPORTED_VERSIONS = /v2/ requires :openstack_auth_url recognizes :openstack_username, :openstack_api_key, :openstack_project_name, :openstack_domain_id ## REQUESTS # request_path 'fog/openstack/workflow/v2/requests' # Workflow requests request :create_execution request :get_execution request :list_executions request :update_execution request :delete_execution request :create_action_execution request :get_action_execution request :list_action_executions request :update_action_execution request :delete_action_execution request :create_workbook request :get_workbook request :list_workbooks request :update_workbook request :validate_workbook request :delete_workbook request :create_workflow request :get_workflow request :list_workflows request :update_workflow request :validate_workflow request :delete_workflow request :create_action request :get_action request :list_actions request :update_action request :validate_action request :delete_action request :get_task request :list_tasks request :rerun_task request :create_cron_trigger request :get_cron_trigger request :list_cron_triggers request :delete_cron_trigger request :create_environment request :get_environment request :list_environments request :update_environment request :delete_environment request :list_services class Mock def self.data @data ||= Hash.new do |hash, key| hash[key] = { :workflows => {} } 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 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 default_path_prefix 'v2' end def default_service_type %w[workflowv2] 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::OpenStack::Workflow::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 end fog-openstack-1.0.8/lib/fog/openstack/baremetal.rb0000644000004100000410000002200013423370527022101 0ustar www-datawww-datamodule Fog module OpenStack class Baremetal < 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, :openstack_identity_api_version ## MODELS # model_path 'fog/openstack/baremetal/models' model :chassis collection :chassis_collection model :driver collection :drivers model :node collection :nodes model :port collection :ports ## REQUESTS # request_path 'fog/openstack/baremetal/requests' # 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 self.not_found_class Fog::OpenStack::Baremetal::NotFound end def default_service_type %w[baremetal] end end end end end fog-openstack-1.0.8/lib/fog/openstack/planning.rb0000644000004100000410000001025113423370527021760 0ustar www-datawww-datamodule 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_api_version ## MODELS # model_path 'fog/openstack/planning/models' model :role collection :roles model :plan collection :plans ## REQUESTS # request_path 'fog/openstack/planning/requests' # 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 ||= {} 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 default_endpoint_type 'admin' end def default_path_prefix 'v2' end def default_service_type %w[management] end # NOTE: uncommenting this should be treated as api-change! # def self.not_found_class # Fog::Planning::OpenStack::NotFound # end end end # TODO: get rid of inconform self.[] & self.new & self.services 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) 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-1.0.8/lib/fog/openstack/metering/0000755000004100000410000000000013423370527021440 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/metering/requests/0000755000004100000410000000000013423370527023313 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/metering/requests/list_meters.rb0000644000004100000410000000213013423370527026166 0ustar www-datawww-datamodule Fog module OpenStack class Metering class Real def list_meters(options = []) data = { 'q' => [] } 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-1.0.8/lib/fog/openstack/metering/requests/get_resource.rb0000644000004100000410000000127213423370527026330 0ustar www-datawww-datamodule Fog module OpenStack class Metering 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-1.0.8/lib/fog/openstack/metering/requests/get_event.rb0000644000004100000410000000113413423370527025617 0ustar www-datawww-datamodule Fog module OpenStack class Metering 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-1.0.8/lib/fog/openstack/metering/requests/get_statistics.rb0000644000004100000410000000264513423370527026700 0ustar www-datawww-datamodule Fog module OpenStack class Metering class Real def get_statistics(meter_id, options = {}) data = { 'period' => options['period'], 'q' => [] } 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'].kind_of? 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-1.0.8/lib/fog/openstack/metering/requests/get_samples.rb0000644000004100000410000000271013423370527026143 0ustar www-datawww-datamodule Fog module OpenStack class Metering class Real def get_samples(meter_id, options = [], limit = 10000000) data = { 'q' => [] } 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? data['limit'] = limit 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-1.0.8/lib/fog/openstack/metering/requests/list_events.rb0000644000004100000410000000166013423370527026202 0ustar www-datawww-datamodule Fog module OpenStack class Metering class Real def list_events(options = []) data = { 'q' => [] } 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-1.0.8/lib/fog/openstack/metering/requests/list_resources.rb0000644000004100000410000000126413423370527026710 0ustar www-datawww-datamodule Fog module OpenStack class Metering 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-1.0.8/lib/fog/openstack/metering/models/0000755000004100000410000000000013423370527022723 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/metering/models/resources.rb0000644000004100000410000000106113423370527025260 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/metering/models/resource' module Fog module OpenStack class Metering class Resources < Fog::OpenStack::Collection model Fog::OpenStack::Metering::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::OpenStack::Metering::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/metering/models/events.rb0000644000004100000410000000102313423370527024550 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/metering/models/event' module Fog module OpenStack class Metering class Events < Fog::OpenStack::Collection model Fog::OpenStack::Metering::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::OpenStack::Metering::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/metering/models/event.rb0000644000004100000410000000044713423370527024376 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Metering class Event < Fog::OpenStack::Model identity :message_id attribute :event_type attribute :generated attribute :raw attribute :traits end end end end fog-openstack-1.0.8/lib/fog/openstack/metering/models/resource.rb0000644000004100000410000000042413423370527025077 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Metering class Resource < Fog::OpenStack::Model identity :resource_id attribute :project_id attribute :user_id attribute :metadata end end end end fog-openstack-1.0.8/lib/fog/openstack/metering/models/meter.rb0000644000004100000410000000000013423370527024352 0ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/metering/models/meters.rb0000644000004100000410000000000013423370527024535 0ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/image.rb0000644000004100000410000000131613423370527021236 0ustar www-datawww-data module Fog module OpenStack class Image < Fog::Service autoload :V1, 'fog/openstack/image/v1' autoload :V2, 'fog/openstack/image/v2' # Fog::OpenStack::Image.new() will return a Fog::OpenStack::Image::V2 or a Fog::OpenStack::Image::V1, # choosing the latest available def self.new(args = {}) @openstack_auth_uri = URI.parse(args[:openstack_auth_url]) if args[:openstack_auth_url] if inspect == 'Fog::OpenStack::Image' service = Fog::OpenStack::Image::V2.new(args) unless args.empty? service ||= Fog::OpenStack::Image::V1.new(args) else service = Fog::Service.new(args) end service end end end end fog-openstack-1.0.8/lib/fog/openstack/key_manager.rb0000644000004100000410000000700313423370527022435 0ustar www-datawww-datamodule Fog module OpenStack class KeyManager < 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_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_project_domain, :openstack_user_domain, :openstack_domain_name, :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id, :openstack_identity_api_version, :openstack_temp_url_key, :openstack_cache_ttl ## MODELS # model_path 'fog/openstack/key_manager/models' model :secret collection :secrets model :container collection :containers model :acl ## REQUESTS # secrets request_path 'fog/openstack/key_manager/requests' request :create_secret request :list_secrets request :get_secret request :get_secret_payload request :get_secret_metadata request :delete_secret # containers request :create_container request :get_container request :list_containers request :delete_container #ACL request :get_secret_acl request :update_secret_acl request :replace_secret_acl request :delete_secret_acl request :get_container_acl request :update_container_acl request :replace_container_acl request :delete_container_acl class Mock 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 = 9311 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 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::OpenStack::KeyManager::NotFound end def default_path_prefix 'v1' end def default_service_type %w[key-manager] end end end end end fog-openstack-1.0.8/lib/fog/openstack/nfv.rb0000644000004100000410000000661013423370527020747 0ustar www-datawww-datarequire 'yaml' module Fog module OpenStack class NFV < 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, :openstack_identity_api_version ## REQUESTS # request_path 'fog/openstack/nfv/requests' # 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/nfv/models' 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 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 self.not_found_class Fog::OpenStack::NFV::NotFound end def default_path_prefix 'v1.0' end def default_service_type %w[servicevm] end end end end end fog-openstack-1.0.8/lib/fog/openstack/image/0000755000004100000410000000000013423370527020710 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/image/v2/0000755000004100000410000000000013423370527021237 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/image/v2/requests/0000755000004100000410000000000013423370527023112 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/image/v2/requests/add_member_to_image.rb0000644000004100000410000000114513423370527027363 0ustar www-datawww-datamodule Fog module OpenStack class Image 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 Mock def add_member_to_image(_image_id, _tenant_id) response = Excon::Response.new response.status = 200 response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/image/v2/requests/get_image_members.rb0000644000004100000410000000134013423370527027070 0ustar www-datawww-datamodule Fog module OpenStack class Image class V2 class Real def get_image_members(image_id) request( :expects => [200, 204], :method => 'GET', :path => "images/#{image_id}/members" ) end end class Mock def get_image_members(_image_id) response = Excon::Response.new response.status = [200, 204][rand(2)] response.body = { "members" => [ {"member_id" => "ff528b20431645ebb5fa4b0a71ca002f", "can_share" => false} ] } response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/image/v2/requests/get_image.rb0000644000004100000410000000433213423370527025362 0ustar www-datawww-datamodule Fog module OpenStack class Image class V2 class Real def get_image(image_id) request( :expects => [200, 204], :method => 'HEAD', :path => "images/#{image_id}" ) end end class Mock def get_image(_image_id) response = Excon::Response.new response.status = [200, 204][rand(2)] 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 end end end end end fog-openstack-1.0.8/lib/fog/openstack/image/v2/requests/update_image_member.rb0000644000004100000410000000200713423370527027411 0ustar www-datawww-datamodule Fog module OpenStack class Image 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 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 end end end end fog-openstack-1.0.8/lib/fog/openstack/image/v2/requests/remove_tag_from_image.rb0000644000004100000410000000104113423370527027750 0ustar www-datawww-datamodule Fog module OpenStack class Image 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 Mock def remove_tag_from_image(_image_id, _tag) response = Excon::Response.new response.status = 204 response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/image/v2/requests/list_images.rb0000644000004100000410000000174213423370527025743 0ustar www-datawww-datamodule Fog module OpenStack class Image class V2 class Real def list_images(options = {}) request( :expects => [200], :method => 'GET', :path => 'images', :query => options ) end end class Mock def list_images(_options = {}) response = Excon::Response.new response.status = [200, 204][rand(2)] 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 end end end end end fog-openstack-1.0.8/lib/fog/openstack/image/v2/requests/set_tenant.rb0000644000004100000410000000057713423370527025614 0ustar www-datawww-datamodule Fog module OpenStack class Image 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 end end end fog-openstack-1.0.8/lib/fog/openstack/image/v2/requests/remove_member_from_image.rb0000644000004100000410000000112113423370527030443 0ustar www-datawww-datamodule Fog module OpenStack class Image 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 Mock def remove_member_from_image(_image_id, _member_id) response = Excon::Response.new response.status = [200, 204][rand(2)] response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/image/v2/requests/create_image.rb0000644000004100000410000000332013423370527026042 0ustar www-datawww-datamodule Fog module OpenStack class Image 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 = 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-1.0.8/lib/fog/openstack/image/v2/requests/upload_image.rb0000644000004100000410000000150513423370527026066 0ustar www-datawww-datamodule Fog module OpenStack class Image 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-1.0.8/lib/fog/openstack/image/v2/requests/download_image.rb0000644000004100000410000000150213423370527026406 0ustar www-datawww-datamodule Fog module OpenStack class Image 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 Mock def download_image(_image_id, _content_range = nil) response = Excon::Response.new response.status = [200, 204][rand(2)] response.body = "" response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/image/v2/requests/reactivate_image.rb0000644000004100000410000000101713423370527026727 0ustar www-datawww-datamodule Fog module OpenStack class Image 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-1.0.8/lib/fog/openstack/image/v2/requests/add_tag_to_image.rb0000644000004100000410000000102413423370527026663 0ustar www-datawww-datamodule Fog module OpenStack class Image 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 Mock def add_tag_to_image(_image_id, _tag) response = Excon::Response.new response.status = 204 response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/image/v2/requests/update_image.rb0000644000004100000410000000353313423370527026067 0ustar www-datawww-datamodule Fog module OpenStack class Image 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 = 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-1.0.8/lib/fog/openstack/image/v2/requests/get_member_details.rb0000644000004100000410000000165013423370527027254 0ustar www-datawww-datamodule Fog module OpenStack class Image 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 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 end end end end end fog-openstack-1.0.8/lib/fog/openstack/image/v2/requests/get_shared_images.rb0000644000004100000410000000135013423370527027070 0ustar www-datawww-datamodule Fog module OpenStack class Image class V2 class Real def get_shared_images(tenant_id) request( :expects => [200, 204], :method => 'GET', :path => "shared-images/#{tenant_id}" ) end end class Mock def get_shared_images(_tenant_id) response = Excon::Response.new response.status = [200, 204][rand(2)] response.body = { "shared_images" => [ {"image_id" => "ff528b20431645ebb5fa4b0a71ca002f", "can_share" => false} ] } response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/image/v2/requests/delete_image.rb0000644000004100000410000000076613423370527026054 0ustar www-datawww-datamodule Fog module OpenStack class Image 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-1.0.8/lib/fog/openstack/image/v2/requests/get_image_by_id.rb0000644000004100000410000000167213423370527026534 0ustar www-datawww-datamodule Fog module OpenStack class Image class V2 class Real def get_image_by_id(image_id) request( :expects => [200], :method => 'GET', :path => "images/#{image_id}" ) end end class Mock def get_image_by_id(_image_id) response = Excon::Response.new response.status = [200][rand(2)] 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 end end end end end fog-openstack-1.0.8/lib/fog/openstack/image/v2/requests/deactivate_image.rb0000644000004100000410000000101713423370527026711 0ustar www-datawww-datamodule Fog module OpenStack class Image 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-1.0.8/lib/fog/openstack/image/v2/models/0000755000004100000410000000000013423370527022522 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/image/v2/models/image.rb0000644000004100000410000001433013423370527024132 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Image class V2 class Image < Fog::OpenStack::Model identity :id attribute :name attribute :visibility # public or private attribute :tags attribute :self attribute :size attribute :virtual_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] elsif method_sym.to_s.end_with?('=') attributes[method_sym.to_s.gsub(/=$/, '').to_sym] = arguments[0] 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 elsif method_sym.to_s.end_with?('=') true else super end end def create requires :name merge_attributes(service.create_image(attributes).body) self end # Here we convert 'attributes' into a form suitable for Glance's usage of JSON Patch (RFC6902). # We fetch the existing attributes from the server to compute the delta (difference) # Setting value to nil will delete that attribute from the server. def update(attr = nil) requires :id client_attributes = attr || @attributes server_attributes = service.images.get(id).attributes json_patch = build_update_json_patch(client_attributes, server_attributes) merge_attributes( service.update_image(id, json_patch).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 be specified on creation def save if @attributes[:self].nil? create else update end 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 private def build_update_json_patch(client_attributes, server_attributes) [ build_patch_operation('remove', patch_attributes_to_remove(client_attributes, server_attributes)), build_patch_operation('add', patch_attributes_to_add(client_attributes, server_attributes)), build_patch_operation('replace', patch_attributes_to_replace(client_attributes, server_attributes)), ].flatten end def patch_attributes_to_remove(client_attributes, server_attributes) client_attributes.select do |key, value| value.nil? && !server_attributes[key].nil? end end def patch_attributes_to_add(client_attributes, server_attributes) client_attributes.reject do |key, _| server_attributes.key?(key) || client_attributes[key].nil? end end def patch_attributes_to_replace(client_attributes, server_attributes) client_attributes.reject do |key, value| value.nil? || server_attributes[key] == value end end def build_patch_operation(op_name, attributes) json_patch = [] attributes.each do |key, value| json_patch << {:op => op_name, :path => "/#{key}", :value => value} end json_patch end end end end end end fog-openstack-1.0.8/lib/fog/openstack/image/v2/models/images.rb0000644000004100000410000000336213423370527024320 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/image/v2/models/image' module Fog module OpenStack class Image class V2 class Images < Fog::OpenStack::Collection model Fog::OpenStack::Image::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) new(service.get_image_by_id(id).body) rescue Fog::OpenStack::Image::NotFound nil end alias 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(&:is_public) end def destroy(id) image = 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-1.0.8/lib/fog/openstack/image/v1/0000755000004100000410000000000013423370527021236 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/image/v1/requests/0000755000004100000410000000000013423370527023111 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/image/v1/requests/add_member_to_image.rb0000644000004100000410000000110413423370527027355 0ustar www-datawww-datamodule Fog module OpenStack class Image 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 Mock def add_member_to_image(_image_id, _tenant_id) response = Excon::Response.new response.status = [200, 204][rand(2)] response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/image/v1/requests/get_image_members.rb0000644000004100000410000000134013423370527027067 0ustar www-datawww-datamodule Fog module OpenStack class Image class V1 class Real def get_image_members(image_id) request( :expects => [200, 204], :method => 'GET', :path => "images/#{image_id}/members" ) end end class Mock def get_image_members(_image_id) response = Excon::Response.new response.status = [200, 204][rand(2)] response.body = { "members" => [ {"member_id" => "ff528b20431645ebb5fa4b0a71ca002f", "can_share" => false} ] } response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/image/v1/requests/list_public_images_detailed.rb0000644000004100000410000000216713423370527031135 0ustar www-datawww-datamodule Fog module OpenStack class Image class V1 class Real def list_public_images_detailed(options = {}, query_deprecated = nil) if options.kind_of?(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 Mock def list_public_images_detailed(_options = {}, _query_deprecated = nil) response = Excon::Response.new response.status = [200, 204][rand(2)] response.body = {'images' => data[:images].values} response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/image/v1/requests/get_image.rb0000644000004100000410000000433213423370527025361 0ustar www-datawww-datamodule Fog module OpenStack class Image class V1 class Real def get_image(image_id) request( :expects => [200, 204], :method => 'HEAD', :path => "images/#{image_id}" ) end end class Mock def get_image(_image_id) response = Excon::Response.new response.status = [200, 204][rand(2)] 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 end end end end end fog-openstack-1.0.8/lib/fog/openstack/image/v1/requests/set_tenant.rb0000644000004100000410000000057713423370527025613 0ustar www-datawww-datamodule Fog module OpenStack class Image 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 end end end fog-openstack-1.0.8/lib/fog/openstack/image/v1/requests/remove_member_from_image.rb0000644000004100000410000000112113423370527030442 0ustar www-datawww-datamodule Fog module OpenStack class Image 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 Mock def remove_member_from_image(_image_id, _member_id) response = Excon::Response.new response.status = [200, 204][rand(2)] response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/image/v1/requests/update_image_members.rb0000644000004100000410000000212013423370527027567 0ustar www-datawww-datamodule Fog module OpenStack class Image 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 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 end end end end fog-openstack-1.0.8/lib/fog/openstack/image/v1/requests/list_public_images.rb0000644000004100000410000000176513423370527027305 0ustar www-datawww-datamodule Fog module OpenStack class Image class V1 class Real def list_public_images(options = {}) request( :expects => [200, 204], :method => 'GET', :path => 'images', :query => options ) end end class Mock def list_public_images(_options = {}) response = Excon::Response.new response.status = [200, 204][rand(2)] 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 end end end end end fog-openstack-1.0.8/lib/fog/openstack/image/v1/requests/create_image.rb0000644000004100000410000000613113423370527026044 0ustar www-datawww-datamodule Fog module OpenStack class Image 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 = '' 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 = 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-1.0.8/lib/fog/openstack/image/v1/requests/update_image.rb0000644000004100000410000000517213423370527026067 0ustar www-datawww-datamodule Fog module OpenStack class Image 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 = 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-1.0.8/lib/fog/openstack/image/v1/requests/get_shared_images.rb0000644000004100000410000000135013423370527027067 0ustar www-datawww-datamodule Fog module OpenStack class Image class V1 class Real def get_shared_images(tenant_id) request( :expects => [200, 204], :method => 'GET', :path => "shared-images/#{tenant_id}" ) end end class Mock def get_shared_images(_tenant_id) response = Excon::Response.new response.status = [200, 204][rand(2)] response.body = { "shared_images" => [ {"image_id" => "ff528b20431645ebb5fa4b0a71ca002f", "can_share" => false} ] } response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/image/v1/requests/delete_image.rb0000644000004100000410000000076613423370527026053 0ustar www-datawww-datamodule Fog module OpenStack class Image 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-1.0.8/lib/fog/openstack/image/v1/requests/get_image_by_id.rb0000644000004100000410000000314513423370527026530 0ustar www-datawww-datamodule Fog module OpenStack class Image class V1 class Real def get_image_by_id(image_id) request( :expects => [200], :method => 'HEAD', :path => "images/#{image_id}" ) end end class Mock def get_image_by_id(image_id) response = Excon::Response.new response.status = [200, 204][rand(2)] response.headers = { 'X-Image-Meta-Checksum' => '8a40c862b5735975d82605c1dd395796', 'X-Image-Meta-Container_format' => 'aki', 'X-Image-Meta-Created_at' => '2016-01-06T03:22:20.000000', 'X-Image-Meta-Deleted' => 'False', 'X-Image-Meta-Disk_format' => 'aki', 'X-Image-Meta-Id' => image_id, 'X-Image-Meta-Is_public' => 'True', 'X-Image-Meta-Min_disk' => 0, 'X-Image-Meta-Min_ram' => 0, 'X-Image-Meta-Name' => 'cirros-0.3.4-x86_64-uec-kernel', 'X-Image-Meta-Owner' => '13cc6052265b41529e2fd0fc461fa8ef', 'X-Image-Meta-Protected' => 'False', 'X-Image-Meta-Size' => 4979632, 'X-Image-Meta-Status' => 'deactivated', 'X-Image-Meta-Updated_at' => '2016-02-25T03:02:05.000000', 'X-Image-Meta-Property-foo' => 'bar' } response.body = {} response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/image/v1/models/0000755000004100000410000000000013423370527022521 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/image/v1/models/image.rb0000644000004100000410000000350113423370527024127 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Image 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(attributes).body['image']) self end def update requires :name merge_attributes(service.update_image(attributes).body['image']) self end def destroy requires :id service.delete_image(id) true 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_members(members) requires :id service.update_image_members(id, members) end def members requires :id service.get_image_members(id).body['members'] end def metadata requires :id service.get_image(id).headers end end end end end end fog-openstack-1.0.8/lib/fog/openstack/image/v1/models/images.rb0000644000004100000410000000645613423370527024326 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/image/v1/models/image' module Fog module OpenStack class Image class V1 class Images < Fog::OpenStack::Collection model Fog::OpenStack::Image::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) marker = 'X-Image-Meta-' property_marker = 'X-Image-Meta-Property-' headers = service.get_image_by_id(id).headers.select { |h, _| h.start_with?(marker) } # partioning on the longer prefix, leaving X-Image-Meta # headers in the second returned hash. custom_properties, params = headers.partition do |k, _| k.start_with?(property_marker) end.map { |p| Hash[p] } params = remove_prefix_and_convert_type(params, marker) custom_properties = remove_prefix_and_convert_type(custom_properties, property_marker) params['properties'] = custom_properties new(params) rescue Fog::OpenStack::Image::NotFound nil end alias 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(&:is_public) end def destroy(id) image = 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 private def convert_to_type(v) case v when /^\d+$/ v.to_i when 'True' true when 'False' false when /^\d\d\d\d\-\d\d\-\d\dT/ ::Time.parse(v) else v end end def remove_prefix_and_convert_type(hash, prefix) Hash[hash.map { |k, v| [k.gsub(prefix, '').downcase, convert_to_type(v)] }] end end end end end end fog-openstack-1.0.8/lib/fog/openstack/image/v1.rb0000644000004100000410000000741113423370527021566 0ustar www-datawww-datarequire 'fog/openstack/image' module Fog module OpenStack class Image 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_api_version model_path 'fog/openstack/image/v1/models' model :image collection :images request_path 'fog/openstack/image/v1/requests' 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::OpenStack::Image::NotFound end def default_endpoint_type 'admin' end def default_path_prefix 'v1' end def default_service_type %w[imagev1] end end end end end end fog-openstack-1.0.8/lib/fog/openstack/image/v2.rb0000644000004100000410000001003313423370527021561 0ustar www-datawww-datarequire 'fog/openstack/image' module Fog module OpenStack class Image 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_api_version model_path 'fog/openstack/image/v2/models' model :image collection :images request_path 'fog/openstack/image/v2/requests' 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::OpenStack::Image::NotFound end def default_endpoint_type 'admin' end def default_path_prefix 'v2' end def default_service_type %w[image imagev2] end end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute.rb0000644000004100000410000003003313423370527021626 0ustar www-datawww-datamodule Fog module OpenStack class Compute < Fog::Service SUPPORTED_VERSIONS = /v2\.0|v2\.1/ SUPPORTED_MICROVERSION = '2.15'.freeze 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_api_version ## MODELS # model_path 'fog/openstack/compute/models' 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 model :server_group collection :server_groups model :os_interface collection :os_interfaces ## REQUESTS # request_path 'fog/openstack/compute/requests' # 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 # Server Remote Consoles request :remote_consoles # 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 request :get_hypervisor request :list_hypervisors request :list_hypervisors_detail request :list_hypervisor_servers # 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 :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 # Server Group request :list_server_groups request :get_server_group request :create_server_group request :delete_server_group # Server Os Interfaces request :list_os_interfaces request :get_os_interface request :create_os_interface request :delete_os_interface 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_groups => {}, :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 => {}, :os_interfaces => [ { "fixed_ips" => [ { "ip_address" => "192.168.1.3", "subnet_id" => "f8a6e8f8-c2ec-497c-9f23-da9616de54ef" } ], "mac_addr" => "fa:16:3e:4c:2c:30", "net_id" => "3cb9bc59-5699-4588-a4b1-b87f96708bc6", "port_id" => "ce531f90-199f-48c0-816c-13e38010b442", "port_state" => "ACTIVE" } ] } 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 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 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 self.not_found_class Fog::OpenStack::Compute::NotFound end def default_service_type %w[compute] end def initialize(options = {}) @supported_versions = SUPPORTED_VERSIONS @supported_microversion = SUPPORTED_MICROVERSION @microversion_key = 'X-OpenStack-Nova-API-Version' super end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra.rb0000644000004100000410000001044513423370527023320 0ustar www-datawww-datamodule Fog module OpenStack class ContainerInfra < Fog::Service SUPPORTED_VERSIONS = /v1/ SUPPORTED_MICROVERSION = '1.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_api_version model_path 'fog/openstack/container_infra/models' model :bay collection :bays model :bay_model collection :bay_models model :certificate collection :certificates model :cluster collection :clusters model :cluster_template collection :cluster_templates request_path 'fog/openstack/container_infra/requests' # Bay CRUD request :create_bay request :delete_bay request :get_bay request :list_bays request :update_bay # Bay Model CRUD request :create_bay_model request :delete_bay_model request :get_bay_model request :list_bay_models request :update_bay_model # Certificate CRUD request :create_certificate request :get_certificate # Cluster CRUD request :create_cluster request :delete_cluster request :get_cluster request :list_clusters request :update_cluster # Cluster Template CRUD request :create_cluster_template request :delete_cluster_template request :get_cluster_template request :list_cluster_templates request :update_cluster_template 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 = 9511 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::OpenStack::ContainerInfra::NotFound end def default_path_prefix 'v1' end def default_service_type %w[container-infra] end def request(options = {}) options[:headers] = {'OpenStack-API-Version' => "container-infra #{SUPPORTED_MICROVERSION}"} super(options) end end end end end fog-openstack-1.0.8/lib/fog/openstack/network.rb0000644000004100000410000003615513423370527021656 0ustar www-datawww-data module Fog module OpenStack class Network < 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_api_version ## MODELS # model_path 'fog/openstack/network/models' model :extension collection :extensions model :network collection :networks model :port collection :ports model :subnet collection :subnets model :subnet_pool collection :subnet_pools 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 model :network_ip_availability collection :network_ip_availabilities ## REQUESTS # request_path 'fog/openstack/network/requests' # Neutron Extensions request :list_extensions request :get_extension # IP Availability request :get_network_ip_availability request :list_network_ip_availabilities # 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 # Subnet Pools CRUD request :list_subnet_pools request :create_subnet_pool request :delete_subnet_pool request :get_subnet_pool request :update_subnet_pool # 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 V1 # # 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 # # LBaaS V2 # # LBaaS V2 Loadbanacer request :list_lbaas_loadbalancers request :create_lbaas_loadbalancer request :delete_lbaas_loadbalancer request :get_lbaas_loadbalancer request :update_lbaas_loadbalancer # LBaaS V2 Listener request :list_lbaas_listeners request :create_lbaas_listener request :delete_lbaas_listener request :get_lbaas_listener request :update_lbaas_listener # LBaaS V2 Pool request :list_lbaas_pools request :create_lbaas_pool request :delete_lbaas_pool request :get_lbaas_pool request :update_lbaas_pool # LBaaS V2 Pool_Member request :list_lbaas_pool_members request :create_lbaas_pool_member request :delete_lbaas_pool_member request :get_lbaas_pool_member request :update_lbaas_pool_member # LBaaS V2 Healthmonitor request :list_lbaas_healthmonitors request :create_lbaas_healthmonitor request :delete_lbaas_healthmonitor request :get_lbaas_healthmonitor request :update_lbaas_healthmonitor # LBaaS V2 L7Policy request :list_lbaas_l7policies request :create_lbaas_l7policy request :delete_lbaas_l7policy request :get_lbaas_l7policy request :update_lbaas_l7policy # LBaaS V2 L7Rule request :list_lbaas_l7rules request :create_lbaas_l7rule request :delete_lbaas_l7rule request :get_lbaas_l7rule request :update_lbaas_l7rule # 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 request :update_security_group # 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| qos_policy_id = Fog::UUID.uuid network_id = Fog::UUID.uuid extension_id = Fog::UUID.uuid subnet_id = Fog::UUID.uuid tenant_id = Fog::Mock.random_hex(8) hash[key] = { :extensions => { extension_id => { 'id' => extension_id, 'alias' => 'dvr', 'description' => 'Enables configuration of Distributed Virtual Routers.', 'links' => [], 'name' => 'Distributed Virtual Router' } }, :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, 'qos_policy_id' => qos_policy_id, 'port_security_enabled' => 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', 'tenant_id' => 'f8b26a6032bc47718a7702233ac708b9', 'provider:network:type' => 'vlan', 'router:external' => false, 'admin_state_up' => true, 'qos_policy_id' => qos_policy_id, 'port_security_enabled' => true } }, :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, } }, :subnet_pools => {}, :floating_ips => {}, :routers => {}, :lb_pools => {}, :lb_members => {}, :lb_health_monitors => {}, :lb_vips => {}, :lbaas_loadbalancers => {}, :lbaas_listeners => {}, :lbaas_pools => {}, :lbaas_pool_members => {}, :lbaas_health_monitorss => {}, :lbaas_l7policies => {}, :lbaas_l7rules => {}, :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 => {}, :network_ip_availabilities => [ { "network_id" => "4cf895c9-c3d1-489e-b02e-59b5c8976809", "network_name" => "public", "subnet_ip_availability" => [ { "cidr" => "2001:db8::/64", "ip_version" => 6, "subnet_id" => "ca3f46c4-c6ff-4272-9be4-0466f84c6077", "subnet_name" => "ipv6-public-subnet", "total_ips" => 18446744073709552000, "used_ips" => 1 }, { "cidr" => "172.24.4.0/24", "ip_version" => 4, "subnet_id" => "cc02efc1-9d47-46bd-bab6-760919c836b5", "subnet_name" => "public-subnet", "total_ips" => 253, "used_ips" => 1 } ], "project_id" => "1a02cc95f1734fcc9d3c753818f03002", "tenant_id" => "1a02cc95f1734fcc9d3c753818f03002", "total_ips" => 253, "used_ips" => 2 }, { "network_id" => "6801d9c8-20e6-4b27-945d-62499f00002e", "network_name" => "private", "subnet_ip_availability" => [ { "cidr" => "10.0.0.0/24", "ip_version" => 4, "subnet_id" => "44e70d00-80a2-4fb1-ab59-6190595ceb61", "subnet_name" => "private-subnet", "total_ips" => 253, "used_ips" => 2 }, { "ip_version" => 6, "cidr" => "fdbf:ac66:9be8::/64", "subnet_id" => "a90623df-00e1-4902-a675-40674385d74c", "subnet_name" => "ipv6-private-subnet", "total_ips" => 18446744073709552000, "used_ips" => 2 } ], "project_id" => "d56d3b8dd6894a508cf41b96b522328c", "tenant_id" => "d56d3b8dd6894a508cf41b96b522328c", "total_ips" => 18446744073709552000, "used_ips" => 4 } ] } 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 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 self.not_found_class Fog::OpenStack::Network::NotFound end def default_path_prefix 'v2.0' end def default_service_type %w[network] end end end end end fog-openstack-1.0.8/lib/fog/openstack/nfv/0000755000004100000410000000000013423370527020417 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/nfv/requests/0000755000004100000410000000000013423370527022272 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/nfv/requests/delete_vnfd.rb0000644000004100000410000000066513423370527025105 0ustar www-datawww-datamodule Fog module OpenStack class NFV 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-1.0.8/lib/fog/openstack/nfv/requests/create_vnf.rb0000644000004100000410000000152313423370527024734 0ustar www-datawww-datamodule Fog module OpenStack class NFV 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-1.0.8/lib/fog/openstack/nfv/requests/get_vnfd.rb0000644000004100000410000000074513423370527024421 0ustar www-datawww-datamodule Fog module OpenStack class NFV 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-1.0.8/lib/fog/openstack/nfv/requests/list_vnfs.rb0000644000004100000410000000077713423370527024641 0ustar www-datawww-datamodule Fog module OpenStack class NFV 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-1.0.8/lib/fog/openstack/nfv/requests/create_vnfd.rb0000644000004100000410000000143313423370527025100 0ustar www-datawww-datamodule Fog module OpenStack class NFV 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-1.0.8/lib/fog/openstack/nfv/requests/update_vnf.rb0000644000004100000410000000144113423370527024752 0ustar www-datawww-datamodule Fog module OpenStack class NFV 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-1.0.8/lib/fog/openstack/nfv/requests/get_vnf.rb0000644000004100000410000000073513423370527024254 0ustar www-datawww-datamodule Fog module OpenStack class NFV 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-1.0.8/lib/fog/openstack/nfv/requests/list_vnfds.rb0000644000004100000410000000100413423370527024765 0ustar www-datawww-datamodule Fog module OpenStack class NFV 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-1.0.8/lib/fog/openstack/nfv/requests/delete_vnf.rb0000644000004100000410000000065713423370527024742 0ustar www-datawww-datamodule Fog module OpenStack class NFV 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-1.0.8/lib/fog/openstack/nfv/models/0000755000004100000410000000000013423370527021702 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/nfv/models/vnfd.rb0000644000004100000410000000221613423370527023165 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class NFV 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, "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-1.0.8/lib/fog/openstack/nfv/models/vnf.rb0000644000004100000410000000232413423370527023021 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class NFV 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-1.0.8/lib/fog/openstack/nfv/models/vnfds.rb0000644000004100000410000000113313423370527023345 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/nfv/models/vnfd' module Fog module OpenStack class NFV class Vnfds < Fog::OpenStack::Collection model Fog::OpenStack::NFV::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::OpenStack::NFV::NotFound nil end def destroy(uuid) vnfd = get(uuid) vnfd.destroy end end end end end fog-openstack-1.0.8/lib/fog/openstack/nfv/models/vnfs.rb0000644000004100000410000000112213423370527023177 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/nfv/models/vnf' module Fog module OpenStack class NFV class Vnfs < Fog::OpenStack::Collection model Fog::OpenStack::NFV::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::OpenStack::NFV::NotFound nil end def destroy(uuid) vnf = get(uuid) vnf.destroy end end end end end fog-openstack-1.0.8/lib/fog/openstack/metric.rb0000644000004100000410000000640513423370527021443 0ustar www-datawww-datamodule Fog module OpenStack class Metric < 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, :openstack_identity_api_version model_path 'fog/openstack/metric/models' model :metric collection :metrics model :resource collection :resources request_path 'fog/openstack/metric/requests' request :get_resource_metric_measures request :get_metric_measures request :get_metric request :list_metrics request :get_resource 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 = 8041 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 default_path_prefix 'v1' end def self.not_found_class Fog::OpenStack::Metric::NotFound end def default_service_type %w[metric] end end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring.rb0000644000004100000410000000542713423370527022350 0ustar www-datawww-data module Fog module OpenStack class Monitoring < 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_project_domain, :openstack_user_domain, :openstack_domain_name, :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id, :openstack_identity_api_version, :openstack_temp_url_key, :openstack_cache_ttl model_path 'fog/openstack/monitoring/models' model :metric collection :metrics model :measurement collection :measurements model :statistic collection :statistics model :notification_method collection :notification_methods model :alarm_definition collection :alarm_definitions model :alarm collection :alarms model :alarm_state collection :alarm_states model :alarm_count collection :alarm_counts model :dimension_value request_path 'fog/openstack/monitoring/requests' request :create_metric request :create_metric_array request :list_metrics request :list_metric_names request :find_measurements request :list_statistics request :create_notification_method request :get_notification_method request :list_notification_methods request :put_notification_method request :patch_notification_method request :delete_notification_method request :create_alarm_definition request :list_alarm_definitions request :patch_alarm_definition request :update_alarm_definition request :get_alarm_definition request :delete_alarm_definition request :list_alarms request :get_alarm request :patch_alarm request :update_alarm request :delete_alarm request :get_alarm_counts request :list_alarm_state_history_for_specific_alarm request :list_alarm_state_history_for_all_alarms request :list_dimension_values request :list_notification_method_types class Real include Fog::OpenStack::Core def self.not_found_class Fog::OpenStack::Monitoring::NotFound end def default_service_type %w[monitoring] end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system.rb0000644000004100000410000003634113423370527024033 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem < Fog::Service SUPPORTED_VERSIONS = /v2(\.0)*/ SUPPORTED_MICROVERSION = '2.15'.freeze 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_api_version, :openstack_shared_file_system_microversion model_path 'fog/openstack/shared_file_system/models' model :network collection :networks model :share collection :shares model :snapshot collection :snapshots model :share_access_rule collection :share_access_rules model :share_export_location collection :share_export_locations model :availability_zone collection :availability_zones request_path 'fog/openstack/shared_file_system/requests' # share networks request :list_share_networks request :list_share_networks_detail request :get_share_network request :create_share_network request :update_share_network request :delete_share_network request :share_network_action request :add_security_service_to_share_network request :remove_security_service_from_share_network # shares request :list_shares request :list_shares_detail request :get_share request :create_share request :update_share request :delete_share request :share_action request :grant_share_access request :revoke_share_access request :list_share_access_rules request :list_share_export_locations request :extend_share request :shrink_share # snapshots request :list_snapshots request :list_snapshots_detail request :get_snapshot request :create_snapshot request :update_snapshot request :delete_snapshot # security services request :list_security_services request :list_security_services_detail request :get_security_service request :create_security_service request :update_security_service request :delete_security_service # quota + limits request :get_limits request :get_quota request :update_quota # availability zones request :list_availability_zones # rubocop:disable LineLength, Metrics/MethodLength, Metrics/ClassLength, Metrics/AbcSize class Mock def self.data @data ||= Hash.new do |hash, key| hash[key] = { :shares => [ { "id" => "d94a8548-2079-4be0-b21c-0a887acd31ca", "links" => [ { "href" => "http://172.18.198.54:8786/v1/16e1ab15c35a457e9c2b2aa189f544e1/shares/d94a8548-2079-4be0-b21c-0a887acd31ca", "rel" => "self" }, { "href" => "http://172.18.198.54:8786/16e1ab15c35a457e9c2b2aa189f544e1/shares/d94a8548-2079-4be0-b21c-0a887acd31ca", "rel" => "bookmark" } ], "name" => "My_share" }, { "id" => "406ea93b-32e9-4907-a117-148b3945749f", "links" => [ { "href" => "http://172.18.198.54:8786/v1/16e1ab15c35a457e9c2b2aa189f544e1/shares/406ea93b-32e9-4907-a117-148b3945749f", "rel" => "self" }, { "href" => "http://172.18.198.54:8786/16e1ab15c35a457e9c2b2aa189f544e1/shares/406ea93b-32e9-4907-a117-148b3945749f", "rel" => "bookmark" } ], "name" => "Share1" } ], :shares_detail => [ { "links" => [ { "href" => "http://172.18.198.54:8786/v2/16e1ab15c35a457e9c2b2aa189f544e1/shares/f45cc5b2-d1bb-4a3e-ba5b-5c4125613adc", "rel" => "self" }, { "href" => "http://172.18.198.54:8786/16e1ab15c35a457e9c2b2aa189f544e1/shares/f45cc5b2-d1bb-4a3e-ba5b-5c4125613adc", "rel" => "bookmark" } ], "availability_zone" => "nova", "share_network_id" => "f9b2e754-ac01-4466-86e1-5c569424754e", "export_locations" => [], "share_server_id" => "87d8943a-f5da-47a4-b2f2-ddfa6794aa82", "snapshot_id" => '', "id" => "f45cc5b2-d1bb-4a3e-ba5b-5c4125613adc", "size" => 1, "share_type" => "25747776-08e5-494f-ab40-a64b9d20d8f7", "share_type_name" => "default", "export_location" => '', "consistency_group_id" => "9397c191-8427-4661-a2e8-b23820dc01d4", "project_id" => "16e1ab15c35a457e9c2b2aa189f544e1", "metadata" => {}, "status" => "available", "access_rules_status" => "active", "description" => "There is a share description.", "host" => "manila2@generic1#GENERIC1", "task_state" => '', "is_public" => 'true', "snapshot_support" => 'true', "name" => "my_share4", "has_replicas" => 'false', "replication_type" => '', "created_at" => "2015-09-16T18:19:50.000000", "share_proto" => "NFS", "volume_type" => "default", "source_cgsnapshot_member_id" => '' } ], :share_networks => [ { "id" => "32763294-e3d4-456a-998d-60047677c2fb", "name" => "net_my1" }, { "id" => "713df749-aac0-4a54-af52-10f6c991e80c", "name" => "net_my" } ], :share_networks_detail => [ { "name" => "net_my1", "segmentation_id" => '', "created_at" => "2015-09-04T14:57:13.000000", "neutron_subnet_id" => "53482b62-2c84-4a53-b6ab-30d9d9800d06", "updated_at" => '', "id" => "32763294-e3d4-456a-998d-60047677c2fb", "neutron_net_id" => "998b42ee-2cee-4d36-8b95-67b5ca1f2109", "ip_version" => '', "nova_net_id" => '', "cidr" => '', "project_id" => "16e1ab15c35a457e9c2b2aa189f544e1", "network_type" => '', "description" => "descr" } ], :snapshots => [ { "id" => "086a1aa6-c425-4ecd-9612-391a3b1b9375", "links" => [ { "href" => "http://172.18.198.54:8786/v1/16e1ab15c35a457e9c2b2aa189f544e1/snapshots/086a1aa6-c425-4ecd-9612-391a3b1b9375", "rel" => "self" }, { "href" => "http://172.18.198.54:8786/16e1ab15c35a457e9c2b2aa189f544e1/snapshots/086a1aa6-c425-4ecd-9612-391a3b1b9375", "rel" => "bookmark" } ], "name" => "snapshot_My_share" } ], :security_services_detail => [ { "status" => "new", "domain" => "", "project_id" => "16e1ab15c35a457e9c2b2aa189f544e1", "name" => "SecServ1", "created_at" => "2015-09-07T12:19:10.000000", "updated_at" => "", "server" => "", "dns_ip" => "10.0.0.0/24", "user" => "demo", "password" => "supersecret", "type" => "kerberos", "id" => "3c829734-0679-4c17-9637-801da48c0d5f", "description" => "Creating my first Security Service" } ], :security_services => [ { "status" => "new", "type" => "ldap", "id" => "5a1d3a12-34a7-4087-8983-50e9ed03509a", "name" => "SecServ2" } ], :availability_zones => [ { "name" => "nova", "created_at" => "2015-09-18T09:50:55.000000", "updated_at" => nil, "id" => "388c983d-258e-4a0e-b1ba-10da37d766db" } ], :snapshots_detail => [ { "status" => "available", "share_id" => "d94a8548-2079-4be0-b21c-0a887acd31ca", "name" => "snapshot_My_share", "links" => [ { "href" => "http://172.18.198.54:8786/v1/16e1ab15c35a457e9c2b2aa189f544e1/snapshots/086a1aa6-c425-4ecd-9612-391a3b1b9375", "rel" => "self" }, { "href" => "http://172.18.198.54:8786/16e1ab15c35a457e9c2b2aa189f544e1/snapshots/086a1aa6-c425-4ecd-9612-391a3b1b9375", "rel" => "bookmark" } ], "created_at" => "2015-09-07T11:55:09.000000", "description" => "Here is a snapshot of share My_share", "share_proto" => "NFS", "share_size" => 1, "id" => "086a1aa6-c425-4ecd-9612-391a3b1b9375", "size" => 1 } ], :export_locations => [ { "path" => "10.254.0.3:/shares/share-e1c2d35e-fe67-4028-ad7a-45f668732b1d", "share_instance_id" => "e1c2d35e-fe67-4028-ad7a-45f668732b1d", "is_admin_only" => false, "id" => "b6bd76ce-12a2-42a9-a30a-8a43b503867d", "preferred" => false }, { "path" => "10.0.0.3:/shares/share-e1c2d35e-fe67-4028-ad7a-45f668732b1d", "share_instance_id" => "e1c2d35e-fe67-4028-ad7a-45f668732b1d", "is_admin_only" => true, "id" => "6921e862-88bc-49a5-a2df-efeed9acd583", "preferred" => false } ], :access_rules => [ { "share_id" => "406ea93b-32e9-4907-a117-148b3945749f", "created_at" => "2015-09-07T09:14:48.000000", "updated_at" => '', "access_type" => "ip", "access_to" => "0.0.0.0/0", "access_level" => "rw", "access_key" => '', "id" => "a25b2df3-90bd-4add-afa6-5f0dbbd50452" } ], :quota => { "gigabytes" => 1000, "shares" => 50, "snapshot_gigabytes" => 1000, "snapshots" => 50, "share_networks" => 10, "id" => "16e1ab15c35a457e9c2b2aa189f544e1" } } 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 = 8786 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 # rubocop:enable LineLength, Metrics/MethodLength, Metrics/ClassLength, Metrics/AbcSize class Real include Fog::OpenStack::Core def self.not_found_class Fog::OpenStack::SharedFileSystem::NotFound end def action_prefix microversion_newer_than?('2.6') ? '' : 'os-' end def default_service_type %w[sharev2] end def initialize(options = {}) @supported_versions = SUPPORTED_VERSIONS @supported_microversion = SUPPORTED_MICROVERSION @fixed_microversion = options[:openstack_shared_file_system_microversion] @microversion_key = 'X-Openstack-Manila-Api-Version'.freeze super end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/0000755000004100000410000000000013423370527021457 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/identity/v3.rb0000644000004100000410000001255013423370527022337 0ustar www-datawww-datarequire 'fog/openstack/identity' module Fog module OpenStack class Identity 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_api_version, :openstack_cache_ttl model_path 'fog/openstack/identity/v3/models' 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/identity/v3/requests' 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, "No version available at #{uri}" end version end class Real < Fog::OpenStack::Identity::Real def api_path_prefix @path_prefix = version_in_path?(@openstack_management_uri.path) ? '' : 'v3' super end def default_path_prefix @path_prefix end def default_service_type %w[identity_v3 identityv3 identity] end def version_in_path?(url) true if url =~ /\/v3(\/)*.*$/ end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/0000755000004100000410000000000013423370527022007 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/0000755000004100000410000000000013423370527023662 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/update_role.rb0000644000004100000410000000062713423370527026517 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/revoke_project_user_role.rb0000644000004100000410000000063313423370527031311 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/create_policy.rb0000644000004100000410000000062713423370527027036 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/list_domains.rb0000644000004100000410000000066513423370527026703 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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-1.0.8/lib/fog/openstack/identity/v3/requests/create_domain.rb0000644000004100000410000000062613423370527027005 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/delete_group.rb0000644000004100000410000000053113423370527026664 0ustar www-datawww-datamodule Fog module OpenStack class Identity class V3 class Real def delete_group(id) request( :expects => [204], :method => 'DELETE', :path => "groups/#{id}" ) end end class Mock end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/token_validate.rb0000644000004100000410000000070013423370527027175 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/check_domain_user_role.rb0000644000004100000410000000062613423370527030676 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/list_users.rb0000644000004100000410000000065713423370527026413 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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-1.0.8/lib/fog/openstack/identity/v3/requests/revoke_project_group_role.rb0000644000004100000410000000063713423370527031473 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/create_endpoint.rb0000644000004100000410000000064013423370527027352 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/list_roles.rb0000644000004100000410000000065713423370527026376 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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-1.0.8/lib/fog/openstack/identity/v3/requests/get_service.rb0000644000004100000410000000060313423370527026505 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/revoke_domain_user_role.rb0000644000004100000410000000063113423370527031110 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/grant_domain_group_role.rb0000644000004100000410000000063113423370527031106 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/get_group.rb0000644000004100000410000000057513423370527026211 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/list_endpoints.rb0000644000004100000410000000067313423370527027253 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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-1.0.8/lib/fog/openstack/identity/v3/requests/list_services.rb0000644000004100000410000000067013423370527027070 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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-1.0.8/lib/fog/openstack/identity/v3/requests/list_user_projects.rb0000644000004100000410000000071613423370527030135 0ustar www-datawww-datamodule Fog module OpenStack class Identity class V3 class Real def list_user_projects(user_id, options = {}) request( :expects => [200], :method => 'GET', :path => "users/#{user_id}/projects", :query => options ) end end class Mock def list_user_projects end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/update_endpoint.rb0000644000004100000410000000065313423370527027375 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/token_check.rb0000644000004100000410000000070413423370527026465 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/delete_project.rb0000644000004100000410000000053513423370527027202 0ustar www-datawww-datamodule Fog module OpenStack class Identity class V3 class Real def delete_project(id) request( :expects => [204], :method => 'DELETE', :path => "projects/#{id}" ) end end class Mock end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/update_domain.rb0000644000004100000410000000064113423370527027021 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/check_project_user_role.rb0000644000004100000410000000063013423370527031070 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/grant_domain_user_role.rb0000644000004100000410000000062513423370527030733 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/get_project.rb0000644000004100000410000000066313423370527026521 0ustar www-datawww-datamodule Fog module OpenStack class Identity class V3 class Real def get_project(id, options = {}) request( :expects => [200], :method => 'GET', :path => "projects/#{id}", :query => options ) end end class Mock def get_domain(id) end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/group_user_check.rb0000644000004100000410000000060113423370527027533 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/grant_project_group_role.rb0000644000004100000410000000063313423370527031307 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/auth_domains.rb0000644000004100000410000000065413423370527026667 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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-1.0.8/lib/fog/openstack/identity/v3/requests/update_os_credential.rb0000644000004100000410000000067013423370527030367 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/delete_service.rb0000644000004100000410000000053513423370527027174 0ustar www-datawww-datamodule Fog module OpenStack class Identity class V3 class Real def delete_service(id) request( :expects => [204], :method => 'DELETE', :path => "services/#{id}" ) end end class Mock end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/check_domain_group_role.rb0000644000004100000410000000063213423370527031051 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/delete_os_credential.rb0000644000004100000410000000054613423370527030351 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/update_service.rb0000644000004100000410000000064613423370527027217 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/list_policies.rb0000644000004100000410000000067013423370527027054 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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-1.0.8/lib/fog/openstack/identity/v3/requests/remove_user_from_group.rb0000644000004100000410000000061113423370527030777 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/update_group.rb0000644000004100000410000000063413423370527026710 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/list_domain_group_roles.rb0000644000004100000410000000070613423370527031134 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/delete_domain.rb0000644000004100000410000000053313423370527027001 0ustar www-datawww-datamodule Fog module OpenStack class Identity class V3 class Real def delete_domain(id) request( :expects => [204], :method => 'DELETE', :path => "domains/#{id}" ) end end class Mock end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/create_project.rb0000644000004100000410000000063313423370527027202 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/delete_policy.rb0000644000004100000410000000053413423370527027032 0ustar www-datawww-datamodule Fog module OpenStack class Identity class V3 class Real def delete_policy(id) request( :expects => [204], :method => 'DELETE', :path => "policies/#{id}" ) end end class Mock end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/delete_role.rb0000644000004100000410000000052713423370527026476 0ustar www-datawww-datamodule Fog module OpenStack class Identity class V3 class Real def delete_role(id) request( :expects => [204], :method => 'DELETE', :path => "roles/#{id}" ) end end class Mock end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/add_user_to_group.rb0000644000004100000410000000060113423370527027710 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/create_service.rb0000644000004100000410000000063313423370527027174 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/list_domain_user_roles.rb0000644000004100000410000000070113423370527030751 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/get_policy.rb0000644000004100000410000000060113423370527026342 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/delete_user.rb0000644000004100000410000000052713423370527026513 0ustar www-datawww-datamodule Fog module OpenStack class Identity class V3 class Real def delete_user(id) request( :expects => [204], :method => 'DELETE', :path => "users/#{id}" ) end end class Mock end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/create_group.rb0000644000004100000410000000062113423370527026665 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/grant_project_user_role.rb0000644000004100000410000000062713423370527031134 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/revoke_domain_group_role.rb0000644000004100000410000000063513423370527031272 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/get_os_credential.rb0000644000004100000410000000062213423370527027661 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/update_user.rb0000644000004100000410000000062713423370527026534 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/token_revoke.rb0000644000004100000410000000070713423370527026706 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/auth_projects.rb0000644000004100000410000000065713423370527027071 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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-1.0.8/lib/fog/openstack/identity/v3/requests/token_authenticate.rb0000644000004100000410000000062013423370527030063 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/create_os_credential.rb0000644000004100000410000000065513423370527030353 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/create_user.rb0000644000004100000410000000061413423370527026511 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/get_role.rb0000644000004100000410000000057213423370527026013 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/list_user_groups.rb0000644000004100000410000000062713423370527027624 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/list_role_assignments.rb0000644000004100000410000000207313423370527030620 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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-1.0.8/lib/fog/openstack/identity/v3/requests/get_domain.rb0000644000004100000410000000060013423370527026311 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/update_project.rb0000644000004100000410000000064613423370527027225 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/list_project_group_roles.rb0000644000004100000410000000071113423370527031327 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/get_user.rb0000644000004100000410000000057213423370527026030 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/list_projects.rb0000644000004100000410000000123513423370527027074 0ustar www-datawww-datamodule Fog module OpenStack class Identity class V3 class Real def list_projects(options = {}) user_id = options.delete('user_id') || options.delete(:user_id) path = if user_id "users/#{user_id}/projects" else "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-1.0.8/lib/fog/openstack/identity/v3/requests/create_role.rb0000644000004100000410000000061413423370527026474 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/list_os_credentials.rb0000644000004100000410000000070713423370527030244 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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-1.0.8/lib/fog/openstack/identity/v3/requests/list_groups.rb0000644000004100000410000000122613423370527026562 0ustar www-datawww-datamodule Fog module OpenStack class Identity class V3 class Real def list_groups(options = {}) user_id = options.delete('user_id') || options.delete(:user_id) path = if user_id "users/#{user_id}/groups" else "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-1.0.8/lib/fog/openstack/identity/v3/requests/check_project_group_role.rb0000644000004100000410000000063413423370527031252 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/get_endpoint.rb0000644000004100000410000000060613423370527026670 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/update_policy.rb0000644000004100000410000000064213423370527027052 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/list_project_user_roles.rb0000644000004100000410000000070413423370527031153 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/requests/list_group_users.rb0000644000004100000410000000067613423370527027630 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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-1.0.8/lib/fog/openstack/identity/v3/requests/delete_endpoint.rb0000644000004100000410000000053713423370527027356 0ustar www-datawww-datamodule Fog module OpenStack class Identity class V3 class Real def delete_endpoint(id) request( :expects => [204], :method => 'DELETE', :path => "endpoints/#{id}" ) end end class Mock end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/models/0000755000004100000410000000000013423370527023272 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/identity/v3/models/domains.rb0000644000004100000410000000464013423370527025255 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/identity/v3/models/domain' module Fog module OpenStack class Identity class V3 class Domains < Fog::OpenStack::Collection model Fog::OpenStack::Identity::V3::Domain def all(options = {}) if service.openstack_cache_ttl > 0 cached_domain, expires = Fog::OpenStack::Identity::V3::Domain.cache[{:token => service.auth_token, :options => options}] return cached_domain if cached_domain && expires > Time.now end domain_to_cache = load_response(service.list_domains(options), 'domains') if service.openstack_cache_ttl > 0 cache = Fog::OpenStack::Identity::V3::Domain.cache cache[{:token => service.auth_token, :options => options}] = [domain_to_cache, Time.now + service.openstack_cache_ttl] Fog::OpenStack::Identity::V3::Domain.cache = cache end domain_to_cache end def create(attributes) super(attributes) end def auth_domains(options = {}) load(service.auth_domains(options).body['domains']) end def find_by_id(id) if service.openstack_cache_ttl > 0 cached_domain, expires = Fog::OpenStack::Identity::V3::Domain.cache[{:token => service.auth_token, :id => id}] return cached_domain if cached_domain && expires > Time.now end domain_hash = service.get_domain(id).body['domain'] domain_to_cache = Fog::OpenStack::Identity::V3::Domain.new( domain_hash.merge(:service => service) ) if service.openstack_cache_ttl > 0 cache = Fog::OpenStack::Identity::V3::Domain.cache cache[{:token => service.auth_token, :id => id}] = [domain_to_cache, Time.now + service.openstack_cache_ttl] Fog::OpenStack::Identity::V3::Domain.cache = cache end domain_to_cache end def destroy(id) domain = find_by_id(id) domain.destroy end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/models/role_assignment.rb0000644000004100000410000000061213423370527027007 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Identity class V3 class RoleAssignment < Fog::OpenStack::Model attribute :scope attribute :role attribute :user attribute :group attribute :links def to_s links['assignment'] end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/models/group.rb0000644000004100000410000000435413423370527024761 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Identity class V3 class Group < Fog::OpenStack::Model identity :id attribute :description attribute :domain_id attribute :name attribute :links def to_s name end def destroy requires :id service.delete_group(id) true end def update(attr = nil) requires :id, :name merge_attributes( service.update_group(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(id, user_id) end def remove_user(user_id) requires :id service.remove_user_from_group(id, user_id) end def contains_user?(user_id) requires :id begin service.group_user_check(id, user_id) rescue Fog::OpenStack::Identity::NotFound return false end true end def roles requires :id, :domain_id service.list_domain_group_roles(domain_id, id).body['roles'] end def grant_role(role_id) requires :id, :domain_id service.grant_domain_group_role(domain_id, id, role_id) end def check_role(role_id) requires :id, :domain_id begin service.check_domain_group_role(domain_id, id, role_id) rescue Fog::OpenStack::Identity::NotFound return false end true end def revoke_role(role_id) requires :id, :domain_id service.revoke_domain_group_role(domain_id, id, role_id) end def users(attr = {}) requires :id service.list_group_users(id, attr).body['users'] end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/models/tokens.rb0000644000004100000410000000223013423370527025117 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/identity/v3/models/service' module Fog module OpenStack class Identity class V3 class Tokens < Fog::OpenStack::Collection model Fog::OpenStack::Identity::V3::Token def authenticate(auth) response = service.token_authenticate(auth) token_hash = response.body['token'] Fog::OpenStack::Identity::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::OpenStack::Identity::V3::Token.new( token_hash.merge(:service => service, :value => response.headers['X-Subject-Token']) ) end def check(subject_token) service.token_check(subject_token) true end def revoke(subject_token) service.token_revoke(subject_token) true end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/models/policy.rb0000644000004100000410000000155313423370527025122 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Identity class V3 class Policy < Fog::OpenStack::Model identity :id attribute :type attribute :blob attribute :links def to_s name end def destroy requires :id service.delete_policy(id) true end def update(attr = nil) requires :id, :blob, :type merge_attributes( service.update_policy(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-1.0.8/lib/fog/openstack/identity/v3/models/groups.rb0000644000004100000410000000151313423370527025136 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/identity/v3/models/group' module Fog module OpenStack class Identity class V3 class Groups < Fog::OpenStack::Collection model Fog::OpenStack::Identity::V3::Group def all(options = {}) load_response(service.list_groups(options), 'groups') end def find_by_id(id) cached_group = find { |group| group.id == id } return cached_group if cached_group group_hash = service.get_group(id).body['group'] Fog::OpenStack::Identity::V3.group.new( group_hash.merge(:service => service) ) end def destroy(id) group = find_by_id(id) group.destroy end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/models/users.rb0000644000004100000410000000171413423370527024763 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/identity/v3/models/domain' module Fog module OpenStack class Identity class V3 class Users < Fog::OpenStack::Collection model Fog::OpenStack::Identity::V3::User def all(options = {}) load_response(service.list_users(options), 'users') end def find_by_id(id) cached_user = find { |user| user.id == id } return cached_user if cached_user user_hash = service.get_user(id).body['user'] Fog::OpenStack::Identity::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 = find_by_id(id) user.destroy end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/models/services.rb0000644000004100000410000000155613423370527025451 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/identity/v3/models/service' module Fog module OpenStack class Identity class V3 class Services < Fog::OpenStack::Collection model Fog::OpenStack::Identity::V3::Service def all(options = {}) load_response(service.list_services(options), 'services') end def find_by_id(id) cached_service = find { |service| service.id == id } return cached_service if cached_service service_hash = service.get_service(id).body['service'] Fog::OpenStack::Identity::V3::Service.new( service_hash.merge(:service => service) ) end def destroy(id) service = find_by_id(id) service.destroy end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/models/user.rb0000644000004100000410000000364613423370527024606 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Identity 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 name end def groups requires :id service.list_user_groups(id).body['groups'] end def projects requires :id service.list_user_projects(id).body['projects'] end def roles requires :id, :domain_id service.list_domain_user_roles(domain_id, id).body['roles'] end def grant_role(role_id) requires :id, :domain_id service.grant_domain_user_role(domain_id, id, role_id) end def check_role(role_id) requires :id, :domain_id begin service.check_domain_user_role(domain_id, id, role_id) rescue Fog::OpenStack::Identity::NotFound return false end true end def revoke_role(role_id) requires :id, :domain_id service.revoke_domain_user_role(domain_id, id, role_id) end def destroy requires :id service.delete_user(id) true end def update(attr = nil) requires :id merge_attributes( service.update_user(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-1.0.8/lib/fog/openstack/identity/v3/models/os_credential.rb0000644000004100000410000000312613423370527026434 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Identity class V3 class OsCredential < Fog::OpenStack::Model identity :id attribute :project_id attribute :type attribute :blob attribute :user_id attribute :links def to_s name end def destroy requires :id service.delete_os_credential(id) @parsed_blob = nil true end def update(attr = nil) requires :id merge_attributes( service.update_os_credential(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-1.0.8/lib/fog/openstack/identity/v3/models/roles.rb0000644000004100000410000000252613423370527024750 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/identity/v3/models/role' module Fog module OpenStack class Identity class V3 class Roles < Fog::OpenStack::Collection model Fog::OpenStack::Identity::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 = find { |role| role.id == id } return cached_role if cached_role role_hash = service.get_role(id).body['role'] Fog::OpenStack::Identity::V3.role.new( role_hash.merge(:service => service) ) end def destroy(id) role = find_by_id(id) role.destroy end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/models/token.rb0000644000004100000410000000072413423370527024742 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Identity 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 value end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/models/service.rb0000644000004100000410000000170613423370527025263 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Identity class V3 class Service < Fog::OpenStack::Model identity :id attribute :description attribute :type attribute :name attribute :links def to_s name end def destroy requires :id service.delete_service(id) true end def update(attr = nil) requires :id merge_attributes( service.update_service(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-1.0.8/lib/fog/openstack/identity/v3/models/endpoints.rb0000644000004100000410000000142213423370527025621 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/identity/v3/models/service' module Fog module OpenStack class Identity class V3 class Endpoints < Fog::OpenStack::Collection model Fog::OpenStack::Identity::V3::Endpoint def all(options = {}) load_response(service.list_endpoints(options), 'endpoints') end def find_by_id(id) cached_endpoint = find { |endpoint| endpoint.id == id } return cached_endpoint if cached_endpoint endpoint_hash = service.get_endpoint(id).body['endpoint'] Fog::OpenStack::Identity::V3::Endpoint.new( endpoint_hash.merge(:service => service) ) end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/models/endpoint.rb0000644000004100000410000000174413423370527025445 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Identity 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 name end def destroy requires :id service.delete_endpoint(id) true end def update(attr = nil) requires :id, :name merge_attributes( service.update_endpoint(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-1.0.8/lib/fog/openstack/identity/v3/models/projects.rb0000644000004100000410000000627213423370527025457 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/identity/v3/models/project' module Fog module OpenStack class Identity class V3 class Projects < Fog::OpenStack::Collection model Fog::OpenStack::Identity::V3::Project def all(options = {}) if service.openstack_cache_ttl > 0 cached_project, expires = Fog::OpenStack::Identity::V3::Project.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 = Fog::OpenStack::Identity::V3::Project.cache cache[{:token => service.auth_token, :options => options}] = [project_to_cache, Time.now + service.openstack_cache_ttl] Fog::OpenStack::Identity::V3::Project.cache = cache end project_to_cache end def create(attributes) 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.kind_of? Symbol # Deal with a single option being passed on its own options = {options => nil} end if service.openstack_cache_ttl > 0 cached_project, expires = Fog::OpenStack::Identity::V3::Project.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 = Fog::OpenStack::Identity::V3::Project.cache cache[{:token => service.auth_token, :id => id, :options => options}] = [ top_project, Time.now + service.openstack_cache_ttl ] Fog::OpenStack::Identity::V3::Project.cache = cache end top_project end private def project_from_hash(project_hash, service) Fog::OpenStack::Identity::V3::Project.new(project_hash.merge(:service => service)) end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/models/role.rb0000644000004100000410000000142513423370527024562 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Identity class V3 class Role < Fog::OpenStack::Model identity :id attribute :name attribute :links def to_s name end def destroy requires :id service.delete_role(id) true end def update(attr = nil) requires :id merge_attributes( service.update_role(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-1.0.8/lib/fog/openstack/identity/v3/models/domain.rb0000644000004100000410000000220613423370527025066 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Identity class V3 class Domain < Fog::OpenStack::Model identity :id attribute :description attribute :enabled attribute :name attribute :links class << self attr_accessor :cache end @cache = {} def to_s name end def destroy clear_cache requires :id service.delete_domain(id) true end def update(attr = nil) clear_cache requires :id, :name merge_attributes( service.update_domain(id, attr || attributes).body['domain'] ) self end def create clear_cache requires :name merge_attributes( service.create_domain(attributes).body['domain'] ) self end private def clear_cache self.class.cache = {} end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/models/os_credentials.rb0000644000004100000410000000165613423370527026625 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/identity/v3/models/os_credential' module Fog module OpenStack class Identity class V3 class OsCredentials < Fog::OpenStack::Collection model Fog::OpenStack::Identity::V3::OsCredential def all(options = {}) load_response(service.list_os_credentials(options), 'credentials') end def find_by_id(id) cached_credential = find { |credential| credential.id == id } return cached_credential if cached_credential credential_hash = service.get_os_credential(id).body['credential'] Fog::OpenStack::Identity::V3::Credential.new( credential_hash.merge(:service => service) ) end def destroy(id) credential = find_by_id(id) credential.destroy end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/models/project.rb0000644000004100000410000000546013423370527025272 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Identity 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 class << self attr_accessor :cache end @cache = {} def to_s name end def destroy clear_cache requires :id service.delete_project(id) true end def update(attr = nil) clear_cache requires :id merge_attributes( service.update_project(id, attr || attributes).body['project'] ) self end def create clear_cache merge_attributes( service.create_project(attributes).body['project'] ) self end def user_roles(user_id) requires :id service.list_project_user_roles(id, user_id).body['roles'] end def grant_role_to_user(role_id, user_id) clear_cache requires :id service.grant_project_user_role(id, user_id, role_id) end def check_user_role(user_id, role_id) requires :id begin service.check_project_user_role(id, user_id, role_id) rescue Fog::OpenStack::Identity::NotFound return false end true end def revoke_role_from_user(role_id, user_id) clear_cache requires :id service.revoke_project_user_role(id, user_id, role_id) end def group_roles(group_id) requires :id service.list_project_group_roles(id, group_id).body['roles'] end def grant_role_to_group(role_id, group_id) clear_cache requires :id service.grant_project_group_role(id, group_id, role_id) end def check_group_role(group_id, role_id) requires :id begin service.check_project_group_role(id, group_id, role_id) rescue Fog::OpenStack::Identity::NotFound return false end true end def revoke_role_from_group(role_id, group_id) clear_cache requires :id service.revoke_project_group_role(id, group_id, role_id) end private def clear_cache self.class.cache = {} end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v3/models/role_assignments.rb0000644000004100000410000000153413423370527027176 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/identity/v3/models/role' module Fog module OpenStack class Identity class V3 class RoleAssignments < Fog::OpenStack::Collection model Fog::OpenStack::Identity::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-1.0.8/lib/fog/openstack/identity/v3/models/policies.rb0000644000004100000410000000154013423370527025426 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/identity/v3/models/policy' module Fog module OpenStack class Identity class V3 class Policies < Fog::OpenStack::Collection model Fog::OpenStack::Identity::V3::Policy def all(options = {}) load_response(service.list_policies(options), 'policies') end def find_by_id(id) cached_policy = find { |policy| policy.id == id } return cached_policy if cached_policy policy_hash = service.get_policy(id).body['policy'] Fog::OpenStack::Identity::V3::Policy.new( policy_hash.merge(:service => service) ) end def destroy(id) policy = find_by_id(id) policy.destroy end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/0000755000004100000410000000000013423370527022006 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/identity/v2/requests/0000755000004100000410000000000013423370527023661 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/identity/v2/requests/get_ec2_credential.rb0000644000004100000410000000304713423370527027714 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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::OpenStack::Identity::NotFound end end class Mock def get_ec2_credential(user_id, access) ec2_credential = 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 end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/requests/add_user_to_tenant.rb0000644000004100000410000000177013423370527030054 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 Mock def add_user_to_tenant(tenant_id, user_id, role_id) role = data[:roles][role_id] data[:user_tenant_membership][tenant_id] ||= {} data[:user_tenant_membership][tenant_id][user_id] ||= [] 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 end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/requests/get_user_by_id.rb0000644000004100000410000000151113423370527027167 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 = 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 end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/requests/list_users.rb0000644000004100000410000000230113423370527026376 0ustar www-datawww-datamodule Fog module OpenStack class Identity class V2 class Real def list_users(options = {}) if options.kind_of?(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 Mock def list_users(options = {}) tenant_id = options[:tenant_id] users = data[:users].values if tenant_id users = users.select do |user| user['tenantId'] == tenant_id end end Excon::Response.new( :body => {'users' => users}, :status => 200 ) end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/requests/list_roles_for_user_on_tenant.rb0000644000004100000410000000155213423370527032341 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end class Mock def list_roles_for_user_on_tenant(tenant_id, user_id) data[:user_tenant_membership][tenant_id] ||= {} data[:user_tenant_membership][tenant_id][user_id] ||= [] roles = data[:user_tenant_membership][tenant_id][user_id].map do |role_id| data[:roles][role_id] end Excon::Response.new( :body => {'roles' => roles}, :status => 200 ) end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/requests/list_ec2_credentials.rb0000644000004100000410000000356413423370527030277 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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.kind_of?(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 = {}) user_id = if options.kind_of?(Hash) options.delete(:user_id) else options end ec2_credentials = data[:ec2_credentials][user_id].values response = Excon::Response.new response.status = 200 response.body = {'credentials' => ec2_credentials} response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/requests/list_roles.rb0000644000004100000410000000144413423370527026370 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 data[:roles].empty? ['admin', 'Member'].each do |name| id = Fog::Mock.random_hex(32) data[:roles][id] = {'id' => id, 'name' => name} end end Excon::Response.new( :body => {'roles' => data[:roles].values}, :status => 200 ) end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/requests/list_user_global_roles.rb0000644000004100000410000000055713423370527030752 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/requests/get_tenants_by_id.rb0000644000004100000410000000055213423370527027671 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/requests/create_tenant.rb0000644000004100000410000000163113423370527027023 0ustar www-datawww-datamodule Fog module OpenStack class Identity class V2 class Real def create_tenant(attributes) request( :expects => [200], :method => 'POST', :path => "tenants", :body => Fog::JSON.encode('tenant' => attributes) ) end end class Mock def create_tenant(attributes) response = Excon::Response.new response.status = [200, 204][rand(2)] response.body = { 'tenant' => { 'id' => "df9a815161eba9b76cc748fd5c5af73e", 'description' => attributes[:description] || 'normal tenant', 'enabled' => true, 'name' => attributes[:name] || 'default' } } response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/requests/set_tenant.rb0000644000004100000410000000060213423370527026350 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/requests/delete_tenant.rb0000644000004100000410000000142413423370527027022 0ustar www-datawww-datamodule Fog module OpenStack class Identity class V2 class Real def delete_tenant(id) request( :expects => [200, 204], :method => 'DELETE', :path => "tenants/#{id}" ) end end class Mock def delete_tenant(_attributes) response = Excon::Response.new response.status = [200, 204][rand(2)] response.body = { 'tenant' => { 'id' => '1', 'description' => 'Has access to everything', 'enabled' => true, 'name' => 'admin' } } response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/requests/delete_ec2_credential.rb0000644000004100000410000000225113423370527030373 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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::OpenStack::Identity::NotFound unless data[:ec2_credentials][user_id][access] data[:ec2_credentials][user_id].delete access response = Excon::Response.new response.status = 204 response rescue end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/requests/check_token.rb0000644000004100000410000000075213423370527026467 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/requests/get_tenant.rb0000644000004100000410000000140113423370527026332 0ustar www-datawww-datamodule Fog module OpenStack class Identity class V2 class Real def get_tenant(id) request( :expects => [200, 204], :method => 'GET', :path => "tenants/#{id}" ) end end class Mock def get_tenant(id) response = Excon::Response.new response.status = [200, 204][rand(2)] response.body = { 'tenant' => { 'id' => id, 'description' => 'Has access to everything', 'enabled' => true, 'name' => 'admin' } } response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/requests/delete_role.rb0000644000004100000410000000125713423370527026476 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 data[:roles][role_id] data[:roles].delete(role_id) response.status = 204 response else raise Fog::OpenStack::Identity::NotFound end end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/requests/delete_user.rb0000644000004100000410000000127413423370527026512 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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) 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::OpenStack::Identity::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/requests/update_user.rb0000644000004100000410000000153713423370527026534 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 = data[:users][user_id] if options['name'] user['name'] = options['name'] end response.status = 200 response else raise Fog::OpenStack::Identity::NotFound end end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/requests/list_tenants.rb0000644000004100000410000000326113423370527026717 0ustar www-datawww-datamodule Fog module OpenStack class Identity class V2 class Real def list_tenants(options = nil, marker = nil) if options.kind_of?(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 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(2)] ) end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/requests/delete_user_role.rb0000644000004100000410000000112713423370527027530 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/requests/create_user.rb0000644000004100000410000000232013423370527026504 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/requests/get_role.rb0000644000004100000410000000124213423370527026005 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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::OpenStack::Identity::NotFound end end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/requests/get_tenants_by_name.rb0000644000004100000410000000054713423370527030221 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/requests/create_ec2_credential.rb0000644000004100000410000000333313423370527030376 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/requests/list_endpoints_for_token.rb0000644000004100000410000000057613423370527031322 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/requests/update_tenant.rb0000644000004100000410000000136213423370527027043 0ustar www-datawww-datamodule Fog module OpenStack class Identity class V2 class Real def update_tenant(id, attributes) request( :expects => [200], :method => 'PUT', :path => "tenants/#{id}", :body => Fog::JSON.encode('tenant' => attributes) ) end end class Mock def update_tenant(_id, attributes) response = Excon::Response.new response.status = [200, 204][rand(2)] attributes = {'enabled' => true, 'id' => '1'}.merge(attributes) response.body = { 'tenant' => attributes } response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/requests/get_user_by_name.rb0000644000004100000410000000122013423370527027510 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 = data[:users].values.select { |u| u['name'] == name }[0] response.body = { 'user' => user } response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/requests/create_role.rb0000644000004100000410000000150713423370527026475 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/requests/remove_user_from_tenant.rb0000644000004100000410000000100713423370527031133 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 Mock def remove_user_from_tenant(tenant_id, user_id, role_id) end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/requests/create_user_role.rb0000644000004100000410000000117113423370527027530 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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' => data[:roles][role_id]}, :status => 200 ) end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/requests/validate_token.rb0000644000004100000410000000075713423370527027210 0ustar www-datawww-datamodule Fog module OpenStack class Identity 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 end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/models/0000755000004100000410000000000013423370527023271 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/identity/v2/models/tenants.rb0000644000004100000410000000153513423370527025276 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/identity/v2/models/tenant' module Fog module OpenStack class Identity class V2 class Tenants < Fog::OpenStack::Collection model Fog::OpenStack::Identity::V2::Tenant def all(options = {}) load_response(service.list_tenants(options), 'tenants') end def find_by_id(id) cached_tenant = find { |tenant| tenant.id == id } return cached_tenant if cached_tenant tenant_hash = service.get_tenant(id).body['tenant'] Fog::OpenStack::Identity::V2::Tenant.new( tenant_hash.merge(:service => service) ) end def destroy(id) tenant = find_by_id(id) tenant.destroy end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/models/users.rb0000644000004100000410000000220113423370527024752 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/identity/v2/models/user' module Fog module OpenStack class Identity class V2 class Users < Fog::OpenStack::Collection model Fog::OpenStack::Identity::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) find { |user| user.id == id } || Fog::OpenStack::Identity::V2::User.new( service.get_user_by_id(id).body['user'].merge( 'service' => service ) ) end def find_by_name(name) find { |user| user.name == name } || Fog::OpenStack::Identity::V2::User.new( service.get_user_by_name(name).body['user'].merge( 'service' => service ) ) end def destroy(id) user = find_by_id(id) user.destroy end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/models/ec2_credentials.rb0000644000004100000410000000274713423370527026656 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/identity/v2/models/ec2_credential' module Fog module OpenStack class Identity class V2 class Ec2Credentials < Fog::OpenStack::Collection model Fog::OpenStack::Identity::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 attributes[:user_id] ||= user.id attributes[:tenant_id] ||= user.tenant_id end super attributes end def destroy(access_key) ec2_credential = 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 = find { |ec2_cred| ec2_cred.access == access_key } unless ec2_credential response = service.get_ec2_credential(user_id, access_key) body = response.body['credential'] body = body.merge 'service' => service ec2_credential = Fog::OpenStack::Identity::V2::EC2Credential.new(body) end ec2_credential end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/models/user.rb0000644000004100000410000000355313423370527024602 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Identity 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, '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) 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, id).body['roles'] else [] end end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/models/tenant.rb0000644000004100000410000000253713423370527025116 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Identity class V2 class Tenant < Fog::OpenStack::Model identity :id attribute :description attribute :enabled attribute :name def to_s name end def roles_for(user) service.roles( :tenant => self, :user => user ) end def users requires :id service.users(:tenant_id => id) end def destroy requires :id service.delete_tenant(id) true end def update(attr = nil) requires :id, :name merge_attributes( service.update_tenant(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(id, user_id, role_id) end def revoke_user_role(user_id, role_id) service.remove_user_from_tenant(id, user_id, role_id) end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/models/roles.rb0000644000004100000410000000073413423370527024746 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/identity/v2/models/role' module Fog module OpenStack class Identity class V2 class Roles < Fog::OpenStack::Collection model Fog::OpenStack::Identity::V2::Role def all(options = {}) load_response(service.list_roles(options), 'roles') end def get(id) service.get_role(id) end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2/models/ec2_credential.rb0000644000004100000410000000163513423370527026466 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Identity 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-1.0.8/lib/fog/openstack/identity/v2/models/role.rb0000644000004100000410000000240513423370527024560 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Identity 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(model_or_string) model_or_string.kind_of?(String) ? id : model_or_string.id end end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity/v2.rb0000644000004100000410000001434313423370527022340 0ustar www-datawww-datarequire 'fog/openstack/identity' module Fog module OpenStack class Identity 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_api_version, :no_path_prefix model_path 'fog/openstack/identity/v2/models' model :tenant collection :tenants model :user collection :users model :role collection :roles model :ec2_credential collection :ec2_credentials request_path 'fog/openstack/identity/v2/requests' 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 = data[:tenants].values.find do |u| u['name'] == 'admin' end if @openstack_tenant @current_tenant = data[:tenants].values.find do |u| u['name'] == @openstack_tenant end if @current_tenant @current_tenant_id = @current_tenant['id'] else @current_tenant_id = Fog::Mock.random_hex(32) @current_tenant = data[:tenants][@current_tenant_id] = { 'id' => @current_tenant_id, 'name' => @openstack_tenant } end else @current_tenant = @admin_tenant end @current_user = data[:users].values.find do |u| u['name'] == @openstack_username end @current_tenant_id = Fog::Mock.random_hex(32) if @current_user @current_user_id = @current_user['id'] else @current_user_id = Fog::Mock.random_hex(32) @current_user = 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 } 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::OpenStack::Identity::Real def api_path_prefix @path_prefix = version_in_path?(@openstack_management_uri.path) ? '' : 'v2.0' super end def default_path_prefix @path_prefix end def default_service_type %w[identity_v2 identityv2 identity] end def version_in_path?(url) true if url =~ /\/v2(\.0)*(\/)*.*$/ end end end end end end fog-openstack-1.0.8/lib/fog/openstack/models/0000755000004100000410000000000013423370527021111 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/models/model.rb0000644000004100000410000000311013423370527022531 0ustar www-datawww-datarequire '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-1.0.8/lib/fog/openstack/models/meta_parent.rb0000644000004100000410000000126313423370527023737 0ustar www-datawww-datamodule Fog module OpenStack class Compute module MetaParent def parent @parent end def parent=(new_parent) @parent = new_parent end def collection_name if @parent.class == Fog::OpenStack::Compute::Image return "images" elsif @parent.class == Fog::OpenStack::Compute::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-1.0.8/lib/fog/openstack/models/collection.rb0000644000004100000410000000331513423370527023573 0ustar www-datawww-datarequire '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-1.0.8/lib/fog/openstack/baremetal/0000755000004100000410000000000013423370527021562 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/baremetal/requests/0000755000004100000410000000000013423370527023435 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/baremetal/requests/list_ports_detailed.rb0000644000004100000410000000107213423370527030017 0ustar www-datawww-datamodule Fog module OpenStack class Baremetal class Real def list_ports_detailed(options = {}) request( :expects => [200, 204], :method => 'GET', :path => 'ports/detail', :query => options ) end end class Mock def list_ports_detailed(_options = {}) response = Excon::Response.new response.status = [200, 204][rand(2)] response.body = {"ports" => data[:ports]} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/baremetal/requests/create_port.rb0000644000004100000410000000246513423370527026300 0ustar www-datawww-datamodule Fog module OpenStack class Baremetal 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 = data[:ports].first response end end end end end fog-openstack-1.0.8/lib/fog/openstack/baremetal/requests/set_node_provision_state.rb0000644000004100000410000000204313423370527031071 0ustar www-datawww-datamodule Fog module OpenStack class Baremetal 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 = data[:nodes].first response end end end end end fog-openstack-1.0.8/lib/fog/openstack/baremetal/requests/patch_node.rb0000644000004100000410000000235213423370527026070 0ustar www-datawww-datamodule Fog module OpenStack class Baremetal 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 = data[:nodes].first response end end end end end fog-openstack-1.0.8/lib/fog/openstack/baremetal/requests/set_node_maintenance.rb0000644000004100000410000000150413423370527030124 0ustar www-datawww-datamodule Fog module OpenStack class Baremetal 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 end end end fog-openstack-1.0.8/lib/fog/openstack/baremetal/requests/list_nodes.rb0000644000004100000410000000152013423370527026123 0ustar www-datawww-datamodule Fog module OpenStack class Baremetal class Real def list_nodes(options = {}) request( :expects => [200, 204], :method => 'GET', :path => 'nodes', :query => options ) end end class Mock def list_nodes(_options = {}) response = Excon::Response.new response.status = [200, 204][rand(2)] response.body = { "nodes" => [{ "instance_uuid" => Fog::UUID.uuid, "maintenance" => false, "power_state" => "power on", "provision_state" => "active", "uuid" => Fog::UUID.uuid, "links" => [] }] } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/baremetal/requests/delete_chassis.rb0000644000004100000410000000105213423370527026737 0ustar www-datawww-datamodule Fog module OpenStack class Baremetal 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-1.0.8/lib/fog/openstack/baremetal/requests/patch_port.rb0000644000004100000410000000237613423370527026135 0ustar www-datawww-datamodule Fog module OpenStack class Baremetal 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 = data[:ports].first response end end end end end fog-openstack-1.0.8/lib/fog/openstack/baremetal/requests/create_node.rb0000644000004100000410000000347113423370527026237 0ustar www-datawww-datamodule Fog module OpenStack class Baremetal 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 = data[:nodes].first response end end end end end fog-openstack-1.0.8/lib/fog/openstack/baremetal/requests/list_chassis.rb0000644000004100000410000000215713423370527026457 0ustar www-datawww-datamodule Fog module OpenStack class Baremetal class Real def list_chassis(options = {}) request( :expects => [200, 204], :method => 'GET', :path => 'chassis', :query => options ) end end class Mock def list_chassis(_parameters = nil) response = Excon::Response.new response.status = [200, 204][rand(2)] 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 end end end end fog-openstack-1.0.8/lib/fog/openstack/baremetal/requests/delete_node.rb0000644000004100000410000000102713423370527026231 0ustar www-datawww-datamodule Fog module OpenStack class Baremetal 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-1.0.8/lib/fog/openstack/baremetal/requests/create_chassis.rb0000644000004100000410000000241113423370527026740 0ustar www-datawww-datamodule Fog module OpenStack class Baremetal 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 = data[:chassis_collection].first response end end end end end fog-openstack-1.0.8/lib/fog/openstack/baremetal/requests/get_port.rb0000644000004100000410000000076613423370527025616 0ustar www-datawww-datamodule Fog module OpenStack class Baremetal class Real def get_port(port_id) request( :expects => [200, 204], :method => 'GET', :path => "ports/#{port_id}" ) end end class Mock def get_port(_port_id) response = Excon::Response.new response.status = [200, 204][rand(2)] response.body = data[:ports].first response end end end end end fog-openstack-1.0.8/lib/fog/openstack/baremetal/requests/get_node.rb0000644000004100000410000000076613423370527025557 0ustar www-datawww-datamodule Fog module OpenStack class Baremetal class Real def get_node(node_id) request( :expects => [200, 204], :method => 'GET', :path => "nodes/#{node_id}" ) end end class Mock def get_node(_node_id) response = Excon::Response.new response.status = [200, 204][rand(2)] response.body = data[:nodes].first response end end end end end fog-openstack-1.0.8/lib/fog/openstack/baremetal/requests/get_chassis.rb0000644000004100000410000000103213423370527026252 0ustar www-datawww-datamodule Fog module OpenStack class Baremetal class Real def get_chassis(chassis_uuid) request( :expects => [200, 204], :method => 'GET', :path => "chassis/#{chassis_uuid}" ) end end class Mock def get_chassis(_chassis_uuid) response = Excon::Response.new response.status = [200, 204][rand(2)] response.body = data[:chassis_collection].first response end end end end end fog-openstack-1.0.8/lib/fog/openstack/baremetal/requests/delete_port.rb0000644000004100000410000000102613423370527026267 0ustar www-datawww-datamodule Fog module OpenStack class Baremetal 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-1.0.8/lib/fog/openstack/baremetal/requests/patch_chassis.rb0000644000004100000410000000241513423370527026600 0ustar www-datawww-datamodule Fog module OpenStack class Baremetal 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 = data[:chassis_collection].first response end end end end end fog-openstack-1.0.8/lib/fog/openstack/baremetal/requests/list_ports.rb0000644000004100000410000000212213423370527026161 0ustar www-datawww-datamodule Fog module OpenStack class Baremetal class Real def list_ports(options = {}) request( :expects => [200, 204], :method => 'GET', :path => 'ports', :query => options ) end end class Mock def list_ports(_options = {}) response = Excon::Response.new response.status = [200, 204][rand(2)] 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 end end end end fog-openstack-1.0.8/lib/fog/openstack/baremetal/requests/list_chassis_detailed.rb0000644000004100000410000000111713423370527030305 0ustar www-datawww-datamodule Fog module OpenStack class Baremetal class Real def list_chassis_detailed(options = {}) request( :expects => [200, 204], :method => 'GET', :path => 'chassis/detail', :query => options ) end end class Mock def list_chassis_detailed(_options = {}) response = Excon::Response.new response.status = [200, 204][rand(2)] response.body = {"chassis" => data[:chassis_collection]} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/baremetal/requests/get_driver_properties.rb0000644000004100000410000000314413423370527030372 0ustar www-datawww-datamodule Fog module OpenStack class Baremetal 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 Mock def get_driver_properties(_driver_name) response = Excon::Response.new response.status = [200, 204][rand(2)] 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 end end end end fog-openstack-1.0.8/lib/fog/openstack/baremetal/requests/unset_node_maintenance.rb0000644000004100000410000000151313423370527030467 0ustar www-datawww-datamodule Fog module OpenStack class Baremetal 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 end end end fog-openstack-1.0.8/lib/fog/openstack/baremetal/requests/set_node_power_state.rb0000644000004100000410000000164613423370527030205 0ustar www-datawww-datamodule Fog module OpenStack class Baremetal 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 = data[:nodes].first response end end end end end fog-openstack-1.0.8/lib/fog/openstack/baremetal/requests/get_driver.rb0000644000004100000410000000101213423370527026106 0ustar www-datawww-datamodule Fog module OpenStack class Baremetal class Real def get_driver(driver_name) request( :expects => [200, 204], :method => 'GET', :path => "drivers/#{driver_name}" ) end end class Mock def get_driver(_driver_name) response = Excon::Response.new response.status = [200, 204][rand(2)] response.body = data[:drivers].first response end end end end end fog-openstack-1.0.8/lib/fog/openstack/baremetal/requests/list_drivers.rb0000644000004100000410000000105313423370527026472 0ustar www-datawww-datamodule Fog module OpenStack class Baremetal class Real def list_drivers(options = {}) request( :expects => [200, 204], :method => 'GET', :path => 'drivers', :query => options ) end end class Mock def list_drivers(_options = {}) response = Excon::Response.new response.status = [200, 204][rand(2)] response.body = {"drivers" => data[:drivers]} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/baremetal/requests/list_nodes_detailed.rb0000644000004100000410000000107213423370527027760 0ustar www-datawww-datamodule Fog module OpenStack class Baremetal class Real def list_nodes_detailed(options = {}) request( :expects => [200, 204], :method => 'GET', :path => 'nodes/detail', :query => options ) end end class Mock def list_nodes_detailed(_options = {}) response = Excon::Response.new response.status = [200, 204][rand(2)] response.body = {"nodes" => data[:nodes]} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/baremetal/models/0000755000004100000410000000000013423370527023045 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/baremetal/models/driver.rb0000644000004100000410000000067613423370527024676 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Baremetal class Driver < Fog::OpenStack::Model identity :name attribute :name attribute :hosts def properties requires :name service.get_driver_properties(name).body end def metadata requires :name service.get_driver(name).headers end end end end end fog-openstack-1.0.8/lib/fog/openstack/baremetal/models/chassis_collection.rb0000644000004100000410000000234713423370527027250 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/baremetal/models/chassis' module Fog module OpenStack class Baremetal class ChassisCollection < Fog::OpenStack::Collection model Fog::OpenStack::Baremetal::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 get find_by_uuid def destroy(uuid) chassis = 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-1.0.8/lib/fog/openstack/baremetal/models/drivers.rb0000644000004100000410000000075713423370527025061 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/baremetal/models/driver' module Fog module OpenStack class Baremetal class Drivers < Fog::OpenStack::Collection model Fog::OpenStack::Baremetal::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 get find_by_name end end end end fog-openstack-1.0.8/lib/fog/openstack/baremetal/models/chassis.rb0000644000004100000410000000226713423370527025036 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Baremetal 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(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(uuid) true end def metadata requires :uuid service.get_chassis(uuid).headers end end end end end fog-openstack-1.0.8/lib/fog/openstack/baremetal/models/node.rb0000644000004100000410000000475213423370527024327 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Baremetal 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(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(uuid) true end def chassis requires :uuid service.get_chassis(chassis_uuid).body end def ports requires :uuid service.list_ports_detailed(:node_uuid => 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(uuid).headers end def set_power_state(power_state) requires :uuid service.set_node_power_state(uuid, power_state) end def set_provision_state(provision_state) requires :uuid service.set_node_provision_state(uuid, provision_state) end end end end end fog-openstack-1.0.8/lib/fog/openstack/baremetal/models/port.rb0000644000004100000410000000232113423370527024354 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Baremetal 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(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(uuid) true end def metadata requires :uuid service.get_port(uuid).headers end end end end end fog-openstack-1.0.8/lib/fog/openstack/baremetal/models/ports.rb0000644000004100000410000000232213423370527024540 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/baremetal/models/port' module Fog module OpenStack class Baremetal class Ports < Fog::OpenStack::Collection model Fog::OpenStack::Baremetal::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 get find_by_uuid def destroy(uuid) port = 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-1.0.8/lib/fog/openstack/baremetal/models/nodes.rb0000644000004100000410000000232413423370527024503 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/baremetal/models/node' module Fog module OpenStack class Baremetal class Nodes < Fog::OpenStack::Collection model Fog::OpenStack::Baremetal::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 get find_by_uuid def destroy(uuid) node = 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-1.0.8/lib/fog/openstack/dns.rb0000644000004100000410000000127113423370527020740 0ustar www-datawww-datamodule Fog module OpenStack class DNS < Fog::Service autoload :V1, 'fog/openstack/dns/v1' autoload :V2, 'fog/openstack/dns/v2' # Fog::OpenStack::DNS.new() will return a Fog::OpenStack::DNS::V2 or a Fog::OpenStack::DNS::V1, # choosing the latest available def self.new(args = {}) @openstack_auth_uri = URI.parse(args[:openstack_auth_url]) if args[:openstack_auth_url] if inspect == 'Fog::OpenStack::DNS' service = Fog::OpenStack::DNS::V2.new(args) unless args.empty? service ||= Fog::OpenStack::DNS::V1.new(args) else service = Fog::Service.new(args) end service end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/0000755000004100000410000000000013423370527020412 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/dns/v2/0000755000004100000410000000000013423370527020741 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/dns/v2/requests/0000755000004100000410000000000013423370527022614 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/dns/v2/requests/list_zone_transfer_requests.rb0000644000004100000410000000121713423370527031007 0ustar www-datawww-datamodule Fog module OpenStack class DNS class V2 class Real def list_zone_transfer_requests(options={}) request( :expects => 200, :method => 'GET', :path => "zones/tasks/transfer_requests", :query => options ) end end class Mock def list_zone_transfer_requests(options={}) response = Excon::Response.new response.status = 200 response.body = data[:zone_transfer_requests]["transfer_requests"] response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v2/requests/delete_zone_transfer_request.rb0000644000004100000410000000113313423370527031110 0ustar www-datawww-data module Fog module OpenStack class DNS class V2 class Real def delete_zone_transfer_request(zone_transfer_request_id) request( :expects => 204, :method => 'DELETE', :path => "zones/tasks/transfer_requests/#{zone_transfer_request_id}" ) end end class Mock def delete_zone_transfer_request(zone_transfer_request_id) response = Excon::Response.new response.status = 204 response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v2/requests/list_zones.rb0000644000004100000410000000126313423370527025334 0ustar www-datawww-datamodule Fog module OpenStack class DNS class V2 class Real def list_zones(options = {}) headers, options = Fog::OpenStack::DNS::V2.setup_headers(options) request( :expects => 200, :method => 'GET', :path => 'zones', :query => options, :headers => headers ) end end class Mock def list_zones(_options = {}) response = Excon::Response.new response.status = 200 response.body = {'zones' => data[:zones]} response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v2/requests/get_recordset.rb0000644000004100000410000000210013423370527025763 0ustar www-datawww-datamodule Fog module OpenStack class DNS class V2 class Real def get_recordset(zone_id, id, options = {}) headers, _options = Fog::OpenStack::DNS::V2.setup_headers(options) request( :expects => 200, :method => 'GET', :path => "zones/#{zone_id}/recordsets/#{id}", :headers => headers ) end end class Mock def get_recordset(zone_id, id) response = Excon::Response.new response.status = 200 recordset = data[:recordset_updated] || data[:recordsets]["recordsets"].first recordset["zone_id"] = zone_id recordset["id"] = id recordset["action"] = "NONE" recordset["status"] = "ACTIVE" recordset["links"]["self"] = "https://127.0.0.1:9001/v2/zones/#{zone_id}/recordsets/#{id}" response.body = recordset response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v2/requests/get_zone_transfer_request.rb0000644000004100000410000000137213423370527030432 0ustar www-datawww-data module Fog module OpenStack class DNS class V2 class Real def get_zone_transfer_request(zone_transfer_request_id) request( :expects => 200, :method => 'GET', :path => "zones/tasks/transfer_requests/#{zone_transfer_request_id}" ) end end class Mock def get_zone_transfer_request(zone_transfer_request_id) response = Excon::Response.new response.status = 200 request = data[:zone_transfer_requests]["transfer_requests"].first request["id"] = zone_transfer_request_id response.body = request response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v2/requests/delete_zone.rb0000644000004100000410000000166013423370527025441 0ustar www-datawww-datamodule Fog module OpenStack class DNS class V2 class Real def delete_zone(id, options = {}) headers, _options = Fog::OpenStack::DNS::V2.setup_headers(options) request( :expects => 202, :method => 'DELETE', :path => "zones/#{id}", :headers => headers ) end end class Mock def delete_zone(id, _options = {}) response = Excon::Response.new response.status = 202 zone = data[:zone_updated] || data[:zones].first.dup zone["id"] = id zone["status"] = "PENDING" zone["action"] = "DELETE" zone["links"]["self"] = "https://127.0.0.1:9001/v2/zones/#{id}" response.body = zone response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v2/requests/list_pools.rb0000644000004100000410000000124613423370527025333 0ustar www-datawww-datamodule Fog module OpenStack class DNS class V2 class Real def list_pools(options = {}) headers, options = Fog::OpenStack::DNS::V2.setup_headers(options) request( :expects => 200, :method => 'GET', :path => 'pools', :query => options, :headers => headers ) end end class Mock def list_pools(_options = {}) response = Excon::Response.new response.status = 200 response.body = data[:pools] response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v2/requests/update_quota.rb0000644000004100000410000000161113423370527025633 0ustar www-datawww-datamodule Fog module OpenStack class DNS class V2 class Real def update_quota(project_id, options = {}) headers, options = Fog::OpenStack::DNS::V2.setup_headers(options) request( :body => Fog::JSON.encode(options), :expects => 200, :method => 'PATCH', :path => "quotas/#{project_id}", :headers => headers ) end end class Mock def update_quota(_project_id, options = {}) # stringify keys options = Hash[options.map { |k, v| [k.to_s, v] }] data[:quota_updated] = data[:quota].merge(options) response = Excon::Response.new response.status = 200 response.body = data[:quota_updated] response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v2/requests/list_zone_transfer_accepts.rb0000644000004100000410000000121213423370527030551 0ustar www-datawww-datamodule Fog module OpenStack class DNS class V2 class Real def list_zone_transfer_accepts(options={}) request( :expects => 200, :method => 'GET', :path => "zones/tasks/transfer_accepts", :query => options ) end end class Mock def list_zone_transfer_accepts(options={}) response = Excon::Response.new response.status = 200 response.body = data[:zone_transfer_accepts]["transfer_accepts"] response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v2/requests/create_recordset.rb0000644000004100000410000000310713423370527026457 0ustar www-datawww-datamodule Fog module OpenStack class DNS class V2 class Real def create_recordset(zone_id, name, type, records, options = {}) data = { 'name' => name, 'type' => type, 'records' => records } vanilla_options = [:ttl, :description] vanilla_options.select { |o| options[o] }.each do |key| data[key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => 202, :method => 'POST', :path => "zones/#{zone_id}/recordsets" ) end end class Mock def create_recordset(zone_id, name, type, records, options = {}) # stringify keys options = Hash[options.map { |k, v| [k.to_s, v] }] response = Excon::Response.new response.status = 202 recordset = data[:recordsets]["recordsets"].first.dup recordset_id = recordset["id"] recordset["zone_id"] = zone_id recordset["name"] = name recordset["type"] = type recordset["records"] = records recordset["status"] = "PENDING" recordset["action"] = "CREATE" recordset["links"]["self"] = "https://127.0.0.1:9001/v2/zones/#{zone_id}/recordsets/#{recordset_id}" response.body = recordset.merge(options) response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v2/requests/update_zone.rb0000644000004100000410000000221513423370527025456 0ustar www-datawww-datamodule Fog module OpenStack class DNS class V2 class Real def update_zone(id, options = {}) headers, options = Fog::OpenStack::DNS::V2.setup_headers(options) request( :body => Fog::JSON.encode(options), :expects => 202, :method => 'PATCH', :path => "zones/#{id}", :headers => headers ) end end class Mock def update_zone(id, options = {}) # stringify keys options = Hash[options.map { |k, v| [k.to_s, v] }] data[:zone_updated] = data[:zones].first.merge(options) data[:zone_updated]["id"] = id data[:zone_updated]["status"] = "PENDING" data[:zone_updated]["action"] = "UPDATE" data[:zone_updated]["links"]["self"] = "https://127.0.0.1:9001/v2/zones/#{id}" response = Excon::Response.new response.status = 202 response.body = data[:zone_updated] response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v2/requests/get_zone_transfer_accept.rb0000644000004100000410000000135613423370527030203 0ustar www-datawww-datamodule Fog module OpenStack class DNS class V2 class Real def get_zone_transfer_accept(zone_transfer_accept_id) request( :expects => 200, :method => 'GET', :path => "zones/tasks/transfer_requests/#{zone_transfer_accept_id}" ) end end class Mock def get_zone_transfer_accept(zone_transfer_accept_id) response = Excon::Response.new response.status = 200 accept = data[:zone_transfer_accepts]["transfer_accepts"].first accept["id"] = zone_transfer_accept_id response.body = accept response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v2/requests/list_recordsets.rb0000644000004100000410000000313513423370527026353 0ustar www-datawww-datamodule Fog module OpenStack class DNS class V2 class Real def list_recordsets(zone_id = nil, options = {}) # for backward compatability: consider removing the zone_id param (breaking change) unless zone_id.nil? if zone_id.kind_of?(Hash) options = zone_id zone_id = nil else Fog::Logger.deprecation( 'Calling list_recordsets(zone_id) is deprecated, use .list_recordsets(zone_id: value) instead' ) end end zone_id = options.delete(:zone_id) if zone_id.nil? path = zone_id.nil? ? 'recordsets' : "zones/#{zone_id}/recordsets" headers, options = Fog::OpenStack::DNS::V2.setup_headers(options) request( :expects => 200, :method => 'GET', :path => path, :query => options, :headers => headers ) end end class Mock def list_recordsets(zone_id = nil, options = {}) if zone_id.kind_of?(Hash) options = zone_id zone_id = nil end zone_id = options.delete(:zone_id) if zone_id.nil? response = Excon::Response.new response.status = 200 data[:recordsets]["recordsets"].each do |rs| rs["zone_id"] = zone_id unless zone_id.nil? end response.body = data[:recordsets] response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v2/requests/create_zone_transfer_accept.rb0000644000004100000410000000171413423370527030665 0ustar www-datawww-datamodule Fog module OpenStack class DNS class V2 class Real def create_zone_transfer_accept(key, zone_transfer_request_id, options = {}) data = { :key => key, :zone_transfer_request_id => zone_transfer_request_id } headers, _options = Fog::OpenStack::DNS::V2.setup_headers(options) request( :headers => headers, :body => Fog::JSON.encode(data), :expects => 200, :method => 'POST', :path => "zones/tasks/transfer_accepts" ) end end class Mock def create_zone_transfer_accept(key, zone_transfer_request_id) response = Excon::Response.new response.status = 200 response.body = data[:zone_transfer_accepts]["transfer_accepts"].first response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v2/requests/update_zone_transfer_request.rb0000644000004100000410000000214113423370527031130 0ustar www-datawww-datamodule Fog module OpenStack class DNS class V2 class Real def update_zone_transfer_request(zone_transfer_request_id,description,options={}) vanilla_options = [:target_project_id] data = vanilla_options.inject({}) do |result,option| result[option] = options[option] if options[option] result end request( :expects => 200, :method => 'PATCH', :path => "zones/tasks/transfer_requests/#{zone_transfer_request_id}", :body => Fog::JSON.encode(data) ) end end class Mock def update_zone_transfer_request(zone_transfer_request_id,description,options={}) response = Excon::Response.new response.status = 200 request = data[:zone_transfer_requests]["transfer_requests"] request.id = zone_transfer_request_id request.description =description response.body = request response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v2/requests/get_zone.rb0000644000004100000410000000133613423370527024756 0ustar www-datawww-datamodule Fog module OpenStack class DNS class V2 class Real def get_zone(id, options = {}) headers, _options = Fog::OpenStack::DNS::V2.setup_headers(options) request( :expects => 200, :method => 'GET', :path => "zones/#{id}", :headers => headers ) end end class Mock def get_zone(id, _options = {}) response = Excon::Response.new response.status = 200 zone = data[:zone_updated] || data[:zones].first zone["id"] = id response.body = zone response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v2/requests/get_quota.rb0000644000004100000410000000131313423370527025127 0ustar www-datawww-datamodule Fog module OpenStack class DNS class V2 class Real def get_quota(project_id = nil) headers, _options = Fog::OpenStack::DNS::V2.setup_headers(:all_projects => !project_id.nil?) request( :expects => 200, :method => 'GET', :path => "quotas/#{project_id}", :headers => headers ) end end class Mock def get_quota(_project_id = nil) response = Excon::Response.new response.status = 200 response.body = data[:quota_updated] || data[:quota] response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v2/requests/get_pool.rb0000644000004100000410000000134713423370527024756 0ustar www-datawww-datamodule Fog module OpenStack class DNS class V2 class Real def get_pool(id, options = {}) headers, _options = Fog::OpenStack::DNS::V2.setup_headers(options) request( :expects => 200, :method => 'GET', :path => "pools/#{id}", :headers => headers ) end end class Mock def get_pool(id, _options = {}) response = Excon::Response.new response.status = 200 pool = data[:pool_updated] || data[:pools]['pools'].first pool['id'] = id response.body = pool response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v2/requests/delete_recordset.rb0000644000004100000410000000213713423370527026460 0ustar www-datawww-datamodule Fog module OpenStack class DNS class V2 class Real def delete_recordset(zone_id, id, options = {}) headers, _options = Fog::OpenStack::DNS::V2.setup_headers(options) request( :expects => 202, :method => 'DELETE', :path => "zones/#{zone_id}/recordsets/#{id}", :headers => headers ) end end class Mock def delete_recordset(zone_id, id, _options = {}) response = Excon::Response.new response.status = 202 recordset = data[:recordset_updated] || data[:recordsets]["recordsets"].first.dup recordset["zone_id"] = zone_id recordset["id"] = id recordset["status"] = "PENDING" recordset["action"] = "DELETE" recordset["links"]["self"] = "https://127.0.0.1:9001/v2/zones/#{zone_id}/recordsets/#{id}" response.body = recordset response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v2/requests/update_recordset.rb0000644000004100000410000000250413423370527026476 0ustar www-datawww-datamodule Fog module OpenStack class DNS class V2 class Real def update_recordset(zone_id, id, options = {}) headers, options = Fog::OpenStack::DNS::V2.setup_headers(options) request( :body => Fog::JSON.encode(options), :expects => 202, :method => 'PUT', :path => "zones/#{zone_id}/recordsets/#{id}", :headers => headers ) end end class Mock def update_recordset(zone_id, id, options = {}) # stringify keys options = Hash[options.map { |k, v| [k.to_s, v] }] data[:recordset_updated] = data[:recordsets]["recordsets"].first.merge(options) data[:recordset_updated]["zone_id"] = zone_id data[:recordset_updated]["id"] = id data[:recordset_updated]["status"] = "PENDING" data[:recordset_updated]["action"] = "UPDATE" data[:recordset_updated]["links"]["self"] = "https://127.0.0.1:9001/v2/zones/#{zone_id}/recordsets/#{id}" response = Excon::Response.new response.status = 202 response.body = data[:recordset_updated] response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v2/requests/create_zone_transfer_request.rb0000644000004100000410000000170013423370527031111 0ustar www-datawww-data module Fog module OpenStack class DNS class V2 class Real def create_zone_transfer_request(zone_id, options = {}) vanilla_options = [:target_project_id, :description, :project_id] data = vanilla_options.inject({}) do |result,option| result[option] = options[option] if options[option] result end request( :body => Fog::JSON.encode(data), :expects => 201, :method => 'POST', :path => "zones/#{zone_id}/tasks/transfer_requests" ) end end class Mock def create_zone_transfer_request(zone_id, options = {}) response = Excon::Response.new response.status = 201 response.body = data[:zone_transfer_requests]["transfer_requests"].first response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v2/requests/create_zone.rb0000644000004100000410000000231613423370527025441 0ustar www-datawww-datamodule Fog module OpenStack class DNS class V2 class Real def create_zone(name, email, options = {}) data = { 'name' => name, 'email' => email } vanilla_options = [:ttl, :description, :type, :masters, :attributes] vanilla_options.select { |o| options[o] }.each do |key| data[key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => 202, :method => 'POST', :path => "zones" ) end end class Mock def create_zone(name, email, options = {}) # stringify keys options = Hash[options.map { |k, v| [k.to_s, v] }] response = Excon::Response.new response.status = 202 zone = data[:zones].first.dup zone["name"] = name zone["email"] = email zone["status"] = "PENDING" zone["action"] = "CREATE" response.body = zone.merge(options) response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v2/models/0000755000004100000410000000000013423370527022224 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/dns/v2/models/recordset.rb0000644000004100000410000000277013423370527024551 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class DNS class V2 class Recordset < Fog::OpenStack::Model identity :id attribute :name attribute :project_id attribute :status attribute :action attribute :zone_id attribute :zone_name attribute :type attribute :records attribute :version attribute :created_at attribute :links attribute :ttl attribute :description attribute :updated_at def save raise Fog::Errors::Error, 'Resaving an existing object may create a duplicate' if persisted? requires :zone_id, :name, :type, :records merge_attributes(service.create_recordset(zone_id, name, type, records, attributes).body) true end # overwritten because zone_id is needed for get def reload(options = {}) requires :zone_id, :id merge_attributes(collection.get(zone_id, id, options).attributes) self end def update(options = nil) requires :zone_id, :id merge_attributes(service.update_recordset(zone_id, id, options || attributes).body) self end def destroy(options = {}) requires :zone_id, :id service.delete_recordset(zone_id, id, options) true end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v2/models/zone_transfer_requests.rb0000644000004100000410000000143613423370527027367 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/dns/v2/models/zone_transfer_request' module Fog module OpenStack class DNS class V2 class ZoneTransferRequests < Fog::OpenStack::Collection model Fog::OpenStack::DNS::V2::ZoneTransferRequest def all(options = {}) load_response(service.list_zone_transfer_requests(options), 'transfer_requests') end def find_by_id(id) zone_transfer_request_hash = service.get_zone_transfer_request(id).body new(zone_transfer_request_hash.merge(:service => service)) end alias get find_by_id def destroy(id) zone = find_by_id(id) zone.destroy end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v2/models/zone.rb0000644000004100000410000000234713423370527023532 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class DNS class V2 class Zone < Fog::OpenStack::Model identity :id attribute :name attribute :email attribute :pool_id attribute :project_id attribute :serial attribute :status attribute :action attribute :masters attribute :version attribute :links attribute :created_at attribute :transfered_at attribute :ttl attribute :description attribute :type attribute :updated_at def save raise Fog::Errors::Error, 'Resaving an existing object may create a duplicate' if persisted? requires :name, :email merge_attributes(service.create_zone(name, email, attributes).body) true end def update(options = nil) requires :id merge_attributes(service.update_zone(id, options || attributes).body) self end def destroy(options = {}) requires :id service.delete_zone(id, options) true end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v2/models/zone_transfer_accepts.rb0000644000004100000410000000126213423370527027133 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/dns/v2/models/zone_transfer_accept' module Fog module OpenStack class DNS class V2 class ZoneTransferAccepts < Fog::OpenStack::Collection model Fog::OpenStack::DNS::V2::ZoneTransferAccept def all(options = {}) load_response(service.list_zone_transfer_accepts(options), 'transfer_accepts') end def find_by_id(id) zone_transfer_accept_hash = service.get_zone_transfer_accept(id).body new(zone_transfer_accept_hash.merge(:service => service)) end alias get find_by_id end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v2/models/pools.rb0000644000004100000410000000112213423370527023701 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/dns/v2/models/pool' module Fog module OpenStack class DNS class V2 class Pools < Fog::OpenStack::Collection model Fog::OpenStack::DNS::V2::Pool def all(options = {}) load_response(service.list_pools(options), 'pools') end def find_by_id(id, options = {}) pool_hash = service.get_pool(id, options).body new(pool_hash.merge(:service => service)) end alias get find_by_id end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v2/models/zone_transfer_request.rb0000644000004100000410000000253613423370527027206 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class DNS class V2 class ZoneTransferRequest < Fog::OpenStack::Model identity :id attribute :project_id attribute :description attribute :status attribute :zone_id attribute :zone_name attribute :key attribute :target_project_id attribute :created_at attribute :updated_at attribute :version def save if persisted? update(description: description, target_project_id: target_project_id) else merge_attributes(ervice.create_zone_transfer_request(zone_id, { :target_project_id => target_project_id, :description => description, :project_id => project_id })) end true end def update(options = nil) requires :id merge_attributes(ervice.update_zone_transfer_request(id,options[:description],{ :target_project_id => options[:target_project_id] })) self end def destroy(options = {}) requires :id service.delete_zone_transfer_request(id) true end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v2/models/zone_transfer_accept.rb0000644000004100000410000000123113423370527026744 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class DNS class V2 class ZoneTransferAccept < Fog::OpenStack::Model identity :id attribute :status attribute :project_id attribute :zone_id attribute :key attribute :created_at attribute :updated_at attribute :zone_transfer_request_id attribute :links def save unless persisted? merge_attributes(service.create_zone_transfer_accept(key, zone_transfer_request_id)) end true end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v2/models/zones.rb0000644000004100000410000000131513423370527023707 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/dns/v2/models/zone' module Fog module OpenStack class DNS class V2 class Zones < Fog::OpenStack::Collection model Fog::OpenStack::DNS::V2::Zone def all(options = {}) load_response(service.list_zones(options), 'zones') end def find_by_id(id, options = {}) zone_hash = service.get_zone(id, options).body new(zone_hash.merge(:service => service)) end alias get find_by_id def destroy(id, options = {}) zone = find_by_id(id, options) zone.destroy end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v2/models/recordsets.rb0000644000004100000410000000144313423370527024730 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/dns/v2/models/recordset' module Fog module OpenStack class DNS class V2 class Recordsets < Fog::OpenStack::Collection model Fog::OpenStack::DNS::V2::Recordset def all(options = {}) load_response(service.list_recordsets(options), 'recordsets') end def find_by_id(zone_id, id, options = {}) recordset_hash = service.get_recordset(zone_id, id, options).body new(recordset_hash.merge(:service => service)) end alias get find_by_id def destroy(zone_id, id, options = {}) recordset = find_by_id(zone_id, id, options) recordset.destroy end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v2/models/pool.rb0000644000004100000410000000064213423370527023524 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class DNS class V2 class Pool < Fog::OpenStack::Model identity :id attribute :name attribute :description attribute :ns_records attribute :project_id attribute :links attribute :created_at attribute :updated_at end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v1/0000755000004100000410000000000013423370527020740 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/dns/v1/requests/0000755000004100000410000000000013423370527022613 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/dns/v1/requests/list_domains.rb0000644000004100000410000000111313423370527025621 0ustar www-datawww-datamodule Fog module OpenStack class DNS class V1 class Real def list_domains(options = {}) request( :expects => 200, :method => 'GET', :path => 'domains', :query => options ) end end class Mock def list_domains(_options = {}) response = Excon::Response.new response.status = 200 response.body = {'domains' => data[:domains]} response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v1/requests/update_quota.rb0000644000004100000410000000142513423370527025635 0ustar www-datawww-datamodule Fog module OpenStack class DNS class V1 class Real def update_quota(project_id, options = {}) request( :body => Fog::JSON.encode(options), :expects => 200, :method => 'PUT', :path => "quotas/#{project_id}" ) end end class Mock def update_quota(_project_id, options = {}) # stringify keys options = Hash[options.map { |k, v| [k.to_s, v] }] data[:quota_updated] = data[:quota].merge(options) response = Excon::Response.new response.status = 200 response.body = data[:quota_updated] response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v1/requests/get_quota.rb0000644000004100000410000000106213423370527025127 0ustar www-datawww-datamodule Fog module OpenStack class DNS class V1 class Real def get_quota(project_id) request( :expects => 200, :method => 'GET', :path => "quotas/#{project_id}" ) end end class Mock def get_quota(_project_id) response = Excon::Response.new response.status = 200 response.body = data[:quota_updated] || data[:quota] response end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v1.rb0000644000004100000410000000774713423370527021304 0ustar www-datawww-datarequire 'fog/openstack/dns' module Fog module OpenStack class DNS class V1 < 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_project_domain, :openstack_user_domain, :openstack_domain_name, :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id, :openstack_identity_api_version, :openstack_temp_url_key, :openstack_cache_ttl request_path 'fog/openstack/dns/v1/requests' request :list_domains request :get_quota request :update_quota class Mock def self.data @data ||= Hash.new do |hash, key| hash[key] = { :domains => [{ "id" => "a86dba58-0043-4cc6-a1bb-69d5e86f3ca3", "name" => "example.org.", "email" => "joe@example.org", "ttl" => 7200, "serial" => 1_404_757_531, "description" => "This is an example zone.", "created_at" => "2014-07-07T18:25:31.275934", "updated_at" => '' }], :quota => { "api_export_size" => 1000, "recordset_records" => 20, "domain_records" => 500, "domain_recordsets" => 500, "domains" => 100 } } 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 = 9001 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::OpenStack::DNS::NotFound end def default_path_prefix 'v1' end def default_service_type %w[dns] end end end end end end fog-openstack-1.0.8/lib/fog/openstack/dns/v2.rb0000644000004100000410000003244213423370527021273 0ustar www-datawww-datarequire 'fog/openstack/dns' module Fog module OpenStack class DNS class V2 < 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_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_project_domain, :openstack_user_domain, :openstack_domain_name, :openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id, :openstack_identity_api_version, :openstack_temp_url_key, :openstack_cache_ttl model_path 'fog/openstack/dns/v2/models' model :zone collection :zones model :recordset collection :recordsets model :pool collection :pools model :zone_transfer_request collection :zone_transfer_requests model :zone_transfer_accept collection :zone_transfer_accepts request_path 'fog/openstack/dns/v2/requests' request :list_zones request :get_zone request :create_zone request :update_zone request :delete_zone request :list_recordsets request :get_recordset request :create_recordset request :update_recordset request :delete_recordset request :list_pools request :get_pool request :get_quota request :update_quota request :create_zone_transfer_request request :get_zone_transfer_request request :list_zone_transfer_requests request :update_zone_transfer_request request :delete_zone_transfer_request request :create_zone_transfer_accept request :get_zone_transfer_accept request :list_zone_transfer_accepts def self.setup_headers(options) # user needs to have admin privileges to ask for all projects all_projects = options.delete(:all_projects) || false # user needs to have admin privileges to impersonate another project # don't ask for all and one project at the same time project_id = options.delete(:project_id) unless all_projects headers = {'X-Auth-All-Projects' => all_projects} headers['X-Auth-Sudo-Project-Id'] = project_id unless project_id.nil? [headers, options] end class Mock def self.data @data ||= Hash.new do |hash, key| hash[key] = { :zones => [{ "id" => "a86dba58-0043-4cc6-a1bb-69d5e86f3ca3", "pool_id" => "572ba08c-d929-4c70-8e42-03824bb24ca2", "project_id" => "4335d1f0-f793-11e2-b778-0800200c9a66", "name" => "example.org.", "email" => "joe@example.org", "ttl" => 7200, "serial" => 1_404_757_531, "status" => "ACTIVE", "action" => "NONE", "description" => "This is an example zone.", "masters" => [], "type" => "PRIMARY", "transferred_at" => '', "version" => 1, "created_at" => "2014-07-07T18:25:31.275934", "updated_at" => '', "links" => { "self" => "https://127.0.0.1:9001/v2/zones/a86dba58-0043-4cc6-a1bb-69d5e86f3ca3" } }], :pools => { "metadata" => { "total_count" => 2 }, "links" => { "self" => "http://127.0.0.1:9001/v2/pools" }, "pools" => [ { "description" => '', "id" => "794ccc2c-d751-44fe-b57f-8894c9f5c842", "project_id" => '', "created_at" => "2015-02-18T22:18:58.000000", "attributes" => '', "ns_records" => [ { "hostname" => "ns1.example.org.", "priority" => 1 } ], "links" => { "self" => "http://127.0.0.1:9001/v2/pools/794ccc2c-d751-44fe-b57f-8894c9f5c842" }, "name" => "default", "updated_at" => "2015-02-19T15:59:44.000000" }, { "description" => '', "id" => "d1716333-8c16-490f-85ee-29af36907605", "project_id" => "noauth-project", "created_at" => "2015-02-23T21:56:33.000000", "attributes" => '', "ns_records" => [ { "hostname" => "ns2.example.org.", "priority" => 1 } ], "links" => { "self" => "http://127.0.0.1:9001/v2/pools/d1716333-8c16-490f-85ee-29af36907605" }, "name" => "example_pool", "updated_at" => '' } ] }, :quota => { "api_export_size" => 1000, "recordset_records" => 20, "zone_records" => 500, "zone_recordsets" => 500, "zones" => 100 }, :recordsets => { "recordsets" => [{ "description" => "This is an example record set.", "links" => { "self" => "https://127.0.0.1:9001/v2/zones/2150b1bf-dee2-4221-9d85-11f7886fb15f/recordsets/f7b10e9b-0cae-4a91-b162-562bc6096648" }, "updated_at" => '', "records" => [ "10.1.0.2" ], "ttl" => 3600, "id" => "f7b10e9b-0cae-4a91-b162-562bc6096648", "name" => "example.org.", "project_id" => "4335d1f0-f793-11e2-b778-0800200c9a66", "zone_id" => "2150b1bf-dee2-4221-9d85-11f7886fb15f", "zone_name" => "example.com.", "created_at" => "2014-10-24T19:59:44.000000", "version" => 1, "type" => "A", "status" => "ACTIVE", "action" => "NONE" }], "links" => { "self" => "http://127.0.0.1:9001/v2/recordsets?limit=1", "next" => "http://127.0.0.1:9001/v2/recordsets?limit=1&marker=45fd892d-7a67-4f65-9df0-87273f228d6c" }, "metadata" => { "total_count" => 2 } }, :zone_transfer_requests => { "transfer_requests" => [ { "created_at" => "2014-07-17T20:34:40.882579", "description" => "This was created by the requesting project", "id" => "f2ad17b5-807a-423f-a991-e06236c247be", "key" => "9Z2R50Y0", "project_id" => "1", "status" => "ACTIVE", "target_project_id" => "123456", "updated_at" => nil, "zone_id" => "6b78734a-aef1-45cd-9708-8eb3c2d26ff8", "zone_name" => "qa.dev.example.com.", "links" => { "self" => "http://127.0.0.1:9001/v2/zones/tasks/transfer_requests/f2ad17b5-807a-423f-a991-e06236c247be" } }, { "description" => "This is scoped to the requesting project", "id" => "efd2d720-b0c4-43d4-99f7-d9b53e08860d", "zone_id" => "2c4d5e37-f823-4bee-9859-031cb44f80e7", "zone_name" => "subdomain.example.com.", "status" => "ACTIVE", "links" => { "self" => "http://127.0.0.1:9001/v2/zones/tasks/transfer_requests/efd2d720-b0c4-43d4-99f7-d9b53e08860d" } } ], "links" => { "self" => "http://127.0.0.1:9001/v2/zones/tasks/transfer_requests" } }, :zone_transfer_accepts => { "metadata" => { "total_count" => 2 }, "links" => { "self" => "http://127.0.0.1:9001/v2/zones/tasks/transfer_accepts" }, "transfer_accepts" => [ { "status" => "COMPLETE", "zone_id" => "8db93d1a-59e3-4143-a393-5821abea0a46", "links" => { "self" => "http://127.0.0.1:9001/v2/zones/tasks/transfer_accepts/afb4222b-18b3-44b3-9f54-e0dfdba1be44", "zone" => "http://127.0.0.1:9001/v2/zones/8db93d1a-59e3-4143-a393-5821abea0a46" }, "created_at" => "2016-06-01 05:35:35", "updated_at" => "2016-06-01 05:35:35", "key" => nil, "project_id" => "85604ecfb5334b50bd40ca53fc1d710f", "id" => "afb4222b-18b3-44b3-9f54-e0dfdba1be44", "zone_transfer_request_id" => "d223f7ef-77a6-459e-abd3-b4dbc97338e7" }, { "status" => "COMPLETE", "zone_id" => "925bfc45-8901-4aca-aa12-18afaf0879e2", "links" => { "self" => "http://127.0.0.1:9001/v2/zones/tasks/transfer_accepts/ecbc7091-c498-4ec4-9893-68b06297fe50", "zone" => "http://127.0.0.1:9001/v2/zones/925bfc45-8901-4aca-aa12-18afaf0879e2" }, "created_at" => "2016-06-01 10:06:36", "updated_at" => "2016-06-01 10:06:37", "key" => nil, "project_id" => "85604ecfb5334b50bd40ca53fc1d710f", "id" => "ecbc7091-c498-4ec4-9893-68b06297fe50", "zone_transfer_request_id" => "94cf9bd3-4137-430b-bf75-4e690430258c" } ] } } 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 = 9001 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 Real include Fog::OpenStack::Core def self.not_found_class Fog::OpenStack::DNS::NotFound end def default_path_prefix 'v2' end def default_service_type %w[dns] end end end end end end fog-openstack-1.0.8/lib/fog/openstack/errors.rb0000644000004100000410000000225713423370527021475 0ustar www-datawww-datamodule 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-1.0.8/lib/fog/openstack/orchestration.rb0000644000004100000410000000773113423370527023047 0ustar www-datawww-datamodule Fog module OpenStack class Orchestration < 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_api_version model_path 'fog/openstack/orchestration/models' model :stack collection :stacks model :resource collection :resources collection :resource_schemas model :event collection :events model :template collection :templates request_path 'fog/openstack/orchestration/requests' 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 request :cancel_update 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(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 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} end end class Real include Fog::OpenStack::Core def self.not_found_class Fog::OpenStack::Orchestration::NotFound end def default_service_type %w[orchestration] end end end end end fog-openstack-1.0.8/lib/fog/openstack/identity.rb0000644000004100000410000000215313423370527022005 0ustar www-datawww-datamodule Fog module OpenStack class Identity < Fog::Service autoload :V2, 'fog/openstack/identity/v2' autoload :V3, 'fog/openstack/identity/v3' def self.new(args = {}) if args[:openstack_identity_api_version] =~ /(v)*2(\.0)*/i Fog::OpenStack::Identity::V2.new(args) else Fog::OpenStack::Identity::V3.new(args) end end class Mock attr_reader :config def initialize(options = {}) @openstack_auth_uri = URI.parse(options[:openstack_auth_url]) @config = options end end class Real include Fog::OpenStack::Core def self.not_found_class Fog::OpenStack::Identity::NotFound end def config_service? true end def config self end def default_endpoint_type 'admin' end private 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-1.0.8/lib/fog/openstack/event.rb0000644000004100000410000000607213423370527021301 0ustar www-datawww-datamodule Fog module OpenStack class Event < 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_api_version model_path 'fog/openstack/event/models' model :event collection :events request_path 'fog/openstack/event/requests' request :get_event request :list_events 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 = 8779 management_url.path = '/v2' @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::OpenStack::Event::NotFound end def default_path_prefix 'v2' end def default_service_type %w[event] end end end end end fog-openstack-1.0.8/lib/fog/openstack/introspection.rb0000644000004100000410000000470113423370527023055 0ustar www-datawww-datarequire 'yaml' module Fog module OpenStack class Introspection < 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, :openstack_identity_api_version ## REQUESTS # request_path 'fog/openstack/introspection/requests' # 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/introspection/models' 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 = "test/fixtures/introspection.yaml" hash[key] = YAML.load(File.read(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 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 self.not_found_class Fog::OpenStack::Introspection::NotFound end def default_path_prefix 'v1' end def default_service_type %w[baremetal-introspection] end end end end end fog-openstack-1.0.8/lib/fog/openstack/event/0000755000004100000410000000000013423370527020747 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/event/requests/0000755000004100000410000000000013423370527022622 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/event/requests/get_event.rb0000644000004100000410000000113113423370527025123 0ustar www-datawww-datamodule Fog module OpenStack class Event 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-1.0.8/lib/fog/openstack/event/requests/list_events.rb0000644000004100000410000000165513423370527025515 0ustar www-datawww-datamodule Fog module OpenStack class Event class Real def list_events(options = []) data = { 'q' => [] } 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-1.0.8/lib/fog/openstack/event/models/0000755000004100000410000000000013423370527022232 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/event/models/events.rb0000644000004100000410000000100713423370527024061 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/event/models/event' module Fog module OpenStack class Event class Events < Fog::OpenStack::Collection model Fog::OpenStack::Event::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::OpenStack::Event::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/event/models/event.rb0000644000004100000410000000044413423370527023702 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Event class Event < Fog::OpenStack::Model identity :message_id attribute :event_type attribute :generated attribute :raw attribute :traits end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/0000755000004100000410000000000013423370527021302 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/compute/requests/0000755000004100000410000000000013423370527023155 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/compute/requests/live_migrate_server.rb0000644000004100000410000000124613423370527027542 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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-1.0.8/lib/fog/openstack/compute/requests/rescue_server.rb0000644000004100000410000000077113423370527026363 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 end class Mock def rescue_server(_server_id) true end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/create_os_interface.rb0000644000004100000410000000215713423370527027473 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real # === Parameters # * server_id <~String> # * options <~Hash> def create_os_interface(server_id, options={}) body = { 'interfaceAttachment' => {} } if options[:port_id] body['interfaceAttachment']['port_id'] = options[:port_id] elsif options[:net_id] body['interfaceAttachment']['net_id'] = options[:net_id] end if options[:ip_address] body['interfaceAttachment']['fixed_ips'] = {ip_address: options[:ip_address]} end request( :body => Fog::JSON.encode(body), :expects => [200, 201, 202, 204], :method => 'POST', :path => "servers/#{server_id}/os-interface" ) end end class Mock def create_os_interface(server_id, options={}) Excon::Response.new( :body => {'interfaceAttachment' => data[:os_interfaces].first}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/get_image_details.rb0000644000004100000410000000131213423370527027125 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def get_image_details(image_id) request( :expects => [200, 203], :method => 'GET', :path => "images/#{image_id}" ) end end class Mock def get_image_details(image_id) response = Excon::Response.new image = list_images_detail.body['images'].find { |im| im['id'] == image_id } if image response.status = [200, 203][rand(2)] response.body = {'image' => image} response else raise Fog::OpenStack::Compute::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/list_hosts.rb0000644000004100000410000000115113423370527025673 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def list_hosts(options = {}) request( :expects => [200, 203], :method => 'GET', :path => 'os-hosts', :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 end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/add_fixed_ip.rb0000644000004100000410000000131513423370527026101 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 end class Mock def add_fixed_ip(_server_id, _network_id) true end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/get_server_volumes.rb0000644000004100000410000000135113423370527027421 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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-1.0.8/lib/fog/openstack/compute/requests/list_snapshots_detail.rb0000644000004100000410000000113313423370527030077 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 = data[:snapshots].values response.body = {'snapshots' => snapshots} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/resize_server.rb0000644000004100000410000000066513423370527026400 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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-1.0.8/lib/fog/openstack/compute/requests/remove_aggregate_host.rb0000644000004100000410000000141113423370527030037 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/get_console_output.rb0000644000004100000410000000077513423370527027434 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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-1.0.8/lib/fog/openstack/compute/requests/shelve_offload_server.rb0000644000004100000410000000112513423370527030047 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 end class Mock def shelve_offload_server(_server_id) true end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/list_servers_detail.rb0000644000004100000410000000216613423370527027555 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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', :query => params ) end end class Mock def list_servers_detail(_filters = {}) response = Excon::Response.new servers = data[:servers].values servers.each do |server| case server['status'] when 'BUILD' if Time.now - data[:last_modified][:servers][server['id']] > Fog::Mock.delay * 2 server['status'] = 'ACTIVE' end end end response.status = [200, 203][rand(2)] response.body = {'servers' => servers} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/list_hypervisors.rb0000644000004100000410000000121213423370527027126 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def list_hypervisors(options = {}) request( :expects => 200, :method => 'GET', :path => 'os-hypervisors', :query => options ) end end class Mock def list_hypervisors(_options = {}) response = Excon::Response.new response.status = 200 response.body = {'hypervisors' => [ {"hypervisor_hostname" => "fake-mini", "id" => 2, "state" => "up", "status" => "enabled"} ]} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/list_usages.rb0000644000004100000410000000247013423370527026027 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def list_usages(date_start = nil, date_end = nil, detailed = false) params = {} 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) 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-1.0.8/lib/fog/openstack/compute/requests/associate_address.rb0000644000004100000410000000162513423370527027166 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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-1.0.8/lib/fog/openstack/compute/requests/delete_os_interface.rb0000644000004100000410000000101713423370527027464 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real # === Parameters # * server_id <~String> # * port_id <~String> def delete_os_interface(server_id, port_id) request( :expects => [200, 202,204], :method => 'DELETE', :path => "servers/#{server_id}/os-interface/#{port_id}" ) end end class Mock def delete_os_interface(server_id, port_id) true end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/update_meta.rb0000644000004100000410000000220013423370527025764 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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" unless list_images_detail.body['images'].find { |image| image['id'] == parent_id } raise Fog::OpenStack::Compute::NotFound end end if collection_name == "servers" unless list_servers_detail.body['servers'].find { |server| server['id'] == parent_id } raise Fog::OpenStack::Compute::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-1.0.8/lib/fog/openstack/compute/requests/shelve_server.rb0000644000004100000410000000077713423370527026371 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 end class Mock def shelve_server(_server_id) true end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/list_all_addresses.rb0000644000004100000410000000341513423370527027345 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def list_all_addresses(options = {}) request( :expects => [200, 203], :method => 'GET', :path => "os-floating-ips", :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 end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/list_flavors_detail.rb0000644000004100000410000000325713423370527027542 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def list_flavors_detail(options = {}) request( :expects => [200, 203], :method => 'GET', :path => 'flavors/detail', :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-1.0.8/lib/fog/openstack/compute/requests/list_zones.rb0000644000004100000410000000132513423370527025674 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def list_zones(options = {}) request( :expects => 200, :method => 'GET', :path => 'os-availability-zone', :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-1.0.8/lib/fog/openstack/compute/requests/rebuild_server.rb0000644000004100000410000000210713423370527026516 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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'] = [] personality.each do |file| 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-1.0.8/lib/fog/openstack/compute/requests/update_flavor_metadata.rb0000644000004100000410000000162213423370527030176 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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-1.0.8/lib/fog/openstack/compute/requests/list_address_pools.rb0000644000004100000410000000107013423370527027374 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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-1.0.8/lib/fog/openstack/compute/requests/create_key_pair.rb0000644000004100000410000000473013423370527026634 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def create_key_pair(key_name, public_key = nil, user_id = nil) data = { 'keypair' => { 'name' => key_name } } data['keypair']['public_key'] = public_key unless public_key.nil? data['keypair']['user_id'] = user_id unless user_id.nil? request( :body => Fog::JSON.encode(data), :expects => [200, 201], :method => 'POST', :path => 'os-keypairs' ) 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 end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/reset_server_state.rb0000644000004100000410000000073713423370527027421 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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-1.0.8/lib/fog/openstack/compute/requests/remove_security_group.rb0000644000004100000410000000071513423370527030145 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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-1.0.8/lib/fog/openstack/compute/requests/list_tenants_with_flavor_access.rb0000644000004100000410000000122313423370527032134 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def list_tenants_with_flavor_access(flavor_ref) request( :expects => [200, 203], :method => 'GET', :path => "flavors/#{flavor_ref}/os-flavor-access" ) 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-1.0.8/lib/fog/openstack/compute/requests/list_services.rb0000644000004100000410000000507413423370527026366 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/create_server_group.rb0000644000004100000410000000153413423370527027552 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def create_server_group(name, policy) Fog::OpenStack::Compute::ServerGroup.validate_server_group_policy policy body = {'server_group' => { 'name' => name, 'policies' => [policy] }} request( :body => Fog::JSON.encode(body), :expects => 200, :method => 'POST', :path => 'os-server-groups' ) end end class Mock def create_server_group(name, policy) Fog::OpenStack::Compute::ServerGroup.validate_server_group_policy policy id = SecureRandom.uuid data[:server_groups][id] = {:name => name, :policies => [policy], :members => []} get_server_group id end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/list_images.rb0000644000004100000410000000126113423370527026002 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def list_images request( :expects => [200, 203], :method => 'GET', :path => 'images' ) end end class Mock def list_images response = Excon::Response.new data = list_images_detail.body['images'] images = [] data.each do |image| images << image.reject { |key, _value| !['id', 'name', 'links'].include?(key) } end response.status = [200, 203][rand(2)] response.body = {'images' => images} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/list_volume_attachments.rb0000644000004100000410000000143013423370527030435 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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-1.0.8/lib/fog/openstack/compute/requests/set_tenant.rb0000644000004100000410000000052013423370527025643 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/add_security_group.rb0000644000004100000410000000070413423370527027376 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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-1.0.8/lib/fog/openstack/compute/requests/delete_snapshot.rb0000644000004100000410000000126413423370527026666 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 { |snap| snap['id'] == snapshot_id } data[:snapshots].delete(snapshot_id) else raise Fog::OpenStack::Compute::NotFound end response end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/resume_server.rb0000644000004100000410000000100013423370527026357 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 end class Mock def resume_server(_server_id) true end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/delete_flavor.rb0000644000004100000410000000117213423370527026316 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/list_zones_detailed.rb0000644000004100000410000000407113423370527027530 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def list_zones_detailed(options = {}) request( :expects => 200, :method => 'GET', :path => 'os-availability-zone/detail', :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-1.0.8/lib/fog/openstack/compute/requests/attach_volume.rb0000644000004100000410000000207513423370527026341 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 self.data[:volumes][volume_id]['status'] = 'in-use' response.body = {'volumeAttachment' => data} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/add_flavor_access.rb0000644000004100000410000000145013423370527027124 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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" ) 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-1.0.8/lib/fog/openstack/compute/requests/detach_volume.rb0000644000004100000410000000151213423370527026320 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 data[:volumes][attachment_id] && data[:volumes][attachment_id]['attachments'].reject! { |attachment| attachment['serverId'] == server_id } data[:volumes][attachment_id]['status'] = 'available' response.status = 202 response else raise Fog::OpenStack::Compute::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/get_usage.rb0000644000004100000410000000432113423370527025445 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def get_usage(tenant_id, date_start, date_end) params = {} 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-1.0.8/lib/fog/openstack/compute/requests/list_public_addresses.rb0000644000004100000410000000140113423370527030044 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def list_public_addresses(server_id) request( :expects => [200, 203], :method => 'GET', :path => "servers/#{server_id}/ips/public" ) end end class Mock def list_public_addresses(server_id) response = Excon::Response.new server = list_servers_detail.body['servers'].find { |srv| srv['id'] == server_id } if server response.status = [200, 203][rand(2)] response.body = {'public' => server['addresses']['public']} response else raise Fog::OpenStack::Compute::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/get_hypervisor_statistics.rb0000644000004100000410000000212013423370527031020 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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-1.0.8/lib/fog/openstack/compute/requests/get_volume_details.rb0000644000004100000410000000147413423370527027363 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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::OpenStack::Compute::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/disassociate_address.rb0000644000004100000410000000120013423370527027653 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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-1.0.8/lib/fog/openstack/compute/requests/add_aggregate_host.rb0000644000004100000410000000140013423370527027270 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/create_snapshot.rb0000644000004100000410000000275213423370527026672 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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::OpenStack::Compute::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-1.0.8/lib/fog/openstack/compute/requests/start_server.rb0000644000004100000410000000077713423370527026240 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 end class Mock def start_server(_server_id) true end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/list_volumes_detail.rb0000644000004100000410000000103113423370527027544 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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' => data[:volumes].values}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/server_action.rb0000644000004100000410000000056013423370527026346 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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" ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/pause_server.rb0000644000004100000410000000076713423370527026217 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 end class Mock def pause_server(_server_id) true end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/suspend_server.rb0000644000004100000410000000100113423370527026541 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 end class Mock def suspend_server(_server_id) true end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/create_volume.rb0000644000004100000410000000327713423370527026345 0ustar www-datawww-data# module Fog module OpenStack class Compute # 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-1.0.8/lib/fog/openstack/compute/requests/delete_server_group.rb0000644000004100000410000000127113423370527027547 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def delete_server_group(group_id) request( :expects => 204, :method => 'DELETE', :path => "os-server-groups/#{group_id}" ) end end class Mock def delete_server_group(group_id) response = Excon::Response.new response.status = data[:server_groups].delete(group_id) ? 204 : 404 response.headers = { "Content-Type" => "text/html; charset=UTF-8", "Content-Length" => "0", "Date" => Date.new } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/create_image.rb0000644000004100000410000000274313423370527026115 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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(%r{.*/(.*)}).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-1.0.8/lib/fog/openstack/compute/requests/delete_service.rb0000644000004100000410000000155213423370527026467 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/disable_service_log_reason.rb0000644000004100000410000000222013423370527031031 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/list_volumes.rb0000644000004100000410000000216613423370527026234 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def list_volumes(options = true) if options.kind_of?(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' => data[:volumes].values}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/get_hypervisor.rb0000644000004100000410000000373313423370527026561 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def get_hypervisor(hypervisor_id) request( :expects => 200, :method => 'GET', :path => "os-hypervisors/#{hypervisor_id}" ) end end class Mock def get_hypervisor(hypervisor_id) response = Excon::Response.new response.status = 200 response.body = { "hypervisor" => { "cpu_info" => { "arch" => "x86_64", "model" => "Nehalem", "vendor" => "Intel", "features" => [ "pge", "clflush" ], "topology" => { "cores" => 1, "threads" => 1, "sockets" => 4 } }, "current_workload" => 0, "status" => "enabled", "state" => "up", "disk_available_least" => 0, "host_ip" => "1.1.1.1", "free_disk_gb" => 1028, "free_ram_mb" => 7680, "hypervisor_hostname" => "fake-mini", "hypervisor_type" => "fake", "hypervisor_version" => 1000, "id" => hypervisor_id, "local_gb" => 1028, "local_gb_used" => 0, "memory_mb" => 8192, "memory_mb_used" => 512, "running_vms" => 0, "service" => { "host" => "host1", "id" => 7, "disabled_reason" => null }, "vcpus" => 1, "vcpus_used" => 0 } } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/create_security_group_rule.rb0000644000004100000410000000357313423370527031147 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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' ) 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 } } data[:security_groups][parent_group_id.to_s]['rules'].push(rule) response.body = { 'security_group_rule' => rule } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/reboot_server.rb0000644000004100000410000000066013423370527026364 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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-1.0.8/lib/fog/openstack/compute/requests/update_quota.rb0000644000004100000410000000124213423370527026174 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def update_quota(tenant_id, options = {}) 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 = {}) data[:quota_updated] = data[:quota].merge options response = Excon::Response.new response.status = 200 response.body = {'quota_set' => data[:quota_updated]} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/list_servers.rb0000644000004100000410000000163413423370527026232 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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', :query => params ) end end class Mock def list_servers(_options = {}) response = Excon::Response.new data = list_servers_detail.body['servers'] servers = [] data.each do |server| servers << server.reject { |key, _value| !['id', 'name', 'links'].include?(key) } end response.status = [200, 203][rand(2)] response.body = {'servers' => servers} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/get_quota_defaults.rb0000644000004100000410000000110413423370527027355 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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' => data[:quota].merge('id' => tenant_id) } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/get_security_group_rule.rb0000644000004100000410000000237713423370527030464 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 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::OpenStack::Compute::NotFound, "Security group rule #{security_group_rule_id} does not exist" end response end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/delete_meta.rb0000644000004100000410000000170713423370527025757 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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" unless list_images_detail.body['images'].find { |image| image['id'] == parent_id } raise Fog::OpenStack::Compute::NotFound end end if collection_name == "servers" unless list_servers_detail.body['servers'].find { |server| server['id'] == parent_id } raise Fog::OpenStack::Compute::NotFound end end response = Excon::Response.new response.status = 204 response end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/create_flavor.rb0000644000004100000410000000552413423370527026324 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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) 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 end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/delete_metadata.rb0000644000004100000410000000102213423370527026577 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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-1.0.8/lib/fog/openstack/compute/requests/get_vnc_console.rb0000644000004100000410000000265213423370527026656 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real # Get a vnc console for an instance. # For microversion < 2.6 as it has been replaced with remote-consoles # # === 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) fixed_microversion = nil if microversion_newer_than?('2.5') fixed_microversion = @microversion @microversion = '2.5' end body = { 'os-getVNCConsole' => { 'type' => console_type } } result = server_action(server_id, body) @microversion = fixed_microversion if fixed_microversion result end end 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 end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/create_server.rb0000644000004100000410000001720613423370527026341 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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.kind_of?(Fog::OpenStack::Compute::SecurityGroup) sg.name else sg end {:name => name} end end if options['personality'] data['server']['personality'] = [] options['personality'].each do |file| 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 = {} neti['uuid'] = (nic['net_id'] || nic[:net_id]) unless (nic['net_id'] || nic[:net_id]).nil? 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, :device_type, :disk_bus, :guest_format, :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' : 'servers' 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::OpenStack::Identity.new(:openstack_auth_url => credentials[:openstack_auth_url], :openstack_identity_api_version => 'v2.0') user = identity.users.find do |u| u.name == @openstack_username end user_id = if user 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' => user_id, 'config_drive' => options['config_drive'] || '', } nics = options['nics'] if 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' {'reservation_id' => "r-#{Fog::Mock.random_numbers(6)}"} else { 'adminPass' => 'password', 'id' => server_id, 'links' => mock_data['links'], } end if block_devices = options["block_device_mapping_v2"] block_devices.each { |bd| volumes.get(bd[:uuid]).attach(server_id, bd[:device_name]) } elsif block_device = options["block_device_mapping"] volumes.get(block_device[:volume_id]).attach(server_id, block_device[:device_name]) end data[:last_modified][:servers][server_id] = Time.now data[:servers][server_id] = mock_data security_groups = options['security_groups'] if security_groups groups = Array(security_groups).map do |sg| if sg.kind_of?(Fog::OpenStack::Compute::SecurityGroup) sg.name else sg end end data[:server_security_group_map][server_id] = groups response_data['security_groups'] = groups end if options['os:scheduler_hints'] && options['os:scheduler_hints']['group'] group = data[:server_groups][options['os:scheduler_hints']['group']] group[:members] << server_id if group end response.body = if options['return_reservation_id'] == 'True' response_data else {'server' => response_data} end response end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/boot_from_snapshot.rb0000644000004100000410000000232513423370527027411 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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'] = [] options['personality'].each do |file| 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' ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/get_metadata.rb0000644000004100000410000000107113423370527026120 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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-1.0.8/lib/fog/openstack/compute/requests/create_flavor_metadata.rb0000644000004100000410000000174313423370527030163 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/list_images_detail.rb0000644000004100000410000000177113423370527027332 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def list_images_detail(filters = {}) request( :expects => [200, 203], :method => 'GET', :path => 'images/detail', :query => filters ) end end class Mock def list_images_detail(_filters = {}) response = Excon::Response.new images = data[:images].values images.each do |image| case image['status'] when 'SAVING' if Time.now - data[:last_modified][:images][image['id']] >= Fog::Mock.delay image['status'] = 'ACTIVE' end end end response.status = [200, 203][rand(2)] 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-1.0.8/lib/fog/openstack/compute/requests/get_flavor_details.rb0000644000004100000410000000350313423370527027340 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def get_flavor_details(flavor_ref) request( :expects => [200, 203], :method => 'GET', :path => "flavors/#{flavor_ref}" ) 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::OpenStack::Compute::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/server_diagnostics.rb0000644000004100000410000000105113423370527027374 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 end class Mock def server_diagnostics(server_id) end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/revert_resize_server.rb0000644000004100000410000000125013423370527027756 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 data[:servers][server_id]['flavorId'] = data[:servers][server_id]['old_flavorId'] data[:servers][server_id].delete('old_flavorId') data[:last_modified][:servers][server_id] = Time.now data[:servers][server_id]['status'] = 'ACTIVE' response end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/delete_security_group_rule.rb0000644000004100000410000000171713423370527031144 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 = 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 end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/stop_server.rb0000644000004100000410000000077313423370527026064 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 end class Mock def stop_server(_server_id) true end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/get_server_group.rb0000644000004100000410000000200713423370527027062 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def get_server_group(group_id) request( :expects => 200, :method => 'GET', :path => "/os-server-groups/#{group_id}" ) end end class Mock def get_server_group(group_id) grp = data[:server_groups][group_id] response = Excon::Response.new response.status = 200 response.headers = { "Content-Type" => "text/html; charset=UTF-8", "Content-Length" => "0", "Date" => Date.new } response.body = {'server_group' => { 'id' => group_id, 'name' => grp[:name], 'policies' => grp[:policies], 'members' => grp[:members], 'metadata' => {}, 'project_id' => 'test-project', 'user_id' => 'test-user' }} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/list_os_interfaces.rb0000644000004100000410000000102213423370527027354 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def list_os_interfaces(server_id) request( :expects => [200, 203], :method => 'GET', :path => "servers/#{server_id}/os-interface" ) end end class Mock def list_os_interfaces(server_id) Excon::Response.new( :body => {'interfaceAttachments' => data[:os_interfaces]}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/evacuate_server.rb0000644000004100000410000000155313423370527026671 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def evacuate_server(server_id, host = nil, on_shared_storage = nil, admin_password = nil) evacuate = {} evacuate['host'] = host if host if !microversion_newer_than?('2.13') && on_shared_storage evacuate['onSharedStorage'] = on_shared_storage end 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-1.0.8/lib/fog/openstack/compute/requests/get_aggregate.rb0000644000004100000410000000102513423370527026265 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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' => data[:aggregates].first.merge("hosts" => [])} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/list_snapshots.rb0000644000004100000410000000230413423370527026556 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def list_snapshots(options = true) if options.kind_of?(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 = data[:snapshots].values response.body = {'snapshots' => snapshots} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/unpause_server.rb0000644000004100000410000000100113423370527026540 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 end class Mock def unpause_server(_server_id) true end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/get_address.rb0000644000004100000410000000176413423370527025776 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/create_aggregate.rb0000644000004100000410000000203413423370527026752 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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' => data[:aggregates].first} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/release_address.rb0000644000004100000410000000125513423370527026632 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/update_metadata.rb0000644000004100000410000000220013423370527026616 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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" ) end end class Mock def update_metadata(collection_name, parent_id, metadata = {}) if collection_name == "images" unless list_images_detail.body['images'].find { |image| image['id'] == parent_id } raise Fog::OpenStack::Compute::NotFound end end if collection_name == "servers" unless list_servers_detail.body['servers'].find { |server| server['id'] == parent_id } raise Fog::OpenStack::Compute::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-1.0.8/lib/fog/openstack/compute/requests/remove_flavor_access.rb0000644000004100000410000000137113423370527027673 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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" ) 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-1.0.8/lib/fog/openstack/compute/requests/remote_consoles.rb0000644000004100000410000000336113423370527026705 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real # Get a vnc console for an instance. # For microversion >= 2.6 # # === Parameters # * server_id <~String> - The ID of the server. # * protocol <~String> - The protocol of remote console. The valid values are vnc, spice, rdp, serial and mks. # The protocol mks is added since Microversion 2.8. # * type <~String> - The type of remote console. The valid values are novnc, xvpvnc, rdp-html5, spice-html5, # serial, and webmks. The type webmks is added since Microversion 2.8. # === Returns # * response <~Excon::Response>: # * body <~Hash>: # * url <~String> # * type <~String> # * protocol <~String> def remote_consoles(server_id, protocol, type) if microversion_newer_than?('2.6') body = { 'remote_console' => { 'protocol' => protocol, 'type' => type } } request( :body => Fog::JSON.encode(body), :expects => 200, :method => 'POST', :path => "servers/#{server_id}/remote-consoles" ) end end end class Mock def remote_consoles(_server_id, _protocol, _type) response = Excon::Response.new response.status = 200 response.body = { "remote_console" => { "url" => "http://192.168.27.100:6080/vnc_auto.html?token=e629bcbf-6f9e-4276-9ea1-d6eb0e618da5", "type" => "novnc", "protocol" => "vnc" } } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/migrate_server.rb0000644000004100000410000000060713423370527026523 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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-1.0.8/lib/fog/openstack/compute/requests/get_server_details.rb0000644000004100000410000000133113423370527027352 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def get_server_details(server_id) request( :expects => [200, 203], :method => 'GET', :path => "servers/#{server_id}" ) end end class Mock def get_server_details(server_id) response = Excon::Response.new server = list_servers_detail.body['servers'].find { |srv| srv['id'] == server_id } if server response.status = [200, 203][rand(2)] response.body = {'server' => server} response else raise Fog::OpenStack::Compute::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/list_key_pairs.rb0000644000004100000410000000240113423370527026520 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def list_key_pairs(options = {}) request( :expects => [200, 203], :method => 'GET', :path => 'os-keypairs', :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 end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/delete_aggregate.rb0000644000004100000410000000120313423370527026746 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/list_availability_zones.rb0000644000004100000410000000064613423370527030433 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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-1.0.8/lib/fog/openstack/compute/requests/get_key_pair.rb0000644000004100000410000000506613423370527026153 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def get_key_pair(key_name) request( :expects => 200, :method => 'GET', :path => "os-keypairs/#{Fog::OpenStack.escape(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-1.0.8/lib/fog/openstack/compute/requests/set_metadata.rb0000644000004100000410000000210713423370527026135 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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" unless list_images_detail.body['images'].find { |image| image['id'] == parent_id } raise Fog::OpenStack::Compute::NotFound end end if collection_name == "servers" unless list_servers_detail.body['servers'].find { |server| server['id'] == parent_id } raise Fog::OpenStack::Compute::NotFound end end response = Excon::Response.new response.body = {"metadata" => metadata} response.status = 200 response end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/list_aggregates.rb0000644000004100000410000000170013423370527026644 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/disable_service.rb0000644000004100000410000000173713423370527026635 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/update_aggregate.rb0000644000004100000410000000174713423370527027003 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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' => data[:aggregates].first} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/get_security_group.rb0000644000004100000410000000213313423370527027423 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 = 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::OpenStack::Compute::NotFound, "Security group #{security_group_id} does not exist" end response end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/change_server_password.rb0000644000004100000410000000073313423370527030242 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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-1.0.8/lib/fog/openstack/compute/requests/delete_image.rb0000644000004100000410000000173713423370527026116 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 image = list_images_detail.body['images'].find { |im| im['id'] == image_id } if image if image['status'] == 'SAVING' response.status = 409 raise(Excon::Errors.status_error({:expects => 202}, response)) else data[:last_modified][:images].delete(image_id) 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-1.0.8/lib/fog/openstack/compute/requests/delete_volume.rb0000644000004100000410000000123213423370527026331 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 data[:volumes].delete(volume_id) response.status = 204 response else raise Fog::OpenStack::Compute::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/list_server_groups.rb0000644000004100000410000000126413423370527027445 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def list_server_groups(options = {}) request( :expects => 200, :method => 'GET', :path => 'os-server-groups', :query => options ) end end class Mock def list_server_groups(_options = {}) groups = data[:server_groups].map do |id, group| group.merge('id' => id, 'project_id' => 'test-project', 'user_id' => 'test-user') end Excon::Response.new( :body => {'server_groups' => groups}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/get_os_interface.rb0000644000004100000410000000106313423370527027002 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def get_os_interface(server_id,port_id) request( :expects => [200, 202, 203], :method => 'GET', :path => "servers/#{server_id}/os-interface/#{port_id}" ) end end class Mock def get_os_interface(server_id,port_id) Excon::Response.new( :body => {'interfaceAttachment' => data[:os_interfaces].first}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/server_actions.rb0000644000004100000410000000210713423370527026530 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 end 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 end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/get_server_password.rb0000644000004100000410000000135613423370527027576 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def get_server_password(server_id) request( :expects => [200, 203], :method => 'GET', :path => "servers/#{server_id}/os-server-password" ) end end class Mock def get_server_password(server_id) response = Excon::Response.new server = list_servers_detail.body['servers'].find { |srv| srv['id'] == server_id } if server response.status = [200, 203][rand(2)] response.body = {'server' => server} response else raise Fog::OpenStack::Compute::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/update_server.rb0000644000004100000410000000150013423370527026346 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def update_server(server_id, options = {}) request( :body => Fog::JSON.encode('server' => options), :expects => 200, :method => 'PUT', :path => "servers/#{server_id}" ) end end class Mock def update_server(server_id, options = {}) response = Excon::Response.new server = list_servers_detail.body['servers'].find { |srv| srv['id'] == server_id } if server if options['name'] server['name'] = options['name'] end response.status = 200 response else raise Fog::OpenStack::Compute::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/get_quota.rb0000644000004100000410000000110313423370527025465 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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' => (data[:quota_updated] || data[:quota]).merge('id' => tenant_id) } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/list_hypervisors_detail.rb0000644000004100000410000000437113423370527030461 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def list_hypervisors_detail(options = {}) request( :expects => 200, :method => 'GET', :path => 'os-hypervisors/detail', :query => options ) end end class Mock def list_hypervisors_detail(_options = {}) response = Excon::Response.new response.status = 200 response.body = { "hypervisors" => [{ "cpu_info" => { "arch" => "x86_64", "model" => "Nehalem", "vendor" => "Intel", "features" => [ "pge", "clflush" ], "topology" => { "cores" => 1, "threads" => 1, "sockets" => 4 } }, "current_workload" => 0, "status" => "enabled", "state" => "up", "disk_available_least" => 0, "host_ip" => "1.1.1.1", "free_disk_gb" => 1028, "free_ram_mb" => 7680, "hypervisor_hostname" => "fake-mini", "hypervisor_type" => "fake", "hypervisor_version" => 1000, "id" => 2, "local_gb" => 1028, "local_gb_used" => 0, "memory_mb" => 8192, "memory_mb_used" => 512, "running_vms" => 0, "service" => { "host" => "host1", "id" => 7, "disabled_reason" => null }, "vcpus" => 1, "vcpus_used" => 0 }], "hypervisors_links" => [ { "href" => "http://openstack.example.com/v2.1/6f70656e737461636b20342065766572/hypervisors/detail?limit=1&marker=2", "rel" => "next" } ] } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/remove_fixed_ip.rb0000644000004100000410000000126613423370527026653 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 end class Mock def remove_fixed_ip(_server_id, _address) true end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/delete_flavor_metadata.rb0000644000004100000410000000145413423370527030161 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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-1.0.8/lib/fog/openstack/compute/requests/get_snapshot_details.rb0000644000004100000410000000134713423370527027712 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 do |snap| snap['id'] == snapshot_id end response.status = 200 response.body = {'snapshot' => snapshot} response else raise Fog::OpenStack::Compute::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/list_flavors.rb0000644000004100000410000000242313423370527026212 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def list_flavors(options = {}) request( :expects => [200, 203], :method => 'GET', :path => 'flavors', :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-1.0.8/lib/fog/openstack/compute/requests/list_hypervisor_servers.rb0000644000004100000410000000225613423370527030525 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def list_hypervisor_servers(hypervisor_id, options = {}) request( :expects => 200, :method => 'GET', :path => "os-hypervisors/#{hypervisor_id}/servers", :query => options ) end end class Mock def list_hypervisor_servers(hypervisor_id, _options = {}) response = Excon::Response.new response.status = 200 response.body = {'hypervisors' => [ { "hypervisor_hostname" => "fake-mini", "id" => hypervisor_id, "state" => "up", "status" => "enabled", "servers" => [ { "name" => "test_server1", "uuid" => "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" }, { "name" => "test_server2", "uuid" => "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb" } ] } ]} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/update_aggregate_metadata.rb0000644000004100000410000000143513423370527030635 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/delete_server.rb0000644000004100000410000000231013423370527026326 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 server = list_servers_detail.body['servers'].find { |srv| srv['id'] == server_id } if server if server['status'] == 'BUILD' response.status = 409 raise(Excon::Errors.status_error({:expects => 204}, response)) else data[:last_modified][:servers].delete(server_id) data[:servers].delete(server_id) response.status = 204 server_groups = data[:server_groups] if server_groups group_id, = server_groups.find { |_id, grp| grp[:members].include?(server_id) } server_groups[group_id][:members] -= [server_id] if group_id end end response else raise Fog::OpenStack::Compute::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/allocate_address.rb0000644000004100000410000000206013423370527026771 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def allocate_address(pool = nil) request( :body => Fog::JSON.encode('pool' => pool), :expects => [200, 202], :method => 'POST', :path => 'os-floating-ips' ) 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 end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/enable_service.rb0000644000004100000410000000173313423370527026454 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/get_flavor_metadata.rb0000644000004100000410000000110513423370527027467 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/get_limits.rb0000644000004100000410000000574213423370527025652 0ustar www-datawww-datamodule Fog module OpenStack class Compute # http://developer.openstack.org/api-ref-compute-v2.1.html#showlimits class Real def get_limits(options = {}) request( :expects => 200, :method => 'GET', :path => '/limits', :query => options ) end end class Mock def get_limits(_options = {}) 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-1.0.8/lib/fog/openstack/compute/requests/unshelve_server.rb0000644000004100000410000000101113423370527026712 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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 end class Mock def unshelve_server(_server_id) true end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/list_security_groups.rb0000644000004100000410000000375713423370527030017 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def list_security_groups(options = {}) path = "os-security-groups" if options.kind_of?(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 = {}) server_id = if options.kind_of?(Hash) options.delete(:server_id) else options end security_groups = data[:security_groups].values groups = if server_id server_group_names = Array(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 end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/delete_security_group.rb0000644000004100000410000000141113423370527030104 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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) 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 end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/create_security_group.rb0000644000004100000410000000321413423370527030110 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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' ) end end class Mock def create_security_group(name, description) Fog::OpenStack::Identity.new(:openstack_auth_url => credentials[:openstack_auth_url], :openstack_identity_api_version => 'v2.0') tenant_id = Fog::OpenStack::Identity::V2::Mock.data[current_tenant][:tenants].keys.first security_group_id = Fog::Mock.random_numbers(2).to_i + 1 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' => data[:security_groups][security_group_id.to_s] } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/confirm_resize_server.rb0000644000004100000410000000064013423370527030106 0ustar www-datawww-datamodule Fog module OpenStack class Compute 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-1.0.8/lib/fog/openstack/compute/requests/list_addresses.rb0000644000004100000410000000134513423370527026515 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def list_addresses(server_id) request( :expects => [200, 203], :method => 'GET', :path => "servers/#{server_id}/ips" ) end end class Mock def list_addresses(server_id) response = Excon::Response.new server = list_servers_detail.body['servers'].find { |srv| srv['id'] == server_id } if server response.status = [200, 203][rand(2)] response.body = {'addresses' => server['addresses']} response else raise Fog::OpenStack::Compute::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/list_private_addresses.rb0000644000004100000410000000140613423370527030245 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def list_private_addresses(server_id) request( :expects => [200, 203], :method => 'GET', :path => "servers/#{server_id}/ips/private" ) end end class Mock def list_private_addresses(server_id) response = Excon::Response.new server = list_servers_detail.body['servers'].find { |srv| srv['id'] == server_id } if server response.status = [200, 203][rand(2)] response.body = {'private' => server['addresses']['private']} response else raise Fog::OpenStack::Compute::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/get_host_details.rb0000644000004100000410000000335713423370527027033 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def get_host_details(host) request( :expects => [200, 203], :method => 'GET', :path => "os-hosts/#{host}" ) 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 end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/delete_key_pair.rb0000644000004100000410000000143213423370527026627 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def delete_key_pair(key_name, user_id = nil) options = {} options[:user_id] = user_id unless user_id.nil? request( :expects => [202, 204], :method => 'DELETE', :path => "os-keypairs/#{Fog::OpenStack.escape(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 end end end fog-openstack-1.0.8/lib/fog/openstack/compute/requests/list_metadata.rb0000644000004100000410000000103613423370527026315 0ustar www-datawww-datamodule Fog module OpenStack class Compute class Real def list_metadata(collection_name, parent_id) request( :expects => [200, 203], :method => 'GET', :path => "/#{collection_name}/#{parent_id}/metadata" ) 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-1.0.8/lib/fog/openstack/compute/models/0000755000004100000410000000000013423370527022565 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/compute/models/tenants.rb0000644000004100000410000000111513423370527024564 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/compute/models/tenant' module Fog module OpenStack class Compute class Tenants < Fog::OpenStack::Collection model Fog::OpenStack::Compute::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) find { |tenant| tenant.id == id } end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/models/server_groups.rb0000644000004100000410000000134313423370527026020 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/compute/models/server_group' module Fog module OpenStack class Compute class ServerGroups < Fog::OpenStack::Collection model Fog::OpenStack::Compute::ServerGroup def all(options = {}) load_response(service.list_server_groups(options), 'server_groups') end def get(server_group_id) if server_group_id new(service.get_server_group(server_group_id).body['server_group']) end rescue Fog::OpenStack::Compute::NotFound nil end def create(*args) new(service.create_server_group(*args).body['server_group']) end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/models/availability_zones.rb0000644000004100000410000000111413423370527026777 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/compute/models/availability_zone' module Fog module OpenStack class Compute class AvailabilityZones < Fog::OpenStack::Collection model Fog::OpenStack::Compute::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-1.0.8/lib/fog/openstack/compute/models/addresses.rb0000644000004100000410000000130413423370527025065 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/compute/models/address' module Fog module OpenStack class Compute class Addresses < Fog::OpenStack::Collection model Fog::OpenStack::Compute::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::OpenStack::Compute::NotFound nil end def get_address_pools service.list_address_pools.body['floating_ip_pools'] end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/models/os_interface.rb0000644000004100000410000000047713423370527025563 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Compute class OsInterface < Fog::OpenStack::Model identity :port_id attribute :fixed_ips, :type => :array attribute :mac_addr attribute :net_id attribute :port_state end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/models/security_group_rule.rb0000644000004100000410000000150313423370527027223 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Compute 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-1.0.8/lib/fog/openstack/compute/models/key_pairs.rb0000644000004100000410000000132213423370527025076 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/compute/models/key_pair' module Fog module OpenStack class Compute class KeyPairs < Fog::OpenStack::Collection model Fog::OpenStack::Compute::KeyPair def all(options = {}) items = [] service.list_key_pairs(options).body['keypairs'].each do |kp| items += kp.values end # TODO: convert to load_response? load(items) end def get(key_pair_name) if key_pair_name all.select { |kp| kp.name == key_pair_name }.first end rescue Fog::OpenStack::Compute::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/models/security_group_rules.rb0000644000004100000410000000111213423370527027402 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/compute/models/security_group_rule' module Fog module OpenStack class Compute class SecurityGroupRules < Fog::OpenStack::Collection model Fog::OpenStack::Compute::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::OpenStack::Compute::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/models/volume_attachments.rb0000644000004100000410000000076713423370527027026 0ustar www-datawww-datarequire 'fog/core/collection' module Fog module OpenStack class Compute class VolumeAttachments < Fog::Collection model Fog::OpenStack::Compute::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::OpenStack::Compute::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/models/snapshot.rb0000644000004100000410000000153513423370527024755 0ustar www-datawww-datarequire 'fog/openstack/models/model' require 'fog/openstack/compute/models/metadata' module Fog module OpenStack class Compute 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-1.0.8/lib/fog/openstack/compute/models/image.rb0000644000004100000410000000227213423370527024177 0ustar www-datawww-datarequire 'fog/openstack/models/model' require 'fog/openstack/compute/models/metadata' module Fog module OpenStack class Compute 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 :size, :aliases => 'OS-EXT-IMG-SIZE:size' attribute :metadata attribute :links def metadata @metadata ||= begin Fog::OpenStack::Compute::Metadata.new(:service => service, :parent => self) end end def metadata=(new_metadata = {}) metas = [] new_metadata.to_hash.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-1.0.8/lib/fog/openstack/compute/models/address.rb0000644000004100000410000000316513423370527024544 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Compute 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, '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) if persisted? @server = nil self.instance_id = new_server.id service.associate_address(instance_id, ip) else @server = new_server 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-1.0.8/lib/fog/openstack/compute/models/metadatum.rb0000644000004100000410000000112513423370527025072 0ustar www-datawww-datarequire 'fog/openstack/models/model' require 'fog/openstack/models/meta_parent' module Fog module OpenStack class Compute class Metadatum < Fog::OpenStack::Model include Fog::OpenStack::Compute::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-1.0.8/lib/fog/openstack/compute/models/services.rb0000644000004100000410000000213413423370527024735 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/compute/models/service' module Fog module OpenStack class Compute class Services < Fog::OpenStack::Collection model Fog::OpenStack::Compute::Service def all(options = {}) load_response(service.list_services(options), 'services') end alias 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::OpenStack::Compute::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/models/security_group.rb0000644000004100000410000000402113423370527026172 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Compute 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::OpenStack::Compute::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::OpenStack::Compute::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::OpenStack::Compute::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::OpenStack::Compute::SecurityGroupRule objects to destroy rules.') service.delete_security_group_rule(rule_id) true end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/models/key_pair.rb0000644000004100000410000000266513423370527024726 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Compute 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, user_id).body['keypair'] else service.create_key_pair(name, nil, user_id).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}_#{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-1.0.8/lib/fog/openstack/compute/models/network.rb0000644000004100000410000000035113423370527024602 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Compute class Network < Fog::OpenStack::Model identity :id attribute :name attribute :addresses end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/models/availability_zone.rb0000644000004100000410000000050713423370527026621 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Compute class AvailabilityZone < Fog::OpenStack::Model identity :zoneName attribute :hosts attribute :zoneLabel attribute :zoneState def to_s zoneName end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/models/volumes.rb0000644000004100000410000000216613423370527024611 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/compute/models/volume' module Fog module OpenStack class Compute class Volumes < Fog::OpenStack::Collection model Fog::OpenStack::Compute::Volume def all(options = true) if !options.kind_of?(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::OpenStack::Compute::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/models/server_group.rb0000644000004100000410000000123313423370527025633 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Compute class ServerGroup < Fog::OpenStack::Model identity :id attribute :name attribute :policies, :type => :array attribute :members VALID_SERVER_GROUP_POLICIES = ['affinity', 'anti-affinity', 'soft-affinity', 'soft-anti-affinity'].freeze def self.validate_server_group_policy(policy) raise ArgumentError, "#{policy} is an invalid policy... must use one of #{VALID_SERVER_GROUP_POLICIES.join(', ')}" \ unless VALID_SERVER_GROUP_POLICIES.include? policy true end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/models/metadata.rb0000644000004100000410000000355513423370527024702 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/models/meta_parent' require 'fog/openstack/compute/models/metadatum' require 'fog/openstack/compute/models/image' require 'fog/openstack/compute/models/server' module Fog module OpenStack class Compute class Metadata < Fog::OpenStack::Collection model Fog::OpenStack::Compute::Metadatum include Fog::OpenStack::Compute::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::OpenStack::Compute::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 = {} each do |meta| if meta.kind_of?(Fog::OpenStack::Compute::Metadatum) data.store(meta.key, meta.value) else data.store(meta["key"], meta["value"]) end end end data end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/models/tenant.rb0000644000004100000410000000071113423370527024402 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Compute class Tenant < Fog::OpenStack::Model identity :id attribute :description attribute :enabled attribute :name def to_s name end def usage(start_date, end_date) requires :id service.get_usage(id, start_date, end_date).body['tenant_usage'] end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/models/aggregates.rb0000644000004100000410000000114613423370527025225 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/compute/models/aggregate' module Fog module OpenStack class Compute class Aggregates < Fog::OpenStack::Collection model Fog::OpenStack::Compute::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 get find_by_id def destroy(id) aggregate = find_by_id(id) aggregate.destroy end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/models/flavor.rb0000644000004100000410000000336313423370527024410 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Compute 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::OpenStack::Compute::NotFound nil end def create_metadata(metadata) service.create_flavor_metadata(id, metadata) rescue Fog::OpenStack::Compute::NotFound nil end def update_metadata(key, value) service.update_flavor_metadata(id, key, value) rescue Fog::OpenStack::Compute::NotFound nil end def delete_metadata(key) service.delete_flavor_metadata(id, key) rescue Fog::OpenStack::Compute::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/models/hosts.rb0000644000004100000410000000120613423370527024251 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/compute/models/host' module Fog module OpenStack class Compute class Hosts < Fog::OpenStack::Collection model Fog::OpenStack::Compute::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::OpenStack::Compute::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/models/flavors.rb0000644000004100000410000000132613423370527024570 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/compute/models/flavor' module Fog module OpenStack class Compute class Flavors < Fog::OpenStack::Collection model Fog::OpenStack::Compute::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::OpenStack::Compute::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/models/servers.rb0000644000004100000410000000365213423370527024611 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/compute/models/server' module Fog module OpenStack class Compute class Servers < Fog::OpenStack::Collection attribute :filters model Fog::OpenStack::Compute::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::OpenStack::Compute::Server] # @raise [Fog::OpenStack::Compute::NotFound] - HTTP 404 # @raise [Fog::OpenStack::Compute::BadRequest] - HTTP 400 # @raise [Fog::OpenStack::Compute::InternalServerError] - HTTP 500 # @raise [Fog::OpenStack::Compute::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::OpenStack::Compute::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/models/volume_attachment.rb0000644000004100000410000000037013423370527026631 0ustar www-datawww-datarequire 'fog/core/model' module Fog module OpenStack class Compute class VolumeAttachment < Fog::Model identity :id attribute :serverId attribute :volumeId attribute :device end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/models/service.rb0000644000004100000410000000160613423370527024555 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Compute 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(host, binary) end def disable requires :binary, :host service.disable_service(host, binary) end def disable_and_log_reason requires :binary, :host, :disabled_reason service.disable_service_log_reason(host, binary, disabled_reason) end def destroy requires :id service.delete_service(id) true end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/models/security_groups.rb0000644000004100000410000000121113423370527026353 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/compute/models/security_group' module Fog module OpenStack class Compute class SecurityGroups < Fog::OpenStack::Collection model Fog::OpenStack::Compute::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::OpenStack::Compute::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/models/aggregate.rb0000644000004100000410000000243413423370527025043 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Compute 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(name, attributes).body['aggregate']) self end def update requires :id merge_attributes(service.update_aggregate(id, attributes).body['aggregate']) self end def add_host(host_uuid) requires :id service.add_aggregate_host(id, host_uuid) end def remove_host(host_uuid) requires :id service.remove_aggregate_host(id, host_uuid) end def update_metadata(metadata) service.update_aggregate_metadata(id, metadata) end def destroy requires :id service.delete_aggregate(id) true end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/models/snapshots.rb0000644000004100000410000000223213423370527025133 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/compute/models/snapshot' module Fog module OpenStack class Compute class Snapshots < Fog::OpenStack::Collection model Fog::OpenStack::Compute::Snapshot def all(options = {}) if !options.kind_of?(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::OpenStack::Compute::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/models/host.rb0000644000004100000410000000132213423370527024065 0ustar www-datawww-datarequire 'fog/compute/models/server' require 'fog/openstack/compute/models/metadata' module Fog module OpenStack class Compute 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(host_name).body['host'] rescue Fog::OpenStack::Compute::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/models/os_interfaces.rb0000644000004100000410000000121113423370527025731 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/compute/models/os_interface' module Fog module OpenStack class Compute class OsInterfaces < Fog::OpenStack::Collection model Fog::OpenStack::Compute::OsInterface attribute :server def all requires :server data = service.list_os_interfaces(server.id) load_response(data, 'interfaceAttachments') end def get(port_id) requires :server data = service.get_os_interface(server.id,port_id) load_response(data, 'interfaceAttachment') end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/models/server.rb0000644000004100000410000003120713423370527024423 0ustar www-datawww-datarequire 'fog/compute/models/server' require 'fog/openstack/compute/models/metadata' module Fog module OpenStack class Compute 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::OpenStack::Compute::Metadata.new(:service => service, :parent => self) end end def metadata=(new_metadata = {}) return unless new_metadata metas = [] new_metadata.each { |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 os_interfaces requires :id service.os_interfaces(:server => self) 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? if addresses addresses.select { |s| s[0] =~ /public/i }.collect { |a| a[1][0]['addr'] } else [] end 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 if id requires :id groups = service.list_security_groups(:server_id => id).body['security_groups'] groups.map do |group| Fog::OpenStack::Compute::SecurityGroup.new group.merge(:service => service) end else service.security_groups.all 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-1.0.8/lib/fog/openstack/compute/models/networks.rb0000644000004100000410000000127213423370527024770 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/compute/models/network' module Fog module OpenStack class Compute class Networks < Fog::OpenStack::Collection model Fog::OpenStack::Compute::Network attribute :server def all requires :server networks = [] 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 end end end fog-openstack-1.0.8/lib/fog/openstack/compute/models/volume.rb0000644000004100000410000000272013423370527024422 0ustar www-datawww-datarequire 'fog/openstack/models/model' require 'fog/openstack/compute/models/metadata' module Fog module OpenStack class Compute 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? status == "available" end end end end end fog-openstack-1.0.8/lib/fog/openstack/compute/models/images.rb0000644000004100000410000000160513423370527024361 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/compute/models/image' module Fog module OpenStack class Compute class Images < Fog::OpenStack::Collection attribute :filters model Fog::OpenStack::Compute::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 replace(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::OpenStack::Compute::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/workflow.rb0000644000004100000410000000072313423370527022027 0ustar www-datawww-datamodule Fog module OpenStack class Workflow < Fog::Service autoload :V2, 'fog/openstack/workflow/v2' # Fog::OpenStack::Workflow.new() will return a Fog::OpenStack::Workflow::V2 # Will choose the latest available once Mistral V3 is released. def self.new(args = {}) @openstack_auth_uri = URI.parse(args[:openstack_auth_url]) if args[:openstack_auth_url] Fog::OpenStack::Workflow::V2.new(args) end end end end fog-openstack-1.0.8/lib/fog/openstack/orchestration/0000755000004100000410000000000013423370527022512 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/orchestration/requests/0000755000004100000410000000000013423370527024365 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/orchestration/requests/list_stack_data.rb0000644000004100000410000000104513423370527030043 0ustar www-datawww-datamodule Fog module OpenStack class Orchestration 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 = data[:stacks].values Excon::Response.new( :body => {'stacks' => stacks}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/orchestration/requests/create_stack.rb0000644000004100000410000001007513423370527027345 0ustar www-datawww-datamodule Fog module OpenStack class Orchestration 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. # * :files [Hash] Hash with files resources. # * :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.kind_of?(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 # Templates should always: # - be strings # - contain URI references instead of relative paths. # Passing :template_url may not work well with `get_file` and remote `type`: # the python client implementation in shade retrieves from :template_uri # and replaces it with :template. # see https://github.com/openstack-infra/shade/blob/master/shade/openstackcloud.py#L1201 # see https://developer.openstack.org/api-ref/orchestration/v1/index.html#create-stack file_resolver = Util::RecursiveHotFileLoader.new(options[:template] || options[:template_url], options[:files]) options[:template] = file_resolver.template options[:files] = file_resolver.files unless file_resolver.files.empty? request( :expects => 201, :path => 'stacks', :method => 'POST', :body => Fog::JSON.encode(options) ) end end class Mock def create_stack(arg1, arg2 = nil) if arg1.kind_of?(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 = 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"}] } if options.key?(:files) response.body['files'] = {'foo.sh' => 'hello'} end if options.key?(:template) || options.key?(:template_url) file_resolver = OrchestrationUtil::RecursiveHotFileLoader.new(options[:template] || options[:template_url], options[:files]) response.body['files'] = file_resolver.files unless file_resolver.files.empty? end response end end end end end fog-openstack-1.0.8/lib/fog/openstack/orchestration/requests/show_resource_metadata.rb0000644000004100000410000000116313423370527031442 0ustar www-datawww-datamodule Fog module OpenStack class Orchestration 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 = data[:resources].values Excon::Response.new( :body => {'resources' => resources}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/orchestration/requests/abandon_stack.rb0000644000004100000410000000047113423370527027503 0ustar www-datawww-datamodule Fog module OpenStack class Orchestration 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-1.0.8/lib/fog/openstack/orchestration/requests/cancel_update.rb0000644000004100000410000000112313423370527027476 0ustar www-datawww-data# frozen_string_literal: true module Fog module OpenStack class Orchestration class Real def cancel_update(stack) request( :expects => 200, :method => 'POST', :path => "stacks/#{stack.stack_name}/#{stack.id}/actions", :body => Fog::JSON.encode('cancel_update' => nil) ) end end class Mock def cancel_update(_) response = Excon::Response.new response.status = 200 response.body = {} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/orchestration/requests/list_resource_types.rb0000644000004100000410000000107013423370527031016 0ustar www-datawww-datamodule Fog module OpenStack class Orchestration 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 = data[:resource_types].values Excon::Response.new( :body => {'resource_types' => resources}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/orchestration/requests/list_stack_events.rb0000644000004100000410000000153413423370527030441 0ustar www-datawww-datamodule Fog module OpenStack class Orchestration 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 = data[:events].values Excon::Response.new( :body => {'events' => events}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/orchestration/requests/show_stack_details.rb0000644000004100000410000000101513423370527030561 0ustar www-datawww-datamodule Fog module OpenStack class Orchestration 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 = data[:stack].values Excon::Response.new( :body => {'stack' => stack}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/orchestration/requests/show_resource_data.rb0000644000004100000410000000117313423370527030574 0ustar www-datawww-datamodule Fog module OpenStack class Orchestration 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 = data[:resources].values Excon::Response.new( :body => {'resources' => resources}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/orchestration/requests/list_stack_data_detailed.rb0000644000004100000410000000450313423370527031700 0ustar www-datawww-datamodule Fog module OpenStack class Orchestration 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-1.0.8/lib/fog/openstack/orchestration/requests/build_info.rb0000644000004100000410000000041013423370527027017 0ustar www-datawww-datamodule Fog module OpenStack class Orchestration class Real def build_info request( :expects => [200], :method => 'GET', :path => 'build_info' ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/orchestration/requests/update_stack.rb0000644000004100000410000000710613423370527027365 0ustar www-datawww-datamodule Fog module OpenStack class Orchestration class Real # Update a stack. # # @param [Fog::OpenStack::Orchestration::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. # * :files [Hash] Hash with files resources. # def update_stack(arg1, arg2 = nil, arg3 = nil) if arg1.kind_of?(Stack) # Normal use, update_stack(stack, options = {}) stack = arg1 stack_name = stack.stack_name stack_id = stack.id options = 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 options = { :stack_name => stack_name }.merge(arg3.nil? ? {} : arg3) end # Templates should always: # - be strings # - contain URI references instead of relative paths. # Passing :template_url may not work well with `get_file` and remote `type`: # the python client implementation in shade retrieves from :template_uri # and replaces it with :template. # see https://github.com/openstack-infra/shade/blob/master/shade/openstackcloud.py#L1201 # see https://developer.openstack.org/api-ref/orchestration/v1/index.html#create-stack file_resolver = Util::RecursiveHotFileLoader.new(options[:template] || options[:template_url], options[:files]) options[:template] = file_resolver.template options[:files] = file_resolver.files unless file_resolver.files.empty? request( :expects => 202, :path => "stacks/#{stack_name}/#{stack_id}", :method => 'PUT', :body => Fog::JSON.encode(options) ) end end class Mock def update_stack(arg1, arg2 = nil, arg3 = nil) if arg1.kind_of?(Stack) # Normal use, update_stack(stack, options = {}) stack = arg1 stack_name = stack.stack_name stack_id = stack.id options = 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 options = { :stack_name => stack_name }.merge(arg3.nil? ? {} : arg3) end if options.key?(:files) response.body['files'] = {'foo.sh' => 'hello'} end if options.key?(:template) || options.key?(:template_url) file_resolver = Util::RecursiveHotFileLoader.new(options[:template] || options[:template_url], options[:files]) response.body['files'] = file_resolver.files unless file_resolver.files.empty? end response = Excon::Response.new response.status = 202 response.body = {} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/orchestration/requests/show_resource_schema.rb0000644000004100000410000000044213423370527031121 0ustar www-datawww-datamodule Fog module OpenStack class Orchestration class Real def show_resource_schema(name) request( :method => 'GET', :path => "resource_types/#{name}", :expects => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/orchestration/requests/show_event_details.rb0000644000004100000410000000115713423370527030604 0ustar www-datawww-datamodule Fog module OpenStack class Orchestration 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 = data[:events].values Excon::Response.new( :body => {'events' => events}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/orchestration/requests/list_resource_events.rb0000644000004100000410000000177613423370527031173 0ustar www-datawww-datamodule Fog module OpenStack class Orchestration 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 = data[:events].values Excon::Response.new( :body => {'events' => events}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/orchestration/requests/delete_stack.rb0000644000004100000410000000331113423370527027337 0ustar www-datawww-datamodule Fog module OpenStack class Orchestration 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.kind_of?(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.kind_of?(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 data[:stacks].delete(stack_id) response = Excon::Response.new response.status = 204 response.body = {} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/orchestration/requests/patch_stack.rb0000644000004100000410000000207113423370527027176 0ustar www-datawww-datamodule Fog module OpenStack class Orchestration class Real # patch a stack. # # @param [Fog::OpenStack::Orchestration::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-1.0.8/lib/fog/openstack/orchestration/requests/preview_stack.rb0000644000004100000410000000052113423370527027556 0ustar www-datawww-datamodule Fog module OpenStack class Orchestration 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-1.0.8/lib/fog/openstack/orchestration/requests/list_events.rb0000644000004100000410000000304113423370527027247 0ustar www-datawww-datamodule Fog module OpenStack class Orchestration 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) path = if resource_name "stacks/#{stack_name}/#{stack_id}/resources/#{resource_name}/events" else "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 = data[:events].values Excon::Response.new( :body => {'events' => events}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/orchestration/requests/show_resource_template.rb0000644000004100000410000000057613423370527031504 0ustar www-datawww-datamodule Fog module OpenStack class Orchestration 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-1.0.8/lib/fog/openstack/orchestration/requests/list_resources.rb0000644000004100000410000000342313423370527027761 0ustar www-datawww-datamodule Fog module OpenStack class Orchestration class Real def list_resources(options = {}, options_deprecated = {}) if options.kind_of?(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 = data[:resources].values Excon::Response.new( :body => {'resources' => resources}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/orchestration/requests/get_stack_template.rb0000644000004100000410000000061013423370527030546 0ustar www-datawww-datamodule Fog module OpenStack class Orchestration 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-1.0.8/lib/fog/openstack/orchestration/requests/validate_template.rb0000644000004100000410000000051713423370527030401 0ustar www-datawww-datamodule Fog module OpenStack class Orchestration 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-1.0.8/lib/fog/openstack/orchestration/models/0000755000004100000410000000000013423370527023775 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/orchestration/models/resources.rb0000644000004100000410000000206713423370527026341 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/orchestration/models/resource' module Fog module OpenStack class Orchestration class Resources < Fog::OpenStack::Collection model Fog::OpenStack::Orchestration::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 = first.stack if stack.nil? data = service.show_resource_data(stack.stack_name, stack.id, resource_name).body['resource'] new(data) rescue Fog::OpenStack::Compute::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::OpenStack::Compute::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/orchestration/models/template.rb0000644000004100000410000000044713423370527026142 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Orchestration 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-1.0.8/lib/fog/openstack/orchestration/models/events.rb0000644000004100000410000000167313423370527025635 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/orchestration/models/event' module Fog module OpenStack class Orchestration class Events < Fog::OpenStack::Collection model Fog::OpenStack::Orchestration::Event def all(options = {}, options_deprecated = {}) data = if options.kind_of?(Stack) service.list_stack_events(options, options_deprecated) elsif options.kind_of?(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::OpenStack::Compute::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/orchestration/models/resource_schemas.rb0000644000004100000410000000053313423370527027655 0ustar www-datawww-datarequire 'fog/openstack/models/collection' module Fog module OpenStack class Orchestration class ResourceSchemas < Fog::OpenStack::Collection def get(resource_type) service.show_resource_schema(resource_type).body rescue Fog::OpenStack::Compute::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/orchestration/models/event.rb0000644000004100000410000000062013423370527025441 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Orchestration 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-1.0.8/lib/fog/openstack/orchestration/models/stacks.rb0000644000004100000410000000356213423370527025620 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/orchestration/models/stack' module Fog module OpenStack class Orchestration class Stacks < Fog::OpenStack::Collection model Fog::OpenStack::Orchestration::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})[/]") 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::OpenStack::Compute::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-1.0.8/lib/fog/openstack/orchestration/models/resource.rb0000644000004100000410000000136713423370527026160 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Orchestration 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, resource_name).body['metadata'] end def template @template ||= service.templates.get(self) end end end end end fog-openstack-1.0.8/lib/fog/openstack/orchestration/models/templates.rb0000644000004100000410000000262313423370527026323 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/orchestration/models/template' module Fog module OpenStack class Orchestration class Templates < Fog::OpenStack::Collection model Fog::OpenStack::Orchestration::Template def get(obj) data = if obj.kind_of?(Stack) service.get_stack_template(obj).body else service.show_resource_template(obj.resource_name).body end if data.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::OpenStack::Orchestration::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-1.0.8/lib/fog/openstack/orchestration/models/stack.rb0000644000004100000410000001013413423370527025426 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Orchestration 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 files).each do |a| attribute a.to_sym end def save(options = {}) if persisted? stack_default_options = default_options if (options.key?(:template_url)) stack_default_options.delete(:template) end service.update_stack(self, stack_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 destroy delete def details @details ||= service.stacks.get(stack_name, 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 def cancel_update service.cancel_update(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.kind_of?(Fog::OpenStack::Orchestration::Template) template.content else template end options = { :stack_name => stack_name, :disable_rollback => disable_rollback, :timeout_mins => timeout_mins } options[:template] = template_content if template_content options[:template_url] = @template_url if @template_url options[:files] = @files if @files options end private :default_options end end end end fog-openstack-1.0.8/lib/fog/openstack/orchestration/util/0000755000004100000410000000000013423370527023467 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/orchestration/util/recursive_hot_file_loader.rb0000644000004100000410000001723513423370527031232 0ustar www-datawww-datarequire 'set' require 'yaml' require 'open-uri' require 'objspace' require 'fog/core' module Fog module OpenStack module OrchestrationUtil # # Resolve get_file resources found in a HOT template populating # a files Hash conforming to Heat Specs # https://developer.openstack.org/api-ref/orchestration/v1/index.html?expanded=create-stack-detail#stacks # # Files present in :files are not processed further. The others # are added to the Hash. This behavior is the same implemented in openstack-infra/shade # see https://github.com/openstack-infra/shade/blob/1d16f64fbf376a956cafed1b3edd8e51ccc16f2c/shade/openstackcloud.py#L1200 # # This implementation just process nested templates but not resource # registries. class RecursiveHotFileLoader attr_reader :files attr_reader :template def initialize(template, files = nil) # According to https://github.com/fog/fog-openstack/blame/master/docs/orchestration.md#L122 # templates can be either String or Hash. # If it's an Hash, we deep_copy it so the passed argument # is not modified by get_file_contents. template = deep_copy(template) @visited = Set.new @files = files || {} @template = get_template_contents(template) end # Return string def url_join(prefix, suffix) if prefix # URI.join replaces prefix parts before a # trailing slash. See https://docs.ruby-lang.org/en/2.3.0/URI.html. prefix += '/' unless prefix.to_s.end_with?("/") suffix = URI.join(prefix, suffix) # Force URI to use traditional file scheme representation. suffix.host = "" if suffix.scheme == "file" end suffix.to_s end # Retrieve a template content. # # @param template_file can be either: # - a raw_template string # - an URI string # - an Hash containing the parsed template. # # XXX: we could use named parameters # and better mimic heatclient implementation. def get_template_contents(template_file) Fog::Logger.debug("get_template_contents [#{template_file}]") raise "template_file should be Hash or String, not #{template_file.class.name}" unless template_file.kind_of?(String) || template_file.kind_of?(Hash) local_base_url = url_join("file:/", File.absolute_path(Dir.pwd)) if template_file.kind_of?(Hash) template_base_url = local_base_url template = template_file elsif template_is_raw?(template_file) template_base_url = local_base_url template = YAML.safe_load(template_file, [Date]) elsif template_is_url?(template_file) template_file = normalise_file_path_to_url(template_file) template_base_url = base_url_for_url(template_file) raw_template = read_uri(template_file) template = YAML.safe_load(raw_template, [Date]) Fog::Logger.debug("Template visited: #{@visited}") @visited.add(template_file) else raise "template_file is not a string of the expected form" end get_file_contents(template, template_base_url) template end # Traverse the template tree looking for get_file and type # and populating the @files attribute with their content. # Resource referenced by get_file and type are eventually # replaced with their absolute URI as done in heatclient # and shade. # def get_file_contents(from_data, base_url) Fog::Logger.debug("Processing #{from_data} with base_url #{base_url}") # Recursively traverse the tree # if recurse_data is Array or Hash recurse_data = from_data.kind_of?(Hash) ? from_data.values : from_data recurse_data.each { |value| get_file_contents(value, base_url) } if recurse_data.kind_of?(Array) # I'm on a Hash, process it. return unless from_data.kind_of?(Hash) from_data.each do |key, value| next if ignore_if(key, value) # Resolve relative paths. str_url = url_join(base_url, value) next if @files.key?(str_url) file_content = read_uri(str_url) # get_file should not recurse hot templates. if key == "type" && template_is_raw?(file_content) && !@visited.include?(str_url) template = get_template_contents(str_url) file_content = YAML.dump(template) end @files[str_url] = file_content # replace the data value with the normalised absolute URL as required # by https://docs.openstack.org/heat/pike/template_guide/hot_spec.html#get-file from_data[key] = str_url end end private # Retrive the content of a local or remote file. # # @param A local or remote uri. # # @raise ArgumentError if it's not a valid uri # # Protect open-uri from malign arguments like # - "|ls" # - multiline strings def read_uri(uri_or_filename) remote_schemes = %w[http https ftp] Fog::Logger.debug("Opening #{uri_or_filename}") begin # Validate URI to protect from open-uri attacks. url = URI(uri_or_filename) if remote_schemes.include?(url.scheme) # Remote schemes must contain an host. raise ArgumentError if url.host.nil? # Encode URI with spaces. uri_or_filename = uri_or_filename.gsub(/ /, "%20") end rescue URI::InvalidURIError raise ArgumentError, "Not a valid URI: #{uri_or_filename}" end # TODO: A future revision may implement a retry. content = '' # open-uri doesn't open "file:///" uris. uri_or_filename = uri_or_filename.sub(/^file:/, "") open(uri_or_filename) { |f| content = f.read } content end # Return true if the file is an heat template, false otherwise. def template_is_raw?(content) htv = content.strip.index("heat_template_version") # Tolerate some leading character in case of a json template. htv && htv < 5 end # Return true if it's an URI, false otherwise. def template_is_url?(path) normalise_file_path_to_url(path) true rescue ArgumentError, URI::InvalidURIError false end # Return true if I should I process this this file. # # @param [String] An heat template key # def ignore_if(key, value) return true if key != 'get_file' && key != 'type' return true unless value.kind_of?(String) return true if key == 'type' && !value.end_with?('.yaml', '.template') false end # Returns the string baseurl of the given url. def base_url_for_url(url) parsed = URI(url) parsed_dir = File.dirname(parsed.path) url_join(parsed, parsed_dir) end def normalise_file_path_to_url(path) # Nothing to do on URIs return path if URI(path).scheme path = File.absolute_path(path) url_join('file:/', path) end def deep_copy(item) return item if item.kind_of?(String) YAML.safe_load(YAML.dump(item), [Date]) end end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/0000755000004100000410000000000013423370527022013 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/monitoring/requests/0000755000004100000410000000000013423370527023666 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/monitoring/requests/get_alarm_definition.rb0000644000004100000410000000047413423370527030363 0ustar www-datawww-datamodule Fog module OpenStack class Monitoring class Real def get_alarm_definition(id) request( :expects => [200], :method => 'GET', :path => "alarm-definitions/#{id}" ) end end class Mock end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/requests/delete_notification_method.rb0000644000004100000410000000051013423370527031557 0ustar www-datawww-datamodule Fog module OpenStack class Monitoring class Real def delete_notification_method(id) request( :expects => [204], :method => 'DELETE', :path => "notification-methods/#{id}" ) end end class Mock end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/requests/update_alarm.rb0000644000004100000410000000054513423370527026655 0ustar www-datawww-datamodule Fog module OpenStack class Monitoring class Real def update_alarm(id, options) request( :expects => [200], :method => 'PUT', :path => "alarms/#{id}", :body => Fog::JSON.encode(options) ) end end class Mock end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/requests/get_alarm.rb0000644000004100000410000000054413423370527026151 0ustar www-datawww-datamodule Fog module OpenStack class Monitoring class Real def get_alarm(id) request( :expects => [200], :method => 'GET', :path => "alarms/#{id}" ) end end class Mock # def get_alarm(options = {}) # # end end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/requests/delete_alarm.rb0000644000004100000410000000045413423370527026634 0ustar www-datawww-datamodule Fog module OpenStack class Monitoring class Real def delete_alarm(id) request( :expects => [204], :method => 'DELETE', :path => "alarms/#{id}" ) end end class Mock end end end end ././@LongLink0000644000000000000000000000015100000000000011600 Lustar rootrootfog-openstack-1.0.8/lib/fog/openstack/monitoring/requests/list_alarm_state_history_for_specific_alarm.rbfog-openstack-1.0.8/lib/fog/openstack/monitoring/requests/list_alarm_state_history_for_specific_alar0000644000004100000410000000072213423370527034434 0ustar www-datawww-datamodule Fog module OpenStack class Monitoring class Real def list_alarm_state_history_for_specific_alarm(id, options = {}) request( :expects => [200], :method => 'GET', :path => "alarms/#{id}/state-history", :query => options ) end end class Mock # def list_alarm_state_history(options = {}) # # end end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/requests/find_measurements.rb0000644000004100000410000000064713423370527027732 0ustar www-datawww-datamodule Fog module OpenStack class Monitoring class Real def find_measurements(options = {}) request( :expects => [200], :method => 'GET', :path => "metrics/measurements", :query => options ) end end class Mock # def list_measurements(options = {}) # # end end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/requests/list_dimension_values.rb0000644000004100000410000000077113423370527030617 0ustar www-datawww-datamodule Fog module OpenStack class Monitoring class Real def list_dimension_values(dimension_name, options = {}) request( :expects => [200], :method => 'GET', :path => "metrics/dimensions/names/values", :query => options.merge(:dimension_name => dimension_name) ) end end class Mock # def list_dimension_values(dimension_name, options = {}) # end end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/requests/create_alarm_definition.rb0000644000004100000410000000056713423370527031052 0ustar www-datawww-datamodule Fog module OpenStack class Monitoring class Real def create_alarm_definition(options) request( :body => Fog::JSON.encode(options), :expects => [201, 204], :method => 'POST', :path => 'alarm-definitions' ) end end class Mock end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/requests/list_alarm_definitions.rb0000644000004100000410000000064413423370527030741 0ustar www-datawww-datamodule Fog module OpenStack class Monitoring class Real def list_alarm_definitions(options = {}) request( :expects => [200], :method => 'GET', :path => "alarm-definitions", :query => options ) end end class Mock # def list_metrics(options = {}) # # end end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/requests/patch_notification_method.rb0000644000004100000410000000061513423370527031422 0ustar www-datawww-datamodule Fog module OpenStack class Monitoring class Real def update_notification_method(id, notification) request( :expects => [200], :method => 'PATCH', :path => "notification-methods/#{id}", :body => Fog::JSON.encode(notification) ) end end class Mock end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/requests/list_notification_methods.rb0000644000004100000410000000065213423370527031462 0ustar www-datawww-datamodule Fog module OpenStack class Monitoring class Real def list_notification_methods(options = {}) request( :expects => [200], :method => 'GET', :path => "notification-methods", :query => options ) end end class Mock # def list_metrics(options = {}) # # end end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/requests/create_metric_array.rb0000644000004100000410000000055613423370527030225 0ustar www-datawww-datamodule Fog module OpenStack class Monitoring class Real def create_metric_array(metrics_list) request( :body => Fog::JSON.encode(metrics_list), :expects => [204], :method => 'POST', :path => 'metrics' ) end end class Mock end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/requests/create_notification_method.rb0000644000004100000410000000057513423370527031573 0ustar www-datawww-datamodule Fog module OpenStack class Monitoring class Real def create_notification_method(options) request( :body => Fog::JSON.encode(options), :expects => [201, 204], :method => 'POST', :path => 'notification-methods' ) end end class Mock end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/requests/list_notification_method_types.rb0000644000004100000410000000061213423370527032517 0ustar www-datawww-datamodule Fog module OpenStack class Monitoring class Real def list_notification_method_types request( :expects => [200], :method => 'GET', :path => "notification-methods/types" ) end end class Mock # def list_notification_method_types # # end end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/requests/patch_alarm_definition.rb0000644000004100000410000000061613423370527030701 0ustar www-datawww-datamodule Fog module OpenStack class Monitoring class Real def patch_alarm_definition(id, alarm_definition) request( :expects => [200], :method => 'PATCH', :path => "alarm-definitions/#{id}", :body => Fog::JSON.encode(alarm_definition) ) end end class Mock end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/requests/patch_alarm.rb0000644000004100000410000000054613423370527026473 0ustar www-datawww-datamodule Fog module OpenStack class Monitoring class Real def patch_alarm(id, options) request( :expects => [200], :method => 'PATCH', :path => "alarms/#{id}", :body => Fog::JSON.encode(options) ) end end class Mock end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/requests/create_metric.rb0000644000004100000410000000122013423370527027014 0ustar www-datawww-datamodule Fog module OpenStack class Monitoring class Real def create_metric(options) data = options # data = { # 'name' => name, # 'dimensions' => dimensions, # 'timestamp' => timestamp, # 'value' => value, # 'value_meta' => value_meta # } # _create_metric(data) request( :body => Fog::JSON.encode(data), :expects => [204], :method => 'POST', :path => 'metrics' ) end end class Mock end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/requests/list_metric_names.rb0000644000004100000410000000063313423370527027716 0ustar www-datawww-datamodule Fog module OpenStack class Monitoring class Real def list_metric_names(options = {}) request( :expects => [200], :method => 'GET', :path => "metrics/names", :query => options ) end end class Mock # def list_metrics(options = {}) # # end end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/requests/put_notification_method.rb0000644000004100000410000000061013423370527031126 0ustar www-datawww-datamodule Fog module OpenStack class Monitoring class Real def put_notification_method(id, notification) request( :expects => [200], :method => 'PUT', :path => "notification-methods/#{id}", :body => Fog::JSON.encode(notification) ) end end class Mock end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/requests/get_alarm_counts.rb0000644000004100000410000000063513423370527027545 0ustar www-datawww-datamodule Fog module OpenStack class Monitoring class Real def get_alarm_counts(options = {}) request( :expects => [200], :method => 'GET', :path => "alarms/count", :query => options ) end end class Mock # def get_alarm_counts(options = {}) # # end end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/requests/list_alarm_state_history_for_all_alarms.rb0000644000004100000410000000070413423370527034361 0ustar www-datawww-datamodule Fog module OpenStack class Monitoring class Real def list_alarm_state_history_for_all_alarms(options = {}) request( :expects => [200], :method => 'GET', :path => "alarms/state-history", :query => options ) end end class Mock # def list_alarm_state_history(options = {}) # # end end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/requests/update_alarm_definition.rb0000644000004100000410000000061513423370527031063 0ustar www-datawww-datamodule Fog module OpenStack class Monitoring class Real def update_alarm_definition(id, alarm_definition) request( :expects => [200], :method => 'PUT', :path => "alarm-definitions/#{id}", :body => Fog::JSON.encode(alarm_definition) ) end end class Mock end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/requests/get_notification_method.rb0000644000004100000410000000050213423370527031075 0ustar www-datawww-datamodule Fog module OpenStack class Monitoring class Real def get_notification_method(id) request( :expects => [200], :method => 'GET', :path => "notification-methods/#{id}" ) end end class Mock end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/requests/list_alarms.rb0000644000004100000410000000061513423370527026527 0ustar www-datawww-datamodule Fog module OpenStack class Monitoring class Real def list_alarms(options = {}) request( :expects => [200], :method => 'GET', :path => "alarms", :query => options ) end end class Mock # def list_alarms(options = {}) # # end end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/requests/delete_alarm_definition.rb0000644000004100000410000000050213423370527031036 0ustar www-datawww-datamodule Fog module OpenStack class Monitoring class Real def delete_alarm_definition(id) request( :expects => [204], :method => 'DELETE', :path => "alarm-definitions/#{id}" ) end end class Mock end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/requests/list_statistics.rb0000644000004100000410000000064113423370527027441 0ustar www-datawww-datamodule Fog module OpenStack class Monitoring class Real def list_statistics(options = {}) request( :expects => [200], :method => 'GET', :path => "metrics/statistics", :query => options ) end end class Mock # def list_statistics(options = {}) # # end end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/requests/list_metrics.rb0000644000004100000410000000062013423370527026712 0ustar www-datawww-datamodule Fog module OpenStack class Monitoring class Real def list_metrics(options = {}) request( :expects => [200], :method => 'GET', :path => "metrics", :query => options ) end end class Mock # def list_metrics(options = {}) # # end end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/models/0000755000004100000410000000000013423370527023276 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/monitoring/models/alarm_state.rb0000644000004100000410000000121713423370527026120 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Monitoring class AlarmState < Fog::OpenStack::Model identity :id attribute :alarm_id attribute :metrics attribute :old_state attribute :new_state attribute :reason attribute :reason_data attribute :timestamp attribute :sub_alarms def patch(options) requires :id merge_attributes( service.list_alarm_state_history_for_specific_alarm(id, options) ) self end def to_s name end end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/models/alarm.rb0000644000004100000410000000173313423370527024723 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Monitoring class Alarm < Fog::OpenStack::Model identity :id attribute :links attribute :link attribute :alarm_definition attribute :metrics attribute :state attribute :lifecycle_state attribute :state_updated_timestamp attribute :updated_timestamp attribute :created_timestamp def update(attr = nil) requires :id merge_attributes( service.update_alarm(id, attr || attributes).body ) self end def patch(attr = nil) requires :id merge_attributes( service.patch_alarm(id, attr || attributes).body ) self end def destroy requires :id service.delete_alarm(id) true end def to_s name end end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/models/metric.rb0000644000004100000410000000100413423370527025101 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Monitoring class Metric < Fog::OpenStack::Model identity :id attribute :name attribute :dimensions attribute :timestamp attribute :value attribute :value_meta def to_s name end def create requires :name, :timestamp, :value service.create_metric(attributes).body['metric'] self end end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/models/notification_method.rb0000644000004100000410000000177413423370527027662 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Monitoring class NotificationMethod < Fog::OpenStack::Model identity :id attribute :name attribute :links attribute :type attribute :address attribute :period def create requires :name, :type, :address merge_attributes( service.create_notification_method(attributes).body ) end def update(attr = nil) requires :name, :type, :address merge_attributes( service.put_notification_method(id, attr || attributes).body ) end def patch(attr = nil) merge_attributes( service.patch_notification_method(id, attr || attributes).body ) end def destroy requires :id service.delete_notification_method(id) true end def to_s name end end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/models/alarm_count.rb0000644000004100000410000000043713423370527026133 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Monitoring class AlarmCount < Fog::OpenStack::Model attribute :links attribute :columns attribute :counts def to_s name end end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/models/measurements.rb0000644000004100000410000000062013423370527026331 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/monitoring/models/measurement' module Fog module OpenStack class Monitoring class Measurements < Fog::OpenStack::Collection model Fog::OpenStack::Monitoring::Measurement def find(options = {}) load_response(service.find_measurements(options), 'elements') end end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/models/notification_methods.rb0000644000004100000410000000235013423370527030034 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/monitoring/models/notification_method' module Fog module OpenStack class Monitoring class NotificationMethods < Fog::OpenStack::Collection model Fog::OpenStack::Monitoring::NotificationMethod def all(options = {}) load_response(service.list_notification_methods(options), 'elements') end def create(attributes) super(attributes) end def patch(attributes) super(attributes) end def find_by_id(id) cached_notification_method = detect { |notification_method| notification_method.id == id } return cached_notification_method if cached_notification_method notification_method_hash = service.get_notification_method(id).body Fog::OpenStack::Monitoring::NotificationMethod.new( notification_method_hash.merge(:service => service) ) end def list_types service.list_notification_method_types.body['elements'].map { |x| x['type'].to_sym } end def destroy(id) notification_method = find_by_id(id) notification_method.destroy end end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/models/metrics.rb0000644000004100000410000000202013423370527025263 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/monitoring/models/metric' require 'fog/openstack/monitoring/models/dimension_values' module Fog module OpenStack class Monitoring class Metrics < Fog::OpenStack::Collection model Fog::OpenStack::Monitoring::Metric def all(options = {}) load_response(service.list_metrics(options), 'elements') end def list_metric_names(options = {}) load_response(service.list_metric_names(options), 'elements') end def create(attributes) super(attributes) end def create_metric_array(metrics_list = []) service.create_metric_array(metrics_list) end def list_dimension_values(dimension_name, options = {}) dimension_value = Fog::OpenStack::Monitoring::DimensionValues.new dimension_value.load_response( service.list_dimension_values(dimension_name, options), 'elements' ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/models/statistics.rb0000644000004100000410000000060713423370527026020 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/monitoring/models/statistic' module Fog module OpenStack class Monitoring class Statistics < Fog::OpenStack::Collection model Fog::OpenStack::Monitoring::Statistic def all(options = {}) load_response(service.list_statistics(options), 'elements') end end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/models/alarms.rb0000644000004100000410000000140713423370527025104 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/monitoring/models/alarm' module Fog module OpenStack class Monitoring class Alarms < Fog::OpenStack::Collection model Fog::OpenStack::Monitoring::Alarm def all(options = {}) load_response(service.list_alarms(options), 'elements') end def find_by_id(id) cached_alarm = detect { |alarm| alarm.id == id } return cached_alarm if cached_alarm alarm_hash = service.get_alarm(id).body Fog::OpenStack::Monitoring::Alarm.new( alarm_hash.merge(:service => service) ) end def destroy(id) alarm = find_by_id(id) alarm.destroy end end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/models/alarm_definition.rb0000644000004100000410000000242313423370527027130 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Monitoring class AlarmDefinition < Fog::OpenStack::Model identity :id attribute :links attribute :name attribute :description attribute :expression attribute :deterministic attribute :expression_data attribute :match_by attribute :severity attribute :actions_enabled attribute :alarm_actions attribute :ok_actions attribute :undetermined_actions def create requires :name, :expression merge_attributes( service.create_alarm_definition(attributes).body ) self end def update(attr = nil) requires :name, :expression merge_attributes( service.update_alarm_definition(id, attr || attributes).body ) end def patch(attr = nil) requires :id merge_attributes( service.patch_alarm_definition(id, attr || attributes).body ) self end def destroy requires :id service.delete_alarm_definition(id) true end def to_s name end end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/models/dimension_value.rb0000644000004100000410000000050613423370527027005 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Monitoring class DimensionValue < Fog::OpenStack::Model identity :id attribute :metric_name attribute :dimension_name attribute :values def to_s name end end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/models/alarm_counts.rb0000644000004100000410000000060013423370527026306 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/monitoring/models/alarm_count' module Fog module OpenStack class Monitoring class AlarmCounts < Fog::OpenStack::Collection model Fog::OpenStack::Monitoring::AlarmCount def get(options = {}) load_response(service.get_alarm_counts(options)) end end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/models/statistic.rb0000644000004100000410000000052413423370527025633 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Monitoring class Statistic < Fog::OpenStack::Model identity :id attribute :name attribute :dimension attribute :columns attribute :statistics def to_s name end end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/models/measurement.rb0000644000004100000410000000053113423370527026147 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Monitoring class Measurement < Fog::OpenStack::Model identity :id attribute :name attribute :dimensions attribute :columns attribute :measurements def to_s name end end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/models/dimension_values.rb0000644000004100000410000000067513423370527027177 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/monitoring/models/dimension_value' module Fog module OpenStack class Monitoring class DimensionValues < Fog::OpenStack::Collection model Fog::OpenStack::Monitoring::DimensionValue def all(dimension_name, options = {}) load_response(service.list_dimension_values(dimension_name, options), 'elements') end end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/models/alarm_states.rb0000644000004100000410000000111513423370527026300 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/monitoring/models/alarm_state' module Fog module OpenStack class Monitoring class AlarmStates < Fog::OpenStack::Collection model Fog::OpenStack::Monitoring::AlarmState def all(options = {}) load_response(service.list_alarm_state_history_for_all_alarms(options), 'elements') end def list_alarm_state_history(id, options = {}) load_response(service.list_alarm_state_history_for_specific_alarm(id, options), 'elements') end end end end end fog-openstack-1.0.8/lib/fog/openstack/monitoring/models/alarm_definitions.rb0000644000004100000410000000220013423370527027304 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/monitoring/models/alarm_definition' module Fog module OpenStack class Monitoring class AlarmDefinitions < Fog::OpenStack::Collection model Fog::OpenStack::Monitoring::AlarmDefinition def create(attributes) super(attributes) end def update(attributes) super(attributes) end def patch(attributes) super(attributes) end def all(options = {}) load_response(service.list_alarm_definitions(options), 'elements') end def find_by_id(id) cached_alarm_definition = detect { |alarm_definition| alarm_definition.id == id } return cached_alarm_definition if cached_alarm_definition alarm_definition_hash = service.get_alarm_definition(id).body Fog::OpenStack::Monitoring::AlarmDefinition.new( alarm_definition_hash.merge(:service => service) ) end def destroy(id) alarm_definition = find_by_id(id) alarm_definition.destroy end end end end end fog-openstack-1.0.8/lib/fog/openstack/storage/0000755000004100000410000000000013423370527021272 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/storage/requests/0000755000004100000410000000000013423370527023145 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/storage/requests/delete_multiple_objects.rb0000644000004100000410000000632313423370527030364 0ustar www-datawww-datamodule Fog module OpenStack class Storage 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-1.0.8/lib/fog/openstack/storage/requests/post_set_meta_temp_url_key.rb0000644000004100000410000000210313423370527031113 0ustar www-datawww-datamodule Fog module OpenStack class Storage 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-1.0.8/lib/fog/openstack/storage/requests/put_object_manifest.rb0000644000004100000410000000057713423370527027527 0ustar www-datawww-datamodule Fog module OpenStack class Storage 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-1.0.8/lib/fog/openstack/storage/requests/copy_object.rb0000644000004100000410000000170213423370527025772 0ustar www-datawww-datamodule Fog module OpenStack class Storage 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, 202], :headers => headers, :method => 'PUT', :path => "#{Fog::OpenStack.escape(target_container_name)}/#{Fog::OpenStack.escape(target_object_name)}") end end end end end fog-openstack-1.0.8/lib/fog/openstack/storage/requests/put_object.rb0000644000004100000410000000370413423370527025634 0ustar www-datawww-datamodule Fog module OpenStack class Storage 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, 202], :idempotent => !params[:request_block], :headers => headers, :method => 'PUT', :path => "#{Fog::OpenStack.escape(container)}/#{Fog::OpenStack.escape(object)}" ) request(params) end end class Mock require 'digest' def put_object(container, object, data, options = {}, &block) dgst = Digest::MD5.new if block_given? Kernel.loop do chunk = yield break if chunk.empty? dgst.update chunk end elsif data.kind_of?(String) dgst.update data else dgst.file data end response = Excon::Response.new response.status = 201 response.body = '' response.headers = {'ETag' => dgst.hexdigest} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/storage/requests/post_object.rb0000644000004100000410000000132313423370527026004 0ustar www-datawww-datamodule Fog module OpenStack class Storage class Real # Update object metadata # # ==== Parameters # * container<~String> - Name for container, should be < 256 bytes and must not contain '/' # * object<~String> - Name for object # * headers<~Hash> - metadata headers for object. Defaults to {}. # def post_object(container, object, headers = {}) params = { :expects => 202, :headers => headers, :method => 'POST', :path => "#{Fog::OpenStack.escape(container)}/#{Fog::OpenStack.escape(object)}" } request(params) end end end end end fog-openstack-1.0.8/lib/fog/openstack/storage/requests/delete_container.rb0000644000004100000410000000065313423370527027002 0ustar www-datawww-datamodule Fog module OpenStack class Storage 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-1.0.8/lib/fog/openstack/storage/requests/head_object.rb0000644000004100000410000000107613423370527025725 0ustar www-datawww-datamodule Fog module OpenStack class Storage 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-1.0.8/lib/fog/openstack/storage/requests/head_containers.rb0000644000004100000410000000113113423370527026614 0ustar www-datawww-datamodule Fog module OpenStack class Storage 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-1.0.8/lib/fog/openstack/storage/requests/head_container.rb0000644000004100000410000000135013423370527026434 0ustar www-datawww-datamodule Fog module OpenStack class Storage 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-1.0.8/lib/fog/openstack/storage/requests/put_dynamic_obj_manifest.rb0000644000004100000410000000422413423370527030530 0ustar www-datawww-datamodule Fog module OpenStack class Storage 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::OpenStack::Storage::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-1.0.8/lib/fog/openstack/storage/requests/get_object_https_url.rb0000644000004100000410000000632313423370527027707 0ustar www-datawww-datamodule Fog module OpenStack class Storage 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] || @openstack_management_uri.scheme host = options[:host] || @openstack_management_uri.host port = options[:port] || @openstack_management_uri.port # POST not allowed allowed_methods = %w(GET PUT HEAD) unless allowed_methods.include?(method) raise ArgumentError, "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.to_s) 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 do |c| c.to_s(16) end.map do |h| h.size == 1 ? "0#{h}" : h end.join end end end end end fog-openstack-1.0.8/lib/fog/openstack/storage/requests/get_object.rb0000644000004100000410000000122413423370527025576 0ustar www-datawww-datamodule Fog module OpenStack class Storage 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-1.0.8/lib/fog/openstack/storage/requests/get_object_http_url.rb0000644000004100000410000000125613423370527027524 0ustar www-datawww-datamodule Fog module OpenStack class Storage 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-1.0.8/lib/fog/openstack/storage/requests/delete_static_large_object.rb0000644000004100000410000000402713423370527031006 0ustar www-datawww-datamodule Fog module OpenStack class Storage 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-1.0.8/lib/fog/openstack/storage/requests/public_url.rb0000644000004100000410000000151313423370527025632 0ustar www-datawww-datamodule Fog module OpenStack class Storage module PublicUrl # 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 "#{@openstack_management_uri.scheme}://#{@openstack_management_uri.host}:"\ "#{@openstack_management_uri.port}#{@path}" end end class Real include PublicUrl end class Mock include PublicUrl end end end end fog-openstack-1.0.8/lib/fog/openstack/storage/requests/put_container.rb0000644000004100000410000000127313423370527026347 0ustar www-datawww-datamodule Fog module OpenStack class Storage 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-1.0.8/lib/fog/openstack/storage/requests/delete_object.rb0000644000004100000410000000103113423370527026255 0ustar www-datawww-datamodule Fog module OpenStack class Storage 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-1.0.8/lib/fog/openstack/storage/requests/put_static_obj_manifest.rb0000644000004100000410000000533313423370527030375 0ustar www-datawww-datamodule Fog module OpenStack class Storage 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::OpenStack::Storage::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-1.0.8/lib/fog/openstack/storage/requests/get_container.rb0000644000004100000410000000326313423370527026317 0ustar www-datawww-datamodule Fog module OpenStack class Storage 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-1.0.8/lib/fog/openstack/storage/requests/get_containers.rb0000644000004100000410000000174713423370527026507 0ustar www-datawww-datamodule Fog module OpenStack class Storage 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-1.0.8/lib/fog/openstack/storage/models/0000755000004100000410000000000013423370527022555 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/storage/models/directories.rb0000644000004100000410000000203013423370527025411 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/storage/models/directory' module Fog module OpenStack class Storage class Directories < Fog::OpenStack::Collection model Fog::OpenStack::Storage::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::OpenStack::Storage::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/storage/models/files.rb0000644000004100000410000000510713423370527024207 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/storage/models/file' module Fog module OpenStack class Storage class Files < Fog::OpenStack::Collection attribute :directory attribute :limit attribute :marker attribute :path attribute :prefix model Fog::OpenStack::Storage::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(&:attributes)) end end alias 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::OpenStack::Storage::NotFound nil end def get_url(key) requires :directory if directory.public_url "#{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::OpenStack::Storage::NotFound nil end def new(attributes = {}) requires :directory super({:directory => directory}.merge!(attributes)) end end end end end fog-openstack-1.0.8/lib/fog/openstack/storage/models/file.rb0000644000004100000410000001610313423370527024022 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Storage class File < Fog::OpenStack::Model identity :key, :aliases => 'name' attribute :access_control_allow_origin, :aliases => ['Access-Control-Allow-Origin'] attribute :cache_control, :aliases => ['Cache-Control'] 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 initialize(new_attributes = {}) super @dirty = if last_modified then false else true end end def body attributes[:body] ||= if last_modified collection.get(identity).try(:body) || '' else '' end end def body=(new_body) attributes[:body] = new_body @dirty = true end attr_reader :directory 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) @dirty = true 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 service.create_temp_url(directory.key, key, expires, "GET", options) end def public_url requires :key collection.get_url(key) end def save(options = {}) requires :directory, :key options['Cache-Control'] = cache_control if cache_control 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) if not @dirty data = service.post_object(directory.key, key, options) else requires :body data = service.put_object(directory.key, key, body, options) self.content_length = Fog::Storage.get_body_size(body) self.content_type ||= Fog::Storage.get_content_type(body) end update_attributes_from(data) refresh_metadata true end private attr_writer :directory 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, 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-1.0.8/lib/fog/openstack/storage/models/directory.rb0000644000004100000410000000214013423370527025103 0ustar www-datawww-datarequire 'fog/openstack/models/model' require 'fog/openstack/storage/models/files' module Fog module OpenStack class Storage 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::OpenStack::Storage::Files.new( :directory => self, :service => service ) end end def public_url requires :key @public_url ||= begin service.public_url(key) rescue Fog::OpenStack::Storage::NotFound => err nil end end def save requires :key service.put_container(key, :public => @public) true end end end end end fog-openstack-1.0.8/lib/fog/openstack/core.rb0000644000004100000410000002072213423370527021106 0ustar www-datawww-datamodule Fog module OpenStack module Core attr_accessor :auth_token attr_reader :unscoped_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_api_version # fallback def self.not_found_class Fog::OpenStack::Compute::NotFound end def credentials options = { :provider => 'openstack', :openstack_auth_url => @openstack_auth_uri.to_s, :openstack_auth_token => @auth_token, :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 def initialize(options = {}) setup(options) authenticate @connection = Fog::Core::Connection.new(@openstack_management_url, @persistent, @connection_options) end private def request(params, parse_json = true) retried = false begin response = @connection.request( params.merge( :headers => headers(params.delete(:headers)), :path => "#{@path}/#{params[:path]}" ) ) rescue Excon::Errors::Unauthorized => error # token expiration and token renewal possible if error.response.body != 'Bad username or password' && @openstack_can_reauthenticate && !retried @openstack_must_reauthenticate = true authenticate retried = true retry # bad credentials or token renewal not possible else raise error end rescue Excon::Errors::HTTPStatusError => error raise case error when Excon::Errors::NotFound self.class.not_found_class.slurp(error) else error end end if !response.body.empty? && response.get_header('Content-Type').match('application/json') # TODO: remove parse_json in favor of :raw_body response.body = Fog::JSON.decode(response.body) if parse_json && !params[:raw_body] end response end def set_microversion @microversion_key ||= 'Openstack-API-Version'.freeze @microversion_service_type ||= @openstack_service_type.first @microversion = Fog::OpenStack.get_supported_microversion( @supported_versions, @openstack_management_uri, @auth_token, @connection_options ).to_s # choose minimum out of reported and supported version if microversion_newer_than?(@supported_microversion) @microversion = @supported_microversion end # choose minimum out of set and wished version if @fixed_microversion && microversion_newer_than?(@fixed_microversion) @microversion = @fixed_microversion elsif @fixed_microversion && @microversion != @fixed_microversion Fog::Logger.warning("Microversion #{@fixed_microversion} not supported") end end def microversion_newer_than?(version) Gem::Version.new(version) < Gem::Version.new(@microversion) end def headers(additional_headers) additional_headers ||= {} unless @microversion.nil? || @microversion.empty? microversion_value = if @microversion_key == 'Openstack-API-Version' "#{@microversion_service_type} #{@microversion}" else @microversion end microversion_header = {@microversion_key => microversion_value} additional_headers.merge!(microversion_header) end { 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'X-Auth-Token' => @auth_token }.merge!(additional_headers) end def openstack_options options = {} # Create a hash of (:openstack_*, value) of all the @openstack_* instance variables 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 api_path_prefix path = '' if @openstack_management_uri && @openstack_management_uri.path != '/' path = @openstack_management_uri.path end unless default_path_prefix.empty? path << '/' + default_path_prefix end path end def default_endpoint_type 'public' end def default_path_prefix '' end def setup(options) if options.respond_to?(:config_service?) && options.config_service? configure(options) return end # 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_must_reauthenticate = false @openstack_endpoint_type = options[:openstack_endpoint_type] || 'public' @openstack_cache_ttl = options[:openstack_cache_ttl] || 0 if @auth_token @openstack_can_reauthenticate = false else missing_credentials = [] missing_credentials << :openstack_api_key unless @openstack_api_key unless @openstack_username || @openstack_userid missing_credentials << 'openstack_username or openstack_userid' end unless missing_credentials.empty? raise ArgumentError, "Missing required arguments: #{missing_credentials.join(', ')}" end @openstack_can_reauthenticate = true end @current_user = options[:current_user] @current_user_id = options[:current_user_id] @current_tenant = options[:current_tenant] @openstack_service_type = options[:openstack_service_type] || default_service_type @openstack_endpoint_type = options[:openstack_endpoint_type] || default_endpoint_type @openstack_endpoint_type.gsub!(/URL/, '') @connection_options = options[:connection_options] || {} @persistent = options[:persistent] || false end def authenticate if !@openstack_management_url || @openstack_must_reauthenticate @openstack_auth_token = nil if @openstack_must_reauthenticate token = Fog::OpenStack::Auth::Token.build(openstack_options, @connection_options) @openstack_management_url = if token.catalog && !token.catalog.payload.empty? token.catalog.get_endpoint_url( @openstack_service_type, @openstack_endpoint_type, @openstack_region ) else @openstack_auth_url end @current_user = token.user['name'] @current_user_id = token.user['id'] @current_tenant = token.tenant @expires = token.expires @auth_token = token.token @unscoped_token = token.token @openstack_must_reauthenticate = false else @auth_token = @openstack_auth_token end @openstack_management_uri = URI.parse(@openstack_management_url) # both need to be set in service's initialize for microversions to work set_microversion if @supported_microversion && @supported_versions @path = api_path_prefix true end end end end fog-openstack-1.0.8/lib/fog/openstack/metering.rb0000644000004100000410000000671613423370527021777 0ustar www-datawww-data module Fog module OpenStack class Metering < 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_api_version model_path 'fog/openstack/metering/models' model :resource collection :resources # Events extracted from Ceilometer (metering service) to Panko (event service) since Ocata release model :event collection :events request_path 'fog/openstack/metering/requests' # 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 self.not_found_class Fog::OpenStack::Metering::NotFound end def default_endpoint_type 'admin' end def default_path_prefix 'v2' end def default_service_type %w[metering] end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/0000755000004100000410000000000013423370527021317 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/network/requests/0000755000004100000410000000000013423370527023172 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/network/requests/update_ipsec_site_connection.rb0000644000004100000410000000565713423370527031444 0ustar www-datawww-datamodule Fog module OpenStack class Network 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::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/get_ike_policy.rb0000644000004100000410000000123613423370527026507 0ustar www-datawww-datamodule Fog module OpenStack class Network 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::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/delete_lb_pool.rb0000644000004100000410000000122013423370527026462 0ustar www-datawww-datamodule Fog module OpenStack class Network 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 data[:lb_pools].delete(pool_id) response.status = 204 response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/delete_lb_health_monitor.rb0000644000004100000410000000137613423370527030541 0ustar www-datawww-datamodule Fog module OpenStack class Network 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 data[:lb_health_monitors].delete(health_monitor_id) response.status = 204 response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/create_port.rb0000644000004100000410000000344513423370527026034 0ustar www-datawww-datamodule Fog module OpenStack class Network 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-1.0.8/lib/fog/openstack/network/requests/get_lbaas_pool_member.rb0000644000004100000410000000127613423370527030026 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def get_lbaas_pool_member(pool_id, member_id) request( :expects => [200], :method => 'GET', :path => "lbaas/pools/#{pool_id}/members/#{member_id}" ) end end class Mock def get_lbaas_pool_member(pool_id, member_id) response = Excon::Response.new if data = self.data[:lbaas_pool_members][member_id] response.status = 200 response.body = {'member' => data} response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/update_lb_health_monitor.rb0000644000004100000410000000314013423370527030550 0ustar www-datawww-datamodule Fog module OpenStack class Network 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::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/get_lbaas_l7rule.rb0000644000004100000410000000127413423370527026736 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def get_lbaas_l7rule(l7policy_id, l7rule_id) request( :expects => [200], :method => 'GET', :path => "lbaas/l7policies/#{l7policy_id}/rules/#{l7rule_id}" ) end end class Mock def get_lbaas_l7rule(l7policy_id, l7rule_id) response = Excon::Response.new if data = self.data[:lbaas_l7rules][l7rule_id] response.status = 200 response.body = {'rule' => data} response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/create_lb_health_monitor.rb0000644000004100000410000000334713423370527030542 0ustar www-datawww-datamodule Fog module OpenStack class Network 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-1.0.8/lib/fog/openstack/network/requests/list_networks.rb0000644000004100000410000000100613423370527026423 0ustar www-datawww-datamodule Fog module OpenStack class Network 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' => data[:networks].values}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/list_subnet_pools.rb0000644000004100000410000000103013423370527027260 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def list_subnet_pools(filters = {}) request( :expects => 200, :method => 'GET', :path => 'subnetpools', :query => filters ) end end class Mock def list_subnet_pools(_filters = {}) Excon::Response.new( :body => {'subnetpools' => data[:subnet_pools].values}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/add_router_interface.rb0000644000004100000410000000331513423370527027671 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def add_router_interface(router_id, subnet_id_or_options) if subnet_id_or_options.kind_of? String data = { 'subnet_id' => subnet_id_or_options, } elsif subnet_id_or_options.kind_of? 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-1.0.8/lib/fog/openstack/network/requests/delete_ipsec_site_connection.rb0000644000004100000410000000157013423370527031412 0ustar www-datawww-datamodule Fog module OpenStack class Network 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::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/remove_router_interface.rb0000644000004100000410000000154213423370527030436 0ustar www-datawww-datamodule Fog module OpenStack class Network 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-1.0.8/lib/fog/openstack/network/requests/create_lbaas_pool.rb0000644000004100000410000000343513423370527027162 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def create_lbaas_pool(listener_id, protocol, lb_algorithm, options = {}) data = { 'pool' => { 'listener_id' => listener_id, 'protocol' => protocol, 'lb_algorithm' => lb_algorithm } } vanilla_options = [:name, :description, :admin_state_up, :session_persistence, :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 => 'lbaas/pools' ) end end class Mock def create_lbaas_pool(listener_id, protocol, lb_algorithm, options = {}) response = Excon::Response.new response.status = 201 data = { 'id' => Fog::Mock.random_numbers(6).to_s, 'protocol' => protocol, 'lb_algorithm' => lb_algorithm, 'name' => options[:name], 'description' => options[:description], 'healthmonitor_id' => Fog::Mock.random_numbers(6).to_s, 'members' => [Fog::Mock.random_numbers(6).to_s], 'status' => 'ACTIVE', 'admin_state_up' => options[:admin_state_up], 'tenant_id' => options[:tenant_id], 'listeners' => [ 'id' => listener_id ], 'session_persistence' => {} } self.data[:lbaas_pools][data['id']] = data response.body = {'pool' => data} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/list_lbaas_pool_members.rb0000644000004100000410000000111413423370527030374 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def list_lbaas_pool_members(pool_id, filters = {}) request( :expects => 200, :method => 'GET', :path => "lbaas/pools/#{pool_id}/members", :query => filters ) end end class Mock def list_lbaas_pool_members(pool_id, _filters = {}) Excon::Response.new( :body => {'members' => data[:lbaas_pool_members].values}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/list_lb_vips.rb0000644000004100000410000000077613423370527026222 0ustar www-datawww-datamodule Fog module OpenStack class Network 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' => data[:lb_vips].values}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/associate_lb_health_monitor.rb0000644000004100000410000000177113423370527031251 0ustar www-datawww-datamodule Fog module OpenStack class Network 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 data[:lb_pools][pool_id] = pool response.body = {'health_monitor' => {}} response.status = 200 response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/list_lbaas_l7policies.rb0000644000004100000410000000106313423370527027766 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def list_lbaas_l7policies(filters = {}) request( :expects => 200, :method => 'GET', :path => "lbaas/l7policies", :query => filters ) end end class Mock def list_lbaas_l7policies(filters = {}) Excon::Response.new( :body => {'l7policies' => data[:lbaas_l7policies].values}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/get_router.rb0000644000004100000410000000126113423370527025676 0ustar www-datawww-datamodule Fog module OpenStack class Network 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::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/get_lb_member.rb0000644000004100000410000000120013423370527026273 0ustar www-datawww-datamodule Fog module OpenStack class Network 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::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/create_vpn_service.rb0000644000004100000410000000301613423370527027365 0ustar www-datawww-datamodule Fog module OpenStack class Network 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-1.0.8/lib/fog/openstack/network/requests/update_ike_policy.rb0000644000004100000410000000355613423370527027221 0ustar www-datawww-datamodule Fog module OpenStack class Network 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::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/set_tenant.rb0000644000004100000410000000052013423370527025660 0ustar www-datawww-datamodule Fog module OpenStack class Network 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 end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/list_extensions.rb0000644000004100000410000000102013423370527026742 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def list_extensions(filters = {}) request( :expects => 200, :method => 'GET', :path => 'extensions', :query => filters ) end end class Mock def list_extensions(_filters = {}) Excon::Response.new( :body => {'extensions' => data[:extensions].values}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/delete_lbaas_listener.rb0000644000004100000410000000131313423370527030026 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def delete_lbaas_listener(listener_id) request( :expects => 204, :method => 'DELETE', :path => "lbaas/listeners/#{listener_id}" ) end end class Mock def delete_lbaas_listener(listener_id) response = Excon::Response.new if list_lbaas_listeners.body['listsners'].map { |r| r['id'] }.include? listener_id data[:lbaas_listeners].delete(listener_id) response.status = 204 response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/get_floating_ip.rb0000644000004100000410000000227113423370527026653 0ustar www-datawww-datamodule Fog module OpenStack class Network 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::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/update_router.rb0000644000004100000410000000513313423370527026403 0ustar www-datawww-datamodule Fog module OpenStack class Network 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, :routes].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.kind_of?(Fog::OpenStack::Network::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.kind_of?(Hash) data['router'][:external_gateway_info] = egi else raise ArgumentError, '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::OpenStack::Network::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.kind_of?(Fog::OpenStack::Network::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 } elsif egi.is_a?(Hash) router[:external_gateway_info] = egi else raise ArgumentError.new('Invalid external_gateway_info attribute') end end response.body = {'router' => router} response.status = 200 response end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/associate_floating_ip.rb0000644000004100000410000000272013423370527030046 0ustar www-datawww-datamodule Fog module OpenStack class Network 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-1.0.8/lib/fog/openstack/network/requests/delete_lbaas_pool.rb0000644000004100000410000000123113423370527027151 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def delete_lbaas_pool(pool_id) request( :expects => 204, :method => 'DELETE', :path => "lbaas/pools/#{pool_id}" ) end end class Mock def delete_lbaas_pool(pool_id) response = Excon::Response.new if list_lb_pools.body['pools'].map { |r| r['id'] }.include? pool_id data[:lb_pools].delete(pool_id) response.status = 204 response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/delete_network.rb0000644000004100000410000000124213423370527026531 0ustar www-datawww-datamodule Fog module OpenStack class Network 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 data[:networks].delete(network_id) response.status = 204 response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/disassociate_lb_health_monitor.rb0000644000004100000410000000147513423370527031752 0ustar www-datawww-datamodule Fog module OpenStack class Network 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) data[:lb_pools][pool_id] = pool response.status = 204 response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/disassociate_floating_ip.rb0000644000004100000410000000262013423370527030545 0ustar www-datawww-datamodule Fog module OpenStack class Network 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-1.0.8/lib/fog/openstack/network/requests/delete_subnet_pool.rb0000644000004100000410000000131413423370527027371 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def delete_subnet_pool(subnet_pool_id) request( :expects => 204, :method => 'DELETE', :path => "subnetpools/#{subnet_pool_id}" ) end end class Mock def delete_subnet_pool(subnet_pool_id) response = Excon::Response.new if list_subnet_pools.body['subnetpools'].map { |r| r['id'] }.include? subnet_pool_id data[:subnet_pools].delete(subnet_pool_id) response.status = 204 response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/update_lb_pool.rb0000644000004100000410000000227113423370527026511 0ustar www-datawww-datamodule Fog module OpenStack class Network 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::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/create_floating_ip.rb0000644000004100000410000000256413423370527027344 0ustar www-datawww-datamodule Fog module OpenStack class Network 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, :floating_ip_address, :subnet_id] 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-1.0.8/lib/fog/openstack/network/requests/delete_ike_policy.rb0000644000004100000410000000131513423370527027170 0ustar www-datawww-datamodule Fog module OpenStack class Network 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::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/delete_router.rb0000644000004100000410000000122113423370527026355 0ustar www-datawww-datamodule Fog module OpenStack class Network 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 } data[:routers].delete(router_id) response.status = 204 response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/update_subnet.rb0000644000004100000410000000267313423370527026371 0ustar www-datawww-datamodule Fog module OpenStack class Network 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::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/list_vpn_services.rb0000644000004100000410000000102013423370527027251 0ustar www-datawww-datamodule Fog module OpenStack class Network 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-1.0.8/lib/fog/openstack/network/requests/delete_lbaas_l7rule.rb0000644000004100000410000000134713423370527027422 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def delete_lbaas_l7rule(l7policy_id, l7rule_id) request( :expects => 204, :method => 'DELETE', :path => "lbaas/l7policies/#{l7policy_id}/rules/#{l7rule_id}" ) end end class Mock def delete_lbaas_l7rule(l7policy_id, l7rule_id) response = Excon::Response.new if list_lbaas_l7rules.body['l7rules'].map { |r| r['id'] }.include? l7rule_id data[:lbaas_l7rules].delete(l7rule_id) response.status = 204 response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/create_security_group_rule.rb0000644000004100000410000000740513423370527031162 0ustar www-datawww-datamodule Fog module OpenStack class Network 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-1.0.8/lib/fog/openstack/network/requests/create_lb_vip.rb0000644000004100000410000000377613423370527026332 0ustar www-datawww-datamodule Fog module OpenStack class Network 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-1.0.8/lib/fog/openstack/network/requests/delete_ipsec_policy.rb0000644000004100000410000000134313423370527027524 0ustar www-datawww-datamodule Fog module OpenStack class Network 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::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/get_lbaas_loadbalancer.rb0000644000004100000410000000132613423370527030131 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def get_lbaas_loadbalancer(loadbalancer_id) request( :expects => [200], :method => 'GET', :path => "lbaas/loadbalancers/#{loadbalancer_id}" ) end end class Mock def get_lbaas_loadbalancer(loadbalancer_id) response = Excon::Response.new if data = self.data[:lbaas_loadbalancer][loadbalancer_id] response.status = 200 response.body = {'loadbalancer' => data[:lbaas_loadbalancer]} response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/update_quota.rb0000644000004100000410000000122313423370527026210 0ustar www-datawww-datamodule Fog module OpenStack class Network 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 = {}) data[:quota_updated] = data[:quota].merge options response = Excon::Response.new response.status = 200 response.body = {'quota' => data[:quota_updated]} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/list_routers.rb0000644000004100000410000000100113423370527026245 0ustar www-datawww-datamodule Fog module OpenStack class Network 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' => data[:routers].values}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/update_lbaas_listener.rb0000644000004100000410000000304213423370527030047 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def update_lbaas_listener(listener_id, options = {}) data = { 'listener' => {} } vanilla_options = [:name, :description, :connection_limit, :default_tls_container_ref, :sni_container_refs, :admin_state_up] vanilla_options.select { |o| options.key?(o) }.each do |key| data['listener'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'PUT', :path => "lbaas/listeners/#{listener_id}" ) end end class Mock def update_lbaas_listener(listener_id, options = {}) response = Excon::Response.new if listener = list_lbaas_listeners.body['listeners'].find { |_| _['id'] == listener_id } listener['name'] = options[:name] listener['description'] = options[:description] listener['connection_limit'] = options[:connection_limit] listener['default_tls_container_ref'] = options[:default_tls_container_ref] listener['sni_container_refs'] = options[:sni_container_refs] listener['admin_state_up'] = options[:admin_state_up] response.body = {'listener' => listener} response.status = 200 response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/list_lbaas_l7rules.rb0000644000004100000410000000112413423370527027307 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def list_lbaas_l7rules(l7policy_id, filters = {}) request( :expects => 200, :method => 'GET', :path => "lbaas/l7policies/#{l7policy_id}/rules", :query => filters ) end end class Mock def list_lbaas_l7rules(l7policy_id, filters = {}) Excon::Response.new( :body => {'rules' => data[:lbaas_l7rules].values}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/create_network.rb0000644000004100000410000000543613423370527026543 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real CREATE_OPTIONS = [ :name, :shared, :admin_state_up, :qos_policy_id, :port_security_enabled, :tenant_id, ].freeze # 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 EXTENTED_OPTIONS = [ :provider_network_type, :provider_segmentation_id, :provider_physical_network, :router_external, ].freeze # Map Fog::OpenStack::Network::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' }.freeze def self.create(options) data = {} CREATE_OPTIONS.reject { |o| options[o].nil? }.each do |key| data[key.to_s] = options[key] end EXTENTED_OPTIONS.reject { |o| options[o].nil? }.each do |key| aliased_key = ALIASES[key] || key data[aliased_key] = options[key] end data end def create_network(options = {}) data = {} data['network'] = self.class.create(options) 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] || false, 'subnets' => [], 'status' => 'ACTIVE', 'admin_state_up' => options[:admin_state_up] || false, 'tenant_id' => options[:tenant_id], 'qos_policy_id' => options[:qos_policy_id], 'port_security_enabled' => options[:port_security_enabled] || false } data.merge!(Fog::OpenStack::Network::Real.create(options)) self.data[:networks][data['id']] = data response.body = {'network' => data} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/update_security_group.rb0000644000004100000410000000225113423370527030144 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def update_security_group(security_group_id, options = {}) data = {'security_group' => {}} [:name, :description].each do |key| data['security_group'][key] = options[key] if options[key] end request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'PUT', :path => "security-groups/#{security_group_id}" ) end end class Mock def update_security_group(security_group_id, options = {}) response = Excon::Response.new security_group = list_security_groups.body['security_groups'].find do |sg| sg['id'] == security_group_id end if security_group security_group['name'] = options[:name] security_group['description'] = options[:description] response.body = {'security_group' => security_group} response.status = 200 response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/update_lbaas_healthmonitor.rb0000644000004100000410000000313713423370527031104 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def update_lbaas_healthmonitor(healthmonitor_id, options = {}) data = {'healthmonitor' => {}} vanilla_options = [:name, :delay, :timeout, :max_retries, :http_method, :url_path, :expected_codes, :admin_state_up] vanilla_options.select { |o| options.key?(o) }.each do |key| data['healthmonitor'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'PUT', :path => "lbaas/healthmonitors/#{healthmonitor_id}" ) end end class Mock def update_lbaas_healthmonitor(healthmonitor_id, options = {}) response = Excon::Response.new if healthmonitor = list_lbaas_health_monitors.body['healthmonitors'].find { |_| _['id'] == healthmonitor_id } healthmonitor['delay'] = options[:delay] healthmonitor['timeout'] = options[:timeout] healthmonitor['max_retries'] = options[:max_retries] healthmonitor['http_method'] = options[:http_method] healthmonitor['url_path'] = options[:url_path] healthmonitor['expected_codes'] = options[:expected_codes] healthmonitor['admin_state_up'] = options[:admin_state_up] response.body = {'healthmonitor' => healthmonitor} response.status = 200 response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/update_lbaas_l7policy.rb0000644000004100000410000000263013423370527027766 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def update_lbaas_l7policy(l7policy_id, options = {}) data = {'l7policy' => {}} vanilla_options = [:action, :name, :description, :redirect_pool_id, :redirect_url, :position] vanilla_options.select { |o| options.key?(o) }.each do |key| data['l7policy'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => [200], :method => 'PUT', :path => "lbaas/l7policies/#{l7policy_id}" ) end end class Mock def update_lbaas_l7rule(l7policy_id, options = {}) response = Excon::Response.new if l7policy = list_l7policies.body['l7policies'].find { |_| _['id'] == l7policy_id } l7policy['action'] = options[:action] l7policy['name'] = options[:name] l7policy['description'] = options[:description] l7policy['redirect_pool_id'] = options[:redirect_pool_id] l7policy['redirect_url'] = options[:redirect_url] l7policy['position'] = options[:position] response.body = {'l7policy' => l7policy} response.status = 200 response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/update_lbaas_pool_member.rb0000644000004100000410000000231113423370527030520 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def update_lbaas_pool_member(pool_id, member_id, options = {}) data = {'member' => {}} vanilla_options = [:weight, :admin_state_up, :name] 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 => "lbaas/pools/#{pool_id}/members/#{member_id}" ) end end class Mock def update_lbaas_pool_member(pool_id, member_id, options = {}) response = Excon::Response.new if member = list_lbaas_pool_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::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/get_security_group_rule.rb0000644000004100000410000000362313423370527030474 0ustar www-datawww-datamodule Fog module OpenStack class Network 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 = data[:security_group_rules][security_group_rule_id] response.status = 200 response.body = {"security_group_rule" => sec_group_rule} response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/create_subnet_pool.rb0000644000004100000410000000400313423370527027370 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def create_subnet_pool(name, prefixes, options = {}) data = { 'subnetpool' => { 'name' => name, 'prefixes' => prefixes } } vanilla_options = [:description, :address_scope_id, :shared, :min_prefixlen, :max_prefixlen, :default_prefixlen] vanilla_options.select { |o| options.key?(o) }.each do |key| data['subnetpool'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => [201], :method => 'POST', :path => 'subnetpools' ) end end class Mock def create_subnet_pool(name, prefixes, options = {}) response = Excon::Response.new response.status = 201 data = { 'id' => Fog::Mock.random_numbers(6).to_s, 'name' => name, 'prefixes' => prefixes, 'description' => options[:description], 'min_prefixlen' => options[:min_prefixlen] || 64, 'max_prefixlen' => options[:max_prefixlen] || 64, 'default_prefixlen' => options[:default_prefixlen] || 64, 'address_scope_id' => options[:address_scope_id], 'default_quota' => options[:default_quota], 'ip_version' => options[:ip_version] || 4, 'shared' => options[:shared].nil? ? false : options[:shared], 'is_default' => options[:is_default].nil? ? false : options[:is_default], 'created_at' => Time.now.to_s, 'updated_at' => Time.now.to_s, 'tenant_id' => Fog::Mock.random_hex(8).to_s } self.data[:subnet_pools][data['id']] = data response.body = {'subnetpool' => data} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/list_floating_ips.rb0000644000004100000410000000103013423370527027222 0ustar www-datawww-datamodule Fog module OpenStack class Network 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' => data[:floating_ips].values}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/create_lb_pool.rb0000644000004100000410000000347513423370527026501 0ustar www-datawww-datamodule Fog module OpenStack class Network 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-1.0.8/lib/fog/openstack/network/requests/list_lbaas_listeners.rb0000644000004100000410000000104713423370527027726 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def list_lbaas_listeners(filters = {}) request( :expects => 200, :method => 'GET', :path => 'lbaas/listeners', :query => filters ) end end class Mock def list_lbaas_listeners(_filters = {}) Excon::Response.new( :body => {'listeners' => data[:lbaas_listeners].values}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/list_rbac_policies.rb0000644000004100000410000000102313423370527027344 0ustar www-datawww-datamodule Fog module OpenStack class Network 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-1.0.8/lib/fog/openstack/network/requests/get_lbaas_pool.rb0000644000004100000410000000117213423370527026472 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def get_lbaas_pool(pool_id) request( :expects => [200], :method => 'GET', :path => "lbaas/pools/#{pool_id}" ) end end class Mock def get_lbaas_pool(pool_id) response = Excon::Response.new if data = self.data[:lbaas_pools][pool_id] response.status = 200 response.body = {'pool' => data} response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/get_network.rb0000644000004100000410000000117513423370527026053 0ustar www-datawww-datamodule Fog module OpenStack class Network 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::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/get_lbaas_listener.rb0000644000004100000410000000123613423370527027347 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def get_lbaas_listener(listener_id) request( :expects => [200], :method => 'GET', :path => "lbaas/listeners/#{listener_id}" ) end end class Mock def get_lbaas_listener(listener_id) response = Excon::Response.new if data = self.data[:lbaas_listeners][listener_id] response.status = 200 response.body = {'listener' => data} response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/get_rbac_policy.rb0000644000004100000410000000124513423370527026646 0ustar www-datawww-datamodule Fog module OpenStack class Network 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::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/get_ipsec_site_connection.rb0000644000004100000410000000140113423370527030720 0ustar www-datawww-datamodule Fog module OpenStack class Network 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::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/delete_rbac_policy.rb0000644000004100000410000000132613423370527027331 0ustar www-datawww-datamodule Fog module OpenStack class Network 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::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/get_lb_health_monitor.rb0000644000004100000410000000131013423370527030042 0ustar www-datawww-datamodule Fog module OpenStack class Network 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::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/list_network_ip_availabilities.rb0000644000004100000410000000124513423370527031777 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def list_network_ip_availabilities request( :expects => [200], :method => 'GET', :path => "network-ip-availabilities" ) end end class Mock def list_network_ip_availabilities response = Excon::Response.new if data = self.data[:network_ip_availabilities] response.status = 200 response.body = {'network_ip_availabilities' => data} response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/get_vpn_service.rb0000644000004100000410000000124513423370527026703 0ustar www-datawww-datamodule Fog module OpenStack class Network 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::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/list_security_group_rules.rb0000644000004100000410000000345613423370527031057 0ustar www-datawww-datamodule Fog module OpenStack class Network 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 = data[:security_group_rules].values unless data[:security_group_rules].nil? response.status = 200 response.body = {'security_group_rules' => sec_group_rules} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/update_rbac_policy.rb0000644000004100000410000000221113423370527027343 0ustar www-datawww-datamodule Fog module OpenStack class Network 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::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/create_lbaas_healthmonitor.rb0000644000004100000410000000363213423370527031065 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def create_lbaas_healthmonitor(pool_id, type, delay, timeout, max_retries, options = {}) data = { 'healthmonitor' => { 'pool_id' => pool_id, '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['healthmonitor'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => [201], :method => 'POST', :path => 'lbaas/healthmonitors' ) end end class Mock def create_lbaas_healthmonitor(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], 'name' => options[:name], 'pools' => [{ 'id'=> Fog::Mock.random_numbers(6).to_s}] } self.data[:lbaas_healthmonitors][data['id']] = data response.body = {'healthmonitor' => data} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/delete_security_group_rule.rb0000644000004100000410000000162413423370527031156 0ustar www-datawww-datamodule Fog module OpenStack class Network 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 data[:security_group_rules][security_group_rule_id] data[:security_group_rules].delete(security_group_rule_id) response.status = 204 response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/update_lb_vip.rb0000644000004100000410000000254713423370527026344 0ustar www-datawww-datamodule Fog module OpenStack class Network 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::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/create_lb_member.rb0000644000004100000410000000300013423370527026757 0ustar www-datawww-datamodule Fog module OpenStack class Network 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-1.0.8/lib/fog/openstack/network/requests/get_lb_pool.rb0000644000004100000410000000115613423370527026007 0ustar www-datawww-datamodule Fog module OpenStack class Network 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::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/list_lb_pools.rb0000644000004100000410000000100313423370527026355 0ustar www-datawww-datamodule Fog module OpenStack class Network 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' => data[:lb_pools].values}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/update_lbaas_pool.rb0000644000004100000410000000234113423370527027174 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def update_lbaas_pool(pool_id, options = {}) data = {'pool' => {}} vanilla_options = [:name, :description, :lb_algorithm, :session_persistence, :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 => "lbaas/pools/#{pool_id}" ) end end class Mock def update_lbaas_pool(pool_id, options = {}) response = Excon::Response.new if pool = list_lbaas_pools.body['pools'].find { |_| _['id'] == pool_id } pool['name'] = options[:name] pool['description'] = options[:description] pool['lb_algorithm'] = options[:lb_algorithm] pool['admin_state_up'] = options[:admin_state_up] response.body = {'pool' => pool} response.status = 200 response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/list_lb_health_monitors.rb0000644000004100000410000000106513423370527030430 0ustar www-datawww-datamodule Fog module OpenStack class Network 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' => data[:lb_health_monitors].values}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/create_router.rb0000644000004100000410000000511013423370527026357 0ustar www-datawww-datamodule Fog module OpenStack class Network 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.kind_of?(Fog::OpenStack::Network::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.kind_of?(Hash) && egi[:network_id] data['router'][:external_gateway_info] = egi else raise ArgumentError, '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.kind_of?(Fog::OpenStack::Network::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-1.0.8/lib/fog/openstack/network/requests/list_subnets.rb0000644000004100000410000000100113423370527026225 0ustar www-datawww-datamodule Fog module OpenStack class Network 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' => data[:subnets].values}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/create_ipsec_site_connection.rb0000644000004100000410000000471113423370527031413 0ustar www-datawww-datamodule Fog module OpenStack class Network 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-1.0.8/lib/fog/openstack/network/requests/create_ipsec_policy.rb0000644000004100000410000000331613423370527027527 0ustar www-datawww-datamodule Fog module OpenStack class Network 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-1.0.8/lib/fog/openstack/network/requests/get_extension.rb0000644000004100000410000000115713423370527026376 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def get_extension(name) request( :expects => [200], :method => 'GET', :path => "extensions/#{name}" ) end end class Mock def get_extension(name) response = Excon::Response.new if data = self.data[:extensions][name] response.status = 200 response.body = {'extension' => data} response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/delete_quota.rb0000644000004100000410000000070313423370527026172 0ustar www-datawww-datamodule Fog module OpenStack class Network 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-1.0.8/lib/fog/openstack/network/requests/update_ipsec_policy.rb0000644000004100000410000000370513423370527027550 0ustar www-datawww-datamodule Fog module OpenStack class Network 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::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/get_quotas.rb0000644000004100000410000000074613423370527025701 0ustar www-datawww-datamodule Fog module OpenStack class Network 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' => data[:quotas] } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/get_subnet_pool.rb0000644000004100000410000000126013423370527026706 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def get_subnet_pool(subnet_pool_id) request( :expects => [200], :method => 'GET', :path => "subnetpools/#{subnet_pool_id}" ) end end class Mock def get_subnet_pool(subnet_pool_id) data = self.data[:subnet_pools][subnet_pool_id] if data response = Excon::Response.new response.status = 200 response.body = {'subnetpool' => data} response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/delete_lbaas_pool_member.rb0000644000004100000410000000135213423370527030504 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def delete_lbaas_pool_member(pool_id, member_id) request( :expects => 204, :method => 'DELETE', :path => "lbaas/pools/#{pool_id}/members/#{member_id}" ) end end class Mock def delete_lbaas_pool_member(pool_id, member_id) response = Excon::Response.new if list_lbaas_pool_members(pool_id).body['members'].map { |r| r['id'] }.include? member_id data[:members].delete(member_id) response.status = 204 response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/get_port.rb0000644000004100000410000000336013423370527025344 0ustar www-datawww-datamodule Fog module OpenStack class Network 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::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/list_ipsec_site_connections.rb0000644000004100000410000000110413423370527031277 0ustar www-datawww-datamodule Fog module OpenStack class Network 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-1.0.8/lib/fog/openstack/network/requests/get_lbaas_l7policy.rb0000644000004100000410000000124013423370527027257 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def get_lbaas_l7policy(l7policy_id) request( :expects => [200], :method => 'GET', :path => "lbaas/l7policies/#{l7policy_id}" ) end end class Mock def get_lbaas_l7policy(l7policy_id) response = Excon::Response.new if data = self.data[:lbaas_l7policies][l7policy_id] response.status = 200 response.body = {'l7policy' => data} response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/delete_lbaas_healthmonitor.rb0000644000004100000410000000140213423370527031055 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def delete_lbaas_healthmonitor(healthmonitor_id) request( :expects => 204, :method => 'DELETE', :path => "lbaas/healthmonitors/#{healthmonitor_id}" ) end end class Mock def delete_lbaas_healthmonitor(healthmonitor_id) response = Excon::Response.new if list_lbaas_healthmonitors.body['healthmonitors'].map { |r| r['id'] }.include? healthmonitor_id data[:lbaas_healthmonitors].delete(healthmonitor_id) response.status = 204 response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/delete_lb_vip.rb0000644000004100000410000000120513423370527026312 0ustar www-datawww-datamodule Fog module OpenStack class Network 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 data[:lb_vips].delete(vip_id) response.status = 204 response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/delete_subnet.rb0000644000004100000410000000122713423370527026343 0ustar www-datawww-datamodule Fog module OpenStack class Network 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 data[:subnets].delete(subnet_id) response.status = 204 response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/list_ipsec_policies.rb0000644000004100000410000000103213423370527027540 0ustar www-datawww-datamodule Fog module OpenStack class Network 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-1.0.8/lib/fog/openstack/network/requests/get_security_group.rb0000644000004100000410000000427613423370527027452 0ustar www-datawww-datamodule Fog module OpenStack class Network 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 = data[:security_groups][security_group_id] response.status = 200 response.body = {"security_group" => sec_group} response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/create_lbaas_listener.rb0000644000004100000410000000403513423370527030033 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def create_lbaas_listener(loadbalancer_id, protocol, protocol_port, options = {}) data = { 'listener' => { 'loadbalancer_id' => loadbalancer_id, 'protocol' => protocol, 'protocol_port' => protocol_port } } vanilla_options = [:name, :description, :default_pool_id, :connection_limit, :default_tls_container_ref, :sni_container_refs, :admin_state_up, :tenant_id] vanilla_options.reject { |o| options[o].nil? }.each do |key| data['listener'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => [201], :method => 'POST', :path => 'lbaas/listeners' ) end end class Mock def create_lbaas_listener(loadbalancer_id, protocol, protocol_port, options = {}) response = Excon::Response.new response.status = 201 data = { 'id' => Fog::Mock.random_numbers(6).to_s, 'loadbalancers' => [{'id' => loadbalancer_id }], 'protocol' => protocol, 'protocol_port' => protocol_port, 'name' => options[:name], 'description' => options[:description], 'default_pool_id' => options[:default_pool_id], 'connection_limit' => options[:connection_limit], 'default_tls_container_ref' => options[:default_tls_container_ref], 'sni_container_refs' => options[:sni_container_refs], 'admin_state_up' => options[:admin_state_up], 'tenant_id' => options[:tenant_id] } self.data[:lbaas_listener][data['id']] = data response.body = {'listener' => data} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/delete_lbaas_loadbalancer.rb0000644000004100000410000000136713423370527030621 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def delete_lbaas_loadbalancer(loadbalancer_id) request( :expects => 204, :method => 'DELETE', :path => "lbaas/loadbalancers/#{loadbalancer_id}" ) end end class Mock def delete_lbaas_loadbalancer(loadbalancer_id) response = Excon::Response.new if list_lbaas_loadbalancers.body['loadbalancers'].map { |r| r['id'] }.include? loadbalancer_id data[:lbaas_loadbalancers].delete(loadbalancer_id) response.status = 204 response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/update_subnet_pool.rb0000644000004100000410000000330713423370527027415 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def update_subnet_pool(subnet_pool_id, options = {}) data = {'subnetpool' => {}} vanilla_options = [:name, :description, :prefixes, :address_scope_id, :min_prefixlen, :max_prefixlen, :default_prefixlen] vanilla_options.select { |o| options.key?(o) }.each do |key| data['subnetpool'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'PUT', :path => "subnetpools/#{subnet_pool_id}" ) end end class Mock def update_subnet_pool(subnet_pool_id, options = {}) subnet_pool = list_subnet_pools.body['subnetpools'].find { |s| s['id'] == subnet_pool_id } if subnet_pool subnet_pool['name'] = options[:name] subnet_pool['description'] = options[:description] subnet_pool['prefixes'] = options[:prefixes] || [] subnet_pool['min_prefixlen'] = options[:min_prefixlen] || 64 subnet_pool['max_prefixlen'] = options[:max_prefixlen] || 64 subnet_pool['default_prefixlen'] = options[:default_prefixlen] || 64 subnet_pool['address_scope_id'] = options[:address_scope_id] subnet_pool['updated_at'] = Time.now.to_s response = Excon::Response.new response.body = {'subnetpool' => subnet_pool} response.status = 200 response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/get_network_ip_availability.rb0000644000004100000410000000131113423370527031265 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def get_network_ip_availability(network_id) request( :expects => [200], :method => 'GET', :path => "network-ip-availabilities/#{network_id}" ) end end class Mock def get_network_ip_availability(network_id) response = Excon::Response.new if data = self.data[:network_ip_availabilities].first response.status = 200 response.body = {'network_ip_availability' => data} response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/list_ike_policies.rb0000644000004100000410000000102013423370527027202 0ustar www-datawww-datamodule Fog module OpenStack class Network 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-1.0.8/lib/fog/openstack/network/requests/delete_port.rb0000644000004100000410000000120113423370527026017 0ustar www-datawww-datamodule Fog module OpenStack class Network 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 data[:ports].delete(port_id) response.status = 204 response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/create_lbaas_loadbalancer.rb0000644000004100000410000000341613423370527030617 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def create_lbaas_loadbalancer(vip_subnet_id, options = {}) data = { 'loadbalancer' => { 'vip_subnet_id' => vip_subnet_id } } vanilla_options = [:name, :description, :vip_address, :provider, :flavor, :admin_state_up, :tenant_id] vanilla_options.reject { |o| options[o].nil? }.each do |key| data['loadbalancer'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => [201], :method => 'POST', :path => 'lbaas/loadbalancers' ) end end class Mock def create_lbaas_loadbalancer(vip_subnet_id, options = {}) response = Excon::Response.new response.status = 201 data = { 'id' => Fog::Mock.random_numbers(6).to_s, 'subnet_id' => vip_subnet_id, 'name' => options[:name], 'description' => options[:description], 'vip_address' => options[:vip_address], 'vip_port_id'=> Fog::Mock.random_numbers(6).to_s, 'vip_subnet_id'=> vip_subnet_id, 'flavor' => options[:flavor], 'admin_state_up' => options[:admin_state_up], 'tenant_id' => options[:tenant_id], 'listeners'=> [{ 'id'=> Fog::Mock.random_numbers(6).to_s}], 'operating_status'=> 'ONLINE', 'provider'=> 'lbprovider', 'provisioning_status'=> 'ACTIVE' } self.data[:lbaas_loadbalancer][data['id']] = data response.body = {'loadbalancer' => data} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/get_quota.rb0000644000004100000410000000104013423370527025502 0ustar www-datawww-datamodule Fog module OpenStack class Network 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' => (data[:quota_updated] || data[:quota]) } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/get_lb_pool_stats.rb0000644000004100000410000000146513423370527027230 0ustar www-datawww-datamodule Fog module OpenStack class Network 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::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/delete_lbaas_l7policy.rb0000644000004100000410000000131713423370527027747 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def delete_lbaas_l7policy(l7policy_id) request( :expects => 204, :method => 'DELETE', :path => "lbaas/l7policies/#{l7policy_id}" ) end end class Mock def delete_lbaas_l7policy(l7policy_id) response = Excon::Response.new if list_lbaas_l7policies.body['l7policies'].map { |r| r['id'] }.include? l7policy_id data[:lbaas_l7policies].delete(l7policy_id) response.status = 204 response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/list_ports.rb0000644000004100000410000000076713423370527025733 0ustar www-datawww-datamodule Fog module OpenStack class Network 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' => data[:ports].values}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/list_lbaas_pools.rb0000644000004100000410000000101713423370527027047 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def list_lbaas_pools(filters = {}) request( :expects => 200, :method => 'GET', :path => 'lbaas/pools', :query => filters ) end end class Mock def list_lbaas_pools(_filters = {}) Excon::Response.new( :body => {'pools' => data[:lbaas_pools].values}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/delete_vpn_service.rb0000644000004100000410000000132413423370527027364 0ustar www-datawww-datamodule Fog module OpenStack class Network 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::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/delete_lb_member.rb0000644000004100000410000000124613423370527026770 0ustar www-datawww-datamodule Fog module OpenStack class Network 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 data[:lb_members].delete(member_id) response.status = 204 response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/update_lbaas_l7rule.rb0000644000004100000410000000246513423370527027444 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def update_lbaas_l7rule(l7policy_id, l7rule_id, options = {}) data = { 'rule' => {} } vanilla_options = [:type, :compare_type, :key, :value, :invert] vanilla_options.select { |o| options.key?(o) }.each do |key| data['rule'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => [200], :method => 'PUT', :path => "lbaas/l7policies/#{l7policy_id}/rules/#{l7rule_id}" ) end end class Mock def update_lbaas_l7rule(l7policy_id, l7rule_id, options = {}) response = Excon::Response.new if l7rule = list_l7rules.body['l7rules'].find { |_| _['id'] == l7rule_id } l7rule['type'] = options[:type] l7rule['compare_type'] = options[:compare_type] l7rule['key'] = options[:key] l7rule['value'] = options[:value] l7rule['invert'] = options[:invert] response.body = {'rule' => l7rule} response.status = 200 response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/update_port.rb0000644000004100000410000000300313423370527026041 0ustar www-datawww-datamodule Fog module OpenStack class Network 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::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/list_lbaas_loadbalancers.rb0000644000004100000410000000106213423370527030505 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def list_lbaas_loadbalancers(filters = {}) request( :expects => 200, :method => 'GET', :path => 'lbaas/loadbalancers', :query => filters ) end end class Mock def list_lbaas_loadbalancers(_filters = {}) Excon::Response.new( :body => {'loadbalancers' => [data[:lbaas_loadbalancer]]}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/create_lbaas_l7rule.rb0000644000004100000410000000275613423370527027430 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def create_lbaas_l7rule(l7policy_id, type, compare_type, value, options = {}) data = { 'rule' => { 'type' => type, 'compare_type' => compare_type, 'value' => value } } vanilla_options = [:tenant_id, :key, :invert] vanilla_options.reject { |o| options[o].nil? }.each do |key| data['rule'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => [201], :method => 'POST', :path => "lbaas/l7policies/#{l7policy_id}/rules" ) end end class Mock def create_lbaas_l7rule(l7policy_id, type, compare_type, value, options = {}) response = Excon::Response.new response.status = 201 data = { 'id' => Fog::Mock.random_numbers(6).to_s, 'type' => type, 'compare_type' => compare_type, 'value' => value, 'tenant_id' => options[:tenant_id], 'key' => options[:key], 'invert' => options[:invert], 'l7policy_id' => l7policy_id } self.data[:lbaas_l7rules][data['id']] = data response.body = {'rule' => data} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/update_vpn_service.rb0000644000004100000410000000320213423370527027401 0ustar www-datawww-datamodule Fog module OpenStack class Network 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::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/create_subnet.rb0000644000004100000410000000336713423370527026353 0ustar www-datawww-datamodule Fog module OpenStack class Network 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-1.0.8/lib/fog/openstack/network/requests/update_lb_member.rb0000644000004100000410000000221613423370527027006 0ustar www-datawww-datamodule Fog module OpenStack class Network 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::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/list_lbaas_healthmonitors.rb0000644000004100000410000000107413423370527030756 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def list_lbaas_healthmonitors(filters = {}) request( :expects => 200, :method => 'GET', :path => 'lbaas/healthmonitors', :query => filters ) end end class Mock def list_lbaas_healthmonitors(_filters = {}) Excon::Response.new( :body => {'healthmonitors' => data[:lbaas_healthmonitors].values}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/list_lb_members.rb0000644000004100000410000000101513423370527026656 0ustar www-datawww-datamodule Fog module OpenStack class Network 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' => data[:lb_members].values}, :status => 200 ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/create_rbac_policy.rb0000644000004100000410000000233313423370527027331 0ustar www-datawww-datamodule Fog module OpenStack class Network 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-1.0.8/lib/fog/openstack/network/requests/get_subnet.rb0000644000004100000410000000257713423370527025671 0ustar www-datawww-datamodule Fog module OpenStack class Network 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::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/update_network.rb0000644000004100000410000000312613423370527026554 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real # Not all options can be updated UPDATE_OPTIONS = [ :name, :shared, :admin_state_up, :qos_policy_id, :port_security_enabled ].freeze # Not all extra options can be updated UPDATE_EXTENTED_OPTIONS = [ :router_external ].freeze def self.update(options) data = {} UPDATE_OPTIONS.select { |o| options.key?(o) }.each do |key| data[key.to_s] = options[key] end UPDATE_EXTENTED_OPTIONS.reject { |o| options[o].nil? }.each do |key| aliased_key = ALIASES[key] || key data[aliased_key] = options[key] end data end def update_network(network_id, options = {}) data = {'network' => self.class.update(options)} 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.merge!(Fog::OpenStack::Network::Real.update(options)) response.body = {'network' => network} response.status = 200 response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/get_lbaas_healthmonitor.rb0000644000004100000410000000131313423370527030373 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def get_lbaas_healthmonitor(healthmonitor_id) request( :expects => [200], :method => 'GET', :path => "lbaas/healthmonitors/#{healthmonitor_id}" ) end end class Mock def get_lbaas_healthmonitor(healthmonitor_id) response = Excon::Response.new if data = self.data[:lbaas_healthmonitors][healthmonitor_id] response.status = 200 response.body = {'healthmonitor' => data} response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/update_lbaas_loadbalancer.rb0000644000004100000410000000245513423370527030640 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def update_lbaas_loadbalancer(loadbalancer_id, options = {}) data = { 'loadbalancer' => {} } vanilla_options = [:name, :description, :admin_state_up] vanilla_options.select { |o| options.key?(o) }.each do |key| data['loadbalancer'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => 200, :method => 'PUT', :path => "lbaas/loadbalancers/#{loadbalancer_id}" ) end end class Mock def update_lbaas_loadbalancer(loadbalancer_id, options = {}) response = Excon::Response.new if loadbalancer = list_lbaas_loadbalancers.body['loadbalancers'].find { |_| _['id'] == loadbalancer_id } loadbalancer['name'] = options[:name] loadbalancer['description'] = options[:description] loadbalancer['admin_state_up'] = options[:admin_state_up] response.body = {'loadbalancer' => loadbalancer} response.status = 200 response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/create_lbaas_l7policy.rb0000644000004100000410000000305713423370527027753 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def create_lbaas_l7policy(listener_id, action, options = {}) data = { 'l7policy' => { 'listener_id' => listener_id, 'action' => action } } vanilla_options = [:tenant_id, :name, :description, :redirect_pool_id, :redirect_url, :position] vanilla_options.reject { |o| options[o].nil? }.each do |key| data['l7policy'][key] = options[key] end request( :body => Fog::JSON.encode(data), :expects => [201], :method => 'POST', :path => 'lbaas/l7policies' ) end end class Mock def create_lbaas_l7policy(listener_id, action, options = {}) response = Excon::Response.new response.status = 201 data = { 'id' => Fog::Mock.random_numbers(6).to_s, 'listener_id' => listener_id, 'action' => action, 'position' => options[:position], 'tenant_id' => options[:tenant_id], 'name' => options[:name], 'description' => options[:description], 'redirect_pool_id' => options[:redirect_pool_id], 'redirect_url' => options[:redirect_url] } self.data[:lbaas_l7policies][data['id']] = data response.body = {'l7policy' => data} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/create_lbaas_pool_member.rb0000644000004100000410000000306413423370527030507 0ustar www-datawww-datamodule Fog module OpenStack class Network class Real def create_lbaas_pool_member(pool_id, address, protocol_port, options = {}) data = { 'member' => { 'address' => address, 'protocol_port' => protocol_port } } vanilla_options = [:admin_state_up, :tenant_id, :weight, :subnet_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 => "lbaas/pools/#{pool_id}/members" ) end end class Mock def create_lbaas_pool_member(pool_id, address, protocol_port, 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' => options[:weight], 'status' => 'ACTIVE', 'admin_state_up' => options[:admin_state_up], 'tenant_id' => options[:tenant_id], 'subnet_id' => ptions[:subnet_id] } self.data[:lb_members][data['id']] = data response.body = {'member' => data} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/delete_floating_ip.rb0000644000004100000410000000131413423370527027333 0ustar www-datawww-datamodule Fog module OpenStack class Network 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 data[:floating_ips].delete(floating_ip_id) response.status = 204 response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/get_ipsec_policy.rb0000644000004100000410000000126013423370527027037 0ustar www-datawww-datamodule Fog module OpenStack class Network 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::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/list_security_groups.rb0000644000004100000410000000415413423370527030024 0ustar www-datawww-datamodule Fog module OpenStack class Network 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 = data[:security_groups].values unless data[:security_groups].nil? response.status = 200 response.body = {'security_groups' => sec_groups} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/get_lb_vip.rb0000644000004100000410000000114513423370527025632 0ustar www-datawww-datamodule Fog module OpenStack class Network 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::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/delete_security_group.rb0000644000004100000410000000152313423370527030125 0ustar www-datawww-datamodule Fog module OpenStack class Network 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 data[:security_groups][security_group_id] data[:security_groups].delete(security_group_id) response.status = 204 response else raise Fog::OpenStack::Network::NotFound end end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/requests/create_ike_policy.rb0000644000004100000410000000333213423370527027172 0ustar www-datawww-datamodule Fog module OpenStack class Network 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-1.0.8/lib/fog/openstack/network/requests/create_security_group.rb0000644000004100000410000001016413423370527030127 0ustar www-datawww-datamodule Fog module OpenStack class Network 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-1.0.8/lib/fog/openstack/network/models/0000755000004100000410000000000013423370527022602 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/network/models/subnet.rb0000644000004100000410000000216213423370527024430 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Network 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(network_id, cidr, ip_version, attributes).body['subnet']) self end def update requires :id merge_attributes(service.update_subnet(id, attributes).body['subnet']) self end def destroy requires :id service.delete_subnet(id) true end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/models/network_ip_availability.rb0000644000004100000410000000061013423370527030037 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Network class NetworkIpAvailability < Fog::OpenStack::Model attribute :used_ips attribute :subnet_ip_availability attribute :network_id attribute :project_id attribute :tenant_id attribute :total_ips attribute :network_name end end end end fog-openstack-1.0.8/lib/fog/openstack/network/models/floating_ips.rb0000644000004100000410000000144113423370527025605 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/network/models/floating_ip' module Fog module OpenStack class Network class FloatingIps < Fog::OpenStack::Collection attribute :filters model Fog::OpenStack::Network::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::OpenStack::Network::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/models/lb_health_monitors.rb0000644000004100000410000000150713423370527027006 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/network/models/lb_health_monitor' module Fog module OpenStack class Network class LbHealthMonitors < Fog::OpenStack::Collection attribute :filters model Fog::OpenStack::Network::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::OpenStack::Network::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/models/rbac_policies.rb0000644000004100000410000000147113423370527025730 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/network/models/rbac_policy' module Fog module OpenStack class Network class RbacPolicies < Fog::OpenStack::Collection attribute :filters model Fog::OpenStack::Network::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::OpenStack::Network::NotFound nil end alias find_by_id get end end end end fog-openstack-1.0.8/lib/fog/openstack/network/models/security_group_rule.rb0000644000004100000410000000156213423370527027245 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Network 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, '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-1.0.8/lib/fog/openstack/network/models/security_group_rules.rb0000644000004100000410000000153313423370527027426 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/network/models/security_group_rule' module Fog module OpenStack class Network class SecurityGroupRules < Fog::OpenStack::Collection attribute :filters model Fog::OpenStack::Network::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::OpenStack::Network::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/models/subnet_pools.rb0000644000004100000410000000145513423370527025650 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/network/models/subnet_pool' module Fog module OpenStack class Network class SubnetPools < Fog::OpenStack::Collection attribute :filters model Fog::OpenStack::Network::SubnetPool def initialize(attributes) self.filters ||= {} super end def all(filters_arg = filters) filters = filters_arg load_response(service.list_subnet_pools(filters), 'subnetpools') end def get(subnet_pool_id) subnet_pool = service.get_subnet_pool(subnet_pool_id).body['subnetpool'] if subnet_pool new(subnet_pool) end rescue Fog::OpenStack::Network::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/models/lb_members.rb0000644000004100000410000000136113423370527025237 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/network/models/lb_member' module Fog module OpenStack class Network class LbMembers < Fog::OpenStack::Collection attribute :filters model Fog::OpenStack::Network::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::OpenStack::Network::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/models/security_group.rb0000644000004100000410000000157713423370527026224 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Network 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::OpenStack::Network::SecurityGroupRules.new(:service => service).load(attributes[:security_group_rules]) end def save merge_attributes(service.create_security_group(attributes).body['security_group']) self end def update requires :id merge_attributes(service.update_security_group(id, attributes).body['security_group']) self end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/models/subnets.rb0000644000004100000410000000134413423370527024614 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/network/models/subnet' module Fog module OpenStack class Network class Subnets < Fog::OpenStack::Collection attribute :filters model Fog::OpenStack::Network::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::OpenStack::Network::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/models/network.rb0000644000004100000410000000215013423370527024616 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Network class Network < Fog::OpenStack::Model identity :id attribute :name 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 == id } end def create merge_attributes(service.create_network(attributes).body['network']) self end def update requires :id merge_attributes(service.update_network(id, attributes).body['network']) self end def destroy requires :id service.delete_network(id) true end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/models/network_ip_availabilities.rb0000644000004100000410000000130413423370527030350 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/network/models/network_ip_availability' module Fog module OpenStack class Network class NetworkIpAvailabilities < Fog::OpenStack::Collection model Fog::OpenStack::Network::NetworkIpAvailability def all load_response(service.list_network_ip_availabilities, 'network_ip_availabilities') end def get(network_id) if network_ip_availability = service.get_network_ip_availability(network_id).body['network_ip_availability'] new(network_ip_availability) end rescue Fog::OpenStack::Network::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/models/rbac_policy.rb0000644000004100000410000000143213423370527025415 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Network class RbacPolicy < Fog::OpenStack::Model identity :id attribute :object_type 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-1.0.8/lib/fog/openstack/network/models/extension.rb0000644000004100000410000000043613423370527025146 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Network class Extension < Fog::OpenStack::Model identity :id attribute :name attribute :links attribute :description attribute :alias end end end end fog-openstack-1.0.8/lib/fog/openstack/network/models/ike_policies.rb0000644000004100000410000000141713423370527025571 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/network/models/ike_policy' module Fog module OpenStack class Network class IkePolicies < Fog::OpenStack::Collection attribute :filters model Fog::OpenStack::Network::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::OpenStack::Network::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/models/ipsec_site_connection.rb0000644000004100000410000000314213423370527027475 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Network 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-1.0.8/lib/fog/openstack/network/models/lb_pool.rb0000644000004100000410000000344513423370527024563 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Network 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(subnet_id, protocol, lb_method, attributes).body['pool']) self end def update requires :id, :subnet_id, :protocol, :lb_method merge_attributes(service.update_lb_pool(id, attributes).body['pool']) self end def destroy requires :id service.delete_lb_pool(id) true end def stats requires :id merge_attributes(service.get_lb_pool_stats(id).body['stats']) self end def associate_health_monitor(health_monitor_id) requires :id service.associate_lb_health_monitor(id, health_monitor_id) true end def disassociate_health_monitor(health_monitor_id) requires :id service.disassociate_lb_health_monitor(id, health_monitor_id) true end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/models/lb_vip.rb0000644000004100000410000000250613423370527024405 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Network 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(subnet_id, pool_id, protocol, protocol_port, attributes).body['vip']) self end def update requires :id, :subnet_id, :pool_id, :protocol, :protocol_port merge_attributes(service.update_lb_vip(id, attributes).body['vip']) self end def destroy requires :id service.delete_lb_vip(id) true end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/models/routers.rb0000644000004100000410000000134413423370527024634 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/network/models/router' module Fog module OpenStack class Network class Routers < Fog::OpenStack::Collection attribute :filters model Fog::OpenStack::Network::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::OpenStack::Network::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/models/router.rb0000644000004100000410000000311013423370527024442 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Network # 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(name, options) merge_attributes(response.body['router']) self end def update requires :id response = service.update_router(id, options) merge_attributes(response.body['router']) self end def destroy requires :id service.delete_router(id) true end private def options options = attributes.dup if options[:external_gateway_info] if options[:external_gateway_info].kind_of?(Fog::OpenStack::Network::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-1.0.8/lib/fog/openstack/network/models/port.rb0000644000004100000410000000174613423370527024123 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Network 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(network_id, attributes).body['port']) self end def update requires :id, :network_id merge_attributes(service.update_port(id, attributes).body['port']) self end def destroy requires :id service.delete_port(id) true end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/models/security_groups.rb0000644000004100000410000000147213423370527026401 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/network/models/security_group' module Fog module OpenStack class Network class SecurityGroups < Fog::OpenStack::Collection attribute :filters model Fog::OpenStack::Network::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::OpenStack::Network::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/models/subnet_pool.rb0000644000004100000410000000232013423370527025455 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Network class SubnetPool < Fog::OpenStack::Model identity :id attribute :name attribute :prefixes attribute :description attribute :address_scope_id attribute :shared attribute :ip_version attribute :min_prefixlen attribute :max_prefixlen attribute :default_prefixlen attribute :is_default attribute :default_quota attribute :created_at attribute :updated_at attribute :tenant_id def create requires :name, :prefixes merge_attributes(service.create_subnet_pool(name, prefixes, attributes).body['subnetpool']) self end def update requires :id merge_attributes(service.update_subnet_pool(id, attributes).body['subnetpool']) self end def destroy requires :id service.delete_subnet_pool(id) true end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/models/extensions.rb0000644000004100000410000000140513423370527025326 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/network/models/extension' module Fog module OpenStack class Network class Extensions < Fog::OpenStack::Collection attribute :filters model Fog::OpenStack::Network::Extension def initialize(attributes) self.filters ||= {} super end def all(filters_arg = filters) filters = filters_arg load_response(service.list_extensions(filters), 'extensions') end def get(extension_id) if extension = service.get_extension(extension_id).body['extension'] new(extension) end rescue Fog::OpenStack::Network::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/models/lb_health_monitor.rb0000644000004100000410000000315513423370527026624 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Network 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(type, delay, timeout, max_retries, attributes).body['health_monitor']) self end def update requires :id, :type, :delay, :timeout, :max_retries merge_attributes(service.update_lb_health_monitor(id, attributes).body['health_monitor']) self end def destroy requires :id service.delete_lb_health_monitor(id) true end def associate_to_pool(pool_id) requires :id service.associate_lb_health_monitor(pool_id, id) true end def disassociate_from_pool(pool_id) requires :id service.disassociate_lb_health_monitor(pool_id, id) true end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/models/lb_pools.rb0000644000004100000410000000133313423370527024740 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/network/models/lb_pool' module Fog module OpenStack class Network class LbPools < Fog::OpenStack::Collection attribute :filters model Fog::OpenStack::Network::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::OpenStack::Network::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/models/lb_vips.rb0000644000004100000410000000132013423370527024561 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/network/models/lb_vip' module Fog module OpenStack class Network class LbVips < Fog::OpenStack::Collection attribute :filters model Fog::OpenStack::Network::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::OpenStack::Network::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/models/lb_member.rb0000644000004100000410000000223713423370527025057 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Network 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(pool_id, address, protocol_port, weight, attributes).body['member']) self end def update requires :id, :pool_id, :address, :protocol_port, :weight merge_attributes(service.update_lb_member(id, attributes).body['member']) self end def destroy requires :id service.delete_lb_member(id) true end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/models/ipsec_site_connections.rb0000644000004100000410000000160413423370527027661 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/network/models/ipsec_site_connection' module Fog module OpenStack class Network class IpsecSiteConnections < Fog::OpenStack::Collection attribute :filters model Fog::OpenStack::Network::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::OpenStack::Network::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/models/ike_policy.rb0000644000004100000410000000224513423370527025261 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Network 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-1.0.8/lib/fog/openstack/network/models/floating_ip.rb0000644000004100000410000000277513423370527025435 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Network 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-1.0.8/lib/fog/openstack/network/models/ports.rb0000644000004100000410000000131613423370527024277 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/network/models/port' module Fog module OpenStack class Network class Ports < Fog::OpenStack::Collection attribute :filters model Fog::OpenStack::Network::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::OpenStack::Network::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/models/networks.rb0000644000004100000410000000135713423370527025011 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/network/models/network' module Fog module OpenStack class Network class Networks < Fog::OpenStack::Collection attribute :filters model Fog::OpenStack::Network::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::OpenStack::Network::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/models/ipsec_policies.rb0000644000004100000410000000144513423370527026125 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/network/models/ipsec_policy' module Fog module OpenStack class Network class IpsecPolicies < Fog::OpenStack::Collection attribute :filters model Fog::OpenStack::Network::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::OpenStack::Network::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/models/vpn_services.rb0000644000004100000410000000142713423370527025641 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/network/models/vpn_service' module Fog module OpenStack class Network class VpnServices < Fog::OpenStack::Collection attribute :filters model Fog::OpenStack::Network::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::OpenStack::Network::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/network/models/vpn_service.rb0000644000004100000410000000220413423370527025450 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Network 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-1.0.8/lib/fog/openstack/network/models/ipsec_policy.rb0000644000004100000410000000233513423370527025614 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Network 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-1.0.8/lib/fog/openstack/container_infra/0000755000004100000410000000000013423370527022767 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/container_infra/requests/0000755000004100000410000000000013423370527024642 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/container_infra/requests/get_certificate.rb0000644000004100000410000000133713423370527030314 0ustar www-datawww-datamodule Fog module OpenStack class ContainerInfra class Real def get_certificate(bay_uuid) request( :expects => [200], :method => 'GET', :path => "certificates/#{cluster_uuid}" ) end end class Mock def get_certificate(_bay_uuid) response = Excon::Response.new response.status = 200 response.body = { "pem" => "-----BEGIN CERTIFICATE-----\nMIICzDCCAbSgAwIBAgIQOOkVcEN7TNa9E80GoUs4xDANBgkqhkiG9w0BAQsFADAO\n-----END CERTIFICATE-----\n", "bay_uuid" => "0b4b766f-1500-44b3-9804-5a6e12fe6df4" } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra/requests/create_cluster_template.rb0000644000004100000410000000412213423370527032065 0ustar www-datawww-datamodule Fog module OpenStack class ContainerInfra class Real def create_cluster_template(params) request( :expects => [201, 200], :method => 'POST', :path => "clustertemplates", :body => Fog::JSON.encode(params) ) end end class Mock def create_cluster_template(_params) response = Excon::Response.new response.status = 201 response.body = { "insecure_registry" => nil, "http_proxy" => "http://10.164.177.169:8080", "updated_at" => nil, "floating_ip_enabled" => true, "fixed_subnet" => nil, "master_flavor_id" => nil, "uuid" => "085e1c4d-4f68-4bfd-8462-74b9e14e4f39", "no_proxy" => "10.0.0.0/8,172.0.0.0/8,192.0.0.0/8,localhost", "https_proxy" => "http://10.164.177.169:8080", "tls_disabled" => false, "keypair_id" => "kp", "public" => false, "labels" => {}, "docker_volume_size" => 3, "server_type" => "vm", "external_network_id" => "public", "cluster_distro" => "fedora-atomic", "image_id" => "fedora-atomic-latest", "volume_driver" => "cinder", "registry_enabled" => false, "docker_storage_driver" => "devicemapper", "apiserver_port" => nil, "name" => "k8s-bm2", "created_at" => "2016-08-29T02:08:08+00:00", "network_driver" => "flannel", "fixed_network" => nil, "coe" => "kubernetes", "flavor_id" => "m1.small", "master_lb_enabled" => true, "dns_nameserver" => "8.8.8.8" } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra/requests/delete_cluster_template.rb0000644000004100000410000000102213423370527032060 0ustar www-datawww-datamodule Fog module OpenStack class ContainerInfra class Real def delete_cluster_template(uuid_or_name) request( :expects => [204], :method => 'DELETE', :path => "clustertemplates/#{uuid_or_name}" ) end end class Mock def delete_cluster_template(_uuid_or_name) response = Excon::Response.new response.status = 204 response.body = {} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra/requests/list_bays.rb0000644000004100000410000000370113423370527027161 0ustar www-datawww-datamodule Fog module OpenStack class ContainerInfra class Real def list_bays request( :expects => [200], :method => 'GET', :path => "bays/detail" ) end end class Mock def list_bays response = Excon::Response.new response.status = 200 response.body = { "bays" => [ { "status" => "CREATE_COMPLETE", "uuid" => "746e779a-751a-456b-a3e9-c883d734946f", "stack_id" => "9c6f1169-7300-4d08-a444-d2be38758719", "created_at" => "2016-08-29T06:51:31+00:00", "api_address" => "https://172.24.4.6:6443", "discovery_url" => "https://discovery.etcd.io/cbeb580da58915809d59ee69348a84f3", "updated_at" => "2016-08-29T06:53:24+00:00", "master_count" => 1, "coe_version" => "v1.2.0", "baymodel_id" => "0562d357-8641-4759-8fed-8173f02c9633", "master_addresses" => ["172.24.4.6"], "node_count" => 1, "node_addresses" => ["172.24.4.13"], "status_reason" => "Stack CREATE completed successfully", "bay_create_timeout" => 60, "name" => "k8s", "links" => [ { "href" => "http://10.164.180.104:9511/v1/bays/746e779a-751a-456b-a3e9-c883d734946f", "rel" => "self" }, { "href" => "http://10.164.180.104:9511/bays/746e779a-751a-456b-a3e9-c883d734946f", "rel" => "bookmark" } ] } ] } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra/requests/get_cluster.rb0000644000004100000410000000271213423370527027511 0ustar www-datawww-datamodule Fog module OpenStack class ContainerInfra class Real def get_cluster(uuid_or_name) request( :expects => [200], :method => 'GET', :path => "clusters/#{uuid_or_name}" ) end end class Mock def get_cluster(_uuid_or_name) response = Excon::Response.new response.status = 200 response.body = { "status" => "CREATE_COMPLETE", "uuid" => "746e779a-751a-456b-a3e9-c883d734946f", "stack_id" => "9c6f1169-7300-4d08-a444-d2be38758719", "created_at" => "2016-08-29T06:51:31+00:00", "api_address" => "https://172.24.4.6:6443", "discovery_url" => "https://discovery.etcd.io/cbeb580da58915809d59ee69348a84f3", "updated_at" => "2016-08-29T06:53:24+00:00", "master_count" => 1, "coe_version" => "v1.2.0", "cluster_template_id" => "0562d357-8641-4759-8fed-8173f02c9633", "master_addresses" => ["172.24.4.6"], "node_count" => 1, "node_addresses" => ["172.24.4.13"], "status_reason" => "Stack CREATE completed successfully", "create_timeout" => 60, "name" => "k8s" } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra/requests/get_bay_model.rb0000644000004100000410000000403313423370527027761 0ustar www-datawww-datamodule Fog module OpenStack class ContainerInfra class Real def get_bay_model(uuid_or_name) request( :expects => [200], :method => 'GET', :path => "baymodels/#{uuid_or_name}" ) end end class Mock def get_bay_model(_uuid_or_name) response = Excon::Response.new response.status = 200 response.body = { "insecure_registry" => nil, "http_proxy" => "http://10.164.177.169:8080", "updated_at" => nil, "floating_ip_enabled" => true, "fixed_subnet" => nil, "master_flavor_id" => nil, "uuid" => "085e1c4d-4f68-4bfd-8462-74b9e14e4f39", "no_proxy" => "10.0.0.0/8,172.0.0.0/8,192.0.0.0/8,localhost", "https_proxy" => "http://10.164.177.169:8080", "tls_disabled" => false, "keypair_id" => "kp", "public" => false, "labels" => {}, "docker_volume_size" => 3, "server_type" => "vm", "external_network_id" => "public", "cluster_distro" => "fedora-atomic", "image_id" => "fedora-atomic-latest", "volume_driver" => "cinder", "registry_enabled" => false, "docker_storage_driver" => "devicemapper", "apiserver_port" => nil, "name" => "k8s-bm2", "created_at" => "2016-08-29T02:08:08+00:00", "network_driver" => "flannel", "fixed_network" => nil, "coe" => "kubernetes", "flavor_id" => "m1.small", "master_lb_enabled" => true, "dns_nameserver" => "8.8.8.8" } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra/requests/get_bay.rb0000644000004100000410000000346513423370527026611 0ustar www-datawww-datamodule Fog module OpenStack class ContainerInfra class Real def get_bay(uuid_or_name) request( :expects => [200], :method => 'GET', :path => "bays/#{uuid_or_name}" ) end end class Mock def get_bay(_uuid_or_name) response = Excon::Response.new response.status = 200 response.body = { "status" => "CREATE_COMPLETE", "uuid" => "746e779a-751a-456b-a3e9-c883d734946f", "stack_id" => "9c6f1169-7300-4d08-a444-d2be38758719", "created_at" => "2016-08-29T06:51:31+00:00", "api_address" => "https://172.24.4.6:6443", "discovery_url" => "https://discovery.etcd.io/cbeb580da58915809d59ee69348a84f3", "updated_at" => "2016-08-29T06:53:24+00:00", "master_count" => 1, "coe_version" => "v1.2.0", "baymodel_id" => "0562d357-8641-4759-8fed-8173f02c9633", "master_addresses" => ["172.24.4.6"], "node_count" => 1, "node_addresses" => ["172.24.4.13"], "status_reason" => "Stack CREATE completed successfully", "bay_create_timeout" => 60, "name" => "k8s", "links" => [ { "href" => "http://10.164.180.104:9511/v1/bays/746e779a-751a-456b-a3e9-c883d734946f", "rel" => "self" }, { "href" => "http://10.164.180.104:9511/bays/746e779a-751a-456b-a3e9-c883d734946f", "rel" => "bookmark" } ] } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra/requests/update_cluster.rb0000644000004100000410000000120713423370527030212 0ustar www-datawww-datamodule Fog module OpenStack class ContainerInfra class Real def update_cluster(uuid_or_name, params) request( :expects => [202, 200], :method => 'PATCH', :path => "clusters/#{uuid_or_name}", :body => Fog::JSON.encode(params) ) end end class Mock def update_cluster(_uuid_or_name, _params) response = Excon::Response.new response.status = 202 response.body = { "uuid" => "746e779a-751a-456b-a3e9-c883d734946f" } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra/requests/list_bay_models.rb0000644000004100000410000000515013423370527030341 0ustar www-datawww-datamodule Fog module OpenStack class ContainerInfra class Real def list_bay_models request( :expects => [200], :method => 'GET', :path => "baymodels/detail" ) end end class Mock def list_bay_models response = Excon::Response.new response.status = 200 response.body = { "baymodels" => [ { "insecure_registry" => nil, "http_proxy" => "http://10.164.177.169:8080", "updated_at" => nil, "floating_ip_enabled" => true, "fixed_subnet" => nil, "master_flavor_id" => nil, "uuid" => "085e1c4d-4f68-4bfd-8462-74b9e14e4f39", "no_proxy" => "10.0.0.0/8,172.0.0.0/8,192.0.0.0/8,localhost", "https_proxy" => "http://10.164.177.169:8080", "tls_disabled" => false, "keypair_id" => "kp", "public" => false, "labels" => {}, "docker_volume_size" => 3, "server_type" => "vm", "external_network_id" => "public", "cluster_distro" => "fedora-atomic", "image_id" => "fedora-atomic-latest", "volume_driver" => "cinder", "registry_enabled" => false, "docker_storage_driver" => "devicemapper", "apiserver_port" => nil, "name" => "k8s-bm2", "created_at" => "2016-08-29T02:08:08+00:00", "network_driver" => "flannel", "fixed_network" => nil, "coe" => "kubernetes", "flavor_id" => "m1.small", "master_lb_enabled" => true, "dns_nameserver" => "8.8.8.8", "links" => [ { "href" => "http://10.164.180.104:9511/v1/baymodels/085e1c4d-4f68-4bfd-8462-74b9e14e4f39", "rel" => "self" }, { "href" => "http://10.164.180.104:9511/baymodels/085e1c4d-4f68-4bfd-8462-74b9e14e4f39", "rel" => "bookmark" } ] } ] } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra/requests/delete_bay_model.rb0000644000004100000410000000077513423370527030455 0ustar www-datawww-datamodule Fog module OpenStack class ContainerInfra class Real def delete_bay_model(uuid_or_name) request( :expects => [204], :method => 'DELETE', :path => "baymodels/#{uuid_or_name}" ) end end class Mock def delete_bay_model(_uuid_or_name) response = Excon::Response.new response.status = 204 response.body = {} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra/requests/update_cluster_template.rb0000644000004100000410000000422013423370527032103 0ustar www-datawww-datamodule Fog module OpenStack class ContainerInfra class Real def update_cluster_template(uuid_or_name, params) request( :expects => [200], :method => 'PATCH', :path => "clustertemplates/#{uuid_or_name}", :body => Fog::JSON.encode(params) ) end end class Mock def update_cluster_template(_uuid_or_name, _params) response = Excon::Response.new response.status = 200 response.body = { "insecure_registry" => nil, "http_proxy" => "http://10.164.177.169:8080", "updated_at" => nil, "floating_ip_enabled" => true, "fixed_subnet" => nil, "master_flavor_id" => nil, "uuid" => "085e1c4d-4f68-4bfd-8462-74b9e14e4f39", "no_proxy" => "10.0.0.0/8,172.0.0.0/8,192.0.0.0/8,localhost", "https_proxy" => "http://10.164.177.169:8080", "tls_disabled" => false, "keypair_id" => "kp", "public" => false, "labels" => {}, "docker_volume_size" => 3, "server_type" => "vm", "external_network_id" => "public", "cluster_distro" => "fedora-atomic", "image_id" => "fedora-atomic-latest", "volume_driver" => "cinder", "registry_enabled" => false, "docker_storage_driver" => "devicemapper", "apiserver_port" => nil, "name" => "rename-test-cluster-template", "created_at" => "2016-08-29T02:08:08+00:00", "network_driver" => "flannel", "fixed_network" => nil, "coe" => "kubernetes", "flavor_id" => "m1.small", "master_lb_enabled" => true, "dns_nameserver" => "8.8.8.8" } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra/requests/create_bay_model.rb0000644000004100000410000000407513423370527030453 0ustar www-datawww-datamodule Fog module OpenStack class ContainerInfra class Real def create_bay_model(params) request( :expects => [201, 200], :method => 'POST', :path => "baymodels", :body => Fog::JSON.encode(params) ) end end class Mock def create_bay_model(_params) response = Excon::Response.new response.status = 201 response.body = { "insecure_registry" => nil, "http_proxy" => "http://10.164.177.169:8080", "updated_at" => nil, "floating_ip_enabled" => true, "fixed_subnet" => nil, "master_flavor_id" => nil, "uuid" => "085e1c4d-4f68-4bfd-8462-74b9e14e4f39", "no_proxy" => "10.0.0.0/8,172.0.0.0/8,192.0.0.0/8,localhost", "https_proxy" => "http://10.164.177.169:8080", "tls_disabled" => false, "keypair_id" => "kp", "public" => false, "labels" => {}, "docker_volume_size" => 3, "server_type" => "vm", "external_network_id" => "public", "cluster_distro" => "fedora-atomic", "image_id" => "fedora-atomic-latest", "volume_driver" => "cinder", "registry_enabled" => false, "docker_storage_driver" => "devicemapper", "apiserver_port" => nil, "name" => "k8s-bm2", "created_at" => "2016-08-29T02:08:08+00:00", "network_driver" => "flannel", "fixed_network" => nil, "coe" => "kubernetes", "flavor_id" => "m1.small", "master_lb_enabled" => true, "dns_nameserver" => "8.8.8.8" } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra/requests/get_cluster_template.rb0000644000004100000410000000406013423370527031402 0ustar www-datawww-datamodule Fog module OpenStack class ContainerInfra class Real def get_cluster_template(uuid_or_name) request( :expects => [200], :method => 'GET', :path => "clustertemplates/#{uuid_or_name}" ) end end class Mock def get_cluster_template(_uuid_or_name) response = Excon::Response.new response.status = 200 response.body = { "insecure_registry" => nil, "http_proxy" => "http://10.164.177.169:8080", "updated_at" => nil, "floating_ip_enabled" => true, "fixed_subnet" => nil, "master_flavor_id" => nil, "uuid" => "085e1c4d-4f68-4bfd-8462-74b9e14e4f39", "no_proxy" => "10.0.0.0/8,172.0.0.0/8,192.0.0.0/8,localhost", "https_proxy" => "http://10.164.177.169:8080", "tls_disabled" => false, "keypair_id" => "kp", "public" => false, "labels" => {}, "docker_volume_size" => 3, "server_type" => "vm", "external_network_id" => "public", "cluster_distro" => "fedora-atomic", "image_id" => "fedora-atomic-latest", "volume_driver" => "cinder", "registry_enabled" => false, "docker_storage_driver" => "devicemapper", "apiserver_port" => nil, "name" => "k8s-bm2", "created_at" => "2016-08-29T02:08:08+00:00", "network_driver" => "flannel", "fixed_network" => nil, "coe" => "kubernetes", "flavor_id" => "m1.small", "master_lb_enabled" => true, "dns_nameserver" => "8.8.8.8" } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra/requests/delete_bay.rb0000644000004100000410000000075413423370527027272 0ustar www-datawww-datamodule Fog module OpenStack class ContainerInfra class Real def delete_bay(uuid_or_name) request( :expects => [204], :method => 'DELETE', :path => "bays/#{uuid_or_name}" ) end end class Mock def delete_bay(_uuid_or_name) response = Excon::Response.new response.status = 204 response.body = {} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra/requests/delete_cluster.rb0000644000004100000410000000077013423370527030176 0ustar www-datawww-datamodule Fog module OpenStack class ContainerInfra class Real def delete_cluster(uuid_or_name) request( :expects => [204], :method => 'DELETE', :path => "clusters/#{uuid_or_name}" ) end end class Mock def delete_cluster(_uuid_or_name) response = Excon::Response.new response.status = 204 response.body = {} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra/requests/create_bay.rb0000644000004100000410000000112213423370527027261 0ustar www-datawww-datamodule Fog module OpenStack class ContainerInfra class Real def create_bay(params) request( :expects => [202, 201, 200], :method => 'POST', :path => "bays", :body => Fog::JSON.encode(params) ) end end class Mock def create_bay(_params) response = Excon::Response.new response.status = 202 response.body = { "uuid" => "746e779a-751a-456b-a3e9-c883d734946f" } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra/requests/update_bay.rb0000644000004100000410000000117313423370527027306 0ustar www-datawww-datamodule Fog module OpenStack class ContainerInfra class Real def update_bay(uuid_or_name, params) request( :expects => [202, 200], :method => 'PATCH', :path => "bays/#{uuid_or_name}", :body => Fog::JSON.encode(params) ) end end class Mock def update_bay(_uuid_or_name, _params) response = Excon::Response.new response.status = 202 response.body = { "uuid" => "746e779a-751a-456b-a3e9-c883d734946f" } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra/requests/create_certificate.rb0000644000004100000410000000166513423370527031004 0ustar www-datawww-datamodule Fog module OpenStack class ContainerInfra class Real def create_certificate(params) request( :expects => [201, 200], :method => 'POST', :path => "certificates", :body => Fog::JSON.encode(params) ) end end class Mock def create_certificate(_params) response = Excon::Response.new response.status = 201 response.body = { "pem" => "-----BEGIN CERTIFICATE-----\nMIIDxDCCAqygAwIBAgIRALgUbIjdKUy8lqErJmCxVfkwDQYJKoZIhvcNAQELBQAw\n-----END CERTIFICATE-----\n", "bay_uuid" => "0b4b766f-1500-44b3-9804-5a6e12fe6df4", "csr" => "-----BEGIN CERTIFICATE REQUEST-----\nMIIEfzCCAmcCAQAwFDESMBAGA1UEAxMJWW91ciBOYW1lMIICIjANBgkqhkiG9w0B\n-----END CERTIFICATE REQUEST-----\n" } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra/requests/create_cluster.rb0000644000004100000410000000113613423370527030174 0ustar www-datawww-datamodule Fog module OpenStack class ContainerInfra class Real def create_cluster(params) request( :expects => [202, 201, 200], :method => 'POST', :path => "clusters", :body => Fog::JSON.encode(params) ) end end class Mock def create_cluster(_params) response = Excon::Response.new response.status = 202 response.body = { "uuid" => "746e779a-751a-456b-a3e9-c883d734946f" } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra/requests/list_cluster_templates.rb0000644000004100000410000000433013423370527031761 0ustar www-datawww-datamodule Fog module OpenStack class ContainerInfra class Real def list_cluster_templates request( :expects => [200], :method => 'GET', :path => "clustertemplates/detail" ) end end class Mock def list_cluster_templates response = Excon::Response.new response.status = 200 response.body = { "clustertemplates" => [ { "insecure_registry" => nil, "http_proxy" => "http://10.164.177.169:8080", "updated_at" => nil, "floating_ip_enabled" => true, "fixed_subnet" => nil, "master_flavor_id" => nil, "uuid" => "0562d357-8641-4759-8fed-8173f02c9633", "no_proxy" => "10.0.0.0/8,172.0.0.0/8,192.0.0.0/8,localhost", "https_proxy" => "http://10.164.177.169:8080", "tls_disabled" => false, "keypair_id" => "kp", "public" => false, "labels" => {}, "docker_volume_size" => 3, "server_type" => "vm", "external_network_id" => "public", "cluster_distro" => "fedora-atomic", "image_id" => "fedora-atomic-latest", "volume_driver" => "cinder", "registry_enabled" => false, "docker_storage_driver" => "devicemapper", "apiserver_port" => nil, "name" => "k8s-bm", "created_at" => "2016-08-26T09:34:41+00:00", "network_driver" => "flannel", "fixed_network" => nil, "coe" => "kubernetes", "flavor_id" => "m1.small", "master_lb_enabled" => false, "dns_nameserver" => "8.8.8.8" } ] } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra/requests/update_bay_model.rb0000644000004100000410000000416513423370527030472 0ustar www-datawww-datamodule Fog module OpenStack class ContainerInfra class Real def update_bay_model(uuid_or_name, params) request( :expects => [200], :method => 'PATCH', :path => "baymodels/#{uuid_or_name}", :body => Fog::JSON.encode(params) ) end end class Mock def update_bay_model(_uuid_or_name, _params) response = Excon::Response.new response.status = 200 response.body = { "insecure_registry" => nil, "http_proxy" => "http://10.164.177.169:8080", "updated_at" => nil, "floating_ip_enabled" => true, "fixed_subnet" => nil, "master_flavor_id" => nil, "uuid" => "085e1c4d-4f68-4bfd-8462-74b9e14e4f39", "no_proxy" => "10.0.0.0/8,172.0.0.0/8,192.0.0.0/8,localhost", "https_proxy" => "http://10.164.177.169:8080", "tls_disabled" => false, "keypair_id" => "kp", "public" => false, "labels" => {}, "docker_volume_size" => 3, "server_type" => "vm", "external_network_id" => "public", "cluster_distro" => "fedora-atomic", "image_id" => "fedora-atomic-latest", "volume_driver" => "cinder", "registry_enabled" => false, "docker_storage_driver" => "devicemapper", "apiserver_port" => nil, "name" => "rename-test-bay-model", "created_at" => "2016-08-29T02:08:08+00:00", "network_driver" => "flannel", "fixed_network" => nil, "coe" => "kubernetes", "flavor_id" => "m1.small", "master_lb_enabled" => true, "dns_nameserver" => "8.8.8.8", } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra/requests/list_clusters.rb0000644000004100000410000000201013423370527030057 0ustar www-datawww-datamodule Fog module OpenStack class ContainerInfra class Real def list_clusters request( :expects => [200], :method => 'GET', :path => "clusters/detail" ) end end class Mock def list_clusters response = Excon::Response.new response.status = 200 response.body = { "clusters" => [ { "status" => "CREATE_IN_PROGRESS", "cluster_template_id" => "0562d357-8641-4759-8fed-8173f02c9633", "uuid" => "731387cf-a92b-4c36-981e-3271d63e5597", "stack_id" => "31c1ee6c-081e-4f39-9f0f-f1d87a7defa1", "master_count" => 1, "create_timeout" => 60, "node_count" => 1, "name" => "k8s" } ] } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra/models/0000755000004100000410000000000013423370527024252 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/container_infra/models/cluster.rb0000644000004100000410000000250713423370527026264 0ustar www-datawww-datarequire_relative 'base' module Fog module OpenStack class ContainerInfra class Cluster < Fog::OpenStack::ContainerInfra::Base identity :uuid attribute :api_address attribute :coe_version attribute :cluster_template_id attribute :create_timeout attribute :created_at attribute :discovery_url attribute :master_addresses attribute :master_count attribute :name attribute :node_addresses attribute :node_count attribute :stack_id attribute :status attribute :status_reason attribute :updated_at def create requires :name, :cluster_template_id merge_attributes(service.create_cluster(attributes).body) self end def update requires :uuid, :name, :cluster_template_id attrs = attributes.select{|k,_| allowed_update_attributes.include? k} attrs = convert_update_params(attrs) merge_attributes(service.update_cluster(uuid, attrs).body) self end def destroy requires :uuid service.delete_cluster(uuid) true end private def allowed_update_attributes [ :node_count ] end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra/models/cluster_templates.rb0000644000004100000410000000122113423370527030332 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/container_infra/models/cluster_template' module Fog module OpenStack class ContainerInfra class ClusterTemplates < Fog::OpenStack::Collection model Fog::OpenStack::ContainerInfra::ClusterTemplate def all load_response(service.list_cluster_templates, 'clustertemplates') end def get(cluster_template_uuid_or_name) resource = service.get_cluster_template(cluster_template_uuid_or_name).body new(resource) rescue Fog::OpenStack::ContainerInfra::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra/models/clusters.rb0000644000004100000410000000111413423370527026440 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/container_infra/models/cluster' module Fog module OpenStack class ContainerInfra class Clusters < Fog::OpenStack::Collection model Fog::OpenStack::ContainerInfra::Cluster def all load_response(service.list_clusters, "clusters") end def get(cluster_uuid_or_name) resource = service.get_cluster(cluster_uuid_or_name).body new(resource) rescue Fog::OpenStack::ContainerInfra::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra/models/bays.rb0000644000004100000410000000105313423370527025534 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/container_infra/models/bay' module Fog module OpenStack class ContainerInfra class Bays < Fog::OpenStack::Collection model Fog::OpenStack::ContainerInfra::Bay def all load_response(service.list_bays, "bays") end def get(bay_uuid_or_name) resource = service.get_bay(bay_uuid_or_name).body new(resource) rescue Fog::OpenStack::ContainerInfra::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra/models/base.rb0000644000004100000410000000100313423370527025503 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class ContainerInfra class Base < Fog::OpenStack::Model def convert_update_params(params) params = params.map do |key, value| { "path" => "/#{key}", "op" => value ? "replace" : "remove" }.merge(value ? {"value" => value} : {}) end params.each {|k,v| params[k] = v.to_s.capitalize if [true, false].include?(v)} end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra/models/cluster_template.rb0000644000004100000410000000332713423370527030160 0ustar www-datawww-datarequire_relative 'base' module Fog module OpenStack class ContainerInfra class ClusterTemplate < Fog::OpenStack::ContainerInfra::Base identity :uuid attribute :apiserver_port attribute :cluster_distro attribute :coe attribute :created_at attribute :dns_nameserver attribute :docker_storage_driver attribute :docker_volume_size attribute :external_network_id attribute :fixed_network attribute :fixed_subnet attribute :flavor_id attribute :floating_ip_enabled attribute :http_proxy attribute :image_id attribute :insecure_registry attribute :keypair_id attribute :labels attribute :master_flavor_id attribute :master_lb_enabled attribute :name attribute :network_driver attribute :no_proxy attribute :public attribute :registry_enabled attribute :server_type attribute :tls_disabled attribute :updated_at attribute :volume_driver def create requires :name, :keypair_id, :flavor_id, :image_id, :external_network_id, :coe merge_attributes(service.create_cluster_template(attributes).body) self end def update requires :uuid, :name, :keypair_id, :flavor_id, :image_id, :external_network_id, :coe attrs = convert_update_params(attributes) merge_attributes(service.update_cluster_template(uuid, attrs).body) self end def destroy requires :uuid service.delete_cluster_template(uuid) true end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra/models/bay_models.rb0000644000004100000410000000113013423370527026710 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/container_infra/models/bay_model' module Fog module OpenStack class ContainerInfra class BayModels < Fog::OpenStack::Collection model Fog::OpenStack::ContainerInfra::BayModel def all load_response(service.list_bay_models, 'baymodels') end def get(bay_model_uuid_or_name) resource = service.get_bay_model(bay_model_uuid_or_name).body new(resource) rescue Fog::OpenStack::ContainerInfra::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra/models/bay_model.rb0000644000004100000410000000333213423370527026533 0ustar www-datawww-datarequire_relative 'base' module Fog module OpenStack class ContainerInfra class BayModel < Fog::OpenStack::ContainerInfra::Base identity :uuid attribute :apiserver_port attribute :cluster_distro attribute :coe attribute :created_at attribute :dns_nameserver attribute :docker_storage_driver attribute :docker_volume_size attribute :external_network_id attribute :fixed_network attribute :fixed_subnet attribute :flavor_id attribute :floating_ip_enabled attribute :http_proxy attribute :https_proxy attribute :image_id attribute :insecure_registry attribute :keypair_id attribute :labels attribute :master_flavor_id attribute :master_lb_enabled attribute :name attribute :network_driver attribute :no_proxy attribute :public attribute :registry_enabled attribute :server_type attribute :tls_disabled attribute :updated_at attribute :volume_driver def create requires :name, :keypair_id, :flavor_id, :image_id, :external_network_id, :coe merge_attributes(service.create_bay_model(attributes).body) self end def update requires :uuid, :name, :keypair_id, :flavor_id, :image_id, :external_network_id, :coe attrs = convert_update_params(attributes) merge_attributes(service.update_bay_model(uuid, attrs).body) self end def destroy requires :uuid service.delete_bay_model(uuid) true end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra/models/certificates.rb0000644000004100000410000000115513423370527027246 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/container_infra/models/certificate' module Fog module OpenStack class ContainerInfra class Certificates < Fog::OpenStack::Collection model Fog::OpenStack::ContainerInfra::Certificate def create(bay_uuid) resource = service.create_certificate(bay_uuid).body new(resource) end def get(bay_uuid) resource = service.get_certificate(bay_uuid).body new(resource) rescue Fog::OpenStack::ContainerInfra::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra/models/certificate.rb0000644000004100000410000000062013423370527027057 0ustar www-datawww-datarequire_relative 'base' module Fog module OpenStack class ContainerInfra class Certificate < Fog::OpenStack::ContainerInfra::Base identity :bay_uuid attribute :pem attribute :csr def create requires :csr, :bay_uuid merge_attributes(service.create_certificate(attributes).body) self end end end end end fog-openstack-1.0.8/lib/fog/openstack/container_infra/models/bay.rb0000644000004100000410000000243713423370527025360 0ustar www-datawww-datarequire_relative 'base' module Fog module OpenStack class ContainerInfra class Bay < Fog::OpenStack::ContainerInfra::Base identity :uuid attribute :api_address attribute :coe_version attribute :baymodel_id attribute :create_timeout attribute :created_at attribute :discovery_url attribute :master_addresses attribute :master_count attribute :name attribute :node_addresses attribute :node_count attribute :stack_id attribute :status attribute :status_reason attribute :updated_at def create requires :name, :baymodel_id merge_attributes(service.create_bay(attributes).body) self end def update requires :uuid, :name, :baymodel_id attrs = attributes.select{|k,_| allowed_update_attributes.include? k} attrs = convert_update_params(attrs) merge_attributes(service.update_bay(uuid, attrs).body) self end def destroy requires :uuid service.delete_bay(uuid) true end private def allowed_update_attributes [ :node_count ] end end end end end fog-openstack-1.0.8/lib/fog/openstack/volume.rb0000644000004100000410000000276013423370527021467 0ustar www-datawww-data module Fog module OpenStack class Volume < Fog::Service autoload :V1, 'fog/openstack/volume/v1' autoload :V2, 'fog/openstack/volume/v2' @@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_api_version] # Fog::OpenStack::Image.new() will return a Fog::OpenStack::Volume::V2 or a Fog::OpenStack::Volume::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] service = if inspect == 'Fog::OpenStack::Volume' Fog::OpenStack::Volume::V2.new(args) || Fog::OpenStack::Volume::V1.new(args) else super end service end end end end fog-openstack-1.0.8/lib/fog/openstack/auth/0000755000004100000410000000000013423370527020567 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/auth/catalog/0000755000004100000410000000000013423370527022201 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/auth/catalog/v3.rb0000644000004100000410000000077013423370527023062 0ustar www-datawww-datarequire 'fog/openstack/auth/catalog' module Fog module OpenStack module Auth module Catalog class V3 include Fog::OpenStack::Auth::Catalog def endpoint_match?(endpoint, interface, region) if endpoint['interface'] == interface true unless !region.nil? && endpoint['region'] != region end end def endpoint_url(endpoint, _) endpoint['url'] end end end end end end fog-openstack-1.0.8/lib/fog/openstack/auth/catalog/v2.rb0000644000004100000410000000101213423370527023047 0ustar www-datawww-datarequire 'fog/openstack/auth/catalog' module Fog module OpenStack module Auth module Catalog class V2 include Fog::OpenStack::Auth::Catalog def endpoint_match?(endpoint, interface, region) if endpoint.key?("#{interface}URL") true unless !region.nil? && endpoint['region'] != region end end def endpoint_url(endpoint, interface) endpoint["#{interface}URL"] end end end end end end fog-openstack-1.0.8/lib/fog/openstack/auth/token/0000755000004100000410000000000013423370527021707 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/auth/token/v3.rb0000644000004100000410000001052513423370527022567 0ustar www-datawww-datarequire 'fog/openstack/auth/token' require 'fog/openstack/auth/name' module Fog module OpenStack module Auth module Token class V3 include Fog::OpenStack::Auth::Token attr_reader :domain, :project # Default Domain ID DOMAIN_ID = 'default'.freeze def credentials identity = if @token { 'methods' => ['token'], 'token' => {'id' => @token} } else { 'methods' => ['password'], 'password' => @user.identity } end if scope { 'auth' => { 'identity' => identity, 'scope' => scope } } else {'auth' => {'identity' => identity}} end end def prefix_path(uri) if uri.path =~ /\/v3(\/)*.*$/ '' else '/v3' end end def path '/auth/tokens' end def scope return @project.identity if @project return @domain.identity if @domain end def set(response) @data = Fog::JSON.decode(response.body) @token = response.headers['x-subject-token'] @expires = @data['token']['expires_at'] @tenant = @data['token']['project'] @user = @data['token']['user'] catalog = @data['token']['catalog'] if catalog @catalog = Fog::OpenStack::Auth::Catalog::V3.new(catalog) end end def build_credentials(auth) if auth[:openstack_project_id] || auth[:openstack_project_name] # project scoped @project = Fog::OpenStack::Auth::ProjectScope.new( auth[:openstack_project_id], auth[:openstack_project_name] ) @project.domain = if auth[:openstack_project_domain_id] || auth[:openstack_project_domain_name] Fog::OpenStack::Auth::Name.new( auth[:openstack_project_domain_id], auth[:openstack_project_domain_name] ) elsif auth[:openstack_domain_id] || auth[:openstack_domain_name] Fog::OpenStack::Auth::Name.new( auth[:openstack_domain_id], auth[:openstack_domain_name] ) else Fog::OpenStack::Auth::Name.new(DOMAIN_ID, nil) end elsif auth[:openstack_domain_id] || auth[:openstack_domain_name] # domain scoped @domain = Fog::OpenStack::Auth::DomainScope.new( auth[:openstack_domain_id], auth[:openstack_domain_name] ) end if auth[:openstack_auth_token] @token = auth[:openstack_auth_token] else @user = Fog::OpenStack::Auth::User.new(auth[:openstack_userid], auth[:openstack_username]) @user.password = auth[:openstack_api_key] @user.domain = if auth[:openstack_user_domain_id] || auth[:openstack_user_domain_name] Fog::OpenStack::Auth::Name.new( auth[:openstack_user_domain_id], auth[:openstack_user_domain_name] ) elsif auth[:openstack_domain_id] || auth[:openstack_domain_name] Fog::OpenStack::Auth::Name.new( auth[:openstack_domain_id], auth[:openstack_domain_name] ) else Fog::OpenStack::Auth::Name.new(DOMAIN_ID, nil) end end credentials end end end end end end fog-openstack-1.0.8/lib/fog/openstack/auth/token/v2.rb0000644000004100000410000000432413423370527022566 0ustar www-datawww-datarequire 'fog/openstack/auth/token' require 'fog/openstack/auth/name' module Fog module OpenStack module Auth module Token class CredentialsError < RuntimeError; end class V2 include Fog::OpenStack::Auth::Token attr_reader :tenant def credentials if @token identity = {'token' => {'id' => @token}} else raise CredentialsError, "#{self.class}: User name is required" if @user.name.nil? raise CredentialsError, "#{self.class}: User password is required" if @user.password.nil? identity = {'passwordCredentials' => user_credentials} end if @tenant.id identity['tenantId'] = @tenant.id.to_s elsif @tenant.name identity['tenantName'] = @tenant.name.to_s end {'auth' => identity} end def prefix_path(uri) if uri.path =~ /\/v2(\.0)*(\/)*.*$/ '' else '/v2.0' end end def path '/tokens' end def user_credentials { 'username' => @user.name.to_s, 'password' => @user.password } end def set(response) @data = Fog::JSON.decode(response.body) @token = @data['access']['token']['id'] @expires = @data['access']['token']['expires'] @tenant = @data['access']['token']['tenant'] @user = @data['access']['user'] catalog = @data['access']['serviceCatalog'] @catalog = Fog::OpenStack::Auth::Catalog::V2.new(catalog) if catalog end def build_credentials(auth) if auth[:openstack_auth_token] @token = auth[:openstack_auth_token] else @user = Fog::OpenStack::Auth::User.new(auth[:openstack_userid], auth[:openstack_username]) @user.password = auth[:openstack_api_key] end @tenant = Fog::OpenStack::Auth::Name.new(auth[:openstack_tenant_id], auth[:openstack_tenant]) credentials end end end end end end fog-openstack-1.0.8/lib/fog/openstack/auth/token.rb0000644000004100000410000000402613423370527022236 0ustar www-datawww-datarequire 'fog/openstack/auth/token/v2' require 'fog/openstack/auth/token/v3' require 'fog/openstack/auth/catalog/v2' require 'fog/openstack/auth/catalog/v3' module Fog module OpenStack module Auth module Token attr_reader :catalog, :expires, :tenant, :token, :user, :data class ExpiryError < RuntimeError; end class StandardError < RuntimeError; end class URLError < RuntimeError; end def self.build(auth, options) if auth[:openstack_identity_api_version] =~ /(v)*2(\.0)*/i || auth[:openstack_tenant_id] || auth[:openstack_tenant] Fog::OpenStack::Auth::Token::V2.new(auth, options) else Fog::OpenStack::Auth::Token::V3.new(auth, options) end end def initialize(auth, options) raise URLError, 'No URL provided' if auth[:openstack_auth_url].nil? || auth[:openstack_auth_url].empty? @creds = { :data => build_credentials(auth), :uri => URI.parse(auth[:openstack_auth_url]) } response = authenticate(@creds, options) set(response) end def get set(authenticate(@creds, {})) if expired? @token end private def authenticate(creds, options) connection = Fog::Core::Connection.new(creds[:uri].to_s, false, options) request = { :expects => [200, 201], :headers => {'Content-Type' => 'application/json'}, :body => Fog::JSON.encode(creds[:data]), :method => 'POST', :path => creds[:uri].path + prefix_path(creds[:uri]) + path } connection.request(request) end def expired? if @expires.nil? || @expires.empty? raise ExpiryError, 'Missing token expiration data' end Time.parse(@expires) < Time.now.utc end def refresh raise StandardError, "__method__ not implemented yet!" end end end end end fog-openstack-1.0.8/lib/fog/openstack/auth/catalog.rb0000644000004100000410000000352613423370527022534 0ustar www-datawww-datamodule Fog module OpenStack module Auth module Catalog attr_reader :payload class CatalogError < RuntimeError; end class EndpointError < RuntimeError; end class ServiceTypeError < RuntimeError; end def initialize(payload) @payload = payload end def get_endpoint_url(names, interfaces, region = nil) # TODO: Inject OpenStack Service Types Authority names_list = if names.kind_of?(String) [names] else names end entries = get_by_type(names_list) raise ServiceTypeError, 'No endpoint match' if entries.empty? interfaces_list = if interfaces.kind_of?(String) [interfaces] else interfaces end list = [] interfaces_list.each do |interface| val = get_endpoint(entries, interface, region) list << val if val end raise EndpointError, 'No endpoint found' if list.empty? list[0] end private def get_by_type(names) raise CatalogError, 'Empty content' unless @payload @payload.select do |e| names.include?(e['type']) end end def get_endpoint(entries, interface, region) list = [] entries.each do |type| next unless type.key?('endpoints') type['endpoints'].each do |endpoint| list << endpoint_url(endpoint, interface) if endpoint_match?(endpoint, interface, region) end end raise EndpointError, 'Multiple endpoints found' if list.size > 1 list[0] end end end end end fog-openstack-1.0.8/lib/fog/openstack/auth/name.rb0000644000004100000410000000276513423370527022046 0ustar www-datawww-datamodule Fog module OpenStack module Auth class CredentialsError < RuntimeError; end module Domain attr_accessor :domain def identity data = {} if !id.nil? data.merge!(to_h(:id)) elsif !name.nil? && !domain.nil? data.merge!(to_h(:name)) data[:domain] = @domain.identity else raise Fog::OpenStack::Auth::CredentialsError, "#{self.class}: An Id, or a name with its domain, must be provided" end data end end Name = Struct.new(:id, :name) class Name def identity return to_h(:id) unless id.nil? return to_h(:name) unless name.nil? raise Fog::OpenStack::Auth::CredentialsError, "#{self.class}: No available id or name" end def to_h(var) {var => send(var)} end end class DomainScope < Name def identity {:domain => super} end end class ProjectScope < Name include Fog::OpenStack::Auth::Domain def identity {:project => super} end end class User < Name include Fog::OpenStack::Auth::Domain attr_accessor :password def identity data = super raise CredentialsError, "#{self.class}: No password available" if password.nil? data.merge!(to_h(:password)) {:user => data} end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/0000755000004100000410000000000013423370527023477 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/0000755000004100000410000000000013423370527025352 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/list_security_services_detail.rb0000644000004100000410000000115113423370527034024 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def list_security_services_detail(options = {}) request( :expects => 200, :method => 'GET', :path => 'security-services/detail', :query => options ) end end class Mock def list_security_services_detail(_options = {}) response = Excon::Response.new response.status = 200 response.body = {'security_services' => data[:security_services_detail]} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/list_snapshots_detail.rb0000644000004100000410000000110113423370527032267 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def list_snapshots_detail(options = {}) request( :expects => 200, :method => 'GET', :path => 'snapshots/detail', :query => options ) end end class Mock def list_snapshots_detail(_options = {}) response = Excon::Response.new response.status = 200 response.body = {'snapshots' => data[:snapshots_detail]} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/update_share_network.rb0000644000004100000410000000153113423370527032114 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def update_share_network(id, options = {}) request( :body => Fog::JSON.encode('share_network' => options), :expects => 200, :method => 'PUT', :path => "share-networks/#{id}" ) end end class Mock def update_share_network(id, options = {}) # stringify keys options = Hash[options.map { |k, v| [k.to_s, v] }] data[:share_net_updated] = data[:share_networks_detail].first.merge(options) data[:share_net_updated]['id'] = id response = Excon::Response.new response.status = 200 response.body = {'share_network' => data[:share_net_updated]} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/share_action.rb0000644000004100000410000000057313423370527030343 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def share_action(id, options = {}, expects_status = 202) request( :body => Fog::JSON.encode(options), :expects => expects_status, :method => 'POST', :path => "shares/#{id}/action" ) end end end end end ././@LongLink0000644000000000000000000000015300000000000011602 Lustar rootrootfog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/add_security_service_to_share_network.rbfog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/add_security_service_to_share_netw0000644000004100000410000000145513423370527034422 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def add_security_service_to_share_network(security_service_id, share_network_id) action = { 'add_security_service' => { 'security_service_id' => security_service_id } } share_network_action(share_network_id, action) end end class Mock def add_security_service_to_share_network(_security_service_id, share_network_id) response = Excon::Response.new response.status = 200 share_net = data[:share_network_updated] || data[:share_networks].first share_net['id'] = share_network_id response.body = {'share_network' => share_net} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/get_share.rb0000644000004100000410000000105413423370527027640 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def get_share(id) request( :expects => 200, :method => 'GET', :path => "shares/#{id}" ) end end class Mock def get_share(id) response = Excon::Response.new response.status = 200 share = data[:share_updated] || data[:shares_detail].first share['id'] = id response.body = share response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/delete_snapshot.rb0000644000004100000410000000140213423370527031055 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def delete_snapshot(id) request( :expects => 202, :method => 'DELETE', :path => "snapshots/#{id}" ) end end class Mock def delete_snapshot(id) response = Excon::Response.new response.status = 202 snapshot = data[:snapshot_updated] || data[:snapshots_detail].first.dup snapshot['id'] = id snapshot['status'] = 'deleting' snapshot['links']['self'] = "https://127.0.0.1:8786/v2/snapshots/#{id}" response.body = {'snapshot' => snapshot} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/delete_share.rb0000644000004100000410000000126013423370527030322 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def delete_share(id) request( :expects => 202, :method => 'DELETE', :path => "shares/#{id}" ) end end class Mock def delete_share(id) response = Excon::Response.new response.status = 202 share = data[:share_updated] || data[:shares_detail].first.dup share['id'] = id share['links']['self'] = "https://127.0.0.1:8786/v2/shares/#{id}" response.body = {'share' => share} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/list_shares.rb0000644000004100000410000000102613423370527030216 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def list_shares(options = {}) request( :expects => 200, :method => 'GET', :path => 'shares', :query => options ) end end class Mock def list_shares(_options = {}) response = Excon::Response.new response.status = 200 response.body = {'shares' => data[:shares]} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/update_share.rb0000644000004100000410000000206213423370527030343 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def update_share(id, options = {}) request( :body => Fog::JSON.encode('share' => options), :expects => 200, :method => 'PUT', :path => "shares/#{id}" ) end end class Mock def update_share(id, options = {}) # stringify keys options = Hash[options.map { |k, v| [k.to_s, v] }] update_data(id, options) response = Excon::Response.new response.status = 200 response.body = {'share' => data[:share_updated]} response end private def update_data(id, options) data[:share_updated] = data[:shares_detailed].first.merge(options) data[:share_updated]['id'] = id data[:share_updated]['status'] = "PENDING" data[:share_updated]['links']['self'] = "https://127.0.0.1:8786/v2/shares/#{id}" end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/list_share_export_locations.rb0000644000004100000410000000147513423370527033517 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real # For older versions v1.0-2.8 the export locations are responsed as an attribute of share (export_locations). # For newer API versions (>= 2.9) it is available in separate APIs. # This method returns a list of the export locations. def list_share_export_locations(share_id) request( :expects => 200, :method => 'GET', :path => "shares/#{share_id}/export_locations" ) end end class Mock def list_share_export_locations(share_id) response = Excon::Response.new response.status = 200 response.body = {'export_locations' => data[:export_locations]} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/delete_security_service.rb0000644000004100000410000000073013423370527032610 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def delete_security_service(id) request( :expects => 202, :method => 'DELETE', :path => "security-services/#{id}" ) end end class Mock def delete_security_service(_id) response = Excon::Response.new response.status = 202 response end end end end end ././@LongLink0000644000000000000000000000016000000000000011600 Lustar rootrootfog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/remove_security_service_from_share_network.rbfog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/remove_security_service_from_share0000644000004100000410000000147213423370527034452 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def remove_security_service_from_share_network(security_service_id, share_network_id) action = { 'remove_security_service' => { 'security_service_id' => security_service_id } } share_network_action(share_network_id, action) end end class Mock def remove_security_service_from_share_network(_security_service_id, share_network_id) response = Excon::Response.new response.status = 200 share_net = data[:share_network_updated] || data[:share_networks].first share_net['id'] = share_network_id response.body = {'share_network' => share_net} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/create_snapshot.rb0000644000004100000410000000217013423370527031061 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def create_snapshot(share_id, options = {}) data = { 'share_id' => share_id } vanilla_options = [ :name, :description, :display_name, :display_description, :force ] vanilla_options.select { |o| options[o] }.each do |key| data[key] = options[key] end request( :body => Fog::JSON.encode('snapshot' => data), :expects => 202, :method => 'POST', :path => 'snapshots' ) end end class Mock def create_snapshot(share_id, options = {}) # stringify keys options = Hash[options.map { |k, v| [k.to_s, v] }] response = Excon::Response.new response.status = 202 snapshot = data[:snapshots_detail].first.dup snapshot['share_id'] = share_id snapshot['status'] = 'creating' response.body = {'snapshot' => snapshot.merge(options)} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/list_share_networks_detail.rb0000644000004100000410000000113213423370527033307 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def list_share_networks_detail(options = {}) request( :expects => 200, :method => 'GET', :path => 'share-networks/detail', :query => options ) end end class Mock def list_share_networks_detail(_options = {}) response = Excon::Response.new response.status = 200 response.body = {'share_networks' => data[:share_networks_detail]} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/list_share_access_rules.rb0000644000004100000410000000120113423370527032561 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def list_share_access_rules(share_id) action = { "#{action_prefix}access_list" => nil } share_action(share_id, action, 200) end end class Mock def list_share_access_rules(share_id) response = Excon::Response.new response.status = 200 rules = data[:access_rules] rules.each do |rule| rule[:share_id] = share_id end response.body = {'access_list' => rules} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/list_share_networks.rb0000644000004100000410000000107613423370527031774 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def list_share_networks(options = {}) request( :expects => 200, :method => 'GET', :path => 'share-networks', :query => options ) end end class Mock def list_share_networks(_options = {}) response = Excon::Response.new response.status = 200 response.body = {'share_networks' => data[:share_networks]} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/grant_share_access.rb0000644000004100000410000000174313423370527031522 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def grant_share_access(share_id, access_to = '0.0.0.0/0', access_type = 'ip', access_level = 'rw') action = { "#{action_prefix}allow_access" => { 'access_to' => access_to, 'access_type' => access_type, 'access_level' => access_level } } share_action(share_id, action, 200) end end class Mock def grant_share_access(share_id, access_to, access_type, access_level) response = Excon::Response.new response.status = 200 access = data[:access_rules].first access[:share_id] = share_id access[:access_level] = access_level access[:access_type] = access_type access[:access_to] = access_to response.body = {'access' => access} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/get_share_network.rb0000644000004100000410000000115613423370527031414 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def get_share_network(id) request( :expects => 200, :method => 'GET', :path => "share-networks/#{id}" ) end end class Mock def get_share_network(id) response = Excon::Response.new response.status = 200 share_net = data[:share_network_updated] || data[:share_networks].first share_net['id'] = id response.body = {'share_network' => share_net} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/update_quota.rb0000644000004100000410000000150413423370527030372 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def update_quota(project_id, options = {}) request( :body => Fog::JSON.encode('quota_set' => options), :expects => 200, :method => 'PUT', :path => "#{action_prefix}quota-sets/#{project_id}" ) end end class Mock def update_quota(project_id, options = {}) # stringify keys options = Hash[options.map { |k, v| [k.to_s, v] }] data[:quota_updated] = data[:quota].merge(options) data[:quota_updated]['id'] = project_id response = Excon::Response.new response.status = 200 response.body = {'quota_set' => data[:quota_updated]} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/shrink_share.rb0000644000004100000410000000077113423370527030364 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def shrink_share(share_id, new_size) action = { "#{action_prefix}shrink" => { 'new_size' => new_size } } share_action(share_id, action) end end class Mock def shrink_share(_share_id, _new_size) response = Excon::Response.new response.status = 202 response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/list_shares_detail.rb0000644000004100000410000000106213423370527031540 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def list_shares_detail(options = {}) request( :expects => 200, :method => 'GET', :path => 'shares/detail', :query => options ) end end class Mock def list_shares_detail(_options = {}) response = Excon::Response.new response.status = 200 response.body = {'shares' => data[:shares_detail]} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/share_network_action.rb0000644000004100000410000000061313423370527032107 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def share_network_action(id, options = {}, expects_status = 200) request( :body => Fog::JSON.encode(options), :expects => expects_status, :method => 'POST', :path => "share-networks/#{id}/action" ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/list_snapshots.rb0000644000004100000410000000104513423370527030754 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def list_snapshots(options = {}) request( :expects => 200, :method => 'GET', :path => 'snapshots', :query => options ) end end class Mock def list_snapshots(_options = {}) response = Excon::Response.new response.status = 200 response.body = {'snapshots' => data[:snapshots]} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/delete_share_network.rb0000644000004100000410000000120613423370527032073 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def delete_share_network(id) request( :expects => 202, :method => 'DELETE', :path => "share-networks/#{id}" ) end end class Mock def delete_share_network(id) response = Excon::Response.new response.status = 202 share_net = data[:share_net_updated] || data[:share_networks_detail].first.dup share_net['id'] = id response.body = {'share_network' => share_net} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/update_security_service.rb0000644000004100000410000000160013423370527032625 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def update_security_service(id, options = {}) request( :body => Fog::JSON.encode('security_service' => options), :expects => 200, :method => 'PUT', :path => "security-services/#{id}" ) end end class Mock def update_security_service(id, options = {}) # stringify keys options = Hash[options.map { |k, v| [k.to_s, v] }] data[:security_service_updated] = data[:security_services_detail].first.merge(options) data[:security_service_updated]['id'] = id response = Excon::Response.new response.status = 200 response.body = {'security_service' => data[:security_service_updated]} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/get_snapshot.rb0000644000004100000410000000110413423370527030371 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def get_snapshot(id) request( :expects => 200, :method => 'GET', :path => "snapshots/#{id}" ) end end class Mock def get_snapshot(id) response = Excon::Response.new response.status = 200 snapshot = data[:snapshot_updated] || data[:snapshots_detail].first snapshot['id'] = id response.body = snapshot response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/list_availability_zones.rb0000644000004100000410000000112313423370527032617 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def list_availability_zones() request( :expects => 200, :method => 'GET', :path => microversion_newer_than?('2.6') ? 'availability-zones' : 'os-availability-zone' ) end end class Mock def list_availability_zones() response = Excon::Response.new response.status = 200 response.body = {'availability_zones' => data[:availability_zones]} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/revoke_share_access.rb0000644000004100000410000000102013423370527031666 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def revoke_share_access(share_id, access_id) action = { "#{action_prefix}deny_access" => { 'access_id' => access_id } } share_action(share_id, action) end end class Mock def revoke_share_access(_share_id, _access_id) response = Excon::Response.new response.status = 202 response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/get_security_service.rb0000644000004100000410000000123413423370527032125 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def get_security_service(id) request( :expects => 200, :method => 'GET', :path => "security-services/#{id}" ) end end class Mock def get_security_service(id) response = Excon::Response.new response.status = 200 security_service = data[:security_service_updated] || data[:security_services_detail].first security_service['id'] = id response.body = {'security_service' => security_service} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/create_share_network.rb0000644000004100000410000000200613423370527032073 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def create_share_network(options = {}) data = {} vanilla_options = [ :name, :description, :neutron_net_id, :neutron_subnet_id, :nova_net_id ] vanilla_options.select { |o| options[o] }.each do |key| data[key] = options[key] end request( :body => Fog::JSON.encode('share_network' => data), :expects => 200, :method => 'POST', :path => 'share-networks' ) end end class Mock def create_share_network(options = {}) # stringify keys options = Hash[options.map { |k, v| [k.to_s, v] }] response = Excon::Response.new response.status = 200 share_net = data[:share_networks_detail].first.dup response.body = {'share_networks' => share_net.merge(options)} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/get_quota.rb0000644000004100000410000000116213423370527027667 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def get_quota(project_id) request( :expects => 200, :method => 'GET', :path => "#{action_prefix}quota-sets/#{project_id}" ) end end class Mock def get_quota(project_id) response = Excon::Response.new response.status = 200 quota_data = data[:quota_updated] || data[:quota] quota_data['id'] = project_id response.body = {'quota_set' => quota_data} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/create_share.rb0000644000004100000410000000247213423370527030331 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def create_share(protocol, size, options = {}) data = { 'share_proto' => protocol, 'size' => size } vanilla_options = [ :name, :description, :display_name, :display_description, :share_type, :volume_type, :snapshot_id, :is_public, :metadata, :share_network_id, :consistency_group_id, :availability_zone ] vanilla_options.select { |o| options[o] }.each do |key| data[key] = options[key] end request( :body => Fog::JSON.encode('share' => data), :expects => 200, :method => 'POST', :path => 'shares' ) end end class Mock def create_share(protocol, size, options = {}) # stringify keys options = Hash[options.map { |k, v| [k.to_s, v] }] response = Excon::Response.new response.status = 200 share = data[:shares_detail].first.dup share['share_proto'] = protocol share['size'] = size share['status'] = 'creating' response.body = {'share' => share.merge(options)} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/list_security_services.rb0000644000004100000410000000111513423370527032502 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def list_security_services(options = {}) request( :expects => 200, :method => 'GET', :path => 'security-services', :query => options ) end end class Mock def list_security_services(_options = {}) response = Excon::Response.new response.status = 200 response.body = {'security_services' => data[:security_services]} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/create_security_service.rb0000644000004100000410000000230713423370527032613 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def create_security_service(type, name, options = {}) data = { 'type' => type, 'name' => name } vanilla_options = [ :description, :dns_ip, :user, :password, :domain, :server ] vanilla_options.select { |o| options[o] }.each do |key| data[key] = options[key] end request( :body => Fog::JSON.encode('security_service' => data), :expects => 200, :method => 'POST', :path => 'security-services' ) end end class Mock def create_security_service(type, name, options = {}) # stringify keys options = Hash[options.map { |k, v| [k.to_s, v] }] response = Excon::Response.new response.status = 200 security_service = data[:security_services_detail].first.dup security_service['type'] = type security_service['name'] = name response.body = {'security_service' => security_service.merge(options)} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/update_snapshot.rb0000644000004100000410000000147013423370527031102 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def update_snapshot(id, options = {}) request( :body => Fog::JSON.encode('snapshot' => options), :expects => 200, :method => 'PUT', :path => "snapshots/#{id}" ) end end class Mock def update_snapshot(id, options = {}) # stringify keys options = Hash[options.map { |k, v| [k.to_s, v] }] data[:snapshot_updated] = data[:snapshots_detail].first.merge(options) data[:snapshot_updated]['id'] = id response = Excon::Response.new response.status = 200 response.body = {'snapshot' => data[:snapshot_updated]} response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/get_share_export_location.rb0000644000004100000410000000165613423370527033141 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real # For older versions v1.0-2.8 the export locations are responsed as an attribute of share (export_locations). # For newer API versions (>= 2.9) it is available in separate APIs. # This method returns the export location detail. def get_share_export_location(share_id,export_location_id) request( :expects => 200, :method => 'GET', :path => "shares/#{share_id}/export_locations/​{export_location_id}​" ) end end class Mock def get_share_export_location(id) response = Excon::Response.new response.status = 200 share_export_location = data[:export_locations].first share_export_location['id'] = id response.body = share_export_location response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/get_limits.rb0000644000004100000410000000213513423370527030040 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def get_limits request( :expects => 200, :method => 'GET', :path => 'limits' ) end end class Mock def get_limits absolute_limits = { # Max 'maxTotalShareGigabytes' => 1000, 'maxTotalShareNetworks' => 10, 'maxTotalShares' => 50, 'maxTotalSnapshotGigabytes' => 1000, 'maxTotalShareSnapshots' => 50, # Used 'totalShareNetworksUsed' => 0, 'totalSharesUsed' => 0, 'totalShareGigabytesUsed' => 0, 'totalShareSnapshotsUsed' => 0, 'totalSnapshotGigabytesUsed' => 0 } Excon::Response.new( :status => 200, :body => { 'limits' => { 'rate' => [], 'absolute' => absolute_limits } } ) end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/requests/extend_share.rb0000644000004100000410000000077113423370527030355 0ustar www-datawww-datamodule Fog module OpenStack class SharedFileSystem class Real def extend_share(share_id, new_size) action = { "#{action_prefix}extend" => { 'new_size' => new_size } } share_action(share_id, action) end end class Mock def extend_share(_share_id, _new_size) response = Excon::Response.new response.status = 202 response end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/models/0000755000004100000410000000000013423370527024762 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/shared_file_system/models/availability_zones.rb0000644000004100000410000000065613423370527031206 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/shared_file_system/models/availability_zone' module Fog module OpenStack class SharedFileSystem class AvailabilityZones < Fog::OpenStack::Collection model Fog::OpenStack::SharedFileSystem::AvailabilityZone def all load_response(service.list_availability_zones(), 'availability_zones') end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/models/share.rb0000644000004100000410000000456713423370527026425 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class SharedFileSystem class Share < Fog::OpenStack::Model identity :id attribute :share_proto attribute :size attribute :status attribute :links attribute :share_type attribute :share_type_name attribute :availability_zone attribute :share_network_id attribute :share_server_id attribute :host attribute :snapshot_id attribute :snapshot_support attribute :task_state attribute :access_rules_status attribute :has_replicas attribute :consistency_group_id attribute :source_cgsnapshot_member_id attribute :project_id attribute :created_at # optional attribute :name attribute :description attribute :export_location attribute :export_locations attribute :metadata attribute :is_public attribute :volume_type def save raise Fog::Errors::Error, 'Resaving an existing object may create a duplicate' if persisted? requires :size, :share_proto merge_attributes(service.create_share(share_proto, size, attributes).body['share']) true end def update(options = nil) requires :id merge_attributes(service.update_share(id, options || attributes).body['share']) self end def destroy requires :id service.delete_share(id) true end def ready? status == 'available' end def extend(size) requires :id service.extend_share(id, size) true end def shrink(size) requires :id service.shrink_share(id, size) true end def grant_access(access_to, access_type, access_level) requires :id service.grant_share_access(id, access_to, access_type, access_level) true end def revoke_access(access_id) requires :id service.revoke_share_access(id, access_id) true end def access_rules service.share_access_rules(:share => self) end def export_locations service.share_export_locations(:share => self) end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/models/share_export_locations.rb0000644000004100000410000000152613423370527032071 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/shared_file_system/models/share_access_rule' module Fog module OpenStack class SharedFileSystem class ShareExportLocations < Fog::OpenStack::Collection model Fog::OpenStack::SharedFileSystem::ShareExportLocation attr_accessor :share def all requires :share load_response(service.list_share_export_locations(@share.id), 'export_locations') end def find_by_id(id) location_hash = service.get_share_export_location(@share.id,id).body['export_location'] new(location_hash.merge(:service => service)) end alias get find_by_id def new(attributes = {}) requires :share super({:share => @share}.merge!(attributes)) end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/models/share_access_rules.rb0000644000004100000410000000132713423370527031147 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/shared_file_system/models/share_access_rule' module Fog module OpenStack class SharedFileSystem class ShareAccessRules < Fog::OpenStack::Collection model Fog::OpenStack::SharedFileSystem::ShareAccessRule attr_accessor :share def all requires :share load_response(service.list_share_access_rules(@share.id), 'access_list') end def find_by_id(id) all.find { |rule| rule.id == id } end alias get find_by_id def new(attributes = {}) requires :share super({:share => @share}.merge!(attributes)) end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/models/snapshot.rb0000644000004100000410000000211213423370527027142 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class SharedFileSystem class Snapshot < Fog::OpenStack::Model identity :id attribute :share_id attribute :status attribute :name attribute :description attribute :share_proto attribute :share_size attribute :size attribute :provider_location attribute :links attribute :created_at def save raise Fog::Errors::Error, 'Resaving an existing object may create a duplicate' if persisted? requires :share_id merge_attributes(service.create_snapshot(share_id, attributes).body['snapshot']) true end def update(options = nil) requires :id merge_attributes(service.update_snapshot(id, options || attributes).body['snapshot']) self end def destroy requires :id service.delete_snapshot(id) true end def ready? status == 'available' end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/models/network.rb0000644000004100000410000000211513423370527026777 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class SharedFileSystem class Network < Fog::OpenStack::Model identity :id attribute :name attribute :description attribute :neutron_net_id attribute :neutron_subnet_id attribute :nova_net_id attribute :network_type attribute :segmentation_id attribute :cidr attribute :ip_version attribute :project_id attribute :created_at attribute :updated_at def save raise Fog::Errors::Error, 'Resaving an existing object may create a duplicate' if persisted? merge_attributes(service.create_share_network(attributes).body['share_network']) true end def update(options = nil) requires :id merge_attributes(service.update_share_network(id, options || attributes).body['share_network']) self end def destroy requires :id service.delete_share_network(id) true end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/models/availability_zone.rb0000644000004100000410000000043213423370527031013 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class SharedFileSystem class AvailabilityZone < Fog::OpenStack::Model identity :id attribute :name attribute :created_at attribute :updated_at end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/models/shares.rb0000644000004100000410000000124413423370527026575 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/shared_file_system/models/share' module Fog module OpenStack class SharedFileSystem class Shares < Fog::OpenStack::Collection model Fog::OpenStack::SharedFileSystem::Share def all(options = {}) load_response(service.list_shares_detail(options), 'shares') end def find_by_id(id) share_hash = service.get_share(id).body['share'] new(share_hash.merge(:service => service)) end alias get find_by_id def destroy(id) share = find_by_id(id) share.destroy end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/models/share_access_rule.rb0000644000004100000410000000154613423370527030767 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class SharedFileSystem class ShareAccessRule < Fog::OpenStack::Model attr_accessor :share identity :id attribute :access_level attribute :access_type attribute :access_to attribute :state def save requires :share, :access_level, :access_type, :access_to raise Fog::Errors::Error, 'Resaving an existing object may create a duplicate' if persisted? merge_attributes(service.grant_share_access(@share.id, access_to, access_type, access_level).body['access']) true end def destroy requires :id, :share service.revoke_share_access(@share.id, id) true end def ready? state == 'active' end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/models/snapshots.rb0000644000004100000410000000130513423370527027330 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/shared_file_system/models/snapshot' module Fog module OpenStack class SharedFileSystem class Snapshots < Fog::OpenStack::Collection model Fog::OpenStack::SharedFileSystem::Snapshot def all(options = {}) load_response(service.list_snapshots_detail(options), 'snapshots') end def find_by_id(id) snapshot_hash = service.get_snapshot(id).body['snapshot'] new(snapshot_hash.merge(:service => service)) end alias get find_by_id def destroy(id) snapshot = find_by_id(id) snapshot.destroy end end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/models/share_export_location.rb0000644000004100000410000000050413423370527031701 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class SharedFileSystem class ShareExportLocation < Fog::OpenStack::Model identity :id attribute :share_instance_id attribute :path attribute :is_admin_only attribute :preferred end end end end fog-openstack-1.0.8/lib/fog/openstack/shared_file_system/models/networks.rb0000644000004100000410000000130213423370527027157 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/shared_file_system/models/network' module Fog module OpenStack class SharedFileSystem class Networks < Fog::OpenStack::Collection model Fog::OpenStack::SharedFileSystem::Network def all(options = {}) load_response(service.list_share_networks_detail(options), 'share_networks') end def find_by_id(id) net_hash = service.get_share_network(id).body['share_network'] new(net_hash.merge(:service => service)) end alias get find_by_id def destroy(id) net = find_by_id(id) net.destroy end end end end end fog-openstack-1.0.8/lib/fog/openstack/key_manager/0000755000004100000410000000000013423370527022110 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/key_manager/requests/0000755000004100000410000000000013423370527023763 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/key_manager/requests/get_secret.rb0000644000004100000410000000045513423370527026440 0ustar www-datawww-datamodule Fog module OpenStack class KeyManager class Real def get_secret(uuid) request( :expects => [200], :method => 'GET', :path => "secrets/#{uuid}", ) end end class Mock end end end end fog-openstack-1.0.8/lib/fog/openstack/key_manager/requests/list_secrets.rb0000644000004100000410000000051713423370527027016 0ustar www-datawww-datamodule Fog module OpenStack class KeyManager class Real def list_secrets(options = {}) request( :expects => [200], :method => 'GET', :path => 'secrets', :query => options ) end end class Mock end end end end fog-openstack-1.0.8/lib/fog/openstack/key_manager/requests/get_secret_acl.rb0000644000004100000410000000141713423370527027256 0ustar www-datawww-datamodule Fog module OpenStack class KeyManager class Real def get_secret_acl(uuid) request( :expects => [200], :method => 'GET', :path => "secrets/#{uuid}/acl" ) end end class Mock def get_secret_acl(_uuid) response = Excon::Response.new response.status = 200 response.body = { "read" => { "project-access" => false, "updated" => "2017-04-25T19:10:52", "users" => %w(45895d3a393f42b2a8760f5dafa9c6d8 dc2cb4f0d30044e2b0251409c94cc955), "created" => "2017-04-25T19:10:52" } } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/key_manager/requests/delete_secret.rb0000644000004100000410000000045613423370527027124 0ustar www-datawww-datamodule Fog module OpenStack class KeyManager class Real def delete_secret(id) request( :expects => [204], :method => 'DELETE', :path => "secrets/#{id}" ) end end class Mock end end end end fog-openstack-1.0.8/lib/fog/openstack/key_manager/requests/create_secret.rb0000644000004100000410000000053613423370527027124 0ustar www-datawww-datamodule Fog module OpenStack class KeyManager class Real def create_secret(options) request( :body => Fog::JSON.encode(options), :expects => [201], :method => 'POST', :path => 'secrets' ) end end class Mock end end end end fog-openstack-1.0.8/lib/fog/openstack/key_manager/requests/create_container.rb0000644000004100000410000000054413423370527027620 0ustar www-datawww-datamodule Fog module OpenStack class KeyManager class Real def create_container(options) request( :body => Fog::JSON.encode(options), :expects => [201], :method => 'POST', :path => 'containers' ) end end class Mock end end end end fog-openstack-1.0.8/lib/fog/openstack/key_manager/requests/delete_container.rb0000644000004100000410000000046413423370527027620 0ustar www-datawww-datamodule Fog module OpenStack class KeyManager class Real def delete_container(id) request( :expects => [204], :method => 'DELETE', :path => "containers/#{id}" ) end end class Mock end end end end fog-openstack-1.0.8/lib/fog/openstack/key_manager/requests/update_secret_acl.rb0000644000004100000410000000123113423370527027753 0ustar www-datawww-datamodule Fog module OpenStack class KeyManager class Real def update_secret_acl(uuid, options) request( :body => Fog::JSON.encode(options), :expects => [200], :method => 'PATCH', :path => "secrets/#{uuid}/acl" ) end end class Mock def update_secret_acl(_uuid, _options) response = Excon::Response.new response.status = 200 response.body = { "acl_ref" => "https://10.0.2.15:9311/v1/secrets/17ca49d9-0804-4ba7-b931-d34cabaa1f04/acl" } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/key_manager/requests/get_secret_metadata.rb0000644000004100000410000000047713423370527030304 0ustar www-datawww-datamodule Fog module OpenStack class KeyManager class Real def get_secret_metadata(uuid) request( :expects => [200], :method => 'GET', :path => "secrets/#{uuid}/metadata", ) end end class Mock end end end end fog-openstack-1.0.8/lib/fog/openstack/key_manager/requests/update_container_acl.rb0000644000004100000410000000124513423370527030455 0ustar www-datawww-datamodule Fog module OpenStack class KeyManager class Real def update_container_acl(uuid, options) request( :body => Fog::JSON.encode(options), :expects => [200], :method => 'PATCH', :path => "containers/#{uuid}/acl" ) end end class Mock def update_container_acl(_uuid, _options) response = Excon::Response.new response.status = 200 response.body = { "acl_ref" => "https://10.0.2.15:9311/v1/containers/4ab86cb0-a736-48df-ae97-b10d3e5bc60a/acl" } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/key_manager/requests/replace_secret_acl.rb0000644000004100000410000000123213423370527030105 0ustar www-datawww-datamodule Fog module OpenStack class KeyManager class Real def replace_secret_acl(uuid, options) request( :body => Fog::JSON.encode(options), :expects => [200], :method => 'PUT', :path => "secrets/#{uuid}/acl" ) end end class Mock def replace_secret_acl(_uuid, _options) response = Excon::Response.new response.status = 200 response.body = { "acl_ref" => "https://10.0.2.15:9311/v1/secrets/17ca49d9-0804-4ba7-b931-d34cabaa1f04/acl" } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/key_manager/requests/delete_container_acl.rb0000644000004100000410000000076113423370527030437 0ustar www-datawww-datamodule Fog module OpenStack class KeyManager class Real def delete_container_acl(uuid) request( :expects => [200], :method => 'DELETE', :path => "containers/#{uuid}/acl" ) end end class Mock def delete_container_acl(_uuid) response = Excon::Response.new response.status = 200 response.body = "null" response end end end end end fog-openstack-1.0.8/lib/fog/openstack/key_manager/requests/replace_container_acl.rb0000644000004100000410000000124613423370527030607 0ustar www-datawww-datamodule Fog module OpenStack class KeyManager class Real def replace_container_acl(uuid, options) request( :body => Fog::JSON.encode(options), :expects => [200], :method => 'PUT', :path => "containers/#{uuid}/acl" ) end end class Mock def replace_container_acl(_uuid, _options) response = Excon::Response.new response.status = 200 response.body = { "acl_ref" => "https://10.0.2.15:9311/v1/containers/4ab86cb0-a736-48df-ae97-b10d3e5bc60a/acl" } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/key_manager/requests/get_container.rb0000644000004100000410000000046313423370527027134 0ustar www-datawww-datamodule Fog module OpenStack class KeyManager class Real def get_container(uuid) request( :expects => [200], :method => 'GET', :path => "containers/#{uuid}", ) end end class Mock end end end end fog-openstack-1.0.8/lib/fog/openstack/key_manager/requests/delete_secret_acl.rb0000644000004100000410000000075013423370527027740 0ustar www-datawww-datamodule Fog module OpenStack class KeyManager class Real def delete_secret_acl(uuid) request( :expects => [200], :method => 'DELETE', :path => "secrets/#{uuid}/acl" ) end end class Mock def delete_secret_acl(_uuid) response = Excon::Response.new response.status = 200 response.body = "null" response end end end end end fog-openstack-1.0.8/lib/fog/openstack/key_manager/requests/get_container_acl.rb0000644000004100000410000000136613423370527027756 0ustar www-datawww-datamodule Fog module OpenStack class KeyManager class Real def get_container_acl(uuid) request( :expects => [200], :method => 'GET', :path => "containers/#{uuid}/acl" ) end end class Mock def get_container_acl(_uuid) response = Excon::Response.new response.status = 200 response.body = { "read" => { "project-access" => true, "updated" => "2017-04-25T19:10:52", "users" => ["45895d3a393f42b2a8760f5dafa9c6d8"], "created" => "2017-04-25T19:10:52" } } response end end end end end fog-openstack-1.0.8/lib/fog/openstack/key_manager/requests/list_containers.rb0000644000004100000410000000052513423370527027512 0ustar www-datawww-datamodule Fog module OpenStack class KeyManager class Real def list_containers(options = {}) request( :expects => [200], :method => 'GET', :path => 'containers', :query => options ) end end class Mock end end end end fog-openstack-1.0.8/lib/fog/openstack/key_manager/requests/get_secret_payload.rb0000644000004100000410000000060513423370527030146 0ustar www-datawww-datamodule Fog module OpenStack class KeyManager class Real def get_secret_payload(uuid) request( :expects => [200], :method => 'GET', :path => "secrets/#{uuid}/payload", :headers => { 'Accept' => '*/*' } ) end end class Mock end end end end fog-openstack-1.0.8/lib/fog/openstack/key_manager/models/0000755000004100000410000000000013423370527023373 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/key_manager/models/acl.rb0000644000004100000410000000066013423370527024461 0ustar www-datawww-data require 'fog/openstack/models/model' module Fog module OpenStack class KeyManager class ACL < Fog::OpenStack::Model identity :acl_ref attribute :uuid attribute :operation_type attribute :users, type: Array attribute :project_access attribute :secret_type attribute :created attribute :creator_id attribute :updated end end end end fog-openstack-1.0.8/lib/fog/openstack/key_manager/models/containers.rb0000644000004100000410000000112613423370527026065 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/key_manager/models/container' module Fog module OpenStack class KeyManager class Containers < Fog::OpenStack::Collection model Fog::OpenStack::KeyManager::Container def all(options = {}) load_response(service.list_containers(options), 'containers') end def get(secret_ref) if secret = service.get_container(secret_ref).body new(secret) end rescue Fog::OpenStack::Compute::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/key_manager/models/secrets.rb0000644000004100000410000000110413423370527025364 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/key_manager/models/secret' module Fog module OpenStack class KeyManager class Secrets < Fog::OpenStack::Collection model Fog::OpenStack::KeyManager::Secret def all(options = {}) load_response(service.list_secrets(options), 'secrets') end def get(secret_ref) if secret = service.get_secret(secret_ref).body new(secret) end rescue Fog::OpenStack::Compute::NotFound nil end end end end end fog-openstack-1.0.8/lib/fog/openstack/key_manager/models/secret.rb0000644000004100000410000000204213423370527025203 0ustar www-datawww-datarequire 'fog/openstack/models/model' require 'uri' module Fog module OpenStack class KeyManager class Secret < Fog::OpenStack::Model identity :secret_ref # create attribute :uuid attribute :name attribute :expiration attribute :bit_length, type: Integer attribute :algorithm attribute :mode attribute :secret_type attribute :content_types attribute :created attribute :creator_id attribute :status attribute :updated attribute :payload attribute :payload_content_type attribute :payload_content_encoding attribute :metadata def uuid URI(self.secret_ref).path.split('/').last rescue nil end def create merge_attributes(service.create_secret(attributes).body) self end def destroy requires :secret_ref service.delete_secret(uuid) true end end end end end fog-openstack-1.0.8/lib/fog/openstack/key_manager/models/container.rb0000644000004100000410000000145313423370527025705 0ustar www-datawww-datarequire 'fog/openstack/models/model' require 'uri' module Fog module OpenStack class KeyManager class Container < Fog::OpenStack::Model identity :container_ref attribute :uuid attribute :name attribute :type attribute :status attribute :creator_id attribute :secret_refs attribute :consumers attribute :created attribute :updated def uuid URI(self.container_ref).path.split('/').last rescue nil end def create merge_attributes(service.create_container(attributes).body) self end def destroy requires :container_ref service.delete_container(uuid) true end end end end end fog-openstack-1.0.8/lib/fog/openstack/storage.rb0000644000004100000410000001234313423370527021622 0ustar www-datawww-data module Fog module OpenStack class Storage < 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_api_version, :openstack_temp_url_key model_path 'fog/openstack/storage/models' model :directory collection :directories model :file collection :files request_path 'fog/openstack/storage/requests' 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 :post_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 module Utils def require_mime_types # Use mime/types/columnar if available, for reduced memory usage require 'mime/types/columnar' rescue LoadError begin require 'mime/types' rescue LoadError Fog::Logger.warning("'mime-types' missing, please install and try again.") exit(1) end end end class Mock include Utils def self.data @data ||= Hash.new do |hash, key| hash[key] = {} end end def self.reset @data = nil end def initialize(options = {}) require_mime_types @openstack_api_key = options[:openstack_api_key] @openstack_username = options[:openstack_username] @openstack_management_url = options[:openstack_management_url] || 'http://example:8774/v2/AUTH_1234' @openstack_management_uri = URI.parse(@openstack_management_url) @path = @openstack_management_uri.path @path.sub!(%r{/$}, '') 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 Utils include Fog::OpenStack::Core def self.not_found_class Fog::OpenStack::Storage::NotFound end def default_service_type %w[object-store] end def initialize(options = {}) require_mime_types super 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::OpenStack::Storage.new # 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 end end end end fog-openstack-1.0.8/lib/fog/openstack/introspection/0000755000004100000410000000000013423370527022526 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/introspection/requests/0000755000004100000410000000000013423370527024401 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/introspection/requests/create_rules.rb0000644000004100000410000000150513423370527027404 0ustar www-datawww-datamodule Fog module OpenStack class Introspection 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-1.0.8/lib/fog/openstack/introspection/requests/get_rules.rb0000644000004100000410000000076213423370527026724 0ustar www-datawww-datamodule Fog module OpenStack class Introspection 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-1.0.8/lib/fog/openstack/introspection/requests/delete_rules.rb0000644000004100000410000000070113423370527027400 0ustar www-datawww-datamodule Fog module OpenStack class Introspection 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-1.0.8/lib/fog/openstack/introspection/requests/list_rules.rb0000644000004100000410000000072613423370527027120 0ustar www-datawww-datamodule Fog module OpenStack class Introspection 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-1.0.8/lib/fog/openstack/introspection/requests/create_introspection.rb0000644000004100000410000000151013423370527031146 0ustar www-datawww-datamodule Fog module OpenStack class Introspection 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-1.0.8/lib/fog/openstack/introspection/requests/delete_rules_all.rb0000644000004100000410000000065313423370527030236 0ustar www-datawww-datamodule Fog module OpenStack class Introspection 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-1.0.8/lib/fog/openstack/introspection/requests/get_introspection.rb0000644000004100000410000000102413423370527030462 0ustar www-datawww-datamodule Fog module OpenStack class Introspection 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-1.0.8/lib/fog/openstack/introspection/requests/abort_introspection.rb0000644000004100000410000000102413423370527031012 0ustar www-datawww-datamodule Fog module OpenStack class Introspection 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-1.0.8/lib/fog/openstack/introspection/requests/get_introspection_details.rb0000644000004100000410000000104513423370527032172 0ustar www-datawww-datamodule Fog module OpenStack class Introspection 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-1.0.8/lib/fog/openstack/introspection/models/0000755000004100000410000000000013423370527024011 5ustar www-datawww-datafog-openstack-1.0.8/lib/fog/openstack/introspection/models/rules_collection.rb0000644000004100000410000000131213423370527027700 0ustar www-datawww-datarequire 'fog/openstack/models/collection' require 'fog/openstack/introspection/models/rules' module Fog module OpenStack class Introspection class RulesCollection < Fog::OpenStack::Collection model Fog::OpenStack::Introspection::Rules def all(_options = {}) load_response(service.list_rules, 'rules') end def get(uuid) data = service.get_rules(uuid).body new(data) rescue Fog::OpenStack::Introspection::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-1.0.8/lib/fog/openstack/introspection/models/rules.rb0000644000004100000410000000115213423370527025467 0ustar www-datawww-datarequire 'fog/openstack/models/model' module Fog module OpenStack class Introspection 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-1.0.8/CONTRIBUTING.md0000644000004100000410000000156513423370527016556 0ustar www-datawww-data## 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-1.0.8/.ruby-gemset0000644000004100000410000000001613423370527016557 0ustar www-datawww-datafog-openstack fog-openstack-1.0.8/fog-openstack.gemspec0000644000004100000410000000276013423370527020430 0ustar www-datawww-data# 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.required_ruby_version = '>= 2.2.0' spec.add_dependency 'fog-core', '~> 2.1' spec.add_dependency 'fog-json', '>= 1.0' spec.add_dependency 'ipaddress', '>= 0.8' spec.add_development_dependency 'bundler', '~> 1' spec.add_development_dependency 'coveralls' spec.add_development_dependency "mime-types" spec.add_development_dependency "mime-types-data" spec.add_development_dependency 'minitest' spec.add_development_dependency 'pry-byebug' spec.add_development_dependency 'rake', '~> 10.0' spec.add_development_dependency 'rubocop' spec.add_development_dependency 'shindo', '~> 0.3' spec.add_development_dependency 'vcr' spec.add_development_dependency 'webmock', '~> 1.24.6' end fog-openstack-1.0.8/Gemfile0000644000004100000410000000014213423370527015606 0ustar www-datawww-datasource 'https://rubygems.org' # Specify your gem's dependencies in fog-openstack.gemspec gemspec fog-openstack-1.0.8/unit/0000755000004100000410000000000013423370527015275 5ustar www-datawww-datafog-openstack-1.0.8/unit/auth_helper.rb0000644000004100000410000000542313423370527020126 0ustar www-datawww-datadef auth_response_v3(type, name) { 'token' => { 'methods' => ['password'], 'roles' => [{ 'id' => 'id_roles', 'name' => 'admin' }], 'expires_at' => '2017-11-29T07:45:29.908554Z', 'project' => { 'domain' => { 'id' => 'default', 'name' => 'Default' }, 'id' => 'project_id', 'name' => 'admin' }, 'catalog' => [{ 'endpoints' => [ { 'region_id' => 'regionOne', 'url' => 'http://localhost', 'region' => 'regionOne', 'interface' => 'internal', 'id' => 'id_endpoint_internal' }, { 'region_id' => 'regionOne', 'url' => 'http://localhost', 'region' => 'regionOne', 'interface' => 'public', 'id' => 'id_endpoint_public' }, { 'region_id' => 'regionOne', 'url' => 'http://localhost', 'region' => 'regionOne', 'interface' => 'admin', 'id' => 'id_endpoint_admin' } ], 'type' => type, 'id' => 'id_endpoints', 'name' => name }], 'user' => { 'domain' => { 'id' => 'default', 'name' => 'Default' }, 'id' => 'id_user', 'name' => 'admin' }, 'audit_ids' => ['id_audits'], 'issued_at' => '2017-11-29T06:45:29.908578Z' } } end def auth_response_v2(type, name) { 'access' => { 'token' => { 'issued_at' => '2017-12-05T10:44:31.454741Z', 'expires' => '2017-12-05T11:44:31Z', 'id' => '4ae647d3a5294690a3c29bc658e17e26', 'tenant' => { 'description' => 'admin tenant', 'enabled' => true, 'id' => 'tenant_id', 'name' => 'admin' }, 'audit_ids' => ['Ye0Rq1HzTk2ggUAg8nDGbQ'] }, 'serviceCatalog' => [{ 'endpoints' => [{ 'adminURL' => 'http://localhost', 'region' => 'regionOne', 'internalURL' => 'http://localhost', 'id' => 'id_endpoints', 'publicURL' => 'http://localhost' }], 'endpoints_links' => [], 'type' => type, 'name' => name }], 'user' => { 'username' => 'admin', 'roles_links' => [], 'id' => 'user_id', 'roles' => [{ 'name' => 'admin' }], 'name' => 'admin' }, 'metadata' => { 'is_admin' => 0, 'roles' => ['role_id'] } } } end fog-openstack-1.0.8/unit/auth/0000755000004100000410000000000013423370527016236 5ustar www-datawww-datafog-openstack-1.0.8/unit/auth/token_test.rb0000644000004100000410000004515513423370527020754 0ustar www-datawww-datarequire 'test_helper' require 'auth_helper' describe Fog::OpenStack::Auth::Token do describe 'V3' do describe '#new' do it 'fails when missing credentials' do stub_request(:post, 'http://localhost/identity/v3/auth/tokens'). to_return( :status => 200, :body => "{\"token\":{\"catalog\":[]}}", :headers => {'x-subject-token'=>'token_data'} ) proc do Fog::OpenStack::Auth::Token.build({}, {}) end.must_raise Fog::OpenStack::Auth::Token::URLError end describe 'using the password method' do describe 'with a project scope' do it 'authenticates using a project id' do auth = { :openstack_auth_url => 'http://localhost/identity', :openstack_userid => 'user_id', :openstack_api_key => 'secret', :openstack_project_id => 'project_id' } stub_request(:post, 'http://localhost/identity/v3/auth/tokens'). with(:body => "{\"auth\":{\"identity\":{\"methods\":[\"password\"],\"password\":{\"user\":\ {\"id\":\"user_id\",\"password\":\"secret\"}}},\"scope\":{\"project\":{\"id\":\"project_id\"}}}}"). to_return( :status => 200, :body => JSON.dump(auth_response_v3('identity', 'keystone')), :headers => {'x-subject-token'=>'token_data_v3'} ) token = Fog::OpenStack::Auth::Token.build(auth, {}) token.get.must_equal 'token_data_v3' end it 'authenticates using a project name and a project domain id' do auth = { :openstack_auth_url => 'http://localhost/identity', :openstack_userid => 'user_id', :openstack_api_key => 'secret', :openstack_project_name => 'project', :openstack_project_domain_id => 'project_domain_id' } stub_request(:post, 'http://localhost/identity/v3/auth/tokens'). with(:body => "{\"auth\":{\"identity\":{\"methods\":[\"password\"],\"password\":{\"user\":{\"id\":\ \"user_id\",\"password\":\"secret\"}}},\"scope\":{\"project\":{\"name\":\"project\",\"domain\":{\"id\":\ \"project_domain_id\"}}}}}"). to_return( :status => 200, :body => JSON.dump(auth_response_v3('identity', 'keystone')), :headers => {'x-subject-token'=>'token_data'} ) token = Fog::OpenStack::Auth::Token.build(auth, {}) token.get.must_equal 'token_data' end it 'authenticates using a project name and a project domain name' do auth = { :openstack_auth_url => 'http://localhost/identity', :openstack_username => 'user', :openstack_user_domain_name => 'user_domain', :openstack_api_key => 'secret', :openstack_project_name => 'project', :openstack_project_domain_name => 'project_domain' } stub_request(:post, "http://localhost/identity/v3/auth/tokens"). with(:body => "{\"auth\":{\"identity\":{\"methods\":[\"password\"],\"password\":{\"user\":{\"name\":\ \"user\",\"domain\":{\"name\":\"user_domain\"},\"password\":\"secret\"}}},\"scope\":{\"project\":{\"name\":\"project\"\ ,\"domain\":{\"name\":\"project_domain\"}}}}}"). to_return( :status => 200, :body => JSON.dump(auth_response_v3('identity', 'keystone')), :headers => {'x-subject-token'=>'token_data'} ) token = Fog::OpenStack::Auth::Token.build(auth, {}) token.get.must_equal 'token_data' end end describe 'with a domain scope' do it 'authenticates using a domain id' do auth = { :openstack_auth_url => 'http://localhost/identity', :openstack_userid => 'user_id', :openstack_api_key => 'secret', :openstack_domain_id => 'domain_id' } stub_request(:post, 'http://localhost/identity/v3/auth/tokens'). with(:body => "{\"auth\":{\"identity\":{\"methods\":[\"password\"],\"password\":{\"user\":{\"id\":\ \"user_id\",\"password\":\"secret\"}}},\"scope\":{\"domain\":{\"id\":\"domain_id\"}}}}"). to_return( :status => 200, :body => JSON.dump(auth_response_v3('identity', 'keystone')), :headers => {'x-subject-token'=>'token_data'} ) token = Fog::OpenStack::Auth::Token.build(auth, {}) token.get.must_equal 'token_data' end it 'authenticates using a domain name' do auth = { :openstack_auth_url => 'http://localhost/identity', :openstack_userid => 'user_id', :openstack_api_key => 'secret', :openstack_domain_name => 'domain' } stub_request(:post, 'http://localhost/identity/v3/auth/tokens'). with(:body => "{\"auth\":{\"identity\":{\"methods\":[\"password\"],\"password\":{\"user\":{\"id\":\ \"user_id\",\"password\":\"secret\"}}},\"scope\":{\"domain\":{\"name\":\"domain\"}}}}"). to_return( :status => 200, :body => JSON.dump(auth_response_v3('identity', 'keystone')), :headers => {'x-subject-token'=>'token_data'} ) token = Fog::OpenStack::Auth::Token.build(auth, {}) token.get.must_equal 'token_data' end end describe 'unscoped' do it 'authenticates' do auth = { :openstack_auth_url => 'http://localhost/identity', :openstack_userid => 'user_id', :openstack_api_key => 'secret', } stub_request(:post, 'http://localhost/identity/v3/auth/tokens'). with(:body => "{\"auth\":{\"identity\":{\"methods\":[\"password\"],\"password\":{\"user\":{\"id\":\ \"user_id\",\"password\":\"secret\"}}}}}"). to_return( :status => 200, :body => JSON.dump(auth_response_v3('identity', 'keystone')), :headers => {'x-subject-token'=>'token_data'} ) token = Fog::OpenStack::Auth::Token.build(auth, {}) token.get.must_equal 'token_data' end end end describe 'using the token method' do describe 'unscoped' do it 'authenticates using a project id' do auth = { :openstack_auth_url => 'http://localhost/identity', :openstack_auth_token => 'token', } stub_request(:post, 'http://localhost/identity/v3/auth/tokens'). with(:body => "{\"auth\":{\"identity\":{\"methods\":[\"token\"],\"token\":{\"id\":\"token\"}}}}"). to_return( :status => 200, :body => JSON.dump(auth_response_v3('identity', 'keystone')), :headers => {'x-subject-token'=>'token_data'} ) token = Fog::OpenStack::Auth::Token.build(auth, {}) token.get.must_equal 'token_data' end end describe 'with a project scope' do it 'authenticates using a project id' do auth = { :openstack_auth_url => 'http://localhost/identity', :openstack_auth_token => 'token', :openstack_project_id => 'project_id' } stub_request(:post, 'http://localhost/identity/v3/auth/tokens'). with(:body => "{\"auth\":{\"identity\":{\"methods\":[\"token\"],\"token\":{\"id\":\"token\"}},\ \"scope\":{\"project\":{\"id\":\"project_id\"}}}}"). to_return( :status => 200, :body => JSON.dump(auth_response_v3('identity', 'keystone')), :headers => {'x-subject-token'=>'token_data'} ) token = Fog::OpenStack::Auth::Token.build(auth, {}) token.get.must_equal 'token_data' end it 'authenticates using a project name and a project domain id' do auth = { :openstack_auth_url => 'http://localhost/identity', :openstack_auth_token => 'token', :openstack_project_name => 'project', :openstack_project_domain_id => 'domain_id' } stub_request(:post, 'http://localhost/identity/v3/auth/tokens'). with(:body => "{\"auth\":{\"identity\":{\"methods\":[\"token\"],\"token\":{\"id\":\"token\"}},\ \"scope\":{\"project\":{\"name\":\"project\",\"domain\":{\"id\":\"domain_id\"}}}}}"). to_return( :status => 200, :body => JSON.dump(auth_response_v3('identity', 'keystone')), :headers => {'x-subject-token'=>'token_data'} ) token = Fog::OpenStack::Auth::Token.build(auth, {}) token.get.must_equal 'token_data' end end describe 'with a domain scope' do it 'authenticates using a domain id' do auth = { :openstack_auth_url => 'http://localhost/identity', :openstack_auth_token => 'token', :openstack_domain_id => 'domain_id' } stub_request(:post, 'http://localhost/identity/v3/auth/tokens'). with(:body => "{\"auth\":{\"identity\":{\"methods\":[\"token\"],\"token\":{\"id\":\"token\"}},\ \"scope\":{\"domain\":{\"id\":\"domain_id\"}}}}"). to_return( :status => 200, :body => JSON.dump(auth_response_v3('identity', 'keystone')), :headers => {'x-subject-token'=>'token_data'} ) token = Fog::OpenStack::Auth::Token.build(auth, {}) token.get.must_equal 'token_data' end it 'authenticates using a domain name' do auth = { :openstack_auth_url => 'http://localhost/identity', :openstack_auth_token => 'token', :openstack_domain_name => 'domain' } stub_request(:post, 'http://localhost/identity/v3/auth/tokens'). with(:body => "{\"auth\":{\"identity\":{\"methods\":[\"token\"],\"token\":{\"id\":\"token\"}},\ \"scope\":{\"domain\":{\"name\":\"domain\"}}}}"). to_return( :status => 200, :body => JSON.dump(auth_response_v3('identity', 'keystone')), :headers => {'x-subject-token'=>'token_data'} ) token = Fog::OpenStack::Auth::Token.build(auth, {}) token.get.must_equal 'token_data' end end end end describe 'when authenticated' do let(:authv3_creds) do { :openstack_auth_url => 'http://localhost/identity', :openstack_username => 'admin', :openstack_api_key => 'secret', :openstack_project_name => 'admin', :openstack_project_domain_id => 'default' } end describe '#get' do it 'when token has not expired' do stub_request(:post, 'http://localhost/identity/v3/auth/tokens'). to_return( :status => 200, :body => "{\"token\":{\"catalog\":[\"catalog_data\"]}}", :headers => {'x-subject-token'=>'token_data'} ) token = Fog::OpenStack::Auth::Token.build(authv3_creds, {}) token.stub :expired?, false do token.get.must_equal 'token_data' end end it 'when token has expired' do stub_request(:post, 'http://localhost/identity/v3/auth/tokens'). to_return( :status => 200, :body => "{\"token\":{\"catalog\":[\"catalog_data\"]}}", :headers => {'x-subject-token'=>'token_data'} ) token = Fog::OpenStack::Auth::Token.build(authv3_creds, {}) token.stub :expired?, true do token.get.must_equal 'token_data' end end end it '#catalog' do stub_request(:post, 'http://localhost/identity/v3/auth/tokens'). to_return( :status => 200, :body => "{\"token\":{\"catalog\":[\"catalog_data\"]}}", :headers => {'x-subject-token'=>'token_data'} ) token = Fog::OpenStack::Auth::Token.build(authv3_creds, {}) token.catalog.payload.must_equal ['catalog_data'] end it '#get_endpoint_url' do stub_request(:post, 'http://localhost/identity/v3/auth/tokens'). to_return( :status => 200, :body => JSON.dump(auth_response_v3("identity", "keystone")), :headers => {'x-subject-token'=>'token_data'} ) token = Fog::OpenStack::Auth::Token.build(authv3_creds, {}) token.catalog.get_endpoint_url(%w[identity], 'public', 'regionOne').must_equal 'http://localhost' end end end describe 'V2' do describe '#new' do it 'fails when missing credentials' do stub_request(:post, 'http://localhost/identity/v2.0/tokens'). to_return(:status => 200, :body => "{\"access\":{\"token\":{\"id\":\"token_data\"}}}", :headers => {}) proc do Fog::OpenStack::Auth::Token.build({}, {}) end.must_raise Fog::OpenStack::Auth::Token::URLError end describe 'using the password method' do it 'authenticates using the tenant name' do auth = { :openstack_auth_url => 'http://localhost/identity', :openstack_username => 'user', :openstack_api_key => 'secret', :openstack_tenant => 'tenant', } stub_request(:post, 'http://localhost/identity/v2.0/tokens'). with(:body => "{\"auth\":{\"passwordCredentials\":{\"username\":\"user\",\"password\":\"secret\"},\ \"tenantName\":\"tenant\"}}"). to_return(:status => 200, :body => JSON.dump(auth_response_v2('identity', 'keystone')), :headers => {}) token = Fog::OpenStack::Auth::Token.build(auth, {}) token.get.must_equal '4ae647d3a5294690a3c29bc658e17e26' end it 'authenticates using the tenant id' do auth = { :openstack_auth_url => 'http://localhost/identity', :openstack_username => 'user', :openstack_api_key => 'secret', :openstack_tenant_id => 'tenant_id', } stub_request(:post, 'http://localhost/identity/v2.0/tokens'). with(:body => "{\"auth\":{\"passwordCredentials\":{\"username\":\"user\",\"password\":\"secret\"},\ \"tenantId\":\"tenant_id\"}}"). to_return(:status => 200, :body => JSON.dump(auth_response_v2('identity', 'keystone')), :headers => {}) token = Fog::OpenStack::Auth::Token.build(auth, {}) token.get.must_equal '4ae647d3a5294690a3c29bc658e17e26' end end describe 'using the token method' do it 'authenticates using the tenant name' do auth = { :openstack_auth_url => 'http://localhost/identity', :openstack_auth_token => 'token_id', :openstack_tenant => 'tenant', } stub_request(:post, 'http://localhost/identity/v2.0/tokens'). with(:body => "{\"auth\":{\"token\":{\"id\":\"token_id\"},\"tenantName\":\"tenant\"}}"). to_return(:status => 200, :body => JSON.dump(auth_response_v2('identity', 'keystone')), :headers => {}) token = Fog::OpenStack::Auth::Token.build(auth, {}) token.get.must_equal '4ae647d3a5294690a3c29bc658e17e26' end it 'authenticates using the tenant id' do auth = { :openstack_auth_url => 'http://localhost/identity', :openstack_auth_token => 'token_id', :openstack_tenant_id => 'tenant_id', } stub_request(:post, 'http://localhost/identity/v2.0/tokens'). with(:body => "{\"auth\":{\"token\":{\"id\":\"token_id\"},\"tenantId\":\"tenant_id\"}}"). to_return(:status => 200, :body => JSON.dump(auth_response_v2('identity', 'keystone')), :headers => {}) Fog::OpenStack::Auth::Token.build(auth, {}) end end end describe 'when authenticated' do let(:authv2_creds) do { :openstack_auth_url => 'http://localhost/identity', :openstack_username => 'admin', :openstack_api_key => 'secret', :openstack_tenant => 'admin' } end describe '#get' do it 'when token has not expired' do stub_request(:post, 'http://localhost/identity/v2.0/tokens'). to_return( :status => 200, :body => "{\"access\":{\"token\":{\"id\":\"token_not_expired\"},\"serviceCatalog\":\ [\"catalog_data\"]}}", :headers => {} ) token = Fog::OpenStack::Auth::Token.build(authv2_creds, {}) token.stub :expired?, false do token.get.must_equal 'token_not_expired' end end it 'when token has expired' do stub_request(:post, 'http://localhost/identity/v2.0/tokens'). to_return( :status => 200, :body => "{\"access\":{\"token\":{\"id\":\"token_expired\"},\"serviceCatalog\":[\"catalog_data\"]}}", :headers => {} ) token = Fog::OpenStack::Auth::Token.build(authv2_creds, {}) token.stub :expired?, true do token.get.must_equal 'token_expired' end end end it '#catalog' do stub_request(:post, 'http://localhost/identity/v2.0/tokens'). to_return( :status => 200, :body => "{\"access\":{\"token\":{\"id\":\"token_data\"},\"serviceCatalog\":[\"catalog_data\"]}}", :headers => {} ) token = Fog::OpenStack::Auth::Token.build(authv2_creds, {}) token.catalog.payload.must_equal ['catalog_data'] end it '#get_endpoint_url' do stub_request(:post, 'http://localhost/identity/v2.0/tokens'). to_return( :status => 200, :body => JSON.dump(auth_response_v2('identity', 'keystone')), :headers => {'x-subject-token'=>'token_data'} ) token = Fog::OpenStack::Auth::Token.build(authv2_creds, {}) token.catalog.get_endpoint_url(%w[identity], 'public', 'regionOne').must_equal 'http://localhost' end end end end fog-openstack-1.0.8/unit/auth/name_test.rb0000644000004100000410000000761613423370527020554 0ustar www-datawww-datarequire 'test_helper' require 'fog/openstack/auth/name' describe Fog::OpenStack::Auth::Name do describe 'creates' do it 'when id and name are provided' do name = Fog::OpenStack::Auth::Name.new('default', 'Default') name.id.must_equal 'default' name.name.must_equal 'Default' end it 'when id is null' do name = Fog::OpenStack::Auth::Name.new(nil, 'Default') name.id.must_be_nil name.name.must_equal 'Default' end it 'when name is null' do name = Fog::OpenStack::Auth::Name.new('default', nil) name.id.must_equal 'default' name.name.must_be_nil end it 'when both id and name is null' do name = Fog::OpenStack::Auth::Name.new(nil, nil) name.name.must_be_nil end end describe '#to_h' do it 'returns the hash of provided attribute' do name = Fog::OpenStack::Auth::Name.new('default', 'Default') name.to_h(:id).must_equal(:id => 'default') name.to_h(:name).must_equal(:name => 'Default') end end end describe Fog::OpenStack::Auth::User do describe '#password' do it 'set/get password' do user = Fog::OpenStack::Auth::User.new('user_id', 'User') user.password = 'secret' user.identity.must_equal(:user => {:id => 'user_id', :password => 'secret'}) end end describe '#identity' do describe 'succesful' do it "with user id and user name" do user = Fog::OpenStack::Auth::User.new('user_id', 'User') user.password = 'secret' user.identity.must_equal(:user => {:id => 'user_id', :password => 'secret'}) end it 'with user name and user domain name' do user = Fog::OpenStack::Auth::User.new(nil, 'User') user.password = 'secret' user.domain = Fog::OpenStack::Auth::Name.new('default', nil) user.identity.must_equal(:user => {:name => 'User', :domain => {:id => 'default'}, :password => 'secret'}) end it 'with user name and domain name' do user = Fog::OpenStack::Auth::User.new(nil, 'User') user.password = 'secret' user.domain = Fog::OpenStack::Auth::Name.new(nil, 'Default') user.identity.must_equal(:user => {:name => 'User', :domain => {:name => 'Default'}, :password => 'secret'}) end end describe 'raises an error' do it 'raises an error when password is missing' do proc do user = Fog::OpenStack::Auth::User.new('user_id', 'User') user.identity end.must_raise Fog::OpenStack::Auth::CredentialsError end it 'with only user name and no domain' do proc do user = Fog::OpenStack::Auth::User.new(nil, 'User') user.identity end.must_raise Fog::OpenStack::Auth::CredentialsError end end end end describe Fog::OpenStack::Auth::ProjectScope do describe '#identity' do it "when id is provided it doesn't require domain" do project = Fog::OpenStack::Auth::ProjectScope.new('project_id', 'Project') project.identity.must_equal(:project => {:id => 'project_id'}) end it 'when id is nul and name is provided it uses domain id' do project = Fog::OpenStack::Auth::ProjectScope.new(nil, 'Project') project.domain = Fog::OpenStack::Auth::Name.new('default', nil) project.identity.must_equal(:project => {:name => 'Project', :domain => {:id => 'default'}}) end it 'when id is nul and name is provided it uses domain name' do project = Fog::OpenStack::Auth::ProjectScope.new(nil, 'Project') project.domain = Fog::OpenStack::Auth::Name.new(nil, 'Default') project.identity.must_equal(:project => {:name => 'Project', :domain => {:name => 'Default'}}) end it 'raises an error with no project id and no domain are provided' do proc do project = Fog::OpenStack::Auth::ProjectScope.new(nil, 'Project') project.identity end.must_raise Fog::OpenStack::Auth::CredentialsError end end end fog-openstack-1.0.8/unit/auth/catalog_test.rb0000644000004100000410000001744513423370527021247 0ustar www-datawww-datarequire 'test_helper' describe Fog::OpenStack::Auth::Catalog::V3 do CATALOGV3 = [ { "endpoints" => [ { "region_id" => "regionOne", "url" => "http://localhost:9696", "region" => "regionOne", "interface" => "internal", "id" => "id_endpoint1_internal" }, { "region_id" => "regionOne", "url" => "http://localhost:9696", "region" => "regionOne", "interface" => "public", "id" => "id_endpoint1_public" }, { "region_id" => "regionOne", "url" => "http://localhost:9696", "region" => "regionOne", "interface" => "admin", "id" => "id_endpoint1_admin" } ], "type" => "network", "id" => "id1", "name" => "neutron" }, { "endpoints" => [ { "region_id" => "regionOne", "url" => "http://localhost:9292", "region" => "regionOne", "interface" => "internal", "id" => "id_endpoint1_internal" }, { "region_id" => "regionOne", "url" => "http://localhost:9292", "region" => "regionOne", "interface" => "public", "id" => "id_endpoint1_public" }, { "region_id" => "regionOne", "url" => "http://localhost:9292", "region" => "regionOne", "interface" => "admin", "id" => "id_endpoint1_admin" } ], "type" => "image", "id" => "id2", "name" => "glance" }, { "endpoints" => [ { "region_id" => "regionOne", "url" => "http://localhost:5000", "region" => "regionOne", "interface" => "internal", "id" => "id_endpoint1_internal" }, { "region_id" => "regionOne", "url" => "http://localhost:5000", "region" => "regionOne", "interface" => "public", "id" => "id_endpoint1_public" }, { "region_id" => "regionOne", "url" => "http://localhost:35357", "region" => "regionOne", "interface" => "admin", "id" => "id_endpoint1_admin" } ], "type" => "identity", "id" => "id3", "name" => "keystone" }, { "endpoints" => [ { "region_id" => "regionOne", "url" => "http://localhost2:5000", "region" => "regionTwo", "interface" => "internal", "id" => "id_endpoint1_internal" }, { "region_id" => "regionTwo", "url" => "http://localhost2:5000", "region" => "regionTwo", "interface" => "public", "id" => "id_endpoint1_public" }, { "region_id" => "regionTwo", "url" => "http://localhost2:35357", "region" => "regionTwo", "interface" => "admin", "id" => "id_endpoint1_admin" } ], "type" => "identity", "id" => "id3", "name" => "keystone" } ].freeze let(:payload) do CATALOGV3 end describe '#get_endpoint_url' do it 'with matching name, interface and region' do catalog = Fog::OpenStack::Auth::Catalog::V3.new(payload) catalog.get_endpoint_url('identity', 'admin', 'regionTwo').must_equal 'http://localhost2:35357' end it 'with matching name and interface using avail region' do catalog = Fog::OpenStack::Auth::Catalog::V3.new(payload) catalog.get_endpoint_url('network', %w[dummy admin]).must_equal 'http://localhost:9696' end it 'with matching name and interface list' do catalog = Fog::OpenStack::Auth::Catalog::V3.new(payload) catalog.get_endpoint_url('network', %w[dummy admin]).must_equal 'http://localhost:9696' end it 'with matching name and interface and several regions available' do catalog = Fog::OpenStack::Auth::Catalog::V3.new(payload) proc do catalog.get_endpoint_url('identity', 'admin') end.must_raise Fog::OpenStack::Auth::Catalog::EndpointError end it 'with unmatched name for service type' do catalog = Fog::OpenStack::Auth::Catalog::V3.new(payload) proc do catalog.get_endpoint_url('service', 'public') end.must_raise Fog::OpenStack::Auth::Catalog::ServiceTypeError end it 'with unmatched region' do catalog = Fog::OpenStack::Auth::Catalog::V3.new(payload) proc do catalog.get_endpoint_url('identity', 'admin', 'regionOther') end.must_raise Fog::OpenStack::Auth::Catalog::EndpointError end it 'with unmatched interface' do catalog = Fog::OpenStack::Auth::Catalog::V3.new(payload) proc do catalog.get_endpoint_url('identity', 'private') end.must_raise Fog::OpenStack::Auth::Catalog::EndpointError end end end describe Fog::OpenStack::Auth::Catalog::V2 do CATALOGV2 = [ { 'endpoints' => [{ 'adminURL' => 'http://localhost', 'region' => 'regionOne', 'internalURL' => 'http://localhost:8888/v2.0', 'id' => 'id_endpoints', 'publicURL' => 'http://localhost' }], 'endpoints_links' => [], 'type' => 'identity', 'name' => 'keystone' }, { 'endpoints' => [{ 'adminURL' => 'http://localhost', 'region' => 'regionTwo', 'internalURL' => 'http://localhost:9999/v2.0', 'id' => 'id_endpoints', 'publicURL' => 'http://localhost' }], 'endpoints_links' => [], 'type' => 'identity', 'name' => 'keystone' }, { 'endpoints' => [{ 'adminURL' => 'http://localhost', 'region' => 'regionOne', 'internalURL' => 'http://localhost:7777/v1.0', 'id' => 'id_endpoints', 'publicURL' => 'http://localhost' }], 'endpoints_links' => [], 'type' => 'compute', 'name' => 'nova' } ].freeze let(:payload) do CATALOGV2 end describe '#get_endpoint_url' do it 'match name, interface and region' do catalog = Fog::OpenStack::Auth::Catalog::V2.new(payload) catalog.get_endpoint_url('identity', 'internal', 'regionTwo').must_equal 'http://localhost:9999/v2.0' end it 'match name, interface and unique region available' do catalog = Fog::OpenStack::Auth::Catalog::V2.new(payload) catalog.get_endpoint_url('compute', 'internal').must_equal 'http://localhost:7777/v1.0' end it 'fails when multiple region match' do catalog = Fog::OpenStack::Auth::Catalog::V2.new(payload) proc do catalog.get_endpoint_url('identity', 'admin') end.must_raise Fog::OpenStack::Auth::Catalog::EndpointError end it 'with unmatched arguments' do catalog = Fog::OpenStack::Auth::Catalog::V2.new(payload) proc do catalog.get_endpoint_url('test', 'unknown', 'regionOther') end.must_raise Fog::OpenStack::Auth::Catalog::ServiceTypeError end it 'with unmatched region' do catalog = Fog::OpenStack::Auth::Catalog::V2.new(payload) proc do catalog.get_endpoint_url('identity', 'admin', 'regionOther') end.must_raise Fog::OpenStack::Auth::Catalog::EndpointError end it 'with unmatched interface' do catalog = Fog::OpenStack::Auth::Catalog::V2.new(payload) proc do catalog.get_endpoint_url('identity', 'private', 'regionTwo') end.must_raise Fog::OpenStack::Auth::Catalog::EndpointError end end end fog-openstack-1.0.8/unit/test_helper.rb0000644000004100000410000000020013423370527020130 0ustar www-datawww-datarequire 'minitest/autorun' require 'webmock/minitest' require 'fog/core' require 'fog/json' require 'fog/openstack/auth/token' fog-openstack-1.0.8/.zuul.yaml0000644000004100000410000000132213423370527016255 0ustar www-datawww-data- project: check: jobs: - fog-openstack-unittest-test - fog-openstack-unittest-spec - job: name: fog-openstack-unittest-test parent: init-test description: | fog-openstack unittest test tests run: playbooks/fog-openstack-unittest-test/run.yaml vars: rvm: 2.3.8 2.4.5 2.5.3 2.6.0 jruby-head nodeset: ubuntu-xenial - job: name: fog-openstack-unittest-spec parent: init-test description: | fog-openstack unittest spec tests run: playbooks/fog-openstack-unittest-spec/run.yaml vars: rvm: 2.3.8 2.4.5 2.5.3 2.6.0 jruby-head nodeset: ubuntu-xenial fog-openstack-1.0.8/supported.md0000644000004100000410000000466313423370527016676 0ustar www-datawww-data# Supported OpenStack Projects ## Supported | Project | Fog Type | API Version(s) | Compliance | Notes | |------------------|--------------------|----------------|------------|-------| | Barbican | Key Manager | v1 | TBD | | | Ceilometer | Metering | v2 | TBD | | | Cinder | Volume | v1, v2 | TBD | | | Designate | DNS | v1, v2 | TBD | | | Glance | Image | v1, v2 | TBD | | | Gnocci | Metric | v1 | TBD | | | Heat | Orchestration | v1 | TBD | | | Ironic | Bare Metal | v1 | TBD | | | Ironic Inspector | Introspection | v1 | TBD | | | Keystone | Identity | v2, v3 | TBD | | | Magnum | Container Infra | v1 | TBD | | | Manila | Shared File System | v2.0 | TBD | | | Mistral | Workflow | v2.0 | TBD | | | Monasca | Monitoring | v2.0 | TBD | | | Neutron | Network | v2 | TBD | | | Nova | Compute | v2.0 | TBD | | | Panko | Event | v2 | TBD | | | Swift | Storage | v2 | TBD | | | Tacker | NFV | v1 | TBD | | | Tuskar | TripleO Planning | v1 | TBD | | ## Wish List Feel free to submit pull requests to add support for these. * [congress](https://wiki.openstack.org/wiki/Congress) (Policy As a Service) * [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) * horizon (Web Frontend) * kolla (Containers) * kuryr (Containers) * murano (Catalog Service) * rally (Benchmarking) * sahara (Map-Reduce) * searchlight (Searching) * senlin (Clustering) * solum (Lifecycle) * tripleo (Orchestration) * zaqar (Messaging)