fog/fog

Name: fog

Owner: fog

Description: The Ruby cloud services library.

Created: 2009-05-18 07:14:04.0

Updated: 2018-01-18 09:31:18.0

Pushed: 2017-10-27 14:29:03.0

Homepage: http://fog.io

Size: 21351

Language: Ruby

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

fog

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

Build Status Dependency Status Code Climate Gem Version

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:

do gem install fog
]

g

lcome to fog interactive!
efault provides [...]

erver = Compute[:aws].servers.create
mentError: image_id is required for this operation

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

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

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:

Collections share basic CRUD type operations, such as:

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

ire 'fog'

ute = Fog::Compute.new(
rovider           => 'Rackspace',
ackspace_api_key  => key,
ackspace_username => username


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

 STUFF

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

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

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:

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.

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

eate a storage connection
age = Fog::Storage.new(:provider => 'AWS', :aws_access_key_id => ACCESS_KEY_ID, :aws_secret_access_key => SECRET_ACCESS_KEY)
orage 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:

.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:

.add_dependency 'fog', '~> 1.16'
Getting Help
Contributing

Please refer to CONTRIBUTING.md.

License

Please refer to LICENSE.md.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.