Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions libraries/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
module CommVault
module Api
def cv_token_local
token = if platform?('windows')
Mixlib::ShellOut.new('C:\\Progra~1\\Commvault\\ContentStore\\Base\\QLogin.exe -localadmin -gt')
else
Mixlib::ShellOut.new('/opt/commvault/Base/qlogin -localadmin -gt')
end
binary = if platform?('windows')
'C:\\Progra~1\\Commvault\\ContentStore\\Base\\QLogin.exe'
else
'/opt/commvault/Base/qlogin'
end
raise "Missing qlogin binary at location: (#{binary})" unless File.exist?(binary)
token = Mixlib::ShellOut.new("#{binary} -localadmin -gt")
token.run_command
raise 'Did not receive a token from the platform' if token.stdout.length <= 10
"QSDK #{token.stdout}"
end

Expand All @@ -26,14 +29,14 @@ def cv_token_api(endpoint, user, pass)
response = _post(url, nil, body)
raise "Incorrect output received while logging into REST API endpoint #{endpoint}" unless response
raise "API gave error code [#{response.code}] for our request to login\nResponse: [#{response.message}]" if response.code.to_i != 200
_extract(response.body(), 'token')
_extract(response.body, 'token')
end

def cv_client_name
if platform?('windows')
registry_get_values('HKLM\SOFTWARE\CommVault Systems\Galaxy\Instance001').select { |x| x[:name].casecmp?('sPhysicalNodeName') }.first[:data]
else
File.readlines('/etc/CommVaultRegistry/Galaxy/Instance001/.properties').grep(/sPhysicalNodeName/)[0].chomp.split[1]
File.readlines('/etc/CommVaultRegistry/Galaxy/Instance001/.properties').grep(/sPhysicalNodeName/).first.chomp.split[1]
end
end

Expand Down Expand Up @@ -161,7 +164,7 @@ def cv_client_id(endpoint, cv_token)
url = URI("#{endpoint}/GetId?clientname=#{cv_client_name}")
response = _get(url, cv_token)
raise "Unable to get client id for client name [#{cv_client_name}]" unless response && response.code.to_i == 200
cid = _extract(response.body(), 'clientId')
cid = _extract(response.body, 'clientId')
raise "Incorrect client id received from API -> [#{cid}], code: [#{response.code}]" unless cid && cid.match(/^(\d)+$/)
cid.to_i
end
Expand Down
2 changes: 1 addition & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
maintainer_email 'int-dms@schubergphilis.com'
license 'Apache-2.0'
description 'Installs and Configured CommVault client software'
version '1.2.1'
version '1.3.0'
chef_version '>= 14.0'

issues_url 'https://github.com/sbp-cookbooks/commvault/issues'
Expand Down
54 changes: 27 additions & 27 deletions resources/fs_subclient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,38 +46,38 @@
end
end

api_token = if new_resource.use_local_login
# Get the api token using qlogin --localadmin
cv_token_local
else
# Get the api token using login to the API
cv_token_api(new_resource.endpoint, new_resource.login_user, new_resource.login_pass)
end

Chef::Log.debug "Token: [#{api_token}]"

# Try 3 times (with 10 secs interval) to get the client id (SAFETY PRECAUTION)
counter = 0
api_token = ''
# Try 3 times (with 30 secs interval) to get the client id (SAFETY PRECAUTION)
counter = 1
loop do
begin
cv_client_id(new_resource.endpoint, api_token)
api_token = if new_resource.use_local_login
# Get the api token using qlogin --localadmin
cv_token_local
else
# Get the api token using login to the API
cv_token_api(new_resource.endpoint, new_resource.login_user, new_resource.login_pass)
end
break
rescue
Chef::Log.warn "Unable to get client id (counter: #{counter}), retrying after sleep of 10 seconds"
sleep(10)
Chef::Log.warn "Unable to get token (counter: #{counter}), retrying after sleep of 30 seconds"
sleep(30)
end

counter += 1
break if counter > 3

# Reinitilize authentication to refresh cache
api_token = if new_resource.use_local_login
# Get the api token using qlogin --localadmin
cv_token_local
else
# Get the api token using login to the API
cv_token_api(new_resource.endpoint, new_resource.login_user, new_resource.login_pass)
end

Chef::Log.debug "Token: [#{api_token}]"
if counter > 8
Chef::Log.error 'Unable to obtain token from platform, bailing for this run'
return
end
end

Chef::Log.debug "Token: [#{api_token}]"

begin
cv_client_id(new_resource.endpoint, api_token)
rescue
Chef::Log.warn 'Unable to get client id'
return
end

# Commvault does not "install" the file system agent anymore if the installation is done in restore only mode, so do it here
Expand Down
2 changes: 1 addition & 1 deletion resources/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
# Delete cache if it exists
ruby_block 'Cache delete' do
block do
cache_delete()
cache_delete
end
end

Expand Down