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

Fog

 Fog

Getting started with the Fog cloud services library. Presented at the SDRuby monthly meeting on November 3, 2011

James Miller

October 26, 2011
Tweet

More Decks by James Miller

Other Decks in Technology

Transcript

  1. Fog
    Ruby Cloud Services Library

    View Slide

  2. github.com/fog/fog
    fog.io
    @fog

    View Slide

  3. APIs Hurt

    View Slide

  4. 1. Search for existing,
    often shoddy library

    View Slide

  5. 2. DIY Wrapper

    View Slide

  6. 3. New vendor comes
    along that does your
    laundry too!

    View Slide

  7. 4. Sad face :(

    View Slide

  8. Amazon EC2
    Amazon S3
    Zerigo DNS
    RS Files
    RS Servers
    Amazon Cloudfront
    Amazon Route 53
    Dynect DNS
    DNSimple
    Amazon RDS
    Linode
    Google Storage

    View Slide

  9. Cross Service
    Compatibility

    View Slide

  10. gem install fog

    View Slide

  11. require 'fog'

    View Slide

  12. Cloud Storage

    View Slide

  13. s3 = Fog::Storage.new(
    provider: "AWS",
    aws_access_key_id: "KEY",
    aws_secret_access_key: "SECRET"
    )
    gg = Fog::Storage.new(
    provider: "Google",
    google_storage_access_key_id: "KEY",
    google_storage_secret_access_key: "SECRET"
    )
    rs = Fog::Storage.new(
    provider: "Rackspace",
    rackspace_api_key: "KEY",
    rackspace_auth_url: "URL",
    rackspace_username: "USERNAME"
    )
    s3.put_object(bucket_name, object_name, data, options = {})
    gg.put_object(bucket_name, object_name, data, options = {})
    rs.put_object(container, object_name, data, options = {})

    View Slide

  14. s3.put_object(bucket_name, object_name, data, options = {})
    gg.put_object(bucket_name, object_name, data, options = {})
    rs.put_object(container, object_name, data, options = {})
    Consistency
    Provider Flexibility

    View Slide

  15. Cloud Servers

    View Slide

  16. ec2 = Fog::Compute.new(
    provider: "AWS",
    aws_access_key_id: "KEY",
    aws_secret_access_key: "SECRET"
    )
    rsc = Fog::Compute.new(
    provider: "Rackspace",
    rackspace_api_key: "KEY",
    rackspace_username: "SECRET"
    )
    ec2.servers.create(
    flavor_id: "c1.medium",
    image_id: "ami-6936fb00", # Ubuntu 10.04 LTS
    key_name: "mykeyname",
    groups: ["default"],
    )
    rsc.servers.create(
    flavor_id: 5, # 4GB Memory
    image_id: 49, # Ubuntu 10.04 LTS
    name: 'my_server_name'
    )

    View Slide

  17. DNS

    View Slide

  18. z = Fog::DNS::Zerigo.new(
    zerigo_email: "email",
    zerigo_token: "secret",
    scheme: "https",
    port: 443
    )
    zone_id = z.create_zone("bensie.com", 14400, "pri_sec")
    .body["id"]
    z.create_host(zone_id, "CNAME", "ghs.google.com",
    hostname: "mail",
    ttl: 14400
    )

    View Slide

  19. AWS Management Console
    RS Cloud Control Panel
    • Multi-step wizards
    • Missing features
    • Slow
    • One account at a time

    View Slide

  20. AWS Management Console

    View Slide

  21. rds = Fog::AWS::RDS.new(
    aws_access_key_id: "KEY",
    aws_secret_access_key: "SECRET"
    )
    rds.create_db_instance("my-db-instance"
    "AllocatedStorage" => 50,
    "AutoMinorVersionUpgrade" => false,
    "BackupRetentionPeriod" => 3,
    "DBInstanceClass" => "db.m1.large",
    "DBParameterGroupName" => "utf8",
    "Engine" => "mysql",
    "EngineVersion" => "5.5.12",
    "MasterUsername" => "username",
    "MasterUserPassword" => "password",
    "MultiAZ" => true
    )

    View Slide

  22. rds = Fog::AWS::RDS.new(
    aws_access_key_id: "KEY",
    aws_secret_access_key: "SECRET"
    )
    rds.create_db_parameter_group(
    "utf8", "mysql5.5", "utf8"
    )
    rds.modify_db_parameter_group("utf8",
    [
    {
    "ParameterName" => "character_set_server",
    "ParameterValue" => "utf8",
    "ApplyMethod" => "immediate"
    },
    {
    "ParameterName" => "collation_server",
    "ParameterValue" => "utf8_general_ci",
    "ApplyMethod" => "immediate"
    }
    ]
    )

    View Slide

  23. elb = Fog::AWS::ELB.new(
    aws_access_key_id: "KEY",
    aws_secret_access_key: "SECRET"
    )
    load_balancers = elb.describe_load_balancers
    .body["DescribeLoadBalancersResult"]
    ["LoadBalancerDescriptions"]
    load_balancers.each do |lb|
    elb.register_instances_with_load_balancer(
    ["i-3dcba453", "i-37cba459"], lb["LoadBalancerName"]
    )
    end

    View Slide

  24. Documentation

    View Slide

  25. Inline

    View Slide

  26. READ
    code that you use

    View Slide

  27. Code Organization

    View Slide

  28. lib/fog/provider/service/requests
    lib/fog/provider/service/models
    lib/fog/provider/service/parsers

    View Slide

  29. Contributing

    View Slide

  30. Forgetting to delete servers after testing
    =

    View Slide

  31. James Miller
    github.com/bensie
    @bensie

    View Slide