summaryrefslogtreecommitdiff
path: root/chef-utils/lib/chef-utils/dsl/cloud.rb
blob: 6e8fc520a533b02735b8631291e869430e28fd4b (plain)
1
2
3
4
5
6
7
8
9
10
11
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# frozen_string_literal: true
#
# Copyright:: Copyright (c) Chef Software Inc.
# 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.
#

require_relative "../internal"

module ChefUtils
  module DSL
    module Cloud
      include Internal

      # Determine if the current node is running in a known cloud.
      #
      # @param [Chef::Node] node the node to check
      # @since 15.8
      #
      # @return [Boolean]
      #
      def cloud?(node = __getnode)
        # cloud is always present, but nil if not on a cloud
        !node["cloud"].nil?
      end

      # Determine if the current node is running in Alibaba Cloud
      #
      # @param [Chef::Node] node the node to check
      # @since 17.0
      #
      # @return [Boolean]
      #
      def alibaba?(node = __getnode)
        node.key?("alibaba")
      end

      # Determine if the current node is running in AWS EC2.
      #
      # @param [Chef::Node] node the node to check
      # @since 15.8
      #
      # @return [Boolean]
      #
      def ec2?(node = __getnode)
        node.key?("ec2")
      end

      # Determine if the current node running in Google Compute Engine (GCE).
      #
      # @param [Chef::Node] node the node to check
      # @since 15.8
      #
      # @return [Boolean]
      #
      def gce?(node = __getnode)
        node.key?("gce")
      end

      # Determine if the current node is running in Rackspace.
      #
      # @param [Chef::Node] node the node to check
      # @since 15.8
      #
      # @return [Boolean]
      #
      def rackspace?(node = __getnode)
        node.key?("rackspace")
      end

      # Determine if the current node is running in Eucalyptus.
      #
      # @param [Chef::Node] node the node to check
      # @since 15.8
      #
      # @return [Boolean]
      #
      def eucalyptus?(node = __getnode)
        node.key?("eucalyptus")
      end
      # chef-sugar backcompat method
      alias_method :euca?, :eucalyptus?

      # Determine if the current node is running in Linode.
      #
      # @param [Chef::Node] node the node to check
      # @since 15.8
      #
      # @return [Boolean]
      #
      def linode?(node = __getnode)
        node.key?("linode")
      end

      # Determine if the current node is running in OpenStack.
      #
      # @param [Chef::Node] node the node to check
      # @since 15.8
      #
      # @return [Boolean]
      #
      def openstack?(node = __getnode)
        node.key?("openstack")
      end

      # Determine if the current node is running in Microsoft Azure.
      #
      # @param [Chef::Node] node the node to check
      # @since 15.8
      #
      # @return [Boolean]
      #
      def azure?(node = __getnode)
        node.key?("azure")
      end

      # Determine if the current node is running in DigitalOcean.
      #
      # @param [Chef::Node] node the node to check
      # @since 15.8
      #
      # @return [Boolean]
      #
      def digital_ocean?(node = __getnode)
        node.key?("digital_ocean")
      end
      # chef-sugar backcompat method
      alias_method :digitalocean?, :digital_ocean?

      # Determine if the current node is running in SoftLayer (IBM Cloud).
      #
      # @param [Chef::Node] node the node to check
      # @since 15.8
      #
      # @return [Boolean]
      #
      def softlayer?(node = __getnode)
        node.key?("softlayer")
      end

      extend self
    end
  end
end