Git Product home page Git Product logo

fog-brightbox's Introduction

fog

fog is the Ruby cloud services library, top to bottom:

  • Collections provide a simplified interface, making clouds easier to work with and switch between.
  • Requests allow power users to get the most out of the features of each individual cloud.
  • Mocks make testing and integrating a breeze.

Build Status Code Climate Gem Version SemVer

Dependency Notice

Currently all fog providers are getting separated into metagems to lower the load time and dependency count.

If there's a metagem available for your cloud provider, e.g. fog-aws, you should be using it instead of requiring the full fog collection to avoid unnecessary dependencies.

'fog' should be required explicitly only if the provider you use doesn't yet have a metagem available.

Getting Started

The easiest way to learn fog is to install the gem and use the interactive console. Here is an example of wading through server creation for Amazon Elastic Compute Cloud:

$ sudo gem install fog
[...]

$ fog

  Welcome to fog interactive!
  :default provides [...]

>> server = Compute[:aws].servers.create
ArgumentError: image_id is required for this operation

>> server = Compute[:aws].servers.create(:image_id => 'ami-5ee70037')
<Fog::AWS::EC2::Server [...]>

>> server.destroy # cleanup after yourself or regret it, trust me
true

Ruby version

Fog requires Ruby 2.0.0 or later.

Ruby 1.8 and 1.9 support was dropped in fog-v2.0.0 as a backwards incompatible change. Please use the later fog 1.x versions if you require 1.8.7 or 1.9.x support.

Collections

A high level interface to each cloud is provided through collections, such as images and servers. You can see a list of available collections by calling collections on the connection object. You can try it out using the fog command:

>> Compute[:aws].collections
[:addresses, :directories, ..., :volumes, :zones]

Some collections are available across multiple providers:

  • compute providers have flavors, images and servers
  • dns providers have zones and records
  • storage providers have directories and files

Collections share basic CRUD type operations, such as:

  • all - fetch every object of that type from the provider.
  • create - initialize a new record locally and a remote resource with the provider.
  • get - fetch a single object by its identity from the provider.
  • new - initialize a new record locally, but do not create a remote resource with the provider.

As an example, we'll try initializing and persisting a Rackspace Cloud server:

require 'fog'

compute = Fog::Compute.new(
  :provider           => 'Rackspace',
  :rackspace_api_key  => key,
  :rackspace_username => username
)

# boot a gentoo server (flavor 1 = 256, image 3 = gentoo 2008.0)
server = compute.servers.create(:flavor_id => 1, :image_id => 3, :name => 'my_server')
server.wait_for { ready? } # give server time to boot

# DO STUFF

server.destroy # cleanup after yourself or regret it, trust me

Models

Many of the collection methods return individual objects, which also provide common methods:

  • destroy - will destroy the persisted object from the provider
  • save - persist the object to the provider
  • wait_for - takes a block and waits for either the block to return true for the object or for a timeout (defaults to 10 minutes)

Mocks

As you might imagine, testing code using Fog can be slow and expensive, constantly turning on and shutting down instances. Mocking allows skipping this overhead by providing an in memory representation of resources as you make requests. Enabling mocking is easy to use: before you run other commands, simply run:

Fog.mock!

Then proceed as usual, if you run into unimplemented mocks, fog will raise an error and as always contributions are welcome!

Requests

Requests allow you to dive deeper when the models just can't cut it. You can see a list of available requests by calling #requests on the connection object.

For instance, ec2 provides methods related to reserved instances that don't have any models (yet). Here is how you can lookup your reserved instances:

$ fog
>> Compute[:aws].describe_reserved_instances
#<Excon::Response [...]>

It will return an excon response, which has body, headers and status. Both return nice hashes.

Go forth and conquer

Play around and use the console to explore or check out fog.io and the provider documentation for more details and examples. Once you are ready to start scripting fog, here is a quick hint on how to make connections without the command line thing to help you.

# create a compute connection
compute = Fog::Compute.new(:provider => 'AWS', :aws_access_key_id => ACCESS_KEY_ID, :aws_secret_access_key => SECRET_ACCESS_KEY)
# compute operations go here

# create a storage connection
storage = Fog::Storage.new(:provider => 'AWS', :aws_access_key_id => ACCESS_KEY_ID, :aws_secret_access_key => SECRET_ACCESS_KEY)
# storage operations go here

geemus says: "That should give you everything you need to get started, but let me know if there is anything I can do to help!"

Versioning

Fog library aims to adhere to Semantic Versioning 2.0.0, although it does not address challenges of multi-provider libraries. Semantic versioning is only guaranteed for the common API, not any provider-specific extensions. You may also need to update your configuration from time to time (even between Fog releases) as providers update or deprecate services.

However, we still aim for forwards compatibility within Fog major versions. As a result of this policy, you can (and should) specify a dependency on this gem using the Pessimistic Version Constraint with two digits of precision. For example:

spec.add_dependency 'fog', '~> 1.0'

This means your project is compatible with Fog 1.0 up until 2.0. You can also set a higher minimum version:

spec.add_dependency 'fog', '~> 1.16'

Getting Help

Contributing

Please refer to CONTRIBUTING.md.

License

Please refer to LICENSE.md.

fog-brightbox's People

Contributors

amatsuda avatar gnufied avatar plribeiro3000 avatar tokengeek avatar voxik avatar weppos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

fog-brightbox's Issues

Could you please add mocks for tests?

When I try to mock fog brightbox in rspec tests with

Fog.mock!

fog_credentials = {
  provider: "Brightbox",
  brightbox_client_id: 'xxx',
  brightbox_secret: 'yyy'
}

CarrierWave.configure do |config|
  config.fog_credentials = fog_credentials
end

connection = ::Fog::Storage.new(fog_credentials)
connection.directories.create(key: ENV['UPLOADS_DIRECTORY'])

and then start to run tests I get

~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/fog-core-1.45.0/lib/fog/core/mock.rb:32:in `not_implemented': Contributions welcome! (Fog::Errors::MockNotImplemented)
	from ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/fog-core-1.45.0/lib/fog/core/service.rb:306:in `put_container'
	from ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/fog-brightbox-0.14.0/lib/fog/brightbox/models/storage/directory.rb:44:in `save'
...

So I have to stub my tests with AWS provider which is not correct

Could you add mocks for storage please? Thank you!

cloud_ip.inspect fails

Calling 'cloud_ip.inspect' fails because formatador is checking for, and calling, the map method:

.bundle/gems/ruby/1.9.1/gems/fog-brightbox-0.7.1/lib/fog/brightbox/models/compute/cloud_ip.rb:32:in `map': wrong number of arguments (0 for 1) (ArgumentError)
.bundle/gems/ruby/1.9.1/gems/fog-core-1.29.0/lib/fog/formatador.rb:87:in `inspect_object'

But in this case, the map method is overridden and actually modifies the cloud_ip. Fortunately, it fails and nothing is modified.

Not sure what the correct thing to do here is? Perhaps rename to map_to or map! and deprecate map? PR for formatador to check the arity? Or override the inspect method in CloudIp?

In general it would help if the methods which actually made changes ended in ! Not sure if this breaks the normal naming convention of fog, but this would make it clear when you were doing a safe 'read' type operation (with no exclamation mark), or more dangerous mutation operations which need more care.

updates & access

Hey, I'm trying to roll through and update fog-core versions to 2.0+, but I just realized I don't have access to push this gem. Could you give me access? Also, if you have time to help update to new fog-core and test that would be most helpful, thanks!

Deprecate `#map` from `CloudIP` to avoid clash with `Enumerable`

Due to fog/fog-core#138 there was an error where CloudIP
addresses could not be inspected.

This appeared here as #17

To avoid potential issues in future we should deprecate #map

Short term; we may want to use something like map! to make it immediately
obvious it is not map and that it commits a change immediately.

Medium term; to keep in-line with Fog's CRUD approach (similar to Rails) we
should probably use #target= followed by #save. This means save needs
to be fully implemented and watch for changes to the target.

However longer term we should help define and implement a Fog standard
for IP Addresses that can be moved between resources.

Fog::AWS::Address for instance is their Elastic IP model but it uses #server=
which is semantically wrong when our CloudIPs can use groups and load balancers
as destinations as well.

I don't think this is high priority since the problem was Fog::Formatador being used
outside it's original context (inspecting anything not just collections and assuming
map == Enumerable#map

Use proper namespace

fog-brightbox is not compatible with recent fog-core and the test suite fails:

  Fog::Compute[:brightbox] (brightbox)
    brightbox has no compute service (Fog::Service::NotFound)
      /usr/share/gems/gems/fog-core-2.1.2/lib/fog/core/services_mixin.rb:18:in `rescue in new'
      /usr/share/gems/gems/fog-core-2.1.2/lib/fog/core/services_mixin.rb:7:in `new'
      /usr/share/gems/gems/fog-core-2.1.2/lib/fog/compute.rb:32:in `new'
      /usr/share/gems/gems/fog-core-2.1.2/lib/fog/core/services_mixin.rb:4:in `[]'
      tests/brightbox/compute_tests.rb:2:in `block in <top (required)>'
      /usr/share/gems/gems/shindo-0.3.8/lib/shindo.rb:79:in `instance_eval'
      /usr/share/gems/gems/shindo-0.3.8/lib/shindo.rb:79:in `tests'
      /usr/share/gems/gems/shindo-0.3.8/lib/shindo.rb:38:in `initialize'
      /usr/share/gems/gems/shindo-0.3.8/lib/shindo.rb:13:in `new'
      /usr/share/gems/gems/shindo-0.3.8/lib/shindo.rb:13:in `tests'
      tests/brightbox/compute_tests.rb:1:in `<top (required)>'
      /usr/share/gems/gems/shindo-0.3.8/lib/shindo/bin.rb:61:in `load'
      /usr/share/gems/gems/shindo-0.3.8/lib/shindo/bin.rb:61:in `block (2 levels) in run_in_thread'
      /usr/share/gems/gems/shindo-0.3.8/lib/shindo/bin.rb:58:in `each'
      /usr/share/gems/gems/shindo-0.3.8/lib/shindo/bin.rb:58:in `block in run_in_thread'

This could be probably fixed by correct namespacing, e.g. Fog::Brightbox::Compute instead of Fog::Compute::Brightbox. This is also suggested by fog/fog-core/pull/229

Need to authenticate every time when generating temporary url

We are experiencing problems with generating temporary url for a file in our carrierwave uploader. The code looks the following way:

def temp_url
  connection.get_object_https_url(fog_directory, version.path, expire_in = 1.day.from_now)
end

where connection is an instance of Fog::Storage::Brightbox. When generating temp_url it fails with NoMethodError: undefined method 'path' for nil:NilClass

I looked into the source code and found out that it fails there. The problem is that management_url is nil

I investigated further and found out that storage_management_url is being set in the Fog::Storage::Brightbox#authenticate

so if I change temp_url to

def temp_url
  connection.authenticate
  connection.get_object_https_url(fog_directory, version.path, expire_in = 1.day.from_now)
end

it doesn't fail with exception

Another way is to configure brightbox_storage_management_url manually

CarrierWave.configure do |config|
  config.fog_credentials = {
    provider: "Brightbox",
    ...
    brightbox_storage_management_url: "https://orbit.brightbox.com/v1/acc-12345" 
  }
end

I think that making authenticate request every time we generate temporary url for a document is not a good practice. The only problem with setting brightbox_storage_management_url is that we get warning from the fog library

[fog][WARNING] Unrecognized arguments: brightbox_storage_management_url

Could you raise a clear exception when brightbox_storage_management_url is not configured?
Could you fix that Unrecognized arguments fog warning?

Make some data available in server#show directly available

Issue in knife-brightbox rubiojr/knife-brightbox#21

This could be solved by having a cleaning interface on Server that respects
Demeter's law and avoids the chaining.

server.image.name was used but when an image has been later set to
"private", server#image returns nil.

If server#image_name was available based on the data already in the original
API call, a second API call would not be needed.

Need to ensure that these also appear in the collection API so they consistently
work in both cases.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.