gogetit 0.1.16

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 991eebbff8a14f432e2e8a5de6bdfcc67ccc4da3
4
+ data.tar.gz: bbbf4a5dc8619bc03d459b9d6187bc9cb7b60ac7
5
+ SHA512:
6
+ metadata.gz: 036e0579d678428b348e98a59821110256b328b30c42acb50e5e3b8853883d1208b8de9bcfbb5c5b2c1d60c30e968c99f114661f2968bc1159a6a532f9090cce
7
+ data.tar.gz: 572a304ab361c705b64a1ea1c943df2d7f2110a9810a80ee5dd3695abb2aa89b60d215e1c87f6cd51708eb8a839b873b66e9dcefc76287b7a1861d83edd6c444
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.*
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .idea/
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1 @@
1
+ gogetit
@@ -0,0 +1 @@
1
+ 2.3.1
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.15.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at donoldfashioned@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in gogetit.gemspec
4
+ gemspec
5
+
6
+ #gem 'etcd-rb', :path => '../etcd-rb'
7
+ #gem 'maas-client', :path => '../maas-client'
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Don Draper
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,52 @@
1
+ # Gogetit
2
+
3
+ Libraries with a CLI tool for dealing with things like MAAS, LXD and Libvirt.
4
+
5
+ ## Installation
6
+
7
+ ### dependent packages
8
+ ```bash
9
+ sudo apt install -y build-essential libvirt-dev lxd-client libvirt-bin
10
+ sudo reboot
11
+
12
+ # to remove default network(virbr0)
13
+ virsh net-destroy default
14
+ virsh net-undefine default
15
+ ```
16
+
17
+ ### install
18
+ ```bash
19
+ $ gem install gogetit
20
+ $ gem install gogetit --no-ri --no-rdoc
21
+ ```
22
+ ## Usage
23
+ ```bash
24
+ gogetit list
25
+ gogetit create lxd lxd01
26
+ gogetit create libvirt kvm01
27
+ gogetit destroy lxd01
28
+ ```
29
+
30
+ ```ruby
31
+ require 'gogetit'
32
+ ```
33
+
34
+ ## TODO
35
+ - Add allocating static IP
36
+
37
+ ## Development and Contributing
38
+ Clone and then execute followings:
39
+
40
+ $ cd gogetit
41
+ $ gem install bundle
42
+ $ bundle
43
+
44
+ Questions and pull requests are always welcome!
45
+
46
+ ## License
47
+
48
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
49
+
50
+ ## Code of Conduct
51
+
52
+ Everyone interacting in the Gogetit project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/gogetit/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gogetit"
5
+ require "pry"
6
+ Pry.start
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ Signal.trap("INT") { exit 1 }
4
+
5
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), %w{.. lib})
6
+
7
+ require "rubygems"
8
+ require "gogetit/cli"
9
+
10
+ Gogetit::CLI.start(ARGV)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,43 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pry'
5
+ require 'gogetit/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'gogetit'
9
+ spec.version = Gogetit::VERSION
10
+ spec.authors = ['Don Draper']
11
+ spec.email = ['donoldfashioned@gmail.com']
12
+
13
+ spec.summary = %q{Libraries with a CLI tool for dealing with things like MAAS, LXD and Libvirt.}
14
+ spec.description = <<-EOF
15
+ This provides the ways that deal with mutiple virtualized and containerized solutions such as Libvirt(KVM) and LXD.
16
+ This uses MAAS for bare-metal provision(KVM machine using Libvirt), DHCP and DNS.
17
+ This will also provide the ways to deal with muchltiple development environment such as development, stage and production.
18
+ EOF
19
+ spec.homepage = 'https://github.com/itisnotdone/gogetit.git'
20
+ spec.license = 'MIT'
21
+
22
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
23
+ f.match(%r{^(test|spec|features)/})
24
+ end
25
+ spec.bindir = 'bin'
26
+ spec.executables = ['gogetit']
27
+ spec.require_paths = ['lib']
28
+
29
+ spec.add_development_dependency 'bundler', '~> 1.15'
30
+ spec.add_development_dependency 'rake', '~> 10.0'
31
+ spec.add_development_dependency 'rspec', '~> 3.0'
32
+ spec.add_development_dependency 'pry', '~> 0.10.4'
33
+ spec.add_development_dependency 'simplecov', '~> 0.14.1'
34
+
35
+ #spec.add_runtime_dependency 'etcd-rb', '~> 1.1.0'
36
+ spec.add_runtime_dependency 'json', '~> 2.1.0'
37
+ spec.add_runtime_dependency 'hyperkit', '~> 1.1.0'
38
+ spec.add_runtime_dependency 'maas-client', '~> 0.1.23'
39
+ spec.add_runtime_dependency 'ruby-libvirt', '~> 0.7.0'
40
+ spec.add_runtime_dependency 'oga', '~> 2.10'
41
+ spec.add_runtime_dependency 'net-ssh', '~> 4.1.0'
42
+ spec.add_runtime_dependency 'thor', '~> 0.19.0'
43
+ end
@@ -0,0 +1,37 @@
1
+ require 'json'
2
+ require 'etcd'
3
+
4
+ module Etcd
5
+ class Etcd
6
+ attr_reader :etcd_conn
7
+
8
+ include Gogetit::Util
9
+
10
+ def initialize(config)
11
+ @etcd_conn = Etcd::Client.connect(uris: config[:etcd_url]).connect
12
+ end
13
+
14
+ def env_name
15
+ if etcd_conn.get('env_name') == nil or etcd_conn.get('env_name') == ''
16
+ etcd_conn.set('env_name', recognize_env)
17
+ etcd_conn.get('env_name')
18
+ else
19
+ etcd_conn.get('env_name')
20
+ end
21
+ end
22
+
23
+ def import_env
24
+ file = File.read('lib/env/'+env_name+'.json')
25
+ env_data = JSON.parse(file)
26
+ etcd_conn.set('env', env_data.to_json)
27
+ end
28
+
29
+ def env
30
+ if ! etcd_conn.get('env')
31
+ import_env
32
+ else
33
+ JSON.parse(etcd_conn.get('env'))
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,50 @@
1
+ # https://gist.github.com/ryanlecompte/1283413
2
+ module Gogetit
3
+ module Gogetit::ExecutionHooks
4
+ # this method is invoked whenever a new instance method is added to a class
5
+ def method_added(method_name)
6
+ # do nothing if the method that was added was an actual hook method, or
7
+ # if it already had hooks added to it
8
+ return if hooks.include?(method_name) || hooked_methods.include?(method_name)
9
+ add_hooks_to(method_name)
10
+ end
11
+
12
+ # this is the DSL method that classes use to add before hooks
13
+ def before_hook(method_name)
14
+ hooks << method_name
15
+ end
16
+
17
+ # keeps track of all before hooks
18
+ def hooks
19
+ @hooks ||= []
20
+ end
21
+
22
+ private
23
+
24
+ # keeps track of all currently hooked methods
25
+ def hooked_methods
26
+ @hooked_methods ||= []
27
+ end
28
+
29
+ def add_hooks_to(method_name)
30
+ # add this method to known hook mappings to avoid infinite
31
+ # recursion when we redefine the method below
32
+ hooked_methods << method_name
33
+
34
+ # grab the original method definition
35
+ original_method = instance_method(method_name)
36
+
37
+ # re-define the method, but notice how we reference the original
38
+ # method definition
39
+ define_method(method_name) do |*args, &block|
40
+ # invoke the hook methods
41
+ self.class.hooks.each do |hook|
42
+ method(hook).call
43
+ end
44
+
45
+ # now invoke the original method
46
+ original_method.bind(self).call(*args, &block)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,103 @@
1
+ require 'executionhooks'
2
+ require 'gogetit/version'
3
+ require 'maas'
4
+ require 'multilogger'
5
+ require 'providers/lxd'
6
+ require 'providers/libvirt'
7
+ require 'yaml'
8
+ require 'logger'
9
+ require 'util'
10
+
11
+ module Gogetit
12
+ extend Gogetit::Util
13
+
14
+ class << self
15
+ attr_reader :config, :maas, :lxd, :libvirt, :logger
16
+ end
17
+
18
+ # TODO: It might be needed to disable one of logging devices according to satiation.
19
+ STDOUT.sync = true
20
+ log_to_stdout = Logger.new(STDOUT)
21
+ @logger = Gogetit::MultiLogger.new(:loggers => log_to_stdout)
22
+ logger.debug('Instantiate main objects..')
23
+
24
+ @config = {}
25
+
26
+ logger.debug('Defining home directory..')
27
+ user_gogetit_home = Dir.home + '/.gogetit'
28
+ config[:user_gogetit_home] = user_gogetit_home
29
+ if not File.directory?(user_gogetit_home)
30
+ logger.debug('Creating home directory..')
31
+ FileUtils.mkdir(user_gogetit_home)
32
+ end
33
+
34
+ # TODO: It can be used to provide different behavior according to consumer.
35
+ logger.debug('Defining default consumer..')
36
+ config[:consumer] = 'gogetit_cli'
37
+
38
+ logger.debug('Defining log directory..')
39
+ log_dir = user_gogetit_home + '/log'
40
+ config[:log_dir] = log_dir
41
+ if not File.directory?(log_dir)
42
+ logger.debug('Creating log directory..')
43
+ FileUtils.mkdir(log_dir)
44
+ end
45
+
46
+ logger.debug('Define file log devices..')
47
+ log_file = File.open(log_dir + '/debug.log', 'a')
48
+ log_file.sync = true
49
+ log_to_file = Logger.new(log_file)
50
+ logger.add_logger(log_to_file)
51
+
52
+ logger.debug('Defining logger..')
53
+ # logger.datetime_format = "%Y-%m-%d %H:%M:%S"
54
+ logger.progname = 'GoGetIt'
55
+
56
+ lib_dir = File.dirname(__FILE__)
57
+
58
+ config[:lib_dir] = lib_dir
59
+ logger.debug('Loading GoGetIt default configuration..')
60
+ conf_file = user_gogetit_home + '/gogetit.yml'
61
+ if not File.exists?(conf_file)
62
+ src = File.new(lib_dir + '/sample_conf/gogetit.yml')
63
+ dst = Dir.new(user_gogetit_home)
64
+ logger.debug('Copying GoGetIt default configuration..')
65
+ FileUtils.cp(src, dst)
66
+ abort('Please define default configuration for GoGetIt at ~/.gogetit/gogetit.yml.')
67
+ end
68
+ config.merge!(symbolize_keys(YAML.load_file(conf_file)))
69
+
70
+ logger.debug('Define provider configuration directory..')
71
+ provider_conf_dir = user_gogetit_home + '/conf'
72
+ config[:provider_conf_dir] = provider_conf_dir
73
+ default_provider_conf_file = provider_conf_dir + '/default.yml'
74
+ config[:default_provider_conf_file] = default_provider_conf_file
75
+ if not File.exists?(default_provider_conf_file)
76
+ if not File.directory?(provider_conf_dir)
77
+ logger.debug('Creating provider configuration directory..')
78
+ FileUtils.mkdir(provider_conf_dir)
79
+ end
80
+ src = File.new(lib_dir + '/sample_conf/default.yml')
81
+ dst = Dir.new(provider_conf_dir)
82
+ logger.debug('Copying provider configuration file..')
83
+ FileUtils.cp(src, dst)
84
+ abort('Please define default configuration for providers at ~/.gogetit/conf/default.yml.')
85
+ end
86
+
87
+ @maas = Gogetit::GogetMAAS.new(config, logger)
88
+ @lxd = Gogetit::GogetLXD.new(config, maas, logger)
89
+ @libvirt = Gogetit::GogetLibvirt.new(config, maas, logger)
90
+
91
+ def self.get_provider_of(name)
92
+ if lxd.container_exists?(name)
93
+ logger.info("Calling <#{__method__.to_s}>, It is a LXD container.")
94
+ return 'lxd'
95
+ elsif libvirt.domain_exists?(name)
96
+ logger.info("Calling <#{__method__.to_s}>, It is a KVM domain.")
97
+ return 'libvirt'
98
+ else
99
+ puts "#{name} is not found"
100
+ return nil
101
+ end
102
+ end
103
+ end