summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-07-02 19:02:16 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2012-07-02 19:02:16 -0700
commitf99dd7c2e43f9117c66e06fc31d10f559c912e86 (patch)
treee73909fc13c0cb2700c256c14dcb09d7da539595 /tools
parent115e53d3a9114326cb7c07e4b95947b87d9e2d02 (diff)
downloadvyos-cloud-init-f99dd7c2e43f9117c66e06fc31d10f559c912e86.tar.gz
vyos-cloud-init-f99dd7c2e43f9117c66e06fc31d10f559c912e86.zip
Update the mock metadata server to return a file (or the default generated content) for the userdata blob.
Diffstat (limited to 'tools')
-rwxr-xr-xtools/mock-meta.py27
1 files changed, 20 insertions, 7 deletions
diff --git a/tools/mock-meta.py b/tools/mock-meta.py
index 0f13acd6..8a73b43c 100755
--- a/tools/mock-meta.py
+++ b/tools/mock-meta.py
@@ -196,18 +196,26 @@ class UserDataHandler(object):
self.opts = opts
def _get_user_blob(self, **kwargs):
- blob_mp = {}
- blob_mp['hostname'] = kwargs.get('who', '')
- lines = []
- lines.append("#cloud-config")
- lines.append(yamlify(blob_mp))
- blob = "\n".join(lines)
+ blob = None
+ if self.opts['user_data_file']:
+ with open(opts['user_data_file'], 'rb') as fh:
+ blob = fh.read()
+ blob = blob.strip()
+ if not blob:
+ blob_mp = {
+ 'hostname': kwargs.get('who', 'localhost'),
+ }
+ lines = [
+ "#cloud-config",
+ yamlify(blob_mp),
+ ]
+ blob = "\n".join(lines)
return blob.strip()
def get_data(self, params, who, **kwargs):
if not params:
return self._get_user_blob(who=who)
- return ''
+ return NOT_IMPL_RESPONSE
# Seem to need to use globals since can't pass
@@ -303,10 +311,15 @@ def extract_opts():
parser = OptionParser()
parser.add_option("-p", "--port", dest="port", action="store", type=int, default=80,
help="port from which to serve traffic (default: %default)", metavar="PORT")
+ parser.add_option("-f", '--user-data-file', dest='user_data_file', action='store',
+ help="user data blob to serve back to incoming requests", metavar='FILE')
(options, args) = parser.parse_args()
out = dict()
out['extra'] = args
out['port'] = options.port
+ out['user_data_file'] = None
+ if options.user_data_file:
+ out['user_data_file'] = options.user_data_file
return out