summaryrefslogtreecommitdiff
path: root/lib/ohai/plugins
diff options
context:
space:
mode:
authorJonathan Amiez <jonathan.amiez@gmail.com>2018-01-29 22:07:23 +0100
committerJonathan Amiez <jonathan.amiez@gmail.com>2018-01-29 22:18:11 +0100
commit522f6a290465768887555d2a12cc8c022355351d (patch)
tree384251d6795ac875a0b4882a49078a965b026b96 /lib/ohai/plugins
parentb5f510c6338f2bc0ced874a126741113fd94fb96 (diff)
downloadohai-522f6a290465768887555d2a12cc8c022355351d.tar.gz
Add scaleway plugin
Scaleway is a young french cloud provider. https://www.scaleway.com/ Signed-off-by: Jonathan Amiez <jonathan.amiez@gmail.com>
Diffstat (limited to 'lib/ohai/plugins')
-rw-r--r--lib/ohai/plugins/scaleway.rb57
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/ohai/plugins/scaleway.rb b/lib/ohai/plugins/scaleway.rb
new file mode 100644
index 00000000..5cfd1079
--- /dev/null
+++ b/lib/ohai/plugins/scaleway.rb
@@ -0,0 +1,57 @@
+#
+# Author:: Jonathan Amiez (<jonathan.amiez@gmail.com>)
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+Ohai.plugin(:Scaleway) do
+ require "ohai/mixin/scaleway_metadata"
+ require "ohai/mixin/http_helper"
+
+ include Ohai::Mixin::ScalewayMetadata
+ include Ohai::Mixin::HttpHelper
+
+ provides "scaleway"
+
+ # looks for `scaleway` keyword in kernel command line
+ # @return [Boolean] do we have the keyword or not?
+ def has_scaleway_cmdline?
+ if ::File.read("/proc/cmdline") =~ /scaleway/
+ Ohai::Log.debug("Plugin Scaleway: has_scaleway_cmdline? == true")
+ return true
+ end
+ Ohai::Log.debug("Plugin Scaleway: has_scaleway_cmdline? == false")
+ false
+ end
+
+ # a single check that combines all the various detection methods for Scaleway
+ # @return [Boolean] Does the system appear to be on Scaleway
+ def looks_like_scaleway?
+ return true if hint?("scaleway")
+ return true if has_scaleway_cmdline? && can_socket_connect?(Ohai::Mixin::ScalewayMetadata::SCALEWAY_METADATA_ADDR, 80)
+ false
+ end
+
+ collect_data do
+ if looks_like_scaleway?
+ Ohai::Log.debug("Plugin Scaleway: looks_like_scaleway? == true")
+ scaleway Mash.new
+ fetch_metadata.each do |k, v|
+ scaleway[k] = v
+ end
+ else
+ Ohai::Log.debug("Plugin Scaleway: No hints present for and doesn't look like scaleway")
+ false
+ end
+ end
+end