Log warning if docker network inspect fails to return json

This commit is contained in:
Brian Cain 2019-03-04 10:25:10 -08:00
parent 5adffb608d
commit 4080f9e64d
No known key found for this signature in database
GPG Key ID: 9FC4639B2E4510A0
1 changed files with 6 additions and 3 deletions

View File

@ -255,16 +255,19 @@ module VagrantPlugins
result.match?(/\"#{network}\"/)
end
# Returns true or false if network is in use or not.
# Nil if Vagrant fails to receive proper JSON from `docker network inspect`
#
# @param [String] network - name of network to look for
# @return [Bool]
# @return [Bool,nil]
def network_used?(network)
result = inspect_network(network)
begin
result = JSON.parse(result)
return result.first["Containers"].size > 0
rescue JSON::ParserError => e
# Could not parse result of network inspection
# Handle this some how, maybe log error but not raise?
@logger.warn("Could not properly parse response from `docker network inspect #{network}`")
return nil
end
end