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_display_name?(name) ⇒ Boolean
- #has_endpoint?(uri) ⇒ Boolean
- #has_policy?(policy_name) ⇒ Boolean
- #has_role?(role_name) ⇒ Boolean
- #has_tenant?(tenant_name) ⇒ Boolean
- #has_tenant_tag?(tag_set, tag) ⇒ 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 32 33 34 35 36 37 38 |
# 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" show-thumbprint --console --nologo --instance #{instance}` thumbprint = thumbprint.gsub('==== ShowThumbprintCommand starting ====', '').strip thumbprint = thumbprint.gsub('The thumbprint of this Tentacle is: ', '').strip thumbprint = thumbprint.gsub('==== ShowThumbprintCommand completed ====', '').strip thumbprint = thumbprint.gsub('==== ShowThumbprintCommand ====', '').strip puts "tentacle thumbprint is #{thumbprint}" @machine = get_machine_via_api(serverUrl, apiKey, thumbprint) else puts "tentacle.exe does not exist" end end |
Instance Method Details
#exists? ⇒ Boolean
120 121 122 |
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb', line 120 def exists? ::File.exists?("c:\\program files\\Octopus Deploy\\Tentacle\\Tentacle.exe") end |
#has_display_name?(name) ⇒ Boolean
97 98 99 100 |
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb', line 97 def has_display_name?(name) return false if @machine.nil? @machine["Name"] == name end |
#has_endpoint?(uri) ⇒ Boolean
102 103 104 105 106 |
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb', line 102 def has_endpoint?(uri) return false if @machine.nil? puts "Expected uri '#{uri}' for Tentacle #{@name}, but got '#{@machine["Uri"]}'" unless (@machine["Uri"].casecmp(uri) == 0) @machine["Uri"].casecmp(uri) == 0 end |
#has_policy?(policy_name) ⇒ Boolean
82 83 84 85 86 87 88 89 |
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb', line 82 def has_policy?(policy_name) return false if @machine.nil? url = "#{@serverUrl}/api/machinepolicies/all?api-key=#{@apiKey}" resp = Net::HTTP.get_response(URI.parse(url)) policies = JSON.parse(resp.body) policy_id = policies.select {|e| e["Name"] == policy_name}.first["Id"] @machine["MachinePolicyId"] == policy_id end |
#has_role?(role_name) ⇒ Boolean
91 92 93 94 95 |
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb', line 91 def has_role?(role_name) return false if @machine.nil? roles = @machine["Roles"] !roles.select {|e| e == role_name}.empty? end |
#has_tenant?(tenant_name) ⇒ Boolean
67 68 69 70 71 72 73 74 |
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb', line 67 def has_tenant?(tenant_name) return false if @machine.nil? url = "#{@serverUrl}/api/tenants/all?api-key=#{@apiKey}" resp = Net::HTTP.get_response(URI.parse(url)) tenants = JSON.parse(resp.body) tenant_id = tenants.select {|e| e["Name"] == tenant_name}.first["Id"] !@machine["TenantIds"].select {|e| e == tenant_id}.empty? end |
#has_tenant_tag?(tag_set, tag) ⇒ Boolean
76 77 78 79 80 |
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb', line 76 def has_tenant_tag?(tag_set, tag) return false if @machine.nil? = @machine["TenantTags"] !.select {|e| e == "#{tag_set}/#{tag}"}.empty? end |
#in_environment?(environment_name) ⇒ Boolean
58 59 60 61 62 63 64 65 |
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb', line 58 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
108 109 110 111 112 |
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb', line 108 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
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb', line 44 def online? return nil if @machine.nil? @machine = poll_until_machine_has_completed_healthcheck(@serverUrl, @apiKey, @machine["Thumbprint"]) status = @machine['Status'] if ("#{status}" == "") status = @machine['HealthStatus'] if "#{status}" == "" puts "Expected status 'Healthy|HasWarnings' for Tentacle #{@name}, but got '#{status}'" if (status != "Healthy" && status != "HasWarnings") status == "Healthy" || status == "HasWarnings" else puts "Expected status 'Online|CalamariNeedsUpgrade|NeedsUpgrade' for Tentacle #{@name}, but got '#{status}'" if (status != "Online" && status != "CalamariNeedsUpgrade" && status != "NeedsUpgrade") status == "Online" || status == "CalamariNeedsUpgrade" || status == "NeedsUpgrade" end end |
#polling_tentacle? ⇒ Boolean
114 115 116 117 118 |
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb', line 114 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
40 41 42 |
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb', line 40 def registered_with_the_server? !@machine.nil? end |