Class: Serverspec::Type::OctopusDeployTentacle
- Inherits:
-
Base
- Object
- Base
- Serverspec::Type::OctopusDeployTentacle
- Defined in:
- lib/octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb
Instance Method Summary collapse
- #exists? ⇒ Boolean
- #has_role?(role_name) ⇒ Boolean
- #in_environment?(environment_name) ⇒ Boolean
-
#initialize(serverUrl, apiKey, instance) ⇒ OctopusDeployTentacle
constructor
A new instance of OctopusDeployTentacle.
- #listening_tentacle? ⇒ Boolean
- #online? ⇒ Boolean
- #polling_tentacle? ⇒ Boolean
- #registered_with_the_server? ⇒ Boolean
Constructor Details
#initialize(serverUrl, apiKey, instance) ⇒ OctopusDeployTentacle
Returns a new instance of OctopusDeployTentacle.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb', line 12 def initialize(serverUrl, apiKey, instance) @name = "Octopus Deploy Tentacle #{instance}" @runner = Specinfra::Runner @serverUrl = serverUrl @apiKey = apiKey if (serverUrl.nil?) puts "'serverUrl' was not provided. Unable to connect to Octopus server to validate configuration." return end if (apiKey.nil?) puts "'apiKey' was not provided. Unable to connect to Octopus server to validate configuration." return end if (exists?) thumbprint = `"c:\\program files\\Octopus Deploy\\Tentacle\\Tentacle.exe" --console --show-thumbprint --nologo --instance #{instance}`.strip.gsub('The thumbprint of this Tentacle is: ', '') @machine = get_machine_via_api(serverUrl, apiKey, thumbprint) end end |
Instance Method Details
#exists? ⇒ Boolean
71 72 73 |
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb', line 71 def exists? ::File.exists?("c:\\program files\\Octopus Deploy\\Tentacle\\Tentacle.exe") end |
#has_role?(role_name) ⇒ Boolean
53 54 55 56 57 |
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb', line 53 def has_role?(role_name) return false if @machine.nil? roles = @machine["Roles"] !roles.select {|e| e == role_name}.empty? end |
#in_environment?(environment_name) ⇒ Boolean
44 45 46 47 48 49 50 51 |
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb', line 44 def in_environment?(environment_name) return false if @machine.nil? url = "#{@serverUrl}/api/environments/all?api-key=#{@apiKey}" resp = Net::HTTP.get_response(URI.parse(url)) environments = JSON.parse(resp.body) environment_id = environments.select {|e| e["Name"] == environment_name}.first["Id"] !@machine["EnvironmentIds"].select {|e| e == environment_id}.empty? end |
#listening_tentacle? ⇒ Boolean
59 60 61 62 63 |
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb', line 59 def listening_tentacle? return false if @machine.nil? puts "Expected CommunicationStyle 'TentaclePassive' for Tentacle #{@name}, but got '#{@machine["EndPoint"]["CommunicationStyle"]}'" if (@machine["EndPoint"]["CommunicationStyle"] != "TentaclePassive") @machine["EndPoint"]["CommunicationStyle"] == "TentaclePassive" end |
#online? ⇒ Boolean
37 38 39 40 41 42 |
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb', line 37 def online? return nil if @machine.nil? @machine = poll_until_machine_has_completed_healthcheck(@serverUrl, @apiKey, @machine["Thumbprint"]) puts "Expected status 'Online|CalamariNeedsUpgrade|NeedsUpgrade' for Tentacle #{@name}, but got '#{@machine["Status"]}'" if (@machine["Status"] != "Online" && @machine["Status"] != "CalamariNeedsUpgrade") @machine["Status"] == "Online" || @machine["Status"] == "CalamariNeedsUpgrade" || @machine["Status"] == "NeedsUpgrade" end |
#polling_tentacle? ⇒ Boolean
65 66 67 68 69 |
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb', line 65 def polling_tentacle? return false if @machine.nil? puts "Expected CommunicationStyle 'TentacleActive' for Tentacle #{@name}, but got '#{@machine["EndPoint"]["CommunicationStyle"]}'" if (@machine["EndPoint"]["CommunicationStyle"] != "TentacleActive") @machine["EndPoint"]["CommunicationStyle"] == "TentacleActive" end |
#registered_with_the_server? ⇒ Boolean
33 34 35 |
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb', line 33 def registered_with_the_server? !@machine.nil? end |