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
Eric Zheng
slapos.core
Commits
5ae90086
Commit
5ae90086
authored
Jul 28, 2021
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cli/request: support yaml format for --parameters-file option
parent
69d8890a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
1 deletion
+18
-1
setup.py
setup.py
+1
-0
slapos/cli/request.py
slapos/cli/request.py
+4
-1
slapos/tests/test_cli.py
slapos/tests/test_cli.py
+13
-0
No files found.
setup.py
View file @
5ae90086
...
@@ -75,6 +75,7 @@ setup(name=name,
...
@@ -75,6 +75,7 @@ setup(name=name,
'cachecontrol'
,
'cachecontrol'
,
'lockfile'
,
'lockfile'
,
'jsonschema'
,
'jsonschema'
,
'pyaml'
,
'uritemplate'
,
# used by hateoas navigator
'uritemplate'
,
# used by hateoas navigator
'subprocess32; python_version<"3"'
,
'subprocess32; python_version<"3"'
,
'ipaddress; python_version<"3"'
,
# used by whitelistfirewall
'ipaddress; python_version<"3"'
,
# used by whitelistfirewall
...
...
slapos/cli/request.py
View file @
5ae90086
...
@@ -33,6 +33,7 @@ import os.path
...
@@ -33,6 +33,7 @@ import os.path
import
pprint
import
pprint
import
lxml.etree
import
lxml.etree
import
yaml
from
slapos.cli.config
import
ClientConfigCommand
from
slapos.cli.config
import
ClientConfigCommand
from
slapos.client
import
(
ClientConfig
,
_getSoftwareReleaseFromSoftwareString
,
from
slapos.client
import
(
ClientConfig
,
_getSoftwareReleaseFromSoftwareString
,
...
@@ -49,7 +50,9 @@ except ImportError:
...
@@ -49,7 +50,9 @@ except ImportError:
def
getParametersFromFile
(
file
,
serialisation
):
def
getParametersFromFile
(
file
,
serialisation
):
# type: (IO[str], SoftwareReleaseSerialisation) -> Dict
# type: (IO[str], SoftwareReleaseSerialisation) -> Dict
extension
=
os
.
path
.
splitext
(
file
.
name
)[
1
]
extension
=
os
.
path
.
splitext
(
file
.
name
)[
1
]
if
extension
==
'.xml'
:
if
extension
in
(
'.yaml'
,
'.yml'
):
params
=
yaml
.
safe_load
(
file
)
elif
extension
==
'.xml'
:
tree
=
lxml
.
etree
.
parse
(
file
)
tree
=
lxml
.
etree
.
parse
(
file
)
params
=
{
e
.
attrib
[
'id'
]:
e
.
text
for
e
in
tree
.
findall
(
'/parameter'
)}
params
=
{
e
.
attrib
[
'id'
]:
e
.
text
for
e
in
tree
.
findall
(
'/parameter'
)}
# because the use case of xml files is to copy paste existing XML parameters
# because the use case of xml files is to copy paste existing XML parameters
...
...
slapos/tests/test_cli.py
View file @
5ae90086
...
@@ -739,6 +739,19 @@ class TestCliRequestParametersFileJson(CliMixin):
...
@@ -739,6 +739,19 @@ class TestCliRequestParametersFileJson(CliMixin):
)
)
class
TestCliRequestParametersFileYaml
(
TestCliRequestParametersFileJson
):
def
_makeParameterFile
(
self
):
f
=
tempfile
.
NamedTemporaryFile
(
suffix
=
'.yaml'
,
mode
=
'w'
,
delete
=
False
)
f
.
write
(
textwrap
.
dedent
(
'''
\
{
"foo": ["bar"]
}
'''
))
f
.
flush
()
self
.
addCleanup
(
os
.
unlink
,
f
.
name
)
return
f
.
name
class
TestCliRequestParametersFileXml
(
TestCliRequestParametersFileJson
):
class
TestCliRequestParametersFileXml
(
TestCliRequestParametersFileJson
):
expected_partition_parameter_kw
=
{
'foo'
:
'bar'
}
expected_partition_parameter_kw
=
{
'foo'
:
'bar'
}
def
_makeParameterFile
(
self
):
def
_makeParameterFile
(
self
):
...
...
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