hammer_cli_csv 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NmZkZjQ0Zjg5NmI0MDZkNzExZTI5ZGM1MWE2NzA2MjAzMGZiMWRlYw==
4
+ NWRiMTE4MzU5Y2ZmMTI3NDM2MGQ4OWZhNWM5M2RiODIyYmI4OWMyOQ==
5
5
  data.tar.gz: !binary |-
6
- MWYyZWY2MWQxNTMwNWM0ODBkN2I3Y2Q0ZmQzNmJmZTRiZTgwZTEwMw==
6
+ ZDc0MTdjMjliZDk4NTMyODZhNmFkYjhjN2M1NmM2OGY4NTlkMDczNw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZGQxN2E3Mjg4MzRiN2Y2Y2VhNGY3NDhjZDI3YTkwMjU3MGUxMzQ2ODBkNmE4
10
- YjFjNTUwMWI4NmIyNmFiMzE0NjdjYjVhZmM3NTE1MWZlNDMxNzYzNjZlYmJh
11
- MzI0YWJlMDE5MTViOTEyOTIxOGI3NDAzMDQ1ZjI5OGJmODA4M2U=
9
+ YzIzNzhkYjE5OWJmZjQyNGRkZDJhNTExY2I0YWYxMWE5NWI2YWIxODA1MjIx
10
+ ODkwNDNiYWM5NjczZjY3NTlmMzlhNTJkN2ExOTllNmQ3Y2MxNWY0OWVmYTE4
11
+ ZTY3YWEwOGFkNmYzMjJlNTMyYjFiZjI0NGY2ZDk4YjA1NTQ3YzQ=
12
12
  data.tar.gz: !binary |-
13
- NzIzZGE4OTg1NmE1ZDc0NjFiYjgzZjExZmQ1ODdkZmM2YmJlNGRhMmExODQ4
14
- MWNhYWQ3MGI3NzIzMzQzZmVkYWM1ODAxYWZiODI3ZDAyNThlNWY4MDNhYmJl
15
- OGZhNjQzMzU2ZDZjY2I2MTRiNWQxOWNiYmRjOTU3ZWNmZjU2Yzk=
13
+ ZWM4ODcwZTdmOGE2OTVkYTgyOWYxMzAxODI3ZmRjYTVjZmFmMGFjYzg4OWUw
14
+ ZWI4YmMzYmRhNTg1MDI1OWVkOTcwMTk4YjVkM2Y5N2NkOWUzNWY1MTRjMzlk
15
+ NDBmMmUxNGFlMTVjY2ViMDA5OTgxNTEyY2RkNzVhMzg1YjIzNDY=
@@ -56,19 +56,19 @@ module HammerCLICsv
56
56
 
57
57
  @server_status = check_server_status
58
58
 
59
- unless @server_status['release'] == 'Headpin'
59
+ if @server_status['release'] == 'Headpin'
60
+ @headpin = HeadpinApi.new({
61
+ :server => server,
62
+ :username => username,
63
+ :password => password
64
+ })
65
+ else
60
66
  @api = ApipieBindings::API.new({
61
67
  :uri => server,
62
68
  :username => username,
63
69
  :password => password,
64
70
  :api_version => 2
65
71
  })
66
- else
67
- @headpin = HeadpinApi.new({
68
- :server => server,
69
- :username => username,
70
- :password => password
71
- })
72
72
  end
73
73
 
74
74
  option_csv_export? ? export : import
@@ -81,9 +81,10 @@ module HammerCLICsv
81
81
  password = option_password || HammerCLI::Settings.get(:csv, :password)
82
82
  url = "#{server}/api/status"
83
83
  uri = URI(url)
84
- server_status = Net::HTTP.start(uri.host, uri.port,
85
- :use_ssl => uri.scheme == 'https',
86
- :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
84
+ nethttp = Net::HTTP.new(uri.host, uri.port)
85
+ nethttp.use_ssl = uri.scheme == 'https'
86
+ nethttp.verify_mode = OpenSSL::SSL::VERIFY_NONE
87
+ server_status = nethttp.start do |http|
87
88
  request = Net::HTTP::Get.new uri.request_uri
88
89
  request.basic_auth(username, password)
89
90
  response = http.request(request)
@@ -58,7 +58,7 @@ module HammerCLICsv
58
58
  CSV.open(option_csv_file || '/dev/stdout', 'wb', {:force_quotes => false}) do |csv|
59
59
  csv << [NAME, COUNT, ORGANIZATION, ENVIRONMENT, CONTENTVIEW, HOSTCOLLECTIONS, VIRTUAL, HOST,
60
60
  OPERATINGSYSTEM, ARCHITECTURE, SOCKETS, RAM, CORES, SLA, PRODUCTS, SUBSCRIPTIONS]
61
- if option_sam?
61
+ if @server_status['release'] == 'Headpin'
62
62
  export_sam csv
63
63
  else
64
64
  export_foretello csv
@@ -68,51 +68,19 @@ module HammerCLICsv
68
68
 
69
69
  def export_sam(csv)
70
70
  guests_host = {}
71
+ system_ids = []
71
72
 
72
- server = option_server || HammerCLI::Settings.get(:csv, :host)
73
- username = option_username || HammerCLI::Settings.get(:csv, :username)
74
- password = option_password || HammerCLI::Settings.get(:csv, :password)
75
- url = "#{server}/api/systems?organization_id=satellite-1"
76
- uri = URI(url)
77
- system_ids = Net::HTTP.start(uri.host, uri.port,
78
- :use_ssl => uri.scheme == 'https',
79
- :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
80
- request = Net::HTTP::Get.new uri.request_uri
81
- request.basic_auth(username, password)
82
- response = http.request(request)
83
-
84
- JSON.parse(response.body).collect do |system|
73
+ @headpin.get(:organizations).each do |organization|
74
+ #url = "#{server}/api/systems?organization_id=satellite-1"
75
+ system_ids = @headpin.get("organizations/#{organization['label']}/systems").collect do |system|
85
76
  system['guests'].each { |guest| guests_host[guest['uuid']] = system['name'] }
86
77
  system['uuid']
87
78
  end
88
79
  end
89
80
 
90
- #system_ids = ['327bf5cc-5498-4927-aa27-39b1503edf58', 'eeb6de95-afaf-4b14-9f92-e845ff269ccb']
91
-
92
81
  system_ids.each do |system_id|
93
- url = "#{server}/api/systems/#{system_id}"
94
- uri = URI(url)
95
- system = Net::HTTP.start(uri.host, uri.port,
96
- :use_ssl => uri.scheme == 'https',
97
- :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
98
- request = Net::HTTP::Get.new uri.request_uri
99
- request.basic_auth(username, password)
100
- response = http.request(request)
101
-
102
- JSON.parse(response.body)
103
- end
104
-
105
- url = "#{server}/api/systems/#{system_id}/subscriptions"
106
- uri = URI(url)
107
- system_subscriptions = Net::HTTP.start(uri.host, uri.port,
108
- :use_ssl => uri.scheme == 'https',
109
- :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
110
- request = Net::HTTP::Get.new uri.request_uri
111
- request.basic_auth(username, password)
112
- response = http.request(request)
113
-
114
- JSON.parse(response.body)['entitlements']
115
- end
82
+ system = @headpin.get("systems/#{system_id}")
83
+ system_subscriptions = @headpin.get("systems/#{system_id}/subscriptions")['entitlements']
116
84
 
117
85
  name = system['name']
118
86
  count = 1
@@ -22,14 +22,16 @@ module HammerCLICsv
22
22
  def get(name)
23
23
  url = "#{@server}/api/#{name}"
24
24
  uri = URI(url)
25
- Net::HTTP.start(uri.host, uri.port,
26
- :use_ssl => uri.scheme == 'https',
27
- :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
25
+ nethttp = Net::HTTP.new(uri.host, uri.port)
26
+ nethttp.use_ssl = uri.scheme == 'https'
27
+ nethttp.verify_mode = OpenSSL::SSL::VERIFY_NONE
28
+ results = nethttp.start do |http|
28
29
  request = Net::HTTP::Get.new uri.request_uri
29
30
  request.basic_auth(@username, @password)
30
31
  response = http.request(request)
31
- return JSON.parse(response.body)
32
+ JSON.parse(response.body)
32
33
  end
34
+ results
33
35
  end
34
36
 
35
37
  def environment(id)
@@ -11,6 +11,6 @@
11
11
 
12
12
  module HammerCLICsv
13
13
  def self.version
14
- @version ||= Gem::Version.new('0.0.4')
14
+ @version ||= Gem::Version.new('0.0.6')
15
15
  end
16
16
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hammer_cli_csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom McKay