kakin 0.4.2 → 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: f7cb1340339d2148723e93bb46b0c2c77a4d427e3f82181313f496db67453c43
4
- data.tar.gz: 8c260ea3698a258a5c46f86d4e161d3fa9a8f565b2f6d48022cddbb854c61a3b
3
+ metadata.gz: 5f0752b03aae430bf490e83b28e5b69d5e0923279ca991c2a71399c90baaa146
4
+ data.tar.gz: 9326074cb9e2cab64ac03b4824c6d477954d50fc210be60eee6bd35b82a82c53
5
5
  SHA512:
6
- metadata.gz: d587580a83521e4a5fb0271f963a30e54c34b6811d934f7def836d6e380e79e2338c5b5cd79d7cfa6b3e12889fb85f65dfbf2e84b53092e16b500a0d55541aa4
7
- data.tar.gz: eb9fab2617a8be2876b2e502656ae679a4078ae9bcfd7c57fdc7d8de47b6caeca26711061dd49cb6e3f0fadf45db84240099ac080fd003d054956c3f30e4ebec
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', ">= 0.13.4"
22
+ spec.add_dependency 'yao', ">= 0.14.0"
23
23
 
24
- spec.add_development_dependency "bundler", "~> 2.1.4"
24
+ spec.add_development_dependency "bundler", ">= 2.2.10"
25
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
@@ -6,7 +6,6 @@ require 'yao'
6
6
  require 'kakin/yao_ext/yao'
7
7
  require 'kakin/yao_ext/tenant'
8
8
  require 'kakin/yao_ext/server'
9
- require 'kakin/yao_ext/floatingip'
10
9
  require 'thor'
11
10
 
12
11
  module Kakin
@@ -16,7 +15,8 @@ module Kakin
16
15
  option :f, type: :string, banner: "<file>", desc: "cost define file(yaml)", required: true
17
16
  option :s, type: :string, banner: "<start>", desc: "start time", default: (DateTime.now << 1).strftime("%Y-%m-01")
18
17
  option :e, type: :string, banner: "<end>", desc: "end time", default: Time.now.strftime("%Y-%m-01")
19
- 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: []
20
20
  desc 'calc', 'Calculate the cost'
21
21
  def calc
22
22
  Kakin::Configuration.setup
@@ -24,55 +24,47 @@ module Kakin
24
24
  yaml = YAML.load_file(options[:f])
25
25
  start_time = Time.parse(options[:s]).strftime("%FT%T")
26
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
27
38
 
28
39
  STDERR.puts "Start: #{start_time}"
29
40
  STDERR.puts "End: #{end_time}"
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
36
- raise "usage data fatch is failed"
37
- else
38
- result = Hash.new
39
- tenant_usages = res.body["tenant_usages"]
40
- tenants = Yao.tenant_klass.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_id = usage["tenant_id"]
51
- tenant = tenants.find { |tenant| tenant.id == tenant_id }
52
- tenant_name = tenant&.name || tenant_id
53
-
54
- total_vcpus_usage = usage["total_vcpus_usage"]
55
- total_memory_mb_usage = usage["total_memory_mb_usage"]
56
- total_local_gb_usage = usage["total_local_gb_usage"]
57
-
58
- bill_vcpu = total_vcpus_usage * yaml["vcpu_per_hour"]
59
- bill_memory = total_memory_mb_usage * yaml["memory_mb_per_hour"]
60
- bill_disk = total_local_gb_usage * yaml["disk_gb_per_hour"]
61
-
62
- result[tenant_name] = {
63
- 'bill_total' => bill_vcpu + bill_memory + bill_disk,
64
- 'bill_vcpu' => bill_vcpu,
65
- 'bill_memory' => bill_memory,
66
- 'bill_disk' => bill_disk,
67
- 'total_hours' => usage["total_hours"],
68
- 'total_vcpus_usage' => total_vcpus_usage,
69
- 'total_memory_mb_usage' => total_memory_mb_usage,
70
- 'total_local_gb_usage' => total_local_gb_usage,
71
- }
72
- end
73
-
74
- 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
+ }
75
65
  end
66
+
67
+ puts YAML.dump(result)
76
68
  end
77
69
 
78
70
  option :f, type: :string, banner: "<file>", desc: "cost define file(yaml)", required: true
@@ -130,7 +122,7 @@ module Kakin
130
122
 
131
123
  tenants.each do |tenant|
132
124
  count = tenant.ports.select {|p| p.fixed_ips[0]["ip_address"] =~ ip_regexp}.count
133
- 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
134
126
  result[tenant.name] = {
135
127
  'count' => count,
136
128
  'total_usage' => count * yaml["cost_per_ip"],
data/lib/kakin/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Kakin
2
- VERSION = "0.4.2"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kakin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - buty4649
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-10-14 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,28 +31,28 @@ dependencies:
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: 0.13.4
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.13.4
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: 2.1.4
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: 2.1.4
55
+ version: 2.2.10
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rake
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -104,7 +104,6 @@ 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
110
109
  - lib/kakin/yao_ext/yao.rb
@@ -126,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
125
  - !ruby/object:Gem::Version
127
126
  version: '0'
128
127
  requirements: []
129
- rubygems_version: 3.0.3
128
+ rubygems_version: 3.2.32
130
129
  signing_key:
131
130
  specification_version: 4
132
131
  summary: kakin is resource calcuration tool for OpenStack
@@ -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