kakin 0.2.1 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9caa520a2dbba63006fe6469ec9a0a88426040b46c321c7d5f50c651b885638c
4
- data.tar.gz: d90a075e0c37f7353102f57c1df6f19ff9d5af37e132c0e760d1236cc6b5dbd7
3
+ metadata.gz: d7aedf46ab98443805029bb0b5d29402c041b6acb8742e733928c8587fd4342c
4
+ data.tar.gz: fd2ba45197979df575a0b28c76c03b288346b576163b2e3327f7d5f93ca8063a
5
5
  SHA512:
6
- metadata.gz: 3b454a80b04a910ddd132e158ced7cc89103500e6e3283021c12d4c42ffcd13005bda4e41a93518491df687ee79ddc0d8b5b76d44139ad97e652534e253beb15
7
- data.tar.gz: 8c318fee8438f19220cb3eca59dd2898101a36131c5100689bfd176ce484053cdca152667ea7853ab7ac7b0f3d5397885ecd570edc0d163bcd2792784ced81b4
6
+ metadata.gz: 406f5f90699577e3897393a944f3cc490d23d976160298f6d4883793a2b904fd8a11c9352590ac032394f72cd7d4b5607e32fa3405f51da86cda1809fa4aa88c
7
+ data.tar.gz: 788b9855df716ef959feff6a0f357c3d91d352534e35a973ade48f35e1c25c02352ad1acc2107f443038c2dc6ef86f9ad65812e88d0fa701cd70c06ebb798e6d
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
  ```
@@ -26,19 +26,17 @@ module Kakin
26
26
 
27
27
  STDERR.puts "Start: #{start_time}"
28
28
  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"
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
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"]
39
+ tenant_usages = res.body["tenant_usages"]
42
40
  tenants = Yao::Tenant.list
43
41
 
44
42
  unless options[:t].empty?
@@ -1,28 +1,46 @@
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
+ 'identity_api_version' => ENV['OS_IDENTITY_API_VERSION'],
17
+ 'user_domain_name' => ENV['OS_USER_DOMAIN_NAME'],
18
+ 'project_domain_name' => ENV['OS_PROJECT_DOMAIN_NAME'],
19
+ 'timeout' => ENV['YAO_TIMEOUT'],
20
+ 'management_url' => ENV['YAO_MANAGEMENT_URL'],
21
+ 'debug' => ENV['YAO_DEBUG'] || false,
22
+ }
23
+
24
+ file_path = File.expand_path('~/.kakin')
25
+ if File.exist?(file_path)
26
+ yaml = YAML.load_file(file_path)
27
+ config.merge!(yaml)
28
+ end
14
29
 
15
- @@_management_url = yaml['management_url']
16
- @@_tenant = yaml['tenant']
30
+ @@_tenant = config['tenant']
17
31
 
18
32
  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']
33
+ auth_url config['auth_url']
34
+ tenant_name config['tenant']
35
+ username config['username']
36
+ password config['password']
37
+ timeout config['timeout'] if config['timeout']
38
+ client_cert config['client_cert'] if config['client_cert']
39
+ client_key config['client_key'] if config['client_key']
40
+ identity_api_version config['identity_api_version'] if config['identity_api_version']
41
+ user_domain_name config['user_domain_name'] if config['user_domain_name']
42
+ project_domain_name config['project_domain_name'] if config['project_domain_name']
43
+ debug config['debug']
26
44
  end
27
45
  end
28
46
  end
@@ -1,3 +1,3 @@
1
1
  module Kakin
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.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.2.1
4
+ version: 0.3.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: 2018-11-16 00:00:00.000000000 Z
12
+ date: 2019-02-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor