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 +4 -4
- data/kakin.gemspec +2 -2
- data/lib/kakin/cli.rb +39 -47
- data/lib/kakin/version.rb +1 -1
- metadata +9 -10
- data/lib/kakin/yao_ext/floatingip.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f0752b03aae430bf490e83b28e5b69d5e0923279ca991c2a71399c90baaa146
|
4
|
+
data.tar.gz: 9326074cb9e2cab64ac03b4824c6d477954d50fc210be60eee6bd35b82a82c53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
22
|
+
spec.add_dependency 'yao', ">= 0.14.0"
|
23
23
|
|
24
|
-
spec.add_development_dependency "bundler", "
|
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: :
|
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
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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::
|
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
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
|
+
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:
|
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.
|
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: 2.
|
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.
|
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.
|
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
|