summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rwxr-xr-xtools/hook-dhclient24
-rwxr-xr-xtools/hook-network-manager24
-rwxr-xr-xtools/hook-rhel.sh27
-rwxr-xr-xtools/make-dist-tarball21
-rwxr-xr-xtools/make-tarball80
-rwxr-xr-xtools/read-dependencies22
-rwxr-xr-xtools/read-version105
7 files changed, 234 insertions, 69 deletions
diff --git a/tools/hook-dhclient b/tools/hook-dhclient
new file mode 100755
index 00000000..6a4626c6
--- /dev/null
+++ b/tools/hook-dhclient
@@ -0,0 +1,24 @@
+#!/bin/sh
+# This script writes DHCP lease information into the cloud-init run directory
+# It is sourced, not executed. For more information see dhclient-script(8).
+is_azure() {
+ local dmi_path="/sys/class/dmi/id/board_vendor" vendor=""
+ if [ -e "$dmi_path" ] && read vendor < "$dmi_path"; then
+ [ "$vendor" = "Microsoft Corporation" ] && return 0
+ fi
+ return 1
+}
+
+is_enabled() {
+ # only execute hooks if cloud-init is enabled and on azure
+ [ -e /run/cloud-init/enabled ] || return 1
+ is_azure
+}
+
+if is_enabled; then
+ case "$reason" in
+ BOUND) cloud-init dhclient-hook up "$interface";;
+ DOWN|RELEASE|REBOOT|STOP|EXPIRE)
+ cloud-init dhclient-hook down "$interface";;
+ esac
+fi
diff --git a/tools/hook-network-manager b/tools/hook-network-manager
new file mode 100755
index 00000000..98a36c8a
--- /dev/null
+++ b/tools/hook-network-manager
@@ -0,0 +1,24 @@
+#!/bin/sh
+# This script hooks into NetworkManager(8) via its scripts
+# arguments are 'interface-name' and 'action'
+#
+is_azure() {
+ local dmi_path="/sys/class/dmi/id/board_vendor" vendor=""
+ if [ -e "$dmi_path" ] && read vendor < "$dmi_path"; then
+ [ "$vendor" = "Microsoft Corporation" ] && return 0
+ fi
+ return 1
+}
+
+is_enabled() {
+ # only execute hooks if cloud-init is enabled and on azure
+ [ -e /run/cloud-init/enabled ] || return 1
+ is_azure
+}
+
+if is_enabled; then
+ case "$1:$2" in
+ *:up) exec cloud-init dhclient-hook up "$1";;
+ *:down) exec cloud-init dhclient-hook down "$1";;
+ esac
+fi
diff --git a/tools/hook-rhel.sh b/tools/hook-rhel.sh
new file mode 100755
index 00000000..8232414c
--- /dev/null
+++ b/tools/hook-rhel.sh
@@ -0,0 +1,27 @@
+#!/bin/sh
+# Current versions of RHEL and CentOS do not honor the directory
+# /etc/dhcp/dhclient-exit-hooks.d so this file can be placed in
+# /etc/dhcp/dhclient.d instead
+is_azure() {
+ local dmi_path="/sys/class/dmi/id/board_vendor" vendor=""
+ if [ -e "$dmi_path" ] && read vendor < "$dmi_path"; then
+ [ "$vendor" = "Microsoft Corporation" ] && return 0
+ fi
+ return 1
+}
+
+is_enabled() {
+ # only execute hooks if cloud-init is enabled and on azure
+ [ -e /run/cloud-init/enabled ] || return 1
+ is_azure
+}
+
+hook-rhel_config(){
+ is_enabled || return 0
+ cloud-init dhclient-hook up "$interface"
+}
+
+hook-rhel_restore(){
+ is_enabled || return 0
+ cloud-init dhclient-hook down "$interface"
+}
diff --git a/tools/make-dist-tarball b/tools/make-dist-tarball
deleted file mode 100755
index 5b078515..00000000
--- a/tools/make-dist-tarball
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/bin/sh
-
-Usage() {
- cat <<EOF
-Usage: ${0##*/} version
- make a tarball of 'version'
- must be in a bzr directory, and 'version' must be a tag
-
-EOF
-}
-
-topdir="$PWD"
-tag="$1"
-
-[ -n "$tag" ] || { Usage 1>&2 ; exit 1; }
-
-out="${topdir}/cloud-init-${tag}.tar.gz"
-
-bzr export --format=tgz --root="cloud-init-$tag" \
- "--revision=tag:${tag}" "$out" "$topdir" &&
- echo "Wrote ${out}"
diff --git a/tools/make-tarball b/tools/make-tarball
index b7039150..c150dd2f 100755
--- a/tools/make-tarball
+++ b/tools/make-tarball
@@ -1,39 +1,63 @@
#!/bin/sh
set -e
-find_root() {
- local topd
- if [ -z "${CLOUD_INIT_TOP_D}" ]; then
- topd=$(cd "$(dirname "${0}")" && cd .. && pwd)
- else
- topd=$(cd "${CLOUD_INIT_TOP_D}" && pwd)
- fi
- [ $? -eq 0 -a -f "${topd}/setup.py" ] || return
- ROOT_DIR="$topd"
+TEMP_D=""
+cleanup() {
+ [ -z "$TEMP_D" ] || rm -Rf "${TEMP_D}"
}
+trap cleanup EXIT
-if ! find_root; then
- echo "Unable to locate 'setup.py' file that should" \
- "exist in the cloud-init root directory." 1>&2
- exit 1;
-fi
+Usage() {
+ cat <<EOF
+Usage: ${0##*/} [revision]
+ create a tarball of revision (default HEAD)
-REVNO=$(bzr revno "$ROOT_DIR")
+ options:
+ -o | --output FILE write to file
+EOF
+}
-if [ ! -z "$1" ]; then
- ARCHIVE_FN="$1"
-else
- VERSION=$("$ROOT_DIR/tools/read-version")
- ARCHIVE_FN="$PWD/cloud-init-$VERSION~bzr$REVNO.tar.gz"
-fi
+short_opts="ho:v"
+long_opts="help,output:,long,verbose"
+getopt_out=$(getopt --name "${0##*/}" \
+ --options "${short_opts}" --long "${long_opts}" -- "$@") &&
+ eval set -- "${getopt_out}" || { Usage 1>&2; exit 1; }
-export_uncommitted=""
-if [ "${UNCOMMITTED:-0}" != "0" ]; then
- export_uncommitted="--uncommitted"
+long_opt=""
+while [ $# -ne 0 ]; do
+ cur=$1; next=$2
+ case "$cur" in
+ -o|--output) output=$next; shift;;
+ --long) long_opt="--long";;
+ --) shift; break;;
+ esac
+ shift;
+done
+
+rev=${1:-HEAD}
+version=$(git describe ${long_opt} $rev)
+
+archive_base="cloud-init-$version"
+if [ -z "$output" ]; then
+ output="$archive_base.tar.gz"
fi
-bzr export ${export_uncommitted} \
- --format=tgz --root="cloud-init-$VERSION~bzr$REVNO" \
- "--revision=${REVNO}" "${ARCHIVE_FN}" "$ROOT_DIR"
+# when building an archiving from HEAD, ensure that there aren't any
+# uncomitted changes in the working directory (because these would not
+# end up in the archive).
+if [ "$rev" = HEAD ] && ! git diff-index --quiet HEAD --; then
+ if [ -z "$SKIP_UNCOMITTED_CHANGES_CHECK" ]; then
+ echo "ERROR: There are uncommitted changes in your working directory." >&2
+ exit 1
+ else
+ echo "WARNING: There are uncommitted changes in your working directory." >&2
+ echo " This changes will not be included in the archive." >&2
+ fi
+fi
-echo "$ARCHIVE_FN"
+TEMP_D=$(mktemp -d)
+tar=${output##*/}
+tar="$TEMP_D/${tar%.gz}"
+git archive --format=tar --prefix="$archive_base/" "$rev" > "$tar"
+gzip -9 -c "$tar" > "$output"
+echo "$output"
diff --git a/tools/read-dependencies b/tools/read-dependencies
index 6a6f3e12..9fc503eb 100755
--- a/tools/read-dependencies
+++ b/tools/read-dependencies
@@ -1,8 +1,13 @@
#!/usr/bin/env python
+# You might be tempted to rewrite this as a shell script, but you
+# would be surprised to discover that things like 'egrep' or 'sed' may
+# differ between Linux and *BSD.
+
import os
import re
import sys
+import subprocess
if 'CLOUD_INIT_TOP_D' in os.environ:
topd = os.path.realpath(os.environ.get('CLOUD_INIT_TOP_D'))
@@ -16,14 +21,21 @@ for fname in ("setup.py", "requirements.txt"):
sys.exit(1)
if len(sys.argv) > 1:
- reqfile = sys.argv[1]
+ reqfile = sys.argv[1]
else:
- reqfile = "requirements.txt"
-
+ reqfile = "requirements.txt"
+
with open(os.path.join(topd, reqfile), "r") as fp:
for line in fp:
- if not line.strip() or line.startswith("#"):
+ line = line.strip()
+ if not line or line.startswith("#"):
continue
- sys.stdout.write(re.split("[>=.<]*", line)[0].strip() + "\n")
+
+ # remove pip-style markers
+ dep = line.split(';')[0]
+
+ # remove version requirements
+ dep = re.split("[>=.<]*", dep)[0].strip()
+ print(dep)
sys.exit(0)
diff --git a/tools/read-version b/tools/read-version
index d02651e9..c10f9b46 100755
--- a/tools/read-version
+++ b/tools/read-version
@@ -1,26 +1,101 @@
#!/usr/bin/env python
import os
-import re
+import json
+import subprocess
import sys
-if 'CLOUD_INIT_TOP_D' in os.environ:
- topd = os.path.realpath(os.environ.get('CLOUD_INIT_TOP_D'))
-else:
- topd = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
+if "avoid-pep8-E402-import-not-top-of-file":
+ _tdir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
+ sys.path.insert(0, _tdir)
+ from cloudinit import version as ci_version
+
+
+def tiny_p(cmd, capture=True):
+ # python 2.6 doesn't have check_output
+ stdout = subprocess.PIPE
+ stderr = subprocess.PIPE
+ sp = subprocess.Popen(cmd, stdout=stdout,
+ stderr=stderr, stdin=None,
+ universal_newlines=True)
+ (out, err) = sp.communicate()
+ ret = sp.returncode
+ if ret not in [0]:
+ raise RuntimeError("Failed running %s [rc=%s] (%s, %s)" %
+ (cmd, ret, out, err))
+ return out
+
+
+def which(program):
+ # Return path of program for execution if found in path
+ def is_exe(fpath):
+ return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
+
+ _fpath, _ = os.path.split(program)
+ if _fpath:
+ if is_exe(program):
+ return program
+ else:
+ for path in os.environ.get("PATH", "").split(os.pathsep):
+ path = path.strip('"')
+ exe_file = os.path.join(path, program)
+ if is_exe(exe_file):
+ return exe_file
+
+ return None
+
+
+use_long = '--long' in sys.argv or os.environ.get('CI_RV_LONG')
+use_tags = '--tags' in sys.argv or os.environ.get('CI_RV_TAGS')
+output_json = '--json' in sys.argv
-for fname in ("setup.py", "ChangeLog"):
- if not os.path.isfile(os.path.join(topd, fname)):
- sys.stderr.write("Unable to locate '%s' file that should "
- "exist in cloud-init root directory." % fname)
+src_version = ci_version.version_string()
+version_long = None
+
+if os.path.isdir(os.path.join(_tdir, ".git")) and which("git"):
+ flags = []
+ if use_tags:
+ flags = ['--tags']
+ cmd = ['git', 'describe'] + flags
+
+ version = tiny_p(cmd).strip()
+
+ if not version.startswith(src_version):
+ sys.stderr.write("git describe version (%s) differs from "
+ "cloudinit.version (%s)\n" % (version, src_version))
sys.exit(1)
-vermatch = re.compile(r"^[0-9]+[.][0-9]+[.][0-9]+:$")
+ version_long = tiny_p(cmd + ["--long"]).strip()
+else:
+ version = src_version
+ version_long = None
+
+# version is X.Y.Z[+xxx.gHASH]
+# version_long is None or X.Y.Z-xxx-gHASH
+release = version.partition("-")[0]
+extra = None
+commit = None
+distance = None
+
+if version_long:
+ info = version_long.partition("-")[2]
+ extra = "-" + info
+ distance, commit = info.split("-")
+ # remove the 'g' from gHASH
+ commit = commit[1:]
-with open(os.path.join(topd, "ChangeLog"), "r") as fp:
- for line in fp:
- if vermatch.match(line):
- sys.stdout.write(line.strip()[:-1] + "\n")
- break
+data = {
+ 'release': release,
+ 'version': version,
+ 'version_long': version_long,
+ 'extra': extra,
+ 'commit': commit,
+ 'distance': distance,
+}
+
+if output_json:
+ sys.stdout.write(json.dumps(data, indent=1) + "\n")
+else:
+ sys.stdout.write(release + "\n")
sys.exit(0)