class Chef::Provisioning::Machine

Attributes

machine_spec[R]

Public Class Methods

new(machine_spec) click to toggle source
# File lib/chef/provisioning/machine.rb, line 4
def initialize(machine_spec)
  @machine_spec = machine_spec
end

Public Instance Methods

cleanup_convergence(action_handler) click to toggle source
# File lib/chef/provisioning/machine.rb, line 29
def cleanup_convergence(action_handler)
  raise "cleanup_convergence not overridden on #{self.class}"
end
converge(action_handler) click to toggle source
# File lib/chef/provisioning/machine.rb, line 25
def converge(action_handler)
  raise "converge not overridden on #{self.class}"
end
create_dir(action_handler, path) click to toggle source
# File lib/chef/provisioning/machine.rb, line 57
def create_dir(action_handler, path)
  raise "create_dir not overridden on #{self.class}"
end
delete_file(action_handler, path) click to toggle source

Delete file

# File lib/chef/provisioning/machine.rb, line 62
def delete_file(action_handler, path)
  raise "delete_file not overridden on #{self.class}"
end
detect_os(action_handler) click to toggle source

TODO get rid of the action_handler attribute, that is ridiculous Detect the OS on the machine (assumes the machine is up) Returns a triplet:

platform, platform_version, machine_architecture = machine.detect_os(action_handler)

This triplet is suitable for passing to the Chef metadata API: www.chef.io/chef/metadata?p=PLATFORM&pv=PLATFORM_VERSION&m=MACHINE_ARCHITECTURE

# File lib/chef/provisioning/machine.rb, line 107
def detect_os(action_handler)
  raise "detect_os not overridden on #{self.class}"
end
disconnect() click to toggle source
# File lib/chef/provisioning/machine.rb, line 97
def disconnect
  raise "disconnect not overridden on #{self.class}"
end
download_file(action_handler, path, local_path) click to toggle source
# File lib/chef/provisioning/machine.rb, line 45
def download_file(action_handler, path, local_path)
  raise "read_file not overridden on #{self.class}"
end
execute(action_handler, command, options = {}) click to toggle source
# File lib/chef/provisioning/machine.rb, line 33
def execute(action_handler, command, options = {})
  raise "execute not overridden on #{self.class}"
end
execute_always(command, options = {}) click to toggle source
# File lib/chef/provisioning/machine.rb, line 37
def execute_always(command, options = {})
  raise "execute_always not overridden on #{self.class}"
end
file_exists?(path) click to toggle source

Return true or false depending on whether file exists

# File lib/chef/provisioning/machine.rb, line 72
def file_exists?(path)
  raise "file_exists? not overridden on #{self.class}"
end
files_different?(path, local_path, content=nil) click to toggle source

Return true or false depending on whether remote file differs from local path or content

# File lib/chef/provisioning/machine.rb, line 77
def files_different?(path, local_path, content=nil)
  raise "file_different? not overridden on #{self.class}"
end
get_attributes(path) click to toggle source

Get file attributes { :mode, :owner, :group }

# File lib/chef/provisioning/machine.rb, line 87
def get_attributes(path)
  raise "get_attributes not overridden on #{self.class}"
end
is_directory?(path) click to toggle source

Return true if directory, false/nil if not

# File lib/chef/provisioning/machine.rb, line 67
def is_directory?(path)
  raise "is_directory? not overridden on #{self.class}"
end
make_url_available_to_remote(local_url) click to toggle source

Ensure the given URL can be reached by the remote side (possibly by port forwarding) Must return the URL that the remote side can use to reach the local_url

# File lib/chef/provisioning/machine.rb, line 93
def make_url_available_to_remote(local_url)
  raise "make_url_available_to_remote not overridden on #{self.class}"
end
name() click to toggle source
# File lib/chef/provisioning/machine.rb, line 10
def name
  machine_spec.name
end
node() click to toggle source
# File lib/chef/provisioning/machine.rb, line 14
def node
  machine_spec.node
end
read_file(path) click to toggle source
# File lib/chef/provisioning/machine.rb, line 41
def read_file(path)
  raise "read_file not overridden on #{self.class}"
end
set_attributes(action_handler, path, attributes) click to toggle source

Set file attributes { mode, :owner, :group }

# File lib/chef/provisioning/machine.rb, line 82
def set_attributes(action_handler, path, attributes)
  raise "set_attributes not overridden on #{self.class}"
end
setup_convergence(action_handler) click to toggle source

Sets up everything necessary for convergence to happen on the machine. The node MUST be saved as part of this procedure. Other than that, nothing is guaranteed except that converge() will work when this is done.

# File lib/chef/provisioning/machine.rb, line 21
def setup_convergence(action_handler)
  raise "setup_convergence not overridden on #{self.class}"
end
upload_file(action_handler, local_path, path) click to toggle source
# File lib/chef/provisioning/machine.rb, line 53
def upload_file(action_handler, local_path, path)
  raise "write_file not overridden on #{self.class}"
end
write_file(action_handler, path, content) click to toggle source
# File lib/chef/provisioning/machine.rb, line 49
def write_file(action_handler, path, content)
  raise "write_file not overridden on #{self.class}"
end

Private Instance Methods

detect_sh() click to toggle source
# File lib/chef/provisioning/machine/unix_machine.rb, line 152
    def detect_sh
      result = <<EOM
prerelease="false"

project="chef"

report_bug() {
echo "Please file a bug report at https://github.com/chef/chef-provisioning/issues"
echo "Project: Chef"
echo "Component: Packages"
echo "Label: Omnibus"
echo "Version: $version"
echo " "
echo "Please detail your operating system type, version and any other relevant details"
}


machine=`uname -m`
os=`uname -s`

# Retrieve Platform and Platform Version
if test -f "/etc/lsb-release" && grep -q DISTRIB_ID /etc/lsb-release; then
platform=`grep DISTRIB_ID /etc/lsb-release | cut -d "=" -f 2 | tr '[A-Z]' '[a-z]'`
platform_version=`grep DISTRIB_RELEASE /etc/lsb-release | cut -d "=" -f 2`
elif test -f "/etc/debian_version"; then
platform="debian"
platform_version=`cat /etc/debian_version`
elif test -f "/etc/redhat-release"; then
platform=`sed 's/^\\(.\\+\\) release.*/\\1/' /etc/redhat-release | tr '[A-Z]' '[a-z]'`
platform_version=`sed 's/^.\\+ release \\([.0-9]\\+\\).*/\\1/' /etc/redhat-release`

# If /etc/redhat-release exists, we act like RHEL by default
if test "$platform" = "fedora"; then
# Change platform version for use below.
platform_version="6.0"
fi
platform="el"
elif test -f "/etc/system-release"; then
platform=`sed 's/^\\(.\\+\\) release.\\+/\\1/' /etc/system-release | tr '[A-Z]' '[a-z]'`
platform_version=`sed 's/^.\\+ release \\([.0-9]\\+\\).*/\\1/' /etc/system-release | tr '[A-Z]' '[a-z]'`
# amazon is built off of fedora, so act like RHEL
if test "$platform" = "amazon linux ami"; then
platform="el"
platform_version="6.0"
fi
# Apple OS X
elif test -f "/usr/bin/sw_vers"; then
platform="mac_os_x"
# Matching the tab-space with sed is error-prone
platform_version=`sw_vers | awk '/^ProductVersion:/ { print $2 }'`

major_version=`echo $platform_version | cut -d. -f1,2`
case $major_version in
"10.6") platform_version="10.6" ;;
"10.7"|"10.8"|"10.9") platform_version="10.7" ;;
*) echo "No builds for platform: $major_version"
 report_bug
 exit 1
 ;;
esac

# x86_64 Apple hardware often runs 32-bit kernels (see OHAI-63)
x86_64=`sysctl -n hw.optional.x86_64`
if test $x86_64 -eq 1; then
machine="x86_64"
fi
elif test -f "/etc/release"; then
platform="solaris2"
machine=`/usr/bin/uname -p`
platform_version=`/usr/bin/uname -r`
elif test -f "/etc/SuSE-release"; then
if grep -q 'Enterprise' /etc/SuSE-release;
then
platform="sles"
platform_version=`awk '/^VERSION/ {V = $3}; /^PATCHLEVEL/ {P = $3}; END {print V "." P}' /etc/SuSE-release`
else
platform="suse"
platform_version=`awk '/^VERSION =/ { print $3 }' /etc/SuSE-release`
fi
elif test "x$os" = "xFreeBSD"; then
platform="freebsd"
platform_version=`uname -r | sed 's/-.*//'`
elif test "x$os" = "xAIX"; then
platform="aix"
platform_version=`uname -v`
machine="ppc"
elif test -f "/etc/os-release"; then
. /etc/os-release
if test "x$ID_LIKE" = "xwrlinux" || test "x$ID_LIKE" = "xcisco-wrlinux"; then
platform="wrlinux"
# 3.4.43-WR5.0.1.13_standard  -->  5
platform_version=`uname -r | sed 's/.*-WR\([0-9]\+\).*/\1/'`
fi
fi

if test "x$platform" = "x"; then
echo "Unable to determine platform version!"
report_bug
exit 1
fi

# Mangle $platform_version to pull the correct build
# for various platforms
major_version=`echo $platform_version | cut -d. -f1`
case $platform in
"el")
platform_version=$major_version
;;
"debian")
case $major_version in
"5") platform_version="6";;
"6") platform_version="6";;
"7") platform_version="6";;
esac
;;
"freebsd")
platform_version=$major_version
;;
"sles")
platform_version=$major_version
;;
"suse")
platform_version=$major_version
;;
esac

if test "x$platform_version" = "x"; then
echo "Unable to determine platform version!"
report_bug
exit 1
fi

if test "x$platform" = "xsolaris2"; then
# hack up the path on Solaris to find wget
PATH=/usr/sfw/bin:$PATH
export PATH
fi

echo "PLATFORM: $platform"
echo "PLATFORM_VERSION: $platform_version"
echo "MACHINE: $machine"
EOM
    end