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
Paul Graydon
slapos.core
Commits
8652fba3
Commit
8652fba3
authored
May 23, 2022
by
Cédric Le Ninivin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slap command line: update request and supply to use jIO API
parent
e42bce91
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
112 additions
and
21 deletions
+112
-21
slapos/cli/request.py
slapos/cli/request.py
+38
-11
slapos/cli/supply.py
slapos/cli/supply.py
+19
-6
slapos/slap/hateoas.py
slapos/slap/hateoas.py
+5
-2
slapos/slap/slap.py
slapos/slap/slap.py
+50
-2
No files found.
slapos/cli/request.py
View file @
8652fba3
...
...
@@ -163,18 +163,45 @@ def do_request(logger, conf, local):
if
conf
.
parameters_file
:
parameters
=
getParametersFromFile
(
conf
.
parameters_file
,
software_schema_serialisation
)
try
:
partition
=
local
[
'slap'
].
registerOpenOrder
().
request
(
software_release
=
conf
.
software_url
,
partition_reference
=
conf
.
reference
,
partition_parameter_kw
=
parameters
,
software_type
=
conf
.
type
,
filter_kw
=
conf
.
node
,
state
=
conf
.
state
,
shared
=
conf
.
slave
)
logger
.
info
(
'Instance requested.
\
n
State is : %s.'
,
partition
.
getState
())
if
local
[
'slap'
].
jio_api_connector
:
request_dict
=
{
"title"
:
conf
.
reference
,
"portal_type"
:
"Software Instance"
,
"software_release_uri"
:
conf
.
software_url
,
}
if
conf
.
state
:
request_dict
[
'state'
]
=
conf
.
state
if
conf
.
slave
:
request_dict
[
"shared"
]
=
True
if
conf
.
node
:
request_dict
[
"sla_parameters"
]
=
conf
.
node
if
conf
.
parameters
:
request_dict
[
"parameters"
]
=
json
.
dumps
(
conf
.
parameters
)
if
conf
.
type
:
request_dict
[
"software_type"
]
=
conf
.
type
partition_dict
=
local
[
'slap'
].
jio_api_connector
.
post
(
request_dict
)
if
"$schema"
in
partition_dict
and
"error-response-schema.json"
in
partition_dict
[
"$schema"
]:
logger
.
warning
(
'Server Response: %s'
%
json
.
dumps
(
partition_dict
,
indent
=
2
))
logger
.
warning
(
'Instance requested. Master is provisioning it. Please rerun in a '
'couple of minutes to get connection information.'
)
exit
(
2
)
instance_state
=
partition_dict
[
"state"
]
connection_parameter_dict
=
partition_dict
[
"connection_parameters"
]
else
:
partition
=
local
[
'slap'
].
registerOpenOrder
().
request
(
software_release
=
conf
.
software_url
,
partition_reference
=
conf
.
reference
,
partition_parameter_kw
=
parameters
,
software_type
=
conf
.
type
,
filter_kw
=
conf
.
node
,
state
=
conf
.
state
,
shared
=
conf
.
slave
)
instance_state
=
partition
.
getState
()
connection_parameter_dict
=
partition
.
getConnectionParameterDict
()
logger
.
info
(
'Instance requested.
\
n
State is : %s.'
,
instance_state
)
logger
.
info
(
'Connection parameters of instance are:'
)
connection_parameter_dict
=
partition
.
getConnectionParameterDict
()
if
software_schema_serialisation
==
SoftwareReleaseSerialisation
.
JsonInXml
:
if
'_'
in
connection_parameter_dict
:
connection_parameter_dict
=
json
.
loads
(
connection_parameter_dict
[
'_'
])
...
...
slapos/cli/supply.py
View file @
8652fba3
...
...
@@ -27,6 +27,8 @@
#
##############################################################################
import
json
from
slapos.cli.config
import
ClientConfigCommand
from
slapos.client
import
init
,
ClientConfig
,
_getSoftwareReleaseFromSoftwareString
...
...
@@ -63,10 +65,21 @@ def do_supply(logger, software_release, computer_id, local):
software_release
=
_getSoftwareReleaseFromSoftwareString
(
logger
,
software_release
,
local
[
'product'
])
local
[
'supply'
](
software_release
=
software_release
,
computer_guid
=
computer_id
,
state
=
'available'
)
if
local
[
'slap'
].
jio_api_connector
:
software_installation
=
local
[
'slap'
].
jio_api_connector
.
post
({
"portal_type"
:
"Software Installation"
,
"software_release_uri"
:
software_release
,
"compute_node_id"
:
computer_id
,
"state"
:
'available'
})
if
"$schema"
in
software_installation
and
"error-response-schema.json"
in
software_installation
[
"$schema"
]:
logger
.
warning
(
'Issue during the request. Server Response: %s'
%
json
.
dumps
(
software_installation
,
indent
=
2
))
logger
.
warning
(
'Message: %s'
%
software_installation
.
get
(
"message"
,
""
))
exit
(
2
)
else
:
local
[
'supply'
](
software_release
=
software_release
,
computer_guid
=
computer_id
,
state
=
'available'
)
logger
.
info
(
'Done.'
)
slapos/slap/hateoas.py
View file @
8652fba3
...
...
@@ -86,7 +86,8 @@ class ConnectionHelper:
self
.
session
=
CacheControl
(
self
.
uncached_session
,
cache
=
FileCache
(
os
.
path
.
expanduser
(
"~/.slapos_cached_get"
)))
def
do_request
(
self
,
method
,
path
,
params
=
None
,
data
=
None
,
headers
=
None
):
def
do_request
(
self
,
method
,
path
,
params
=
None
,
data
=
None
,
headers
=
None
,
expect_json_error
=
False
):
url
=
parse
.
urljoin
(
self
.
slapgrid_uri
,
path
)
if
headers
is
None
:
headers
=
{}
...
...
@@ -106,7 +107,7 @@ class ConnectionHelper:
# Old behavior was to pass empty parameters as "None" value.
# Behavior kept for compatibility with old slapproxies (< v1.3.3).
# Can be removed when old slapproxies are no longer in use.
if
data
:
if
data
and
isinstance
(
data
,
dict
)
:
for
k
,
v
in
six
.
iteritems
(
data
):
if
v
is
None
:
data
[
k
]
=
'None'
...
...
@@ -131,6 +132,8 @@ class ConnectionHelper:
"enabled on your machine and that the server is available. The "
"original error was:
\
n
%s"
%
exc
)
except
requests
.
HTTPError
as
exc
:
if
expect_json_error
and
not
int
(
exc
.
response
.
status_code
)
>=
500
:
return
req
if
exc
.
response
.
status_code
==
requests
.
status_codes
.
codes
.
not_found
:
msg
=
url
if
params
:
...
...
slapos/slap/slap.py
View file @
8652fba3
...
...
@@ -741,7 +741,34 @@ class SlapConnectionHelper(ConnectionHelper):
return
loads
(
xml
)
class
JioAPIConnectionHelper
(
ConnectionHelper
):
def
apiCall
(
self
,
path
,
data
):
req
=
self
.
do_request
(
requests
.
post
,
path
=
path
,
data
=
json
.
dumps
(
data
),
headers
=
{
'Content-type'
:
'application/json'
},
expect_json_error
=
True
)
return
req
.
json
()
def
get
(
self
,
data
):
return
self
.
apiCall
(
path
=
"get/"
,
data
=
data
)
def
post
(
self
,
data
):
return
self
.
apiCall
(
path
=
"post/"
,
data
=
data
)
def
put
(
self
,
data
):
return
self
.
apiCall
(
path
=
"put/"
,
data
=
data
)
def
allDocs
(
self
,
data
):
return
self
.
apiCall
(
path
=
"allDocs/"
,
data
=
data
)
getHateoasUrl_cache
=
{}
getjIOAPI_cache
=
{}
@
implementer
(
interface
.
slap
)
class
slap
:
...
...
@@ -749,10 +776,10 @@ class slap:
key_file
=
None
,
cert_file
=
None
,
master_ca_file
=
None
,
timeout
=
60
,
slapgrid_rest_uri
=
None
):
slapgrid_rest_uri
=
None
,
slapgrid_jio_uri
=
None
):
if
master_ca_file
:
raise
NotImplementedError
(
'Master certificate not verified in this version: %s'
%
master_ca_file
)
self
.
_connection_helper
=
SlapConnectionHelper
(
slapgrid_uri
,
key_file
,
cert_file
,
master_ca_file
,
timeout
)
...
...
@@ -777,6 +804,27 @@ class slap:
else
:
self
.
_hateoas_navigator
=
None
if
not
slapgrid_jio_uri
:
getjIOAPI_cache_key
=
(
slapgrid_uri
,
key_file
,
cert_file
,
master_ca_file
,
timeout
)
try
:
slapgrid_jio_uri
=
getjIOAPI_cache
[
getjIOAPI_cache_key
]
except
KeyError
:
pass
if
not
slapgrid_jio_uri
:
try
:
slapgrid_jio_uri
=
getjIOAPI_cache
[
getjIOAPI_cache_key
]
=
\
bytes2str
(
self
.
_connection_helper
.
GET
(
'getJIOAPIUrl'
))
except
:
pass
if
slapgrid_jio_uri
:
self
.
jio_api_connector
=
JioAPIConnectionHelper
(
slapgrid_jio_uri
,
key_file
,
cert_file
,
master_ca_file
,
timeout
)
else
:
self
.
jio_api_connector
=
None
# XXX-Cedric: this method is never used and thus should be removed.
def
registerSoftwareRelease
(
self
,
software_release
):
"""
...
...
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