Skip to content

A Ruby client for IDCF Cloud ILB Service.

License

Notifications You must be signed in to change notification settings

idcf/idcf-ilb-ruby

Repository files navigation

Idcf::Ilb

Gem Version Build Status Code Climate Test Coverage

A Ruby client for IDCF Cloud ILB service.

Installation

Note: requires Ruby 2.1.0 or higher.

Add this line to your application's Gemfile:

gem 'idcf-ilb'

And then execute:

$ bundle

Or install it yourself as:

$ gem install idcf-ilb

Usage

Basic usage

Client

You can create a instance of client by specifying API_KEY and SECRET_KEY.
You can get API_KEY and SECRET_KEY in IDCF Cloud.
You can also specify HOST. If you do not specify HOST, your client send request to "ilb.jp-east.idcfcloud.com".

require "idcf/ilb"

client =
  Idcf::Ilb::Client.new(
    api_key: ENV["IDCF_API_KEY"],
    secret_key: ENV["IDCF_SECRET_KEY"],
    host: ENV["IDCF_ILB_HOST"]
  )

# Call GET request directly
# returns Response object
response = client.get("loadbalancers")
response.success? #=> true
response.status   #=> 200

# Response#body returns HTTP response body as a hash or an array
response.body     #=> [loadbalancer1, loadbalancer2, ...]
response.body[0]  #=> loadbalancer1

# Response#[] is alias to Response#body[]
response[0]       #=> loadbalancer1

Servers

Add server
# Get target config of loadbalancer
config = client.list_loadbalancers.body.first["configs"].first

# Specify of the adding target server IP address and port
adding_server =
  {
    ipaddress: "xxx.xxx.xxx.xxx",
    port: 80
  }

# Add server to config
response =
  client.add_server(
    config["loadbalancer_id"],
    config["id"],
    adding_server
  )

response #=> server array
Get servers
loadbalancer = client.loadbalancers.body.first # Get one of the loadbalancer
config = loadbalancer["configs"].first # Get one of the loadbalancer's config hash
response = client.list_servers(loadbalancer["id"], config["id"])

response #=> server array
Delete server
# Get one of the loadbalancer's config hash
config = client.list_loadbalancers.body.first["configs"].first

# Specify of the deletion target server IP address and port
deletion_server = config["servers"].first

response =
  client.delete_server(
    config["loadbalancer_id"],
    config["id"],
    deletion_server["id"]
  )

response #=> server array

Contributing

  1. Fork it ( https://github.com/idcf/idcf-ilb-ruby/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request