In part one of this series we introduced a new ruby gem, fog-softlayer, which enables SoftLayer users to leverage fog, the Ruby cloud services library.
In this installment, we will walk users through getting started with fog, covering several examples of using fog-softlayer to manage servers using both VMs and bare metal cloud instances.
These examples assume you have a local file at ~/.fog
that contains:
Having the configuration file described above allows you to establish a connection to the SoftLayer cloud with just two lines of code.
\trequire 'fog/softlayer' \t@sl = Fog::Compute[:softlayer]Alternatively, if you require supporting multiple SoftLayer accounts, credentials and defaults can be passed as arguments when establishing a connection.
\tfirst_account_args = { \t :provider => :softlayer, \t :softlayer_username => 'example-username-1', \t :softlayer_api_key => '1a1a1a1a1a1a1a1a1a11a1a1a1a1a1a1a1a1a1', \t :softlayer_default_domain => 'example.com', \t} \t \tsecond_account_args = { \t :provider => :softlayer, \t :softlayer_username => 'example-username-2', \t :softlayer_api_key => '2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b', \t :softlayer_default_domain => 'another-example.com', \t} \t \t@sl1 = Fog::Compute.new(first_account_args) \t@sl2 = Fog::Compute.new(second_account_args) ##### Use the ModelsFog has a robust, production tested, object model that is intuitive and powerful for working with clouds to provision infrastructure. Your primary interface for working with fog should be the models. If needed, you can directly make requests to SoftLayer with fog, but that code is not portable to OpenStack or other providers, and should be used only when required for performance.
1.
List all servers.
2.
Get a server’s details.
3.
Provision a new VM with flavor (simple).
4.
Provision a new bare metal cloud instance with flavor (simple).
5.
Provision a new VM without flavor.
6.
Provision a bare metal cloud instance without a flavor.
7.
Delete a VM or bare metal cloud instance.
This wraps up our initial tour of working with the Server model using fog-softlayer. In the blog in this series we explore SoftLayer Object Storage using the Directory and File models.
\- Matt
– If you have questions about or problems with fog-softlayer open an issue or email me.