Skip to content

Instantly share code, notes, and snippets.

@pramodshinde
Last active October 2, 2016 08:23
Show Gist options
  • Save pramodshinde/def0c0824d46019e033457ea3e50558b to your computer and use it in GitHub Desktop.
Save pramodshinde/def0c0824d46019e033457ea3e50558b to your computer and use it in GitHub Desktop.

Revisions

  1. Pramod Shinde revised this gist Oct 2, 2016. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions linode_service.rb
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@
    class LinodeService
    #Replace following contacts as per your needs
    PLAN_ID = 1

    API_KEY = 'xyz'
    DATACENTERS = {
    newark: 6,
    london: 7
    @@ -68,7 +68,6 @@ def delete
    private

    def linode_client
    API_KEY = 'xyz'
    @client ||= Linode.new(api_key: API_KEY)
    end
    end
  2. Pramod Shinde created this gist Oct 1, 2016.
    79 changes: 79 additions & 0 deletions linode_service.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,79 @@
    #If you are refering this gist, I would suggest to refer my blog post and Linode gem documentation
    # post url: https://pramodbshinde.wordpress.com/2016/10/01/spot-instances-with-linode
    # gem url: https://github.com/rick/linode

    class LinodeService
    #Replace following contacts as per your needs
    PLAN_ID = 1

    DATACENTERS = {
    newark: 6,
    london: 7
    }

    SOURCE_LINODES = {
    london: 5679,
    newark: 1234
    }

    def initialize
    linode_client
    end

    #Clone new linode and boot
    def launch_linode
    @linode = clone
    boot
    end

    #Launching instance
    def clone
    @client.linode.clone(
    linodeid: SOURCE_LINODES[:london],
    datacenterid: DATACENTERS[:london],
    planid: PLAN_ID
    )
    end

    #Booting instance
    def boot
    @linode.boot(linodeid: @linode.linodeid)
    end

    ##Updating instance
    def update
    @client.linode.update(
    linodeid: @linode.linodeid,
    label: 'Instance' + '-' + @linode.linodeid.to_s,
    lpm_displaygroup: 'My Linodes'
    )
    end

    #Listing instances
    def list
    @client.linode.list
    end

    #Getting IP address of linode
    def ip_address
    data = @client.linode.ip.list(linodeid: @linode.linodeid)
    data.first.ipaddress
    end

    #Deleting instance
    def delete
    @linode.delete(linodeid: linodeid, skipChecks: true)
    end

    private

    def linode_client
    API_KEY = 'xyz'
    @client ||= Linode.new(api_key: API_KEY)
    end
    end

    service = LinodeService.new
    service.launch_linode
    service.ip_address
    => 209.123.234.161