Giter Site home page Giter Site logo

easymanager's Introduction

EasyManager

Simple ruby library to manage cloud servers

Available provider :

  • Scaleway

Scaleway available images:

  • debian-buster
  • ubuntu-jammy

Scaleway available instances:

  • DEV1-S
  • DEV1-M
  • DEV1-L
  • DEV1-XL

Installation

In your Gemfile

gem 'easy_manager', '~> 0.9.4'

Or

gem install easy_manager

Usage example

require 'easy_manager'

options = {
  zone: 'fr-par-1',
  project: 'YOUR-PROJECT-ID',
  secret_token: 'YOUR-SECRET-TOKEN'
}

# It is possible to pass the following arguments :
#  { username: 'root', ssh_key: '/root/.ssh/id_rsa' }
ssh = EasyManager::SSH.new
manager = EasyManager::Scaleway.new(options)

# Displays all instances
servers = manager.list
puts servers

# Create a new instance
# It is possible to pass the following arguments :
#  { srv_type: 'DEV1-S', image: 'ubuntu-jammy', name_pattern: 'scw-easymanager-__RANDOM__', cloud_init: false }
srv = manager.create({ cloud_init: "#{__dir__}/cloud-init.yml" })

# Sleep unitil the server is ready, the default timeout value is 600
timeout = 60
ready = manager.wait_until_ready!(srv, ssh, timeout)
return unless ready

# It is also possible to check independently if the server is ready
manager.srv_ready?(srv, ssh)

# Executes multiple commands and stores the results
cmds = %w[id hostname]
cmd_results = EasyManager::SSH.cmd_exec(ssh, srv, cmds)

cmd_results.each do |cmd, result|
  p "Executed cmd : '#{cmd}' and get : '#{result}'"
  # > "Executed cmd : 'id' and get : 'uid=0(root) gid=0(root) groups=0(root)'"
  # > "Executed cmd : 'hostname' and get : 'scw-easymanager-uklyyuqi'"
end

# Transfer a file and a folder in recursive mode on the server
files = {
  '/tmp/file1.txt' => {
    remote: '/tmp'
  },
  '/tmp/folder' => {
    remote: '/tmp/another',
    recursive: true
  }
}
EasyManager::SSH.scp(ssh, srv, files)

# Delete the server
manager.delete(srv)
manager.delete_by_id('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')

easymanager's People

Contributors

joshuamart 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.