euca 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9d4ed814e4158d6f7be590f9df7ece3daf376274
4
+ data.tar.gz: 9295c0229b1b2c20a6a73dcb12bde38e7946fd9c
5
+ SHA512:
6
+ metadata.gz: f26341db455302fc8433d14b5842f190f9e34922b185d9329940a09f4667db58f4f0afb06cf41bdb759912ca1a228878af19e3322d3cec97be4039b1dda37571
7
+ data.tar.gz: cd487d22b54bde8077e68864f6152d4856b987d66615fa7e6403ab9fed091ca0a7623cd5ff806577780aa1ce72f9246431d1d95f8a8a24811ba102e0f661f709
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in euca.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Onur Uyar
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Euca
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'euca'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install euca
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/euca/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'spec'
6
+ t.libs << 'spec/support'
7
+ t.pattern = "spec/**/*_spec.rb"
8
+ end
9
+
10
+ desc "Run tests"
11
+ task :default => :test
data/euca.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'euca/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "euca"
8
+ spec.version = Euca::VERSION
9
+ spec.authors = ["Onur Uyar"]
10
+ spec.email = ["me@onuruyar.com"]
11
+ spec.summary = %q{Ultra thin ruby wrapper for euca2ools command line tools}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.5"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "minitest"
23
+ end
data/lib/euca.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'logger'
2
+ require 'euca/core_ext/kernel'
3
+ require "euca/version"
4
+
5
+ module Euca
6
+
7
+ def self.logger
8
+ @@logger ||= Logger.new(STDOUT)
9
+ end
10
+
11
+ end
@@ -0,0 +1,25 @@
1
+ require 'stringio'
2
+
3
+ module ::Kernel
4
+
5
+ def called_from(level=1)
6
+ arrs = caller((level||1)+1) or return
7
+ arrs[0] =~ /:(\d+)(?::in `(.*)')?/ ? [$`, $1.to_i, $2] : nil
8
+ end
9
+
10
+ def sh cmd
11
+ output = StringIO.new
12
+
13
+ Euca.logger.debug "[sh] #{cmd}"
14
+
15
+ IO.popen(cmd) do |pipe|
16
+ pipe.each do |line|
17
+ output.puts line
18
+ Euca.logger.debug line
19
+ end
20
+ end
21
+
22
+ output.string
23
+ end
24
+
25
+ end
data/lib/euca/model.rb ADDED
@@ -0,0 +1,41 @@
1
+ require 'euca'
2
+ require 'euca/wrapper'
3
+
4
+ module Euca
5
+ module Model
6
+
7
+ module ClassMethods
8
+
9
+ def columns names = nil
10
+ unless names.nil?
11
+ @@columns = names
12
+ end
13
+ @@columns
14
+ end
15
+
16
+ def type_id
17
+ @@type_id ||= self.name
18
+ end
19
+
20
+ def type_id=type_id
21
+ @@type_id = type_id
22
+ end
23
+
24
+ end
25
+
26
+ def self.included(base)
27
+ base.extend ClassMethods
28
+ end
29
+
30
+ def euca api, *args
31
+ wrapper.run api, *args
32
+ end
33
+
34
+ private
35
+
36
+ def wrapper
37
+ @wrapper ||= Wrapper.new self.class.type_id, self.class.columns
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module Euca
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ module Euca
2
+ class Wrapper
3
+
4
+ def initialize type_id, columns = nil
5
+ @type_id = type_id
6
+ @columns = columns
7
+ end
8
+
9
+ def run api, *args
10
+ parse(sh("euca-#{api} #{args.join(" ")}"))
11
+ end
12
+
13
+ def parse response
14
+ response.split("\n").
15
+ keep_if{ |line| line.match(/^#{@type_id}/i) }.
16
+ map{ |line|
17
+ rows = line.gsub("\n","").split("\t")
18
+ @columns.nil? ? rows : Hash[ @columns.zip( rows ) ]
19
+ }
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ all: |
2
+ IMAGE qmi-b58041dd Ubuntu Server 12.04.1 admin available public x86_64 machine ebs
3
+ IMAGE qmi-098feb2c CentOS-5.8 admin available public x86_64 machine ebs
4
+ IMAGE qmi-05bee719 Ubuntu 12.04.1 Desktop admin available public x86_64 machine ebs
5
+ IMAGE qmi-542v8843 Windows Server 2008 R2 Datacenter admin available public x86_64 machine ebs
6
+ IMAGE qmi-fa4bdae0 Fedora 16 Server admin available public x86_64 machine ebs
7
+ IMAGE qmi-4e5b842f Ubuntu Server 10.04 (64-bit) admin available public x86_64 machine ebs
8
+ IMAGE qmi-399db468 CentOS 6.5 53205cf4-3bd0-48df-b409-e00611aeb9d6 available public x86_64 machine ebs
9
+ IMAGE qmi-d7d77132 FreeBSD 10.0 e93a9745-b528-4fc1-a3f0-705395914ff0 available public x86_64 machine ebs
10
+ IMAGE qmi-9ac92558 Ubuntu Server 11.10 (64-bit) admin available public x86_64 machine ebs
11
+ IMAGE qmi-96f82145 CentOS 6.0 (64-bit) admin available public x86_64 machine ebs
12
+ IMAGE qmi-6ce3a4c7 Debian 7 admin available public x86_64 machine ebs
13
+ IMAGE qmi-42e877f6 CentOS 6.0 GUI (64-bit) admin available public x86_64 machine ebs
14
+ IMAGE qmi-ca255b12 Minix 3.2.1 admin available public x86_64 machine ebs
15
+ IMAGE qmi-ce455aa2 FreeBSD 9.1 admin available public x86_64 machine ebs
16
+ IMAGE qmi-bd224a03 Ubuntu Server 12.10 admin available public x86_64 machine ebs
17
+ IMAGE qmi-1131f352 Windows Server 2012 Datacenter admin available public x86_64 machine ebs
18
+ IMAGE qmi-65419ca1 CentOS 6.3 GUI admin available public x86_64 machine ebs
19
+ IMAGE qmi-b95145f0 CentOS 6.3 admin available public x86_64 machine ebs
@@ -0,0 +1,20 @@
1
+ require 'support/minitest_helper'
2
+ require 'euca/model'
3
+
4
+ describe Euca::Model do
5
+ it "implements wrapper" do
6
+ Api = Class.new
7
+ Api.send :include, Euca::Model
8
+ Api.columns %w(type id name)
9
+ Api.type_id = "image"
10
+ api = Api.new
11
+
12
+ wrapper = MiniTest::Mock.new
13
+ wrapper.expect :run, api.send(:wrapper).parse(fixture(:images)["all"]), [ "describe-images" ]
14
+
15
+ api.instance_variable_set "@wrapper", wrapper
16
+
17
+ images = api.euca("describe-images")
18
+ images.first["name"].must_equal "Ubuntu Server 12.04.1"
19
+ end
20
+ end
@@ -0,0 +1,14 @@
1
+ require "minitest/pride"
2
+ require "minitest/autorun"
3
+ require 'euca'
4
+ require 'yaml'
5
+
6
+ ENV["KEYPAIR"]="~/.ssh/gq_credentials/default_ssh.id"
7
+
8
+ class MiniTest::Spec
9
+
10
+ def fixture name
11
+ YAML.load_file("spec/fixtures/#{name}.yml")
12
+ end
13
+
14
+ end
@@ -0,0 +1,12 @@
1
+ require 'support/minitest_helper'
2
+ require 'euca/wrapper'
3
+
4
+ describe Euca::Wrapper do
5
+ it "runs euca commands and parses results into hash" do
6
+ wrapper = Euca::Wrapper.new("image",%w(type id name))
7
+
8
+ # images = wrapper.run "describe-images"
9
+ images = wrapper.parse fixture(:images)["all"]
10
+ images.first["name"].must_equal "Ubuntu Server 12.04.1"
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: euca
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Onur Uyar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - me@onuruyar.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - euca.gemspec
68
+ - lib/euca.rb
69
+ - lib/euca/core_ext/kernel.rb
70
+ - lib/euca/model.rb
71
+ - lib/euca/version.rb
72
+ - lib/euca/wrapper.rb
73
+ - spec/fixtures/images.yml
74
+ - spec/model_spec.rb
75
+ - spec/support/minitest_helper.rb
76
+ - spec/wrapper_spec.rb
77
+ homepage: ''
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.2.0
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Ultra thin ruby wrapper for euca2ools command line tools
101
+ test_files:
102
+ - spec/fixtures/images.yml
103
+ - spec/model_spec.rb
104
+ - spec/support/minitest_helper.rb
105
+ - spec/wrapper_spec.rb