Class: Ridley::Node

Inherits:
Object
  • Object
show all
Includes:
Resource
Defined in:
lib/ridley/resources/node.rb

Overview

Author:

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Resource

#<=>, #==, #attribute, #attribute=, #attribute?, #attributes, #attributes=, #chef_id, #eql?, #from_hash, #from_json, #hash, #initialize, #reload, #save, #to_hash, #to_json, #to_s

Class Method Details

.bootstrap(connection, nodes, options = {}) ⇒ Object

Parameters:

Options Hash (options):

  • :ssh_user (String)
  • :ssh_password (String)
  • :ssh_keys (Array<String>, String)
  • :ssh_timeout (Float)

    timeout value for SSH bootstrap (default: 1.5)

  • :validator_client (String)
  • :validator_path (String)

    filepath to the validator used to bootstrap the node (required)

  • :bootstrap_proxy (String)

    URL to a proxy server to bootstrap through (default: nil)

  • :encrypted_data_bag_secret_path (String)

    filepath on your host machine to your organizations encrypted data bag secret (default: nil)

  • :hints (Hash)

    a hash of Ohai hints to place on the bootstrapped node (default: Hash.new)

  • :attributes (Hash)

    a hash of attributes to use in the first Chef run (default: Hash.new)

  • :run_list (Array)

    an initial run list to bootstrap with (default: Array.new)

  • :chef_version (String)

    version of Chef to install on the node (default: CHEF_VERSION)

  • :environment (String)

    environment to join the node to (default: ‘_default’)

  • :sudo (Boolean)

    bootstrap with sudo (default: true)

  • :template (String)

    bootstrap template to use (default: omnibus)



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ridley/resources/node.rb', line 34

def bootstrap(connection, *args)
  options = args.last.is_a?(Hash) ? args.pop : Hash.new

  default_options = {
    server_url: connection.server_url,
    ssh_user: connection.ssh[:user],
    ssh_password: connection.ssh[:password],
    ssh_timeout: connection.ssh[:timeout],
    validator_path: connection.validator_path,
    validator_client: connection.validator_client,
    encrypted_data_bag_secret_path: connection.encrypted_data_bag_secret_path
  }

  options = default_options.merge(options)

  Bootstrapper.new(args, options).run
end

Instance Method Details

#automatic=(hash) ⇒ Object Also known as: automatic_attributes=

Parameters:

  • hash (Hash)


82
83
84
# File 'lib/ridley/resources/node.rb', line 82

def automatic=(hash)
  super(HashWithIndifferentAccess.new(hash))
end

#chef_clientSSH::Response

Run Chef-Client on the instantiated node

Returns:



188
189
190
191
192
# File 'lib/ridley/resources/node.rb', line 188

def chef_client
  Ridley::SSH.start(self, connection.ssh) do |ssh|
    ssh.run("sudo chef-client").first
  end
end

#cloud?Boolean

Returns true if the node is identified as a cloud node.

Returns:

  • (Boolean)


160
161
162
# File 'lib/ridley/resources/node.rb', line 160

def cloud?
  self.automatic.has_key?(:cloud)
end

#cloud_providernil, String

Returns the cloud provider of the instantiated node. If the node is not identified as a cloud node, then nil is returned.

Examples:

node_1.cloud_provider => "eucalyptus"
node_2.cloud_provider => "ec2"
node_3.cloud_provider => "rackspace"
node_4.cloud_provider => nil

Returns:

  • (nil, String)


153
154
155
# File 'lib/ridley/resources/node.rb', line 153

def cloud_provider
  self.cloud? ? self.automatic[:cloud][:provider] : nil      
end

#default=(hash) ⇒ Object Also known as: default_attributes=

Parameters:

  • hash (Hash)


88
89
90
# File 'lib/ridley/resources/node.rb', line 88

def default=(hash)
  super(HashWithIndifferentAccess.new(hash))
end

#ec2?Boolean

Returns true if the node is identified as a cloud node using the ec2 provider.

Returns:

  • (Boolean)


174
175
176
# File 'lib/ridley/resources/node.rb', line 174

def ec2?
  self.cloud_provider == "ec2"
end

#eucalyptus?Boolean

Returns true if the node is identified as a cloud node using the eucalyptus provider.

Returns:

  • (Boolean)


167
168
169
# File 'lib/ridley/resources/node.rb', line 167

def eucalyptus?
  self.cloud_provider == "eucalyptus"
end

#normal=(hash) ⇒ Object Also known as: normal_attributes=

Parameters:

  • hash (Hash)


76
77
78
# File 'lib/ridley/resources/node.rb', line 76

def normal=(hash)
  super(HashWithIndifferentAccess.new(hash))
end

#override=(hash) ⇒ Object Also known as: override_attributes=

Parameters:

  • hash (Hash)


94
95
96
# File 'lib/ridley/resources/node.rb', line 94

def override=(hash)
  super(HashWithIndifferentAccess.new(hash))
end

#public_hostnameString

Returns the public hostname of the instantiated node. This hostname should be used for public communications to the node.

Examples:

node.public_hostname => "reset.riotgames.com"

Returns:

  • (String)


127
128
129
# File 'lib/ridley/resources/node.rb', line 127

def public_hostname
  self.cloud? ? self.automatic[:cloud][:public_hostname] : self.automatic[:fqdn]
end

#public_ipv4String Also known as: public_ipaddress

Returns the public IPv4 address of the instantiated node. This ip address should be used for public communications to the node.

Examples:

node.public_ipv4 => "10.33.33.1"

Returns:

  • (String)


138
139
140
# File 'lib/ridley/resources/node.rb', line 138

def public_ipv4
  self.cloud? ? self.automatic[:cloud][:public_ipv4] : self.automatic[:ipaddress]
end

#rackspace?Boolean

Returns true if the node is identified as a cloud node using the rackspace provider.

Returns:

  • (Boolean)


181
182
183
# File 'lib/ridley/resources/node.rb', line 181

def rackspace?
  self.cloud_provider == "rackspace"
end

#set_attribute(key, value) ⇒ HashWithIndifferentAccess

Note:

It is not possible to set any other attribute level on a node and have it persist after a Chef Run. This is because all other attribute levels are truncated at the start of a Chef Run.

Set a node level normal attribute given the dotted path representation of the Chef attribute and value.

Examples:

setting and saving a node level normal attribute


obj = node.find("jwinsor-1")
obj.set_attribute("my_app.billing.enabled", false)
obj.save

Parameters:

  • key (String)
  • value (Object)

Returns:

  • (HashWithIndifferentAccess)


115
116
117
118
# File 'lib/ridley/resources/node.rb', line 115

def set_attribute(key, value)
  attr_hash = HashWithIndifferentAccess.from_dotted_path(key, value)
  self.normal = self.normal.deep_merge(attr_hash)
end