yao-cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9f3453e1ad06288a15e0e8b2d35363fa8d3b0792
4
+ data.tar.gz: 7e8cdd7f20960726070ac6b2f5b181cfca41ec14
5
+ SHA512:
6
+ metadata.gz: 64b68912cad900f36481edc5f05880040707261c44bc69e8efdc1e2df3ff023d009b67e07c6ad76b40a234f2f10cd75972a9fb8b4b54c3623cc208a98d55d067
7
+ data.tar.gz: f8f1934356a52c3669ccb42b9687892bb5aec51fad04621362f8c58a2c114a463039b7c8e5ae1a425210f48dd3035e1dbcdd1f149ecf4e957b55ec8c4533a6d5
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.15.3
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in yao-cli.gemspec
6
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 buty4649
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,37 @@
1
+ [![Build Status](https://travis-ci.org/buty4649/yao-cli.svg?branch=master)](https://travis-ci.org/buty4649/yao-cli)
2
+
3
+ # Yao::Cli
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/yao/cli`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ TODO: Delete this and the text above, and describe your gem
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'yao-cli'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install yao-cli
24
+
25
+ ## Usage
26
+
27
+ TODO: Write usage instructions here
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ 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).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/yao-cli.
@@ -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,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "yao/cli"
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(__FILE__)
@@ -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,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.expand_path("#{File.dirname __FILE__}/../lib")
4
+ require 'rubygems'
5
+ require 'yao/cli'
6
+
7
+ Yao::Cli::Main.start
@@ -0,0 +1,13 @@
1
+ require "yao"
2
+
3
+ require "yao/resources/dumper"
4
+
5
+ require "yao/cli/version"
6
+ require "yao/cli/base"
7
+ require "yao/cli/server"
8
+ require "yao/cli/main"
9
+
10
+ module Yao
11
+ module Cli
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ require 'thor'
2
+ require 'yao/cli/formatter'
3
+
4
+ module Yao::Cli
5
+ class Base < Thor
6
+ class_option :format, :type => :string, :default => "json", :aliases => :f,
7
+ :enum => Yao::Cli::Formatter.formats, :desc => "Output format"
8
+
9
+ private
10
+ def pretty_output(obj)
11
+ puts Yao::Cli::Formatter.get(options[:format]).dump(obj)
12
+ end
13
+
14
+ def is_uuid?(str)
15
+ /^[\da-f]{32}$/ === str or
16
+ /^[\da-f]{8}-([\da-f]{4}-){3}[\da-f]{12}$/ === str
17
+ end
18
+
19
+
20
+ end
21
+ end
@@ -0,0 +1,14 @@
1
+ require 'yao/cli/formatter/json'
2
+ require 'yao/cli/formatter/yaml'
3
+
4
+ module Yao::Cli
5
+ module Formatter
6
+ def self.formats
7
+ constants.map{|c| c.to_s.downcase}.sort
8
+ end
9
+
10
+ def self.get(format)
11
+ const_get(format.upcase)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ require 'json'
2
+
3
+ module Yao::Cli::Formatter
4
+ class JSON
5
+ def self.dump(obj)
6
+ ::JSON.dump(obj)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ require 'yaml'
2
+
3
+ module Yao::Cli::Formatter
4
+ class YAML
5
+ def self.dump(obj)
6
+ ::YAML.dump(obj)
7
+ end
8
+ end
9
+ end
10
+
@@ -0,0 +1,28 @@
1
+ require 'thor'
2
+
3
+ module Yao::Cli
4
+ class Main < Thor
5
+
6
+ def initialize(*args)
7
+ super
8
+
9
+ Yao.configure do
10
+ auth_url ENV['OS_AUTH_URL']
11
+ tenant_name ENV['OS_TENANT_NAME']
12
+ username ENV['OS_USERNAME']
13
+ password ENV['OS_PASSWORD']
14
+ client_cert ENV['OS_CERT']
15
+ client_key ENV['OS_KEY']
16
+ region_name ENV['OS_REGION_NAME']
17
+ end
18
+ end
19
+
20
+ desc "version", "show version"
21
+ def version(*args)
22
+ puts Yao::Cli::VERSION
23
+ end
24
+
25
+ desc "server", "server subcommands"
26
+ subcommand("server", Yao::Cli::Server)
27
+ end
28
+ end
@@ -0,0 +1,78 @@
1
+ require "thor"
2
+ require "json"
3
+
4
+ module Yao::Cli
5
+ class Server < Base
6
+ desc "list", "list servers"
7
+ def list
8
+ server = Yao::Server.list_detail
9
+
10
+ pretty_output(Yao::Resources::Dumper::Server.dump(server))
11
+ end
12
+
13
+ desc "show", "show server details"
14
+ def show(id_or_name)
15
+ if is_uuid?(id_or_name)
16
+ result = Yao::Resources::Server.find id_or_name
17
+ else
18
+ result = Yao::Server.list_detail.select{|s| s.name == id_or_name}
19
+ end
20
+ pretty_output(Yao::Resources::Dumper::Server.dump(result))
21
+ end
22
+
23
+ desc "create <name>", "create server"
24
+ option :flavor, :required => true, :type => :string
25
+ option :image, :required => true, :type => :string
26
+ option :network, :type => :string
27
+ option :port, :type => :string
28
+ def create(name)
29
+ flavor = options[:flavor]
30
+ image = options[:image]
31
+ network = options[:network]
32
+ port = options[:port]
33
+
34
+ if network.nil? && port.nil?
35
+ puts "Error: network or port is must be set."
36
+ exit 1
37
+ end
38
+
39
+ flavor = if is_uuid?(flavor)
40
+ flavor
41
+ else
42
+ f = Yao::Resources::Flavor.list.select{|f| f.name == flavor}
43
+ if f.size > 1
44
+ puts "Error: flavor is not uniq. please use uuid."
45
+ exit 1
46
+ end
47
+ f[0].id
48
+ end
49
+
50
+ image = if is_uuid?(image)
51
+ image
52
+ else
53
+ i = Yao::Resources::Image.list.select{|i| i.name == image}
54
+ if i.size > 1
55
+ puts "Error: image is not uniq. please use uuid."
56
+ exit 1
57
+ end
58
+ i[0].id
59
+ end
60
+
61
+ params = {
62
+ "name" => name,
63
+ "flavorRef" => flavor,
64
+ "imageRef" => image,
65
+ }
66
+
67
+ params.merge!({"networks" => [{"uuid" => network}]}) unless network.nil?
68
+ params.merge!({"networks" => [{"port" => port}]}) unless port.nil?
69
+
70
+ p Yao::Resources::Server.create(params)
71
+ end
72
+
73
+ desc "destroy <name>", "destroy server"
74
+ def destroy(id_or_name)
75
+ p Yao::Resources::Server.destroy(id_or_name)
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,5 @@
1
+ module Yao
2
+ module Cli
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ require 'yao'
2
+
3
+ require 'yao/resources/dumper/base'
4
+ require 'yao/resources/dumper/server'
5
+ require 'yao/resources/dumper/flavor'
6
+ require 'yao/resources/dumper/image'
7
+
8
+ module Yao::Resources
9
+ module Dumper
10
+ end
11
+ end
@@ -0,0 +1,43 @@
1
+ module Yao::Resources::Dumper
2
+ class Base
3
+
4
+ def self.fields=(v)
5
+ @fields = v
6
+ end
7
+
8
+ def self.dump(obj)
9
+ [obj].flatten.map do |o|
10
+ arr = @fields.map{|field|
11
+ result = o.send(field)
12
+
13
+ result = if result.instance_of?(Array)
14
+ result.map{|r| resource_dump(r)}
15
+ else
16
+ resource_dump(result)
17
+ end
18
+
19
+ [field, result]
20
+ }.flatten(1)
21
+
22
+ Hash[*arr]
23
+ end
24
+ end
25
+
26
+ private
27
+ def self.resource_dump(obj)
28
+ result = obj
29
+ if m = obj.class.to_s.match(/^Yao::Resources::(.+)$/)
30
+ if obj.id.nil?
31
+ # とりあえずnameを返しておく(Yao::Resources::SecurityGroup)
32
+ result = {"name": obj.name}
33
+ else
34
+ # Yao::ResourcesにマッピングされているがIDのみなので
35
+ # getして情報を取得する
36
+ resource = obj.class.get(obj.id)
37
+ result = Object.const_get("Yao::Resources::Dumper::#{m[1]}").dump(resource)
38
+ end
39
+ end
40
+ result
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,5 @@
1
+ module Yao::Resources::Dumper
2
+ class Flavor < Base
3
+ self.fields = %w(id name vcpus disk memory public? disabled?)
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ module Yao::Resources::Dumper
2
+ class Image < Base
3
+ self.fields = %w(id name name status progress metadata
4
+ min_disk min_ram size)
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Yao::Resources::Dumper
2
+ class SecurityGroup < Base
3
+ self.fields = %w(id name description tenant_id)
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ module Yao::Resources::Dumper
2
+ class Server < Base
3
+
4
+ self.fields = %w(
5
+ id addresses metadata name progress status tenant_id user_id key_name
6
+ host_id flavor image security_groups availability_zone dcf_disk_config
7
+ ext_srv_attr_host ext_srv_attr_hypervisor_hostname ext_srv_attr_instance_name
8
+ ext_sts_power_state ext_sts_task_state ext_sts_vm_state
9
+ )
10
+
11
+ end
12
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "yao/cli/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "yao-cli"
8
+ spec.version = Yao::Cli::VERSION
9
+ spec.authors = ["Yuki Koya"]
10
+ spec.email = ["ykky@pepabo.com"]
11
+
12
+ spec.summary = %q{CLI tool of yao.}
13
+ spec.description = %q{CLI tool of yao.}
14
+ spec.homepage = "https://github.com/buty4649/yao-cli"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "yao", ">= 0.3.5"
24
+ spec.add_dependency "thor"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.15"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yao-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yuki Koya
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: yao
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.3.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.15'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.15'
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: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: CLI tool of yao.
84
+ email:
85
+ - ykky@pepabo.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - exec/yao
100
+ - lib/yao/cli.rb
101
+ - lib/yao/cli/base.rb
102
+ - lib/yao/cli/formatter.rb
103
+ - lib/yao/cli/formatter/json.rb
104
+ - lib/yao/cli/formatter/yaml.rb
105
+ - lib/yao/cli/main.rb
106
+ - lib/yao/cli/server.rb
107
+ - lib/yao/cli/version.rb
108
+ - lib/yao/resources/dumper.rb
109
+ - lib/yao/resources/dumper/base.rb
110
+ - lib/yao/resources/dumper/flavor.rb
111
+ - lib/yao/resources/dumper/image.rb
112
+ - lib/yao/resources/dumper/security_group.rb
113
+ - lib/yao/resources/dumper/server.rb
114
+ - yao-cli.gemspec
115
+ homepage: https://github.com/buty4649/yao-cli
116
+ licenses: []
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.6.11
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: CLI tool of yao.
138
+ test_files: []