chaos_conoha 0.1.0

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: c98455f5bc2550318876e2c27b673e2dd9e6ab40
4
+ data.tar.gz: dde61009eb89035784c6692e08d8158d5d53003c
5
+ SHA512:
6
+ metadata.gz: 1120786fce8e525bd097f0682cccdfe6c17045a050f1ef511fea70c37f0e4cde1dc1ca7ac828c663a789a6f5003875f045b2e1b433b3f0ad98a575ceb826323d
7
+ data.tar.gz: ca2d5e28347936f794cd3d97745aa96240c3324aecdbce44ea2f8eaf4acbc3237072f723c1894a80477a513a22b04aa3b7ae2cc40c4b4042833983ee345419ce
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in chaos_conoha.gemspec
4
+ gemspec
@@ -0,0 +1,34 @@
1
+ # ChaosConoha
2
+
3
+ Chaos ConoHa is sugoi zashikiwarashi
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'chaos_conoha'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install chaos_conoha
20
+
21
+ ## Usage
22
+
23
+ bundle exec chaos_conoha -l LOGIN_ID -p PASSWD -t TENANT_ID -i IDENTITY_API_HOST_NAME -s SLACK_TOKEN -c CHANNEL_NAME_TO_NOTIFIY
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec chaos_conoha` to use the gem in this directory, ignoring other installed copies of this gem.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kinoppyd/chaos_conoha. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
34
+
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "chaos_conoha"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'chaos_conoha/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "chaos_conoha"
8
+ spec.version = ChaosConoha::VERSION
9
+ spec.authors = ["kinoppyd"]
10
+ spec.email = ["WhoIsDissolvedGirl+github@gmail.com"]
11
+
12
+ spec.summary = %q{Sugoi zashikiwarashi}
13
+ spec.description = %q{Seiso kawaii zashikiwarasi}
14
+ spec.homepage = "https://github.com/kinoppyd/chaos_conoha"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "conoha_api", "~> 0.2"
22
+ spec.add_dependency "slack-ruby-client", "~> 0.7"
23
+ spec.add_development_dependency "bundler", "~> 1.10"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "minitest"
26
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "chaos_conoha"
4
+
5
+ ChaosConoha::Runner.new(ARGV).run!
@@ -0,0 +1,101 @@
1
+ require "optparse"
2
+ require "conoha_api"
3
+ require "slack-ruby-client"
4
+ require "chaos_conoha/version"
5
+
6
+ module ChaosConoha
7
+ class Runner
8
+ COMMANDS = [
9
+ :create,
10
+ :stop,
11
+ :restart,
12
+ :delete
13
+ ]
14
+
15
+ def initialize(args)
16
+ parse!(args.dup)
17
+ rescue => e
18
+ puts e.message
19
+ puts e.backtrace.join("\n")
20
+ puts ""
21
+ puts parser
22
+ exit 1
23
+ end
24
+
25
+ def parser
26
+ @parser ||= begin
27
+ parser = OptionParser.new
28
+ parser.banner = 'Usage: chaos_conoha -l LOGIN_NAME -p PASSWORD -t TENANT_ID -i https://example.com -s SLACK_TOKEN -c CHANNEL_TO_POST'
29
+
30
+ parser.on('-l', '--login LOGIN') { |login| options[:login] = login }
31
+ parser.on('-p', '--password PASS') { |pass| options[:password] = pass }
32
+ parser.on('-t', '--tenant-id TENANT') { |tenant_id| options[:tenant_id] = tenant_id }
33
+ parser.on('-i', '--identity-api-host HOST') { |host| options[:api_endpoint] = host }
34
+ parser.on('-s', '--slack-token TOKEN') { |token| options[:slack_token] = token }
35
+ parser.on('-c', '--slack-channel CHANNEL') { |channel| options[:slack_channel] = channel }
36
+ parser
37
+ end
38
+ end
39
+
40
+ def parse!(args)
41
+ parser.parse!(args)
42
+ rescue => e
43
+ puts e.message
44
+ puts parser
45
+ exit 1
46
+ end
47
+
48
+ def run!
49
+ res = __send__(COMMANDS.sample)
50
+ slack.chat_postMessage(channel: options[:slack_channel], text: res, as_user: true)
51
+ rescue => e
52
+ puts e.message
53
+ puts e.backtrace.join("\n")
54
+ puts ""
55
+ puts parser
56
+ exit 1
57
+ end
58
+
59
+ def conoha
60
+ @conoha ||= ConohaApi::Client.new(options)
61
+ end
62
+
63
+ def slack
64
+ @slack ||= begin
65
+ Slack.configure do |config|
66
+ config.token = options[:slack_token]
67
+ end
68
+ Slack::Web::Client.new
69
+ end
70
+ end
71
+
72
+ def options
73
+ @options ||= {}
74
+ end
75
+
76
+ def create
77
+ image = conoha.images_detail.images.sample
78
+ flavor = conoha.flavors_detail.flavors.sample
79
+ conoha.add_server(image.id, flavor.id)
80
+ "CPUが#{flavor.vcpus}個の、メモリが#{flavor.ram}Mのインスタンスに、#{image.name}を入れて作っておいたよ!\n感謝してね!"
81
+ end
82
+
83
+ def stop
84
+ machine = conoha.servers_detail.servers.select { |s| s.status == "ACTIVE" }.sample
85
+ conoha.stop_server(machine.id)
86
+ "ごめんっ、コンセントに足引っ掛けて#{machine.metadata.instance_name_tag}っていうマシン止めちゃった!"
87
+ end
88
+
89
+ def restart
90
+ machine = conoha.servers_detail.servers.select { |s| s.status == "ACTIVE" }.sample
91
+ conoha.reboot_server(machine.id, 'HARD')
92
+ "なんか、#{machine.metadata.instance_name_tag}っていうマシンから変な音してたから、再起動しといたよっ! えへん!"
93
+ end
94
+
95
+ def delete
96
+ machine = conoha.servers_detail.servers.select { |s| s.status == "ACTIVE" }.sample
97
+ conoha.delete_server(machine.id)
98
+ "#{machine.metadata.instance_name_tag}っていうマシン、なんか使ってなかったっぽいから消しといたよ!"
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,3 @@
1
+ module ChaosConoha
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chaos_conoha
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kinoppyd
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: conoha_api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: slack-ruby-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.7'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Seiso kawaii zashikiwarasi
84
+ email:
85
+ - WhoIsDissolvedGirl+github@gmail.com
86
+ executables:
87
+ - chaos_conoha
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".travis.yml"
93
+ - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - chaos_conoha.gemspec
100
+ - exe/chaos_conoha
101
+ - lib/chaos_conoha.rb
102
+ - lib/chaos_conoha/version.rb
103
+ homepage: https://github.com/kinoppyd/chaos_conoha
104
+ licenses: []
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.4.5
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Sugoi zashikiwarashi
126
+ test_files: []