Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
kamaki
Commits
76f01c50
Commit
76f01c50
authored
Sep 22, 2011
by
Giorgos Verigakis
Browse files
Add personality support for server create
parent
5d1d131b
Changes
2
Hide whitespace changes
Inline
Side-by-side
kamaki/client.py
View file @
76f01c50
...
...
@@ -34,6 +34,7 @@
import
json
import
logging
from
base64
import
b64encode
from
httplib
import
HTTPConnection
,
HTTPSConnection
from
urlparse
import
urlparse
...
...
@@ -126,8 +127,17 @@ class Client(object):
reply
=
self
.
_get
(
path
)
return
reply
[
'server'
]
def
create_server
(
self
,
name
,
flavor
,
image
):
def
create_server
(
self
,
name
,
flavor
,
image
,
personality
=
None
):
"""personality is a list of (path, data) tuples"""
req
=
{
'name'
:
name
,
'flavorRef'
:
flavor
,
'imageRef'
:
image
}
if
personality
:
p
=
[]
for
path
,
data
in
personality
:
contents
=
b64encode
(
data
)
p
.
append
({
'path'
:
path
,
'contents'
:
contents
})
req
[
'personality'
]
=
p
body
=
json
.
dumps
({
'server'
:
req
})
reply
=
self
.
_post
(
'/servers'
,
body
)
return
reply
[
'server'
]
...
...
kamaki/kamaki.py
View file @
76f01c50
...
...
@@ -246,11 +246,28 @@ class CreateServer(Command):
help
=
'use flavor FLAVOR_ID'
)
parser
.
add_option
(
'-i'
,
dest
=
'image'
,
metavar
=
'IMAGE_ID'
,
default
=
1
,
help
=
'use image IMAGE_ID'
)
parser
.
add_option
(
'--personality'
,
dest
=
'personality'
,
action
=
'append'
,
metavar
=
'PATH,SERVERPATH'
,
help
=
'add a personality file'
)
def
main
(
self
,
name
):
flavor_id
=
int
(
self
.
flavor
)
image_id
=
int
(
self
.
image
)
reply
=
self
.
client
.
create_server
(
name
,
flavor_id
,
image_id
)
personality
=
[]
if
self
.
personality
:
for
p
in
self
.
personality
:
lpath
,
sep
,
rpath
=
p
.
partition
(
','
)
if
not
lpath
or
not
rpath
:
logging
.
error
(
"Invalid personality argument '%s'"
,
p
)
return
if
not
os
.
path
.
exists
(
lpath
):
logging
.
error
(
"File %s does not exist"
,
lpath
)
return
with
open
(
lpath
)
as
f
:
personality
.
append
((
rpath
,
f
.
read
()))
reply
=
self
.
client
.
create_server
(
name
,
flavor_id
,
image_id
,
personality
)
print_dict
(
reply
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment