Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Using OpenStack with the Fog library

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →

Using OpenStack with the Fog library

Intro to OpenStack, why should a rubyist care, and easy cloud operations using Fog and OpenStackCore

Avatar for Mike Hagedorn

Mike Hagedorn

June 11, 2014

Other Decks in Technology

Transcript

  1. what is OpenStack? • Open source cloud infrastructure • Broadly

    available • Runs on non proprietary hardware • Governed by the OpenStack Foundation • AT&T, Canonical, HP, IBM, Rackspace (others)
  2. OpenStack birth “ Launched Nova. Apache-Licensed Cloud Computing, in Python.

    It’s live. it’s buggy, it’s beta. Check it out “ - Joshua McKenty blog post, summer 2010 @jmckenty (Joshua McKenty)
  3. OpenStack birth • NASA Aimes CTO • Worked with Microsoft/Google

    on some NASA visualizations • Preferred Google’s approach • NASA needs a cloud! @kemp (Chris Kemp)
  4. OpenStack projects • Nova (Compute) • Swift (Object Storage) •

    Cinder (Block Storage) • Quantum (Networking) • Horizon (Dashboard) • Keystone (Identity) • Glance (VM Images)
  5. ok, why should I care? • Less than 2% of

    global compute workloads run on AWS • Large companies have public data concerns • Countries have security concerns
  6. fog • ruby cloud services • fog.io • github.com/fog/fog •

    @fog • @geemus (Wesley Beary) • “gem install fog”
  7. fog require "fog" require "ostruct" ! user = OpenStruct.new({ :access_key=>{

    :access_key_id => "<MY_HP_KEYID>" :secret_key => "<MY_HP_SECRET_KEY>" }, :tenant_id => "<MY_HP_TENANT_ID>" }) ! @connection ||= Fog::Compute.new( :provider => 'HP', :hp_access_key => user.access_key[:access_key_id], :hp_secret_key => user.access_key[:secret_key], :version => "v2", :hp_auth_uri => "https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0/tokens", :hp_tenant_id => user.tenant_id, :hp_avl_zone => "region-b.geo-1" )
  8. fog flavors = @connection.list_flavors images = @connection.list_images server_response = @connection.create_server("my

    server", flavors.body["flavors"].first["id"], images.body["images"].first["id"]) server_id = server_response.body["server"]["id"] while(true){ response = @connection.list_servers(:status => "ACTIVE") active_ids = response.body["servers"].map { |s| s["id"] } unless active_ids.select { |item| item == server_id }.empty? break end sleep(2) } ! #do stuff now
  9. fog collections module Fog module Compute class HPV2 class VolumeAttachments

    < Fog::Collection ! model Fog::Compute::HPV2::VolumeAttachment ! attr_accessor :server ! def all requires :server data = service.list_server_volumes(server.id).body['volumeAttachments'] load(data) end ! def get(volume_id) requires :server if data = service.get_server_volume_details(server.id, volume_id).body['volumeAttachment'] new(data) end rescue Fog::Compute::HPV2::NotFound nil end end end end end
  10. fog models module Fog module Compute class HPV2 ! class

    AvailabilityZone < Fog::Model ! identity :name, :aliases => 'zoneName' ! attribute :zoneState attribute :hosts ! def available? zoneState['available'] end ! end ! end end end
  11. fog requests • actual business logic for request def list_flavors(options

    = {}) request( :expects => [200, 203], :method => 'GET', :path => 'flavors', :query => options ) end
  12. fog mocks • test data to return example API responses

    • requires no network connection
  13. fog and OpenStack • fog/openstack-core is the official ruby sdk

    for OpenStack • Under active development
  14. fog bin • fog <provider> • convenient way to explore

    with fog • uses .fog file in your home dir