Public: return an Enumerator which yields FrontendHttpServer objects for each gear which has run create.
# File lib/openshift-origin-node/model/frontend_httpd.rb, line 127 def self.all Enumerator.new do |yielder| ApplicationContainer.all.each do |container| begin yielder.yield(self.new(container)) rescue => e NodeLogger.logger.error("Failed to instantiate FrontendHttpServer for #{container.uuid}: #{e}") NodeLogger.logger.error("Backtrace: #{e.backtrace}") end end end end
Public: Load from json
# File lib/openshift-origin-node/model/frontend_httpd.rb, line 255 def self.json_create(obj) data = obj['data'] # Note, the container name, namespace and FQDN can change in this step. new_obj = FrontendHttpServer.new(ApplicationContainer.from_uuid(data['container_uuid'])) new_obj.create if data.has_key?("connections") new_obj.connect(data["connections"]) end if data.has_key?("aliases") data["aliases"].each do |a| new_obj.add_alias(a) end end if data.has_key?("ssl_certs") data["ssl_certs"].each do |c, k, a| new_obj.add_ssl_cert(c, k, a) end end if data.has_key?("idle") if data["idle"] new_obj.idle else new_obj.unidle end end if data.has_key?("sts") if data["sts"] new_obj.sts(data["sts"]) else new_obj.no_sts end end new_obj end
# File lib/openshift-origin-node/model/frontend_httpd.rb, line 174 def initialize(container) @config = ::OpenShift::Config.new @container_uuid = container.uuid @container_name = container.name @namespace = container.namespace if (container.name.to_s == "") or (container.namespace.to_s == "") self.class.plugins.each do |pl| begin entry = pl.lookup_by_uuid(@container_uuid) @fqdn = entry.fqdn @container_name = entry.container_name @namespace = entry.namespace break if not @fqdn.nil? rescue NoMethodError => e # NodeLogger.logger.debug("container #{container.uuid}, NoMethodError #{e.message}") end end else cloud_domain = clean_server_name(@config.get("CLOUD_DOMAIN")) @fqdn = clean_server_name("#{container.name}-#{container.namespace}.#{cloud_domain}") end # Could not infer from any source if (@fqdn.to_s == "") or (@container_name.to_s == "") or (@namespace.to_s == "") raise FrontendHttpServerException.new(%Q{Could not determine gear information for: uuid "#{@container_uuid}" fqdn "#{@fqdn}" container name "#{@container_name}" namespace "#{@namespace}"}, @container_uuid) end @plugins = self.class.plugins.map { |pl| pl.new(@container_uuid, @fqdn, @container_name, @namespace) } end
# File lib/openshift-origin-node/model/frontend_httpd.rb, line 117 def self.plugins ::OpenShift::Runtime::Frontend::Http::Plugins::plugins end
Public: Purge frontend records for broken gears.
Args:
lookup - either the uuid or fqdn of the broken gear.
Note: This API function is intended for use when the ApplicationContainer object is no longer able to instantiate for a gear or no longer has complete information.
# File lib/openshift-origin-node/model/frontend_httpd.rb, line 149 def self.purge(lookup) uuid = fqdn = lookup plugins.each do |pl| [:lookup_by_uuid, :lookup_by_fqdn].each do |call| if pl.methods.include?(call) entry = pl.send(call, lookup) if entry uuid = entry.container_uuid if entry.container_uuid fqdn = entry.fqdn if entry.fqdn end end end end plugins.each do |pl| if fqdn and pl.methods.include?(:purge_by_fqdn) pl.send(:purge_by_fqdn, fqdn) end if uuid and pl.methods.include?(:purge_by_uuid) pl.send(:purge_by_uuid, uuid) end end end
Public: Add an alias to this namespace
Examples
add_alias("foo.example.com") # => nil
Returns nil on Success or raises on Failure
# File lib/openshift-origin-node/model/frontend_httpd.rb, line 498 def add_alias(name) call_plugins(:add_alias, clean_server_name(name)) end
Public: Adds a ssl certificate for an alias
# File lib/openshift-origin-node/model/frontend_httpd.rb, line 520 def add_ssl_cert(ssl_cert, priv_key, server_alias, passphrase='') server_alias_clean = clean_server_name(server_alias) begin priv_key_clean = OpenSSL::PKey.read(priv_key, passphrase) ssl_cert_clean = [] ssl_cert_unit = "" ssl_cert.each_line do |cert_line| ssl_cert_unit += cert_line if cert_line.start_with?('-----END') ssl_cert_clean << OpenSSL::X509::Certificate.new(ssl_cert_unit) ssl_cert_unit = "" end end rescue ArgumentError raise FrontendHttpServerException.new("Invalid Private Key or Passphrase", @container_uuid, @fqdn) rescue OpenSSL::X509::CertificateError => e raise FrontendHttpServerException.new("Invalid X509 Certificate: #{e.message}", @container_uuid, @fqdn) rescue => e raise FrontendHttpServerException.new("Other key/cert error: #{e.message}", @container_uuid, @fqdn) end if ssl_cert_clean.empty? raise FrontendHttpServerException.new("Could not parse certificates", @container_uuid, @fqdn) end if not ssl_cert_clean[0].check_private_key(priv_key_clean) raise FrontendHttpServerException.new("Key/cert mismatch", @container_uuid, @fqdn) end if not [OpenSSL::PKey::RSA, OpenSSL::PKey::DSA].include?(priv_key_clean.class) raise FrontendHttpServerException.new("Key must be RSA or DSA for Apache mod_ssl", @container_uuid, @fqdn) end call_plugins(:add_ssl_cert, ssl_cert_clean.map { |c| c.to_pem}.join, priv_key_clean.to_pem, server_alias_clean) end
Public: List aliases for this gear
Examples
aliases # => ["foo.example.com", "bar.example.com"]
# File lib/openshift-origin-node/model/frontend_httpd.rb, line 486 def aliases call_plugins(:aliases) end
Private: Call the plugin list and collect an array of the results.
# File lib/openshift-origin-node/model/frontend_httpd.rb, line 576 def call_plugins(call, *args) @plugins.map { |pl| begin # Support for any method is optional in any plugin if pl.methods.include?(call) pl.send(call, *args) end # The public facing exceptions should all be FrontendHttp*Exception. rescue ::OpenShift::Runtime::Frontend::Http::Plugins::PluginException => e raise FrontendHttpServerException.new(e.message.gsub(": #{@container_uuid}",'').gsub(": #{@fqdn}",''), @container_uuid, @fqdn) rescue ::OpenShift::Runtime::Frontend::Http::Plugins::PluginExecException => e raise FrontendHttpServerExecException.new(e.message.gsub(": #{@container_uuid}",'').gsub(": #{@fqdn}",''), @container_uuid, @fqdn, e.rc, e.stdout, e.stderr) end }.flatten(1).select { |res| not res.nil? }.uniq end
Private: Validate the server name
The name is validated against DNS host name requirements from RFC 1123 and RFC 952. Additionally, OpenShift does not allow names/aliases to be an IP address.
# File lib/openshift-origin-node/model/frontend_httpd.rb, line 597 def clean_server_name(name) dname = name.downcase.chomp('.') if not dname =~ /^[a-z0-9]/ raise FrontendHttpServerNameException.new("Invalid start character", @container_uuid, @fqdn, dname ) end if not dname =~ /[a-z0-9]$/ raise FrontendHttpServerNameException.new("Invalid end character", @container_uuid, @fqdn, dname ) end if not dname.index(/[^0-9a-z\-.]/).nil? raise FrontendHttpServerNameException.new("Invalid characters", @container_uuid, @fqdn, dname ) end if dname.length > 255 raise FrontendHttpServerNameException.new("Too long", @container_uuid, @fqdn, dname ) end if dname.length == 0 raise FrontendHttpServerNameException.new("Name was blank", @container_uuid, @fqdn, dname ) end if dname =~ /^\d+\.\d+\.\d+\.\d+$/ raise FrontendHttpServerNameException.new("IP addresses are not allowed", @container_uuid, @fqdn, dname ) end return dname end
Public: Connect path elements to a back-end URI for this namespace.
Examples
connect('', '127.0.250.1:8080') connect('/', '127.0.250.1:8080/') connect('/phpmyadmin', '127.0.250.2:8080/') connect('/socket, '127.0.250.3:8080/', {"websocket"=>1} Options: websocket Enable web sockets on a particular path gone Mark the path as gone (uri is ignored) forbidden Mark the path as forbidden (uri is ignored) noproxy Mark the path as not proxied (uri is ignored) redirect Use redirection to uri instead of proxy (uri must be a path) file Ignore request and load file path contained in uri (must be path) tohttps Redirect request to https and use the path contained in the uri (must be path) target_update Preserve existing options and update the target. While more than one option is allowed, the above options conflict with each other. Additional options may be provided which are target specific. # => nil
Returns nil on Success or raises on Failure
# File lib/openshift-origin-node/model/frontend_httpd.rb, line 321 def connect(*elements) elems = elements.flatten.enum_for(:each_slice, 3).map { |path, uri, options| [path, uri, options] } paths_to_update = {} elems.each do |path, uri, options| if options["target_update"] paths_to_update[path]=uri end end if not paths_to_update.empty? connections.each do |path, uri, options| if paths_to_update.include?(path) elems.delete_if { |a, b, c| a == path } elems << [ path, paths_to_update[path], options ] paths_to_update.delete(path) end end end paths_to_update.each do |path, uri| raise FrontendHttpServerException.new("The target_update option specified but no old configuration: #{path}", @container_uuid, @fqdn) end call_plugins(:connect, *elems) end
Public: List connections Returns [ [path, uri, options], [path, uri, options], …]
# File lib/openshift-origin-node/model/frontend_httpd.rb, line 350 def connections conset = Hash.new { |h,k| h[k]={} } call_plugins(:connections).each do |path, uri, options| conset[[path, uri]].merge!(options) do |key, oldval, newval| if key == "protocols" [ oldval, newval ].flatten.uniq.sort else newval end end end conset.map { |k,v| [ k, v ].flatten } end
Public: Initialize a new configuration for this gear
Examples
create # => nil
Returns nil on Success or raises on Failure
# File lib/openshift-origin-node/model/frontend_httpd.rb, line 215 def create call_plugins(:create) end
Public: Remove the frontend httpd configuration for a gear.
Examples
destroy # => nil
Returns nil on Success or raises on Failure
# File lib/openshift-origin-node/model/frontend_httpd.rb, line 227 def destroy call_plugins(:destroy) end
Public: Disconnect a path element from this namespace
Examples
disconnect('') disconnect('/') disconnect('/phpmyadmin) disconnect('/a', '/b', '/c') # => nil
Returns nil on Success or raises on Failure
# File lib/openshift-origin-node/model/frontend_httpd.rb, line 378 def disconnect(*paths) call_plugins(:disconnect, *paths) end
Public: Determine whether the gear has sts
Examples
sts? # => true or nil
Returns true if the gear is idled
# File lib/openshift-origin-node/model/frontend_httpd.rb, line 472 def get_sts call_plugins(:get_sts).each do |val| return val if val end nil end
Public: Mark a gear as idled
Examples
idle() # => nil()
Returns nil on Success or raises on Failure
# File lib/openshift-origin-node/model/frontend_httpd.rb, line 391 def idle call_plugins(:idle) end
Public: Determine whether the gear is idle
Examples
idle? # => true or false
Returns true if the gear is idled
# File lib/openshift-origin-node/model/frontend_httpd.rb, line 430 def idle? call_plugins(:idle?).each do |val| return val if val end nil end
Public: Unmark a gear for sts
Examples
nosts() # => nil()
Returns nil on Success or raises on Failure
# File lib/openshift-origin-node/model/frontend_httpd.rb, line 460 def no_sts call_plugins(:no_sts) end
Public: Removes an alias from this namespace
Examples
add_alias("foo.example.com") # => nil
Returns nil on Success or raises on Failure
# File lib/openshift-origin-node/model/frontend_httpd.rb, line 510 def remove_alias(name) call_plugins(:remove_alias, clean_server_name(name)) end
Public: Removes ssl certificate/private key associated with an alias
# File lib/openshift-origin-node/model/frontend_httpd.rb, line 567 def remove_ssl_cert(server_alias) call_plugins(:remove_ssl_cert, clean_server_name(server_alias)) end
Public: List aliases with SSL certs and unencrypted private keys
# File lib/openshift-origin-node/model/frontend_httpd.rb, line 515 def ssl_certs call_plugins(:ssl_certs) end
Public: Mark a gear for STS
Examples
sts(duration) # => nil()
Returns nil on Success or raises on Failure
# File lib/openshift-origin-node/model/frontend_httpd.rb, line 447 def sts(max_age=15768000) call_plugins(:sts, max_age) end
Public: extract hash version of complete data for this gear
# File lib/openshift-origin-node/model/frontend_httpd.rb, line 232 def to_hash { "container_uuid" => @container_uuid, "fqdn" => @fqdn, "container_name" => @container_name, "namespace" => @namespace, "connections" => connections, "aliases" => aliases, "ssl_certs" => ssl_certs, "idle" => idle?, "sts" => get_sts } end
Public: Generate json
# File lib/openshift-origin-node/model/frontend_httpd.rb, line 247 def to_json(*args) { 'json_class' => self.class.name, 'data' => self.to_hash }.to_json(*args) end
Public: Unmark a gear as idled
Examples
unidle() # => nil()
Returns nil on Success or raises on Failure
# File lib/openshift-origin-node/model/frontend_httpd.rb, line 404 def unidle call_plugins(:unidle) end
Public: Make an unprivileged call to unidle the gear
Examples
unprivileged_unidle() # => nil()
Returns nil. This is an opportunistic call, failure conditions are ignored but the call may take over a minute to complete.
# File lib/openshift-origin-node/model/frontend_httpd.rb, line 418 def unprivileged_unidle call_plugins(:unprivileged_unidle) end