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
Roque
slapos.core
Commits
a981ab14
Commit
a981ab14
authored
Oct 21, 2014
by
Cédric de Saint Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos CLI: add slapos list and slapos info.
parent
4a7c73de
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
248 additions
and
11 deletions
+248
-11
documentation/source/slapos.usage.rst
documentation/source/slapos.usage.rst
+31
-6
setup.py
setup.py
+5
-2
slapos/cli/info.py
slapos/cli/info.py
+76
-0
slapos/cli/list.py
slapos/cli/list.py
+58
-0
slapos/client.py
slapos/client.py
+3
-1
slapos/tests/cli.py
slapos/tests/cli.py
+75
-2
No files found.
documentation/source/slapos.usage.rst
View file @
a981ab14
...
...
@@ -65,11 +65,17 @@ request
.. program-output:: python slapos help request
Request the deployment of a service (instance).
Examples
* Request a wordpress instance named "mybeautifulinstance" on Node named "COMP-12345"::
* Request a wordpress instance named "mybeautifulinstance" on any available machine (either owned by user, public, or shared by other user to current user)::
$ slapos request mybeautifulinstance wordpress
$ slapos request mybeautifulinstance wordpress --node computer_guid=COMP-12345
* Request a wordpress instance named "My Beautiful Instance" on Node named "COMP-12345"::
$ slapos request "My Beautiful Instance" wordpress --node computer_guid=COMP-12345
* Request a kvm instance named "mykvm" on Node named "COMP-12345", specifying nbd-host and nbd-ip parameters::
...
...
@@ -81,14 +87,33 @@ Examples
$ slapos request mykvm \
http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.156:/software/kvm/software.cfg
..
XXX update me
In these examples, ``wordpress`` and ``kvm`` are aliases for the full URL, and are defined in :file:`slapos-client.cfg`.
..
XXX Change in slaplib: allow to fetch instance params without changing anything.
i.e we should do "slapos request myalreadyrequestedinstance" to fetch connection parameters
without erasing previously defined instance parameters.
info
~~~~
.. program-output:: python slapos help info
Get informations of specified instance, like connection parameters, Software Release.
Return an error if instance does not exist for the current user.
Examples:
* Ask informations about an instance named "My Service"
$ slapos info "My Service"
list
~~~~
.. program-output:: python slapos help list
List all deployed services owned by current user.
From SlapOS Master point of view, it should return the list of all non-destroyed Hosting Subscriptions.
..
search
...
...
setup.py
View file @
a981ab14
...
...
@@ -99,11 +99,14 @@ setup(name=name,
'console = slapos.cli.console:ConsoleCommand'
,
'configure local = slapos.cli.configure_local:ConfigureLocalCommand'
,
'configure client = slapos.cli.configure_client:ConfigureClientCommand'
,
'
proxy start = slapos.cli.proxy_start:ProxyStart
Command'
,
'
proxy show = slapos.cli.proxy_show:ProxyShow
Command'
,
'
info = slapos.cli.info:Info
Command'
,
'
list = slapos.cli.list:List
Command'
,
'supply = slapos.cli.supply:SupplyCommand'
,
'remove = slapos.cli.remove:RemoveCommand'
,
'request = slapos.cli.request:RequestCommand'
,
# SlapOS Proxy commands
'proxy start = slapos.cli.proxy_start:ProxyStartCommand'
,
'proxy show = slapos.cli.proxy_show:ProxyShowCommand'
,
]
},
test_suite
=
"slapos.tests"
,
...
...
slapos/cli/info.py
0 → 100644
View file @
a981ab14
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2010-2014 Vifib SARL and Contributors.
# All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation; either version 2.1
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import
pprint
from
slapos.cli.config
import
ClientConfigCommand
from
slapos.client
import
init
,
ClientConfig
from
slapos.slap
import
ResourceNotReady
,
NotFoundError
class
InfoCommand
(
ClientConfigCommand
):
"""get status, software_release and parameters of an instance"""
def
get_parser
(
self
,
prog_name
):
ap
=
super
(
InfoCommand
,
self
).
get_parser
(
prog_name
)
ap
.
add_argument
(
'reference'
,
help
=
'Your instance reference'
)
return
ap
def
take_action
(
self
,
args
):
configp
=
self
.
fetch_config
(
args
)
conf
=
ClientConfig
(
args
,
configp
)
local
=
init
(
conf
,
self
.
app
.
log
)
exit_code
=
do_info
(
self
.
app
.
log
,
conf
,
local
)
if
exit_code
!=
0
:
exit
(
exit_code
)
def
do_info
(
logger
,
conf
,
local
):
try
:
instance
=
local
[
'slap'
].
registerOpenOrder
().
getInformation
(
partition_reference
=
conf
.
reference
,
)
except
ResourceNotReady
:
logger
.
warning
(
'Instance does not exist or is not ready yet.'
)
return
(
2
)
except
NotFoundError
:
logger
.
warning
(
'Instance %s does not exist.'
,
conf
.
reference
)
return
(
2
)
logger
.
info
(
'Software Release URL: %s'
,
instance
.
_software_release_url
)
logger
.
info
(
'Instance state: %s'
,
instance
.
_requested_state
)
logger
.
info
(
'Instance parameters:'
)
logger
.
info
(
pprint
.
pformat
(
instance
.
_parameter_dict
))
logger
.
info
(
'Connection parameters:'
)
logger
.
info
(
pprint
.
pformat
(
instance
.
_connection_dict
))
slapos/cli/list.py
0 → 100644
View file @
a981ab14
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2010-2014 Vifib SARL and Contributors.
# All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation; either version 2.1
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from
slapos.cli.config
import
ClientConfigCommand
from
slapos.client
import
init
,
ClientConfig
from
slapos.slap
import
ResourceNotReady
class
ListCommand
(
ClientConfigCommand
):
"""request an instance and get status and parameters of instance"""
def
get_parser
(
self
,
prog_name
):
ap
=
super
(
ListCommand
,
self
).
get_parser
(
prog_name
)
return
ap
def
take_action
(
self
,
args
):
configp
=
self
.
fetch_config
(
args
)
conf
=
ClientConfig
(
args
,
configp
)
local
=
init
(
conf
,
self
.
app
.
log
)
do_list
(
self
.
app
.
log
,
conf
,
local
)
def
do_list
(
logger
,
conf
,
local
):
# XXX catch exception
instance_dict
=
local
[
'slap'
].
getOpenOrderDict
()
if
instance_dict
==
{}:
logger
.
info
(
'No existing service.'
)
return
logger
.
info
(
'List of services:'
)
for
title
,
instance
in
instance_dict
.
iteritems
():
logger
.
info
(
'%s %s'
,
title
,
instance
.
_software_release_url
)
slapos/client.py
View file @
a981ab14
...
...
@@ -75,6 +75,8 @@ class ClientConfig(object):
else
:
self
.
master_url
=
master_url
self
.
master_rest_url
=
configuration_dict
.
get
(
'master_rest_url'
)
if
self
.
key_file
:
self
.
key_file
=
os
.
path
.
expanduser
(
self
.
key_file
)
...
...
@@ -87,7 +89,7 @@ def init(conf, logger):
aliases to common software releases"""
# XXX check certificate and key existence
slap
=
slapos
.
slap
.
slap
()
slap
.
initializeConnection
(
conf
.
master_url
,
slap
.
initializeConnection
(
conf
.
master_url
,
conf
.
master_rest_url
,
key_file
=
conf
.
key_file
,
cert_file
=
conf
.
cert_file
)
local
=
globals
().
copy
()
local
[
'slap'
]
=
slap
...
...
slapos/tests/cli.py
View file @
a981ab14
...
...
@@ -25,11 +25,29 @@
#
##############################################################################
import
logging
import
pprint
import
unittest
from
mock
import
patch
,
create_autospec
import
slapos.cli.list
import
slapos.cli.info
from
slapos.client
import
ClientConfig
import
slapos.proxy
import
slapos.slap
def
raiseNotFoundError
(
*
args
,
**
kwargs
):
raise
slapos
.
slap
.
NotFoundError
()
class
CliMixin
(
unittest
.
TestCase
):
def
setUp
(
self
):
slap
=
slapos
.
slap
.
slap
()
self
.
local
=
{
'slap'
:
slap
}
self
.
logger
=
create_autospec
(
logging
.
Logger
)
self
.
conf
=
create_autospec
(
ClientConfig
)
class
TestCliProxy
(
unittest
.
TestCase
):
class
TestCliProxy
(
CliMixin
):
def
test_generateSoftwareProductListFromString
(
self
):
"""
Test that generateSoftwareProductListFromString correctly parses a parameter
...
...
@@ -52,4 +70,59 @@ product2 url2"""
self
.
assertEqual
(
slapos
.
proxy
.
_generateSoftwareProductListFromString
(
''
),
{}
)
\ No newline at end of file
)
class
TestCliList
(
CliMixin
):
def
test_list
(
self
):
"""
Test "slapos list" command output.
"""
return_value
=
{
'instance1'
:
slapos
.
slap
.
SoftwareInstance
(
_title
=
'instance1'
,
_software_release_url
=
'SR1'
),
'instance2'
:
slapos
.
slap
.
SoftwareInstance
(
_title
=
'instance2'
,
_software_release_url
=
'SR2'
),
}
with
patch
.
object
(
slapos
.
slap
.
slap
,
'getOpenOrderDict'
,
return_value
=
return_value
)
as
_
:
slapos
.
cli
.
list
.
do_list
(
self
.
logger
,
None
,
self
.
local
)
self
.
logger
.
info
.
assert_any_call
(
'%s %s'
,
'instance1'
,
'SR1'
)
self
.
logger
.
info
.
assert_any_call
(
'%s %s'
,
'instance2'
,
'SR2'
)
def
test_emptyList
(
self
):
with
patch
.
object
(
slapos
.
slap
.
slap
,
'getOpenOrderDict'
,
return_value
=
{})
as
_
:
slapos
.
cli
.
list
.
do_list
(
self
.
logger
,
None
,
self
.
local
)
self
.
logger
.
info
.
assert_called_once_with
(
'No existing service.'
)
@
patch
.
object
(
slapos
.
slap
.
slap
,
'registerOpenOrder'
,
return_value
=
slapos
.
slap
.
OpenOrder
())
class
TestCliInfo
(
CliMixin
):
def
test_info
(
self
,
_
):
"""
Test "slapos info" command output.
"""
setattr
(
self
.
conf
,
'reference'
,
'instance1'
)
instance
=
slapos
.
slap
.
SoftwareInstance
(
_software_release_url
=
'SR1'
,
_requested_state
=
'mystate'
,
_connection_dict
=
{
'myconnectionparameter'
:
'value1'
},
_parameter_dict
=
{
'myinstanceparameter'
:
'value2'
}
)
with
patch
.
object
(
slapos
.
slap
.
OpenOrder
,
'getInformation'
,
return_value
=
instance
):
slapos
.
cli
.
info
.
do_info
(
self
.
logger
,
self
.
conf
,
self
.
local
)
self
.
logger
.
info
.
assert_any_call
(
pprint
.
pformat
(
instance
.
_parameter_dict
))
self
.
logger
.
info
.
assert_any_call
(
'Software Release URL: %s'
,
instance
.
_software_release_url
)
self
.
logger
.
info
.
assert_any_call
(
'Instance state: %s'
,
instance
.
_requested_state
)
self
.
logger
.
info
.
assert_any_call
(
pprint
.
pformat
(
instance
.
_parameter_dict
))
self
.
logger
.
info
.
assert_any_call
(
pprint
.
pformat
(
instance
.
_connection_dict
))
def
test_unknownReference
(
self
,
_
):
"""
Test "slapos info" command output in case reference
of service is not known.
"""
setattr
(
self
.
conf
,
'reference'
,
'instance1'
)
with
patch
.
object
(
slapos
.
slap
.
OpenOrder
,
'getInformation'
,
side_effect
=
raiseNotFoundError
):
slapos
.
cli
.
info
.
do_info
(
self
.
logger
,
self
.
conf
,
self
.
local
)
self
.
logger
.
warning
.
assert_called_once_with
(
'Instance %s does not exist.'
,
self
.
conf
.
reference
)
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