kakin 0.2.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9caa520a2dbba63006fe6469ec9a0a88426040b46c321c7d5f50c651b885638c
4
- data.tar.gz: d90a075e0c37f7353102f57c1df6f19ff9d5af37e132c0e760d1236cc6b5dbd7
3
+ metadata.gz: f7cb1340339d2148723e93bb46b0c2c77a4d427e3f82181313f496db67453c43
4
+ data.tar.gz: 8c260ea3698a258a5c46f86d4e161d3fa9a8f565b2f6d48022cddbb854c61a3b
5
5
  SHA512:
6
- metadata.gz: 3b454a80b04a910ddd132e158ced7cc89103500e6e3283021c12d4c42ffcd13005bda4e41a93518491df687ee79ddc0d8b5b76d44139ad97e652534e253beb15
7
- data.tar.gz: 8c318fee8438f19220cb3eca59dd2898101a36131c5100689bfd176ce484053cdca152667ea7853ab7ac7b0f3d5397885ecd570edc0d163bcd2792784ced81b4
6
+ metadata.gz: d587580a83521e4a5fb0271f963a30e54c34b6811d934f7def836d6e380e79e2338c5b5cd79d7cfa6b3e12889fb85f65dfbf2e84b53092e16b500a0d55541aa4
7
+ data.tar.gz: eb9fab2617a8be2876b2e502656ae679a4078ae9bcfd7c57fdc7d8de47b6caeca26711061dd49cb6e3f0fadf45db84240099ac080fd003d054956c3f30e4ebec
data/README.md CHANGED
@@ -12,12 +12,20 @@ You need to create configuration file located `~/.kakin` for openstack credentia
12
12
 
13
13
  ```
14
14
  auth_url: "http://your-openstack-host:35357/v2.0/tokens"
15
- management_url: "http://your-openstack-host:8774/v2"
16
15
  username: "username"
17
16
  tenant: "your-admin-tenant"
18
17
  password: "password"
19
18
  ```
20
19
 
20
+ Or set with environment variable.
21
+
22
+ ```
23
+ export OS_AUTH_URL=<your openstack auth url>
24
+ export OS_USER=<your username>
25
+ export OS_TENANT_NAME=<your tenant>
26
+ export OS_PASSWORD=<your password>
27
+ ```
28
+
21
29
  You can get resource usage with following command.
22
30
 
23
31
  ```
@@ -19,9 +19,9 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency 'thor'
22
- spec.add_dependency 'yao'
22
+ spec.add_dependency 'yao', ">= 0.13.4"
23
23
 
24
- spec.add_development_dependency "bundler", "~> 1.10"
25
- spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "bundler", "~> 2.1.4"
25
+ spec.add_development_dependency "rake", ">= 12.3.3"
26
26
  spec.add_development_dependency "minitest"
27
27
  end
@@ -3,6 +3,7 @@ require 'yaml'
3
3
  require 'json'
4
4
  require 'net/http'
5
5
  require 'yao'
6
+ require 'kakin/yao_ext/yao'
6
7
  require 'kakin/yao_ext/tenant'
7
8
  require 'kakin/yao_ext/server'
8
9
  require 'kakin/yao_ext/floatingip'
@@ -26,20 +27,17 @@ module Kakin
26
27
 
27
28
  STDERR.puts "Start: #{start_time}"
28
29
  STDERR.puts "End: #{end_time}"
29
- url = URI.parse("#{Kakin::Configuration.management_url}/#{Yao::Tenant.get_by_name(Kakin::Configuration.tenant).id}/os-simple-tenant-usage?start=#{start_time}&end=#{end_time}")
30
- req = Net::HTTP::Get.new(url)
31
- req["Accept"] = "application/json"
32
- req["X-Auth-Token"] = Yao::Auth.try_new.token
33
- res = Net::HTTP.start(url.host, url.port) {|http|
34
- http.request(req)
35
- }
36
-
37
- if res.code != "200"
30
+ client = Yao.default_client.pool['compute']
31
+ res = client.get("./os-simple-tenant-usage?start=#{start_time}&end=#{end_time}") do |req|
32
+ req.headers["Accept"] = "application/json"
33
+ end
34
+
35
+ if res.status != 200
38
36
  raise "usage data fatch is failed"
39
37
  else
40
38
  result = Hash.new
41
- tenant_usages = JSON.load(res.body)["tenant_usages"]
42
- tenants = Yao::Tenant.list
39
+ tenant_usages = res.body["tenant_usages"]
40
+ tenants = Yao.tenant_klass.list
43
41
 
44
42
  unless options[:t].empty?
45
43
  tenant = tenants.find { |tenant| tenant.name == options[:t] }
@@ -49,7 +47,9 @@ module Kakin
49
47
  end
50
48
 
51
49
  tenant_usages.each do |usage|
52
- tenant = tenants.find { |tenant| tenant.id == usage["tenant_id"] }
50
+ tenant_id = usage["tenant_id"]
51
+ tenant = tenants.find { |tenant| tenant.id == tenant_id }
52
+ tenant_name = tenant&.name || tenant_id
53
53
 
54
54
  total_vcpus_usage = usage["total_vcpus_usage"]
55
55
  total_memory_mb_usage = usage["total_memory_mb_usage"]
@@ -59,7 +59,7 @@ module Kakin
59
59
  bill_memory = total_memory_mb_usage * yaml["memory_mb_per_hour"]
60
60
  bill_disk = total_local_gb_usage * yaml["disk_gb_per_hour"]
61
61
 
62
- result[tenant.name] = {
62
+ result[tenant_name] = {
63
63
  'bill_total' => bill_vcpu + bill_memory + bill_disk,
64
64
  'bill_vcpu' => bill_vcpu,
65
65
  'bill_memory' => bill_memory,
@@ -92,9 +92,9 @@ module Kakin
92
92
 
93
93
  result = Hash.new
94
94
  tenants = unless options[:t].empty?
95
- Yao::Tenant.list(name: options[:t])
95
+ Yao.tenant_klass.list(name: options[:t])
96
96
  else
97
- Yao::Tenant.list
97
+ Yao.tenant_klass.list
98
98
  end
99
99
  tenants = [tenants] unless tenants.is_a?(Array)
100
100
 
@@ -122,9 +122,9 @@ module Kakin
122
122
 
123
123
  result = Hash.new
124
124
  tenants = unless options[:t].empty?
125
- Yao::Tenant.list(name: options[:t])
125
+ Yao.tenant_klass.list(name: options[:t])
126
126
  else
127
- Yao::Tenant.list
127
+ Yao.tenant_klass.list
128
128
  end
129
129
  tenants = [tenants] unless tenants.is_a?(Array)
130
130
 
@@ -149,9 +149,9 @@ module Kakin
149
149
 
150
150
  result = Hash.new
151
151
  tenants = unless options[:t].empty?
152
- Yao::Tenant.list(name: options[:t])
152
+ Yao.tenant_klass.list(name: options[:t])
153
153
  else
154
- Yao::Tenant.list
154
+ Yao.tenant_klass.list
155
155
  end
156
156
  tenants = [tenants] unless tenants.is_a?(Array)
157
157
  volume_types = Yao::VolumeType.list
@@ -1,28 +1,48 @@
1
1
  module Kakin
2
2
  class Configuration
3
3
 
4
- def self.management_url
5
- @@_management_url
6
- end
7
-
8
4
  def self.tenant
9
5
  @@_tenant
10
6
  end
11
7
 
12
8
  def self.setup
13
- yaml = YAML.load_file(File.expand_path('~/.kakin'))
9
+ config = {
10
+ 'auth_url' => ENV['OS_AUTH_URL'],
11
+ 'tenant' => ENV['OS_TENANT_NAME'] || ENV['OS_PROJECT_NAME'],
12
+ 'username' => ENV['OS_USERNAME'],
13
+ 'password' => ENV['OS_PASSWORD'],
14
+ 'client_cert' => ENV['OS_CERT'],
15
+ 'client_key' => ENV['OS_KEY'],
16
+ 'ca_cert' => ENV['OS_CACERT'],
17
+ 'identity_api_version' => ENV['OS_IDENTITY_API_VERSION'],
18
+ 'user_domain_name' => ENV['OS_USER_DOMAIN_NAME'],
19
+ 'project_domain_name' => ENV['OS_PROJECT_DOMAIN_NAME'],
20
+ 'timeout' => ENV['YAO_TIMEOUT'],
21
+ 'management_url' => ENV['YAO_MANAGEMENT_URL'],
22
+ 'debug' => ENV['YAO_DEBUG'] || false,
23
+ }
24
+
25
+ file_path = File.expand_path('~/.kakin')
26
+ if File.exist?(file_path)
27
+ yaml = YAML.load_file(file_path)
28
+ config.merge!(yaml)
29
+ end
14
30
 
15
- @@_management_url = yaml['management_url']
16
- @@_tenant = yaml['tenant']
31
+ @@_tenant = config['tenant']
17
32
 
18
33
  Yao.configure do
19
- auth_url yaml['auth_url']
20
- tenant_name yaml['tenant']
21
- username yaml['username']
22
- password yaml['password']
23
- timeout yaml['timeout'] if yaml['timeout']
24
- client_cert yaml['client_cert'] if yaml['client_cert']
25
- client_key yaml['client_key'] if yaml['client_key']
34
+ auth_url config['auth_url']
35
+ tenant_name config['tenant']
36
+ username config['username']
37
+ password config['password']
38
+ timeout config['timeout'].to_i if config['timeout']
39
+ ca_cert config['ca_cert'] if config['ca_cert']
40
+ client_cert config['client_cert'] if config['client_cert']
41
+ client_key config['client_key'] if config['client_key']
42
+ identity_api_version config['identity_api_version'] if config['identity_api_version']
43
+ user_domain_name config['user_domain_name'] if config['user_domain_name']
44
+ project_domain_name config['project_domain_name'] if config['project_domain_name']
45
+ debug config['debug']
26
46
  end
27
47
  end
28
48
  end
@@ -1,3 +1,3 @@
1
1
  module Kakin
2
- VERSION = "0.2.1"
2
+ VERSION = "0.4.2"
3
3
  end
@@ -0,0 +1,10 @@
1
+ module Yao
2
+ def self.tenant_klass
3
+ Yao.keystone_v2? ? Yao::Tenant : Yao::Project
4
+ end
5
+
6
+ # @return [Bool]
7
+ def self.keystone_v2?
8
+ Yao.default_client.pool["identity"].url_prefix.to_s.match(/v2\.0/)
9
+ end
10
+ end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kakin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - buty4649
8
8
  - SHIBATA Hiroshi
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-11-16 00:00:00.000000000 Z
12
+ date: 2020-10-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -31,42 +31,42 @@ dependencies:
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: '0'
34
+ version: 0.13.4
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: '0'
41
+ version: 0.13.4
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: bundler
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '1.10'
48
+ version: 2.1.4
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '1.10'
55
+ version: 2.1.4
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rake
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - "~>"
60
+ - - ">="
61
61
  - !ruby/object:Gem::Version
62
- version: '10.0'
62
+ version: 12.3.3
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - "~>"
67
+ - - ">="
68
68
  - !ruby/object:Gem::Version
69
- version: '10.0'
69
+ version: 12.3.3
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: minitest
72
72
  requirement: !ruby/object:Gem::Requirement
@@ -107,10 +107,11 @@ files:
107
107
  - lib/kakin/yao_ext/floatingip.rb
108
108
  - lib/kakin/yao_ext/server.rb
109
109
  - lib/kakin/yao_ext/tenant.rb
110
+ - lib/kakin/yao_ext/yao.rb
110
111
  homepage: https://github.com/yaocloud/kakin
111
112
  licenses: []
112
113
  metadata: {}
113
- post_install_message:
114
+ post_install_message:
114
115
  rdoc_options: []
115
116
  require_paths:
116
117
  - lib
@@ -125,9 +126,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
126
  - !ruby/object:Gem::Version
126
127
  version: '0'
127
128
  requirements: []
128
- rubyforge_project:
129
- rubygems_version: 2.7.6
130
- signing_key:
129
+ rubygems_version: 3.0.3
130
+ signing_key:
131
131
  specification_version: 4
132
132
  summary: kakin is resource calcuration tool for OpenStack
133
133
  test_files: []