kakin 0.3.1 → 0.5.0

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: 3cb8efde1aaf89f79943e1430156764e6e96983cf35f7d6fac5bca89362dccce
4
- data.tar.gz: f8ad30e03dc74e4ad47e7d8f4f423e87ab1ee0d0c8bc08a12fb458697d7df08a
3
+ metadata.gz: 5f0752b03aae430bf490e83b28e5b69d5e0923279ca991c2a71399c90baaa146
4
+ data.tar.gz: 9326074cb9e2cab64ac03b4824c6d477954d50fc210be60eee6bd35b82a82c53
5
5
  SHA512:
6
- metadata.gz: '049ad99c0c396f8e80c163c990b5fd75399c80e6736f92fbb8cc6a21e1d359f528fdb3081dc538cf2a71a59293ab73042680a85bf112d3bf5d901b67a24b3e03'
7
- data.tar.gz: 8e7ca17705acfd89b4187e9ec769abb0e49e741bf31b869e19d4eb08652bfe72a8e1e4c243de82f94d686d6e1addb320a21e25e6ac2255f9e4661b828a571b6c
6
+ metadata.gz: e429c4356d032c61f9183379ee51548bbae1ce24da90740bb013661c8963af05473586c91af283555ee82e3132111b9848a33ac9be3e5bafc4a3cfa046ad210a
7
+ data.tar.gz: 9a1076127b78ee0bd99dcfc6fffa60a61e99dfd6f7ae06c5a0647af3107b5c6f56364b2c6b01d7896e1e54c3c0d9aa8b4a0067e87f59cbf29384bd66285b3981
data/kakin.gemspec CHANGED
@@ -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.14.0"
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.2.10"
25
+ spec.add_development_dependency "rake", ">= 12.3.3"
26
26
  spec.add_development_dependency "minitest"
27
27
  end
data/lib/kakin/cli.rb CHANGED
@@ -3,9 +3,9 @@ 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
- require 'kakin/yao_ext/floatingip'
9
9
  require 'thor'
10
10
 
11
11
  module Kakin
@@ -15,7 +15,8 @@ module Kakin
15
15
  option :f, type: :string, banner: "<file>", desc: "cost define file(yaml)", required: true
16
16
  option :s, type: :string, banner: "<start>", desc: "start time", default: (DateTime.now << 1).strftime("%Y-%m-01")
17
17
  option :e, type: :string, banner: "<end>", desc: "end time", default: Time.now.strftime("%Y-%m-01")
18
- option :t, type: :string, banner: "<tenant>", desc: "specify tenant", default: ""
18
+ option :t, type: :array, banner: "<tenant>", desc: "specify tenants"
19
+ option :S, type: :array, banner: "<tenant>", desc: "skip tenants", default: []
19
20
  desc 'calc', 'Calculate the cost'
20
21
  def calc
21
22
  Kakin::Configuration.setup
@@ -23,54 +24,47 @@ module Kakin
23
24
  yaml = YAML.load_file(options[:f])
24
25
  start_time = Time.parse(options[:s]).strftime("%FT%T")
25
26
  end_time = Time.parse(options[:e]).strftime("%FT%T")
27
+ skip = options[:S]
28
+ tenants = if tenants = options[:t]
29
+ tenants.map do |tenant|
30
+ Yao.tenant_klass.get(tenant)
31
+ end
32
+ else
33
+ Yao.tenant_klass.list
34
+ end.select do |tenant|
35
+ name = tenant.name || tenant.id
36
+ !skip.include?(name)
37
+ end
26
38
 
27
39
  STDERR.puts "Start: #{start_time}"
28
40
  STDERR.puts "End: #{end_time}"
29
- client = Yao.default_client.pool['compute']
30
- tenant_id = Yao::Tenant.get_by_name(Kakin::Configuration.tenant).id
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
36
- raise "usage data fatch is failed"
37
- else
38
- result = Hash.new
39
- tenant_usages = res.body["tenant_usages"]
40
- tenants = Yao::Tenant.list
41
-
42
- unless options[:t].empty?
43
- tenant = tenants.find { |tenant| tenant.name == options[:t] }
44
- raise "Not Found tenant #{options[:t]}" unless tenant
45
41
 
46
- tenant_usages = tenant_usages.select { |tenant_usage| tenant_usage["tenant_id"] == tenant.id }
47
- end
48
-
49
- tenant_usages.each do |usage|
50
- tenant = tenants.find { |tenant| tenant.id == usage["tenant_id"] }
51
-
52
- total_vcpus_usage = usage["total_vcpus_usage"]
53
- total_memory_mb_usage = usage["total_memory_mb_usage"]
54
- total_local_gb_usage = usage["total_local_gb_usage"]
55
-
56
- bill_vcpu = total_vcpus_usage * yaml["vcpu_per_hour"]
57
- bill_memory = total_memory_mb_usage * yaml["memory_mb_per_hour"]
58
- bill_disk = total_local_gb_usage * yaml["disk_gb_per_hour"]
59
-
60
- result[tenant.name] = {
61
- 'bill_total' => bill_vcpu + bill_memory + bill_disk,
62
- 'bill_vcpu' => bill_vcpu,
63
- 'bill_memory' => bill_memory,
64
- 'bill_disk' => bill_disk,
65
- 'total_hours' => usage["total_hours"],
66
- 'total_vcpus_usage' => total_vcpus_usage,
67
- 'total_memory_mb_usage' => total_memory_mb_usage,
68
- 'total_local_gb_usage' => total_local_gb_usage,
69
- }
70
- end
71
-
72
- puts YAML.dump(result)
42
+ result = tenants.each_with_object({}) do |tenant, result|
43
+ usage = tenant.server_usage(start: start_time, end: end_time)
44
+ next if usage.empty?
45
+
46
+ total_vcpus_usage = usage["total_vcpus_usage"]
47
+ total_memory_mb_usage = usage["total_memory_mb_usage"]
48
+ total_local_gb_usage = usage["total_local_gb_usage"]
49
+
50
+ bill_vcpu = total_vcpus_usage * yaml["vcpu_per_hour"]
51
+ bill_memory = total_memory_mb_usage * yaml["memory_mb_per_hour"]
52
+ bill_disk = total_local_gb_usage * yaml["disk_gb_per_hour"]
53
+
54
+ name = tenant.name || tenant.id
55
+ result[name] = {
56
+ 'bill_total' => bill_vcpu + bill_memory + bill_disk,
57
+ 'bill_vcpu' => bill_vcpu,
58
+ 'bill_memory' => bill_memory,
59
+ 'bill_disk' => bill_disk,
60
+ 'total_hours' => usage["total_hours"],
61
+ 'total_vcpus_usage' => total_vcpus_usage,
62
+ 'total_memory_mb_usage' => total_memory_mb_usage,
63
+ 'total_local_gb_usage' => total_local_gb_usage,
64
+ }
73
65
  end
66
+
67
+ puts YAML.dump(result)
74
68
  end
75
69
 
76
70
  option :f, type: :string, banner: "<file>", desc: "cost define file(yaml)", required: true
@@ -90,9 +84,9 @@ module Kakin
90
84
 
91
85
  result = Hash.new
92
86
  tenants = unless options[:t].empty?
93
- Yao::Tenant.list(name: options[:t])
87
+ Yao.tenant_klass.list(name: options[:t])
94
88
  else
95
- Yao::Tenant.list
89
+ Yao.tenant_klass.list
96
90
  end
97
91
  tenants = [tenants] unless tenants.is_a?(Array)
98
92
 
@@ -120,15 +114,15 @@ module Kakin
120
114
 
121
115
  result = Hash.new
122
116
  tenants = unless options[:t].empty?
123
- Yao::Tenant.list(name: options[:t])
117
+ Yao.tenant_klass.list(name: options[:t])
124
118
  else
125
- Yao::Tenant.list
119
+ Yao.tenant_klass.list
126
120
  end
127
121
  tenants = [tenants] unless tenants.is_a?(Array)
128
122
 
129
123
  tenants.each do |tenant|
130
124
  count = tenant.ports.select {|p| p.fixed_ips[0]["ip_address"] =~ ip_regexp}.count
131
- count += Yao::NetworkingFloatingIP.list(tenant_id: tenant.id).select {|p| p.floating_ip_address =~ ip_regexp}.count
125
+ count += Yao::FloatingIP.list(tenant_id: tenant.id).select {|p| p.floating_ip_address =~ ip_regexp}.count
132
126
  result[tenant.name] = {
133
127
  'count' => count,
134
128
  'total_usage' => count * yaml["cost_per_ip"],
@@ -147,9 +141,9 @@ module Kakin
147
141
 
148
142
  result = Hash.new
149
143
  tenants = unless options[:t].empty?
150
- Yao::Tenant.list(name: options[:t])
144
+ Yao.tenant_klass.list(name: options[:t])
151
145
  else
152
- Yao::Tenant.list
146
+ Yao.tenant_klass.list
153
147
  end
154
148
  tenants = [tenants] unless tenants.is_a?(Array)
155
149
  volume_types = Yao::VolumeType.list
@@ -13,6 +13,7 @@ module Kakin
13
13
  'password' => ENV['OS_PASSWORD'],
14
14
  'client_cert' => ENV['OS_CERT'],
15
15
  'client_key' => ENV['OS_KEY'],
16
+ 'ca_cert' => ENV['OS_CACERT'],
16
17
  'identity_api_version' => ENV['OS_IDENTITY_API_VERSION'],
17
18
  'user_domain_name' => ENV['OS_USER_DOMAIN_NAME'],
18
19
  'project_domain_name' => ENV['OS_PROJECT_DOMAIN_NAME'],
@@ -35,6 +36,7 @@ module Kakin
35
36
  username config['username']
36
37
  password config['password']
37
38
  timeout config['timeout'].to_i if config['timeout']
39
+ ca_cert config['ca_cert'] if config['ca_cert']
38
40
  client_cert config['client_cert'] if config['client_cert']
39
41
  client_key config['client_key'] if config['client_key']
40
42
  identity_api_version config['identity_api_version'] if config['identity_api_version']
data/lib/kakin/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Kakin
2
- VERSION = "0.3.1"
2
+ VERSION = "0.5.0"
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.3.1
4
+ version: 0.5.0
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: 2019-02-20 00:00:00.000000000 Z
12
+ date: 2021-12-03 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.14.0
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.14.0
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.2.10
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.2.10
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
@@ -104,13 +104,13 @@ files:
104
104
  - lib/kakin/cli.rb
105
105
  - lib/kakin/configuration.rb
106
106
  - lib/kakin/version.rb
107
- - lib/kakin/yao_ext/floatingip.rb
108
107
  - lib/kakin/yao_ext/server.rb
109
108
  - lib/kakin/yao_ext/tenant.rb
109
+ - lib/kakin/yao_ext/yao.rb
110
110
  homepage: https://github.com/yaocloud/kakin
111
111
  licenses: []
112
112
  metadata: {}
113
- post_install_message:
113
+ post_install_message:
114
114
  rdoc_options: []
115
115
  require_paths:
116
116
  - lib
@@ -125,9 +125,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  - !ruby/object:Gem::Version
126
126
  version: '0'
127
127
  requirements: []
128
- rubyforge_project:
129
- rubygems_version: 2.7.6
130
- signing_key:
128
+ rubygems_version: 3.2.32
129
+ signing_key:
131
130
  specification_version: 4
132
131
  summary: kakin is resource calcuration tool for OpenStack
133
132
  test_files: []
@@ -1,9 +0,0 @@
1
- module Yao::Resources
2
- class NetworkingFloatingIP < Base
3
- friendly_attributes :floating_network_id, :floating_ip_address, :port_id
4
-
5
- self.service = "network"
6
- self.resource_name = "floatingip"
7
- self.resources_name = "floatingips"
8
- end
9
- end