using openstack with fog

34
Using OpenStack With Fog houston.rb 6/10/14

Upload: mike-hagedorn

Post on 23-Aug-2014

248 views

Category:

Internet


7 download

DESCRIPTION

Brief Primer on what openstack is, why its important and how to use ruby and Fog to create objects in an OpenStack based cloud.

TRANSCRIPT

Page 1: Using OpenStack With Fog

Using OpenStack With Fog

houston.rb 6/10/14

Page 2: Using OpenStack With Fog

• @mwhagedorn (mwhagedorn)

• github.com/mwhagedorn

Page 3: Using OpenStack With Fog

employer

• hpcloud.com

• @hpcloud

Page 4: Using OpenStack With Fog

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)

Page 5: Using OpenStack With Fog

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)

Page 6: Using OpenStack With Fog

OpenStack birth

• NASA Aimes CTO

• Worked with Microsoft/Google on some NASA visualizations

• Preferred Google’s approach

• NASA needs a cloud!

@kemp(Chris Kemp)

Page 7: Using OpenStack With Fog

OpenStack birth

• Rackspace spotted the blog post

• They decided to collaborate

Page 8: Using OpenStack With Fog

Philosophy

“Why Do This?”

Page 9: Using OpenStack With Fog

brief history of computing

• PCs

• Data Centers

• Hypervisors

• Hypervisor chaos

Page 10: Using OpenStack With Fog

the vision

OpenStack

Hyper-V VMware Xen KVM

Page 11: Using OpenStack With Fog

OpenStack projects• Nova (Compute)

• Swift (Object Storage)

• Cinder (Block Storage)

• Quantum (Networking)

• Horizon (Dashboard)

• Keystone (Identity)

• Glance (VM Images)

Page 12: Using OpenStack With Fog

devstack.org

• git clone https://github.com/openstack-dev/devstack.git

• cd devstack && ./stack.sh

Page 13: Using OpenStack With Fog

trystack.org

• sandbox for exploration

Page 14: Using OpenStack With Fog

horizon demo

Page 15: Using OpenStack With Fog

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

Page 16: Using OpenStack With Fog

this stuff is too hard!

Page 17: Using OpenStack With Fog

fog• ruby cloud services • fog.io • github.com/fog/fog • @fog • @geemus (Wesley Beary) • “gem install fog”

Page 18: Using OpenStack With Fog

fog

• portable • powerful • established

Page 19: Using OpenStack With Fog

fog• libraries

• knife • chef • bosh • carrierwave • paperclip

Page 20: Using OpenStack With Fog

fog providers

• set of adapters for specific cloud • aws, hp, rackspace.. etc

Page 21: Using OpenStack With Fog

fogrequire "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" )

Page 22: Using OpenStack With Fog

fog

flavors = @connection.list_flavorsimages = @connection.list_imagesserver_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

Page 23: Using OpenStack With Fog

fog collectionsmodule 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 endend

Page 24: Using OpenStack With Fog

fog modelsmodule Fog module Compute class HPV2! class AvailabilityZone < Fog::Model! identity :name, :aliases => 'zoneName'! attribute :zoneState attribute :hosts! def available? zoneState['available'] end! end! end endend

Page 25: Using OpenStack With Fog

fog requests• actual business logic for request

def list_flavors(options = {}) request( :expects => [200, 203], :method => 'GET', :path => 'flavors', :query => options ) end

Page 26: Using OpenStack With Fog

fog mocks

• test data to return example API responses

• requires no network connection

Page 27: Using OpenStack With Fog

fog real

• actual request implementation

Page 28: Using OpenStack With Fog

the fog “stack”collections

models

requests

cloud provider

servers

server

list_servers

Page 29: Using OpenStack With Fog

fog and OpenStack

• fog/openstack-core is the official ruby sdk for OpenStack

• Under active development

Page 30: Using OpenStack With Fog

fog bin

• fog <provider>

• convenient way to explore with fog

• uses .fog file in your home dir

Page 31: Using OpenStack With Fog

demo

Page 32: Using OpenStack With Fog

examples

• developer.rackspace.com (rails)

• http://goo.gl/HN78A3

• HP provider examples for compute (v2)

• http://goo.gl/bJaO6O

Page 33: Using OpenStack With Fog

getting involved

• OpenStack

• https://wiki.openstack.org/wiki/How_To_Contribute

• Fog

• https://github.com/fog/fog/issues

Page 34: Using OpenStack With Fog

questions?

@mwhagedorn [email protected]