Skip to content

Instantly share code, notes, and snippets.

@bdha
Created February 16, 2012 23:27
Show Gist options
  • Select an option

  • Save bdha/1848735 to your computer and use it in GitHub Desktop.

Select an option

Save bdha/1848735 to your computer and use it in GitHub Desktop.
# /root/sdc-dsimport openbsd-5.0-gateway.dsmanifest
Importing Dataset defined in 'openbsd-5.0-gateway.dsmanifest'.
Checking dataset file '/var/tmp/openbsd-5.0-gateway.zvol.bz2' sha1.
Copy dataset file to datasets dir, '/usbkey/datasets/openbsd-5.0-gateway.zvol.bz2'.
Registering dataset b5de0960-592f-11e1-8536-a7811176bc79 (sdc:admin:openbsd-5.0-gateway:1.0) with MAPI.
# diff -u /smartdc/bin/sdc-dsimport sdc-dsimport
--- /smartdc/bin/sdc-dsimport Thu Jan 26 16:05:13 2012
+++ sdc-dsimport Fri Feb 17 06:19:32 2012
@@ -45,14 +45,15 @@
dsapi=$2
if [[ -z "${dsapi}" ]]; then
dsapi=${CONFIG_dsapi_url}
+ # Need an IP for datasets hostname.
+ local dsapi_ip=${dsapi}
+ hostname=$(echo ${dsapi} | cut -f3 -d "/" | cut -f1 -d ":")
+
+ #if [[ ! `echo "${hostname}" | grep "^[0-9\.]*$" 2>&1` ]]; then
+ # ip=$(dig $hostname +short)
+ # dsapi_ip=$(echo $dsapi | sed "s|\(.*\)$hostname\(.*\)|\1$ip\2|")
+ #fi
fi
- # Need an IP for datasets hostname.
- local dsapi_ip=${dsapi}
- hostname=$(echo ${dsapi} | cut -f3 -d "/" | cut -f1 -d ":")
- if [[ ! `echo "${hostname}" | grep "^[0-9\.]*$" 2>&1` ]]; then
- ip=$(dig $hostname +short)
- dsapi_ip=$(echo $dsapi | sed "s|\(.*\)$hostname\(.*\)|\1$ip\2|")
- fi
# Note: /usr/bin/egrep on smartos doesn't support '{m,n}' quantifiers.
# /usr/xpg4/bin/egrep *does*, so should switch to that.
@@ -68,7 +69,7 @@
fatal "'${dataset_arg}' isn't a Dataset UUID and isn't an existing .dsmanifest file. Aborting."
fi
- local manifest;
+ local manifest
if [[ "${mode}" == "dsapi" ]]; then
echo "Getting dataset info from Dataset API (${dsapi}))."
manifest=$(DSAPI_URL=${dsapi_ip} sdc-dsapi /datasets/$dataset_uuid | json -H)
@trentm
Copy link

trentm commented Feb 17, 2012

Thanks for this!

Preferred patch:

Index: .../sdc-dsimport
index 43ced76..3ab409e 100755
--- a/bin/sdc-dsimport
+++ b/bin/sdc-dsimport
@@ -46,12 +46,16 @@ function dataset_import {
     if [[ -z "${dsapi}" ]]; then
         dsapi=${CONFIG_dsapi_url}
     fi
-    # Need an IP for datasets hostname.
-    local dsapi_ip=${dsapi}
-    hostname=$(echo ${dsapi} | cut -f3 -d "/" | cut -f1 -d ":")
-    if [[ ! `echo "${hostname}" | grep "^[0-9\.]*$" 2>&1` ]]; then
-      ip=$(dig $hostname +short)
-      dsapi_ip=$(echo $dsapi | sed  "s|\(.*\)$hostname\(.*\)|\1$ip\2|")
+
+    local dsapi_ip
+    if [[ "${mode}" == "dsapi" ]]; then
+        # Need an IP for datasets hostname.
+        dsapi_ip=${dsapi}
+        local hostname=$(echo ${dsapi} | cut -f3 -d "/" | cut -f1 -d ":")
+        if [[ ! `echo "${hostname}" | grep "^[0-9\.]*$" 2>&1` ]]; then
+            local ip=$(dig $hostname +short)
+            dsapi_ip=$(echo $dsapi | sed  "s|\(.*\)$hostname\(.*\)|\1$ip\2|")
+        fi
     fi

     # Note: /usr/bin/egrep on smartos doesn't support '{m,n}' quantifiers.
@@ -68,7 +72,7 @@ function dataset_import {
         fatal "'${dataset_arg}' isn't a Dataset UUID and isn't an existing .dsmanifest file. Aborting."
     fi

-    local manifest;
+    local manifest
     if [[ "${mode}" == "dsapi" ]]; then
         echo "Getting dataset info from Dataset API (${dsapi}))."
         manifest=$(DSAPI_URL=${dsapi_ip} sdc-dsapi /datasets/$dataset_uuid | json -H)

(see https://gist.github.com/688a5e5ddcce8af51c46)

The correct guard is whether the DSAPI URL is going to be used (mode == "dsapi"). Will commit this once I get a chance to test it.

@trentm
Copy link

trentm commented Mar 26, 2012

Here is the patch commited to our master (slight corrections to my previously posted patch after actually testing it):

From 06fbdb76132af929c2a3a9e65290f3203950a7bd Mon Sep 17 00:00:00 2001
From: Trent Mick <[email protected]>
Date: Mon, 26 Mar 2012 11:35:01 -0700
Subject: [PATCH] OS-690: sdc-dsimport should not try to resolve datasets.joyent.com -> IP if it doesn't need it


---
 bin/sdc-dsimport |   25 ++++++++++++++++---------
 1 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/bin/sdc-dsimport b/bin/sdc-dsimport
index 43ced76..62fdc16 100755
--- a/bin/sdc-dsimport
+++ b/bin/sdc-dsimport
@@ -15,7 +15,7 @@

 VERSION=2.0.1

-if [ "$DEBUG" != "" ]; then
+if [ "$TRACE" != "" ]; then
     export PS4='${BASH_SOURCE}:${LINENO}: ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
     set -o xtrace
 fi
@@ -46,13 +46,6 @@ function dataset_import {
     if [[ -z "${dsapi}" ]]; then
         dsapi=${CONFIG_dsapi_url}
     fi
-    # Need an IP for datasets hostname.
-    local dsapi_ip=${dsapi}
-    hostname=$(echo ${dsapi} | cut -f3 -d "/" | cut -f1 -d ":")
-    if [[ ! `echo "${hostname}" | grep "^[0-9\.]*$" 2>&1` ]]; then
-      ip=$(dig $hostname +short)
-      dsapi_ip=$(echo $dsapi | sed  "s|\(.*\)$hostname\(.*\)|\1$ip\2|")
-    fi

     # Note: /usr/bin/egrep on smartos doesn't support '{m,n}' quantifiers.
     # /usr/xpg4/bin/egrep *does*, so should switch to that.
@@ -68,7 +61,21 @@ function dataset_import {
         fatal "'${dataset_arg}' isn't a Dataset UUID and isn't an existing .dsmanifest file. Aborting."
     fi

-    local manifest;
+    local dsapi_ip
+    if [[ "${mode}" == "dsapi" ]]; then
+        # Need an IP for datasets hostname.
+        dsapi_ip=${dsapi}
+        local hostname=$(echo ${dsapi} | cut -f3 -d "/" | cut -f1 -d ":")
+        if [[ ! `echo "${hostname}" | grep "^[0-9\.]*$" 2>&1` ]]; then
+            local ip=$(dig $hostname +short)
+            if [[ -n "$(echo ${ip} | grep ';')" ]]; then
+                fatal "Could not determine IP for '${hostname}': '${ip}'"
+            fi
+            dsapi_ip=$(echo $dsapi | sed  "s|\(.*\)$hostname\(.*\)|\1$ip\2|")
+        fi
+    fi
+
+    local manifest
     if [[ "${mode}" == "dsapi" ]]; then
         echo "Getting dataset info from Dataset API (${dsapi}))."
         manifest=$(DSAPI_URL=${dsapi_ip} sdc-dsapi /datasets/$dataset_uuid | json -H)
-- 
1.7.3.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment