Code Monkey home page Code Monkey logo

fleet-api's Introduction

fleet-api

Gem Version Build Status

Provides a Ruby wrapper around the CoreOS Fleet API.

The client allows programmatic access to most of the fleetctl commands including the ability to load, start, stop, unload and destroy unit files.

At this point, there is no official Fleet API (though one is in the works) so this library mimcs the behavior of the fleetctl command line tool and simply writes data to the etcd key-value-store. The Fleet daemon reads data out of specific keys in etcd and processes it as appropiate.

As work on the actual Fleet API progresses, this library will be refactored to use the real API. An initial pass at implementing a client for the official Fleet API can be found on the feature/official-api branch.

An alternative implementation is available in the cloudspace/ruby-fleetctl gem. The ruby-fleetctl gem takes a different approach and uses SSH to interact directly with the fleetctl binary to send commands. Our approach of writing directly to etcd cuts out the fleetctl middleman but is in more danger of being broken by future releases since we're effectively using a "private API".

The current version of the fleet-api gem is known to work with version 0.6.0 of Fleet.

Installation

Install the gem directly:

gem install fleet-api

Alternatively, add this line to your application's Gemfile:

gem 'fleet-api', require: 'fleet'

Usage

Configure the URL for the etcd API:

require 'fleet'

Fleet.configure do |fleet|
  fleet.fleet_api_url = 'http://10.1.42.1:4001'
end

If you don't provide an explicit value for the .fleet_api_url attribute, it will default to using the value of the FLEETCTL_ENDPOINT environment variable.

Note: since this Fleet API is not yet available in the stable version of CoreOS, the URL value provided must be the endpoint for the etcd API.

Service Definitions

When submitting a service definition to the Fleet::Client you must convert your unit file into a Ruby hash. Each section in the unit file is represented as a key/value pair in the hash where the key is the name of the section and the value is another hash containing all the statements for that section.

For example, look at the following unit file.

[Unit]
Description=Useless infinite loop

[Service]
ExecStart=/bin/bash -c "while true; do sleep 1; done"

This unit file would be represented as the following Ruby hash.

{
  'Unit' => {
    'Description' => 'Useless infinite loop'
  },
  'Service' => {
    'ExecStart' => "/bin/bash -c \"while true; do sleep 1; done\""
  }
}

Loading a Unit File

Equivalent of fleetctl load:

service = {
  'Unit' => {
    'Description' => 'Useless infinite loop'
  },
  'Service' => {
    'ExecStart' => "/bin/bash -c \"while true; do sleep 1; done\""
  }
}

client = Fleet.new
client.load('forever.service', service)

Note that the name you pass-in as the first parameter to the .load method should end in ".service"

Starting a Service

Equivalent of fleetctl start:

client = Fleet.new
client.start('forever.service')

Stopping a Service

Equivalent of fleetctl stop:

client = Fleet.new
client.stop('forever.service')

Unloading a Unit File

Equivalent of fleetctl unload:

client = Fleet.new
client.unload('forever.service')

Destroying a Service

Equivalent of fleetctl destroy:

client = Fleet.new
client.destroy('forever.service')

Retrieving Service Status

Equivalent of fleetctl status:

client = Fleet.new
client.status('forever.service')

fleet-api's People

Contributors

bdehamer avatar

Watchers

Nestor G Pestelos Jr avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.