Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ivan Tyagov
slapos.core
Commits
37b346df
Commit
37b346df
authored
Oct 02, 2012
by
Cédric Le Ninivin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Request now works as described in documentation
parent
423e935d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
31 deletions
+69
-31
slapos/console.py
slapos/console.py
+69
-31
No files found.
slapos/console.py
View file @
37b346df
...
...
@@ -27,9 +27,9 @@
#
##############################################################################
import
argparse
import
slapos.slap.slap
from
slapos.slap
import
ResourceNotReady
import
sys
import
os
from
optparse
import
OptionParser
,
Option
...
...
@@ -69,16 +69,49 @@ class Parser(OptionParser):
return
options
,
args
class
RequestParser
(
Parser
):
def
check_args
(
self
):
"""
Check arguments
"""
(
options
,
args
)
=
Parser
.
check_args
(
self
)
if
len
(
args
)
<
3
:
self
.
error
(
"Incorrect number of arguments"
)
return
options
,
args
def
argToDict
(
element
):
"""
convert a table of string 'key=value' to dict
"""
if
element
is
not
None
:
element_dict
=
dict
([
arg
.
split
(
'='
)
for
arg
in
element
])
return
element_dict
def
check_request_args
():
"""
Parser for request
"""
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"configuration_file"
,
nargs
=
1
,
help
=
"SlapOS configuration file."
)
parser
.
add_argument
(
"reference"
,
help
=
"Your instance reference"
)
parser
.
add_argument
(
"software_url"
,
help
=
"Your software url"
)
parser
.
add_argument
(
"--node"
,
nargs
=
'*'
,
help
=
"Node request option "
"'option1=value1 option2=value2'"
)
parser
.
add_argument
(
"--type"
,
type
=
str
,
help
=
"Define software type to be requested"
)
parser
.
add_argument
(
"--slave"
,
action
=
"store_true"
,
default
=
False
,
help
=
"Ask for a slave instance"
)
parser
.
add_argument
(
"--configuration"
,
nargs
=
'*'
,
help
=
"Give your configuration "
"'option1=value1 option2=value2'"
)
args
=
parser
.
parse_args
()
# Convert to dict
if
args
.
configuration
is
not
None
:
args
.
configuration
=
argToDict
(
args
.
configuration
)
if
args
.
node
is
not
None
:
args
.
node
=
argToDict
(
args
.
node
)
return
args
class
Config
:
def
setConfig
(
self
,
option_dict
,
configuration_file_path
):
...
...
@@ -103,12 +136,18 @@ class Config:
setattr
(
self
,
key
,
configuration_dict
[
key
])
configuration_dict
=
dict
(
configuration_parser
.
items
(
'slapos'
))
master_url
=
configuration_dict
.
get
(
'master_url'
,
None
)
# Backward compatibility, if no key and certificate given in option
# take one from slapos configuration
if
not
getattr
(
self
,
'key_file'
,
None
)
and
\
not
getattr
(
self
,
'cert_file'
,
None
):
self
.
key_file
=
configuration_dict
.
get
(
'key_file'
)
self
.
cert_file
=
configuration_dict
.
get
(
'cert_file'
)
if
not
master_url
:
raise
ValueError
(
"No option 'master_url'"
)
elif
master_url
.
startswith
(
'https'
)
and
\
not
getattr
(
self
,
'key_file'
,
None
)
and
\
not
getattr
(
self
,
'cert_file'
,
None
)
:
raise
ValueError
(
"No option 'key_file' and/or 'cert_file'"
)
self
.
key_file
is
None
and
\
self
.
cert_file
is
None
:
raise
ValueError
(
"No option 'key_file' and/or 'cert_file'"
)
else
:
setattr
(
self
,
'master_url'
,
master_url
)
...
...
@@ -138,9 +177,9 @@ def init(config):
# *args, **kwargs, but without the bad parts, in order to be generic?
def
shorthandRequest
(
software_release
,
partition_reference
,
partition_parameter_kw
=
None
,
software_type
=
None
,
filter_kw
=
None
,
state
=
None
):
state
=
None
,
shared
=
False
):
return
slap
.
registerOpenOrder
().
request
(
software_release
,
partition_reference
,
partition_parameter_kw
,
software_type
,
filter_kw
,
state
)
partition_parameter_kw
,
software_type
,
filter_kw
,
state
,
shared
)
def
shorthandSupply
(
software_release
,
computer_guid
=
None
,
state
=
'available'
):
return
slap
.
registerSupply
().
supply
(
software_release
,
computer_guid
,
state
)
local
[
'request'
]
=
shorthandRequest
...
...
@@ -150,27 +189,26 @@ def init(config):
def
request
():
"""Ran when invoking slapos-request"""
# Parse arguments
usage
=
"""usage: %s [options] CONFIGURATION_FILE
SOFTWARE_INSTANCE INSTANCE_REFERE
NCE
# Parse arguments
and inititate needed parameters
usage
=
"""usage: %s [options] CONFIGURATION_FILE
INSTANCE_REFERENCE SOFTWARE_INSTA
NCE
slapos-request allows you to request slapos instances."""
%
sys
.
argv
[
0
]
config
=
Config
()
options
,
arguments
=
RequestParser
(
usage
=
usage
).
check_args
()
config
.
setConfig
(
options
,
arguments
[
0
])
options
=
check_request_args
()
config
.
setConfig
(
options
,
options
.
configuration_file
)
local
=
init
(
config
)
# Request instance
# XXX-Cedric : support things like :
# --instance-type std --configuration-size 23 --computer-region europe/france
# XXX-Cedric : add support for xml_parameter
software_url
=
arguments
[
1
]
partition_reference
=
arguments
[
2
]
print
(
"Requesting %s..."
%
software_url
)
if
software_url
in
local
:
software_url
=
local
[
software_url
]
print
(
"Requesting %s..."
%
config
.
software_url
)
if
config
.
software_url
in
local
:
config
.
software_url
=
local
[
config
.
software_url
]
try
:
partition
=
local
[
'slap'
].
registerOpenOrder
().
request
(
software_url
,
partition_reference
)
partition
=
local
[
'slap'
].
registerOpenOrder
().
request
(
software_release
=
config
.
software_url
,
partition_reference
=
config
.
reference
,
partition_parameter_kw
=
config
.
configuration
,
software_type
=
config
.
type
,
filter_kw
=
config
.
node
,
shared
=
config
.
slave
)
print
(
"Instance requested.
\
n
State is : %s.
\
n
You can "
"rerun to get up-to-date informations."
%
(
partition
.
getState
()))
...
...
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