Commit 0fccd79b authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Allow meta-keys to personality argument

Refs: #4297

Backwards compatibility is preserved (not planed to deprecate it)
The following are semantically equivalent:
-p local-path=/local/path,remote=path=/etc/local/path,mode=-rw-r--r--
-p /local/path,remote=path=/etc/local/path,mode=-rw-r--r--
-p /local/path,/etc/local/path,mode=-rw-r--r--
parent ef3488a7
......@@ -63,11 +63,12 @@ about_authentication = '\nUser Authentication:\
howto_personality = [
'Defines a file to be injected to virtual servers file system.',
' PATH: local file to be injected (relative or absolute)',
' SERVER_PATH: destination location inside server Image',
' OWNER: virtual servers user id of the remote destination file',
' GROUP: virtual servers group id or name of the destination file',
' MODEL: permition in octal (e.g., 0777 or o+rwx)']
' [local-path=]PATH: local file to be injected (relative or absolute)',
' [server-path=]SERVER_PATH: destination location inside server Image',
' [owner=]OWNER: virtual servers user id for the remote file',
' [group=]GROUP: virtual servers group id or name for the remote file',
' [mode=]MODE: permission in octal (e.g., 0777 or o+rwx)',
'e.g., -p /tmp/my.file,owner=root,mode=0777']
class _service_wait(object):
......@@ -302,6 +303,14 @@ class server_info(_init_cyclades, _optional_json):
class PersonalityArgument(KeyValueArgument):
terms = (
('local-path', 'contents'),
('server-path', 'path'),
('owner', 'owner'),
('group', 'group'),
('mode', 'mode'))
def value(self):
return self._value if hasattr(self, '_value') else []
......@@ -310,28 +319,48 @@ class PersonalityArgument(KeyValueArgument):
def value(self, newvalue):
if newvalue == self.default:
return self.value
self._value = []
self._value, input_dict = [], {}
for i, terms in enumerate(newvalue):
termlist = terms.split(',')
if len(termlist) > 5:
msg = 'Wrong number of terms (should be 1 to 5)'
if len(termlist) > len(self.terms):
msg = 'Wrong number of terms (1<=terms<=%s)' % len(self.terms)
raiseCLIError(CLISyntaxError(msg), details=howto_personality)
path = termlist[0]
for k, v in self.terms:
prefix = '%s=' % k
for item in termlist:
if item.lower().startswith(prefix):
input_dict[k] = item[len(k) + 1:]
item = None
if item:
path = input_dict['local-path']
except KeyError:
path = termlist.pop(0)
if not path:
raise CLIInvalidArgument(
'--personality: No local path specified',
if not exists(path):
raise CLIInvalidArgument(
'--personality: File %s does not exist' % path,
importance=1, details=howto_personality)
with open(path) as f:
self._value[i]['contents'] = b64encode(
self._value[i]['path'] = termlist[1]
self._value[i]['owner'] = termlist[2]
self._value[i]['group'] = termlist[3]
self._value[i]['mode'] = termlist[4]
except IndexError:
for k, v in self.terms[1:]:
self._value[i][v] = input_dict[k]
except KeyError:
self._value[i][v] = termlist.pop(0)
except IndexError:
......@@ -354,6 +383,7 @@ class server_create(_init_cyclades, _optional_json, _server_wait):
def _run(self, name, flavor_id, image_id):
print 'hey, wha?'
r = self.client.create_server(
name, int(flavor_id), image_id, personality=self['personality'])
usernames = self._uuids2usernames([r['user_id'], r['tenant_id']])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment