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
synnefo
Commits
146326c4
Commit
146326c4
authored
Apr 18, 2013
by
Giorgos Korfiatis
Browse files
astakos: update service-add and service-list
parent
4d9d67d5
Changes
2
Hide whitespace changes
Inline
Side-by-side
snf-astakos-app/astakos/im/management/commands/service-add.py
View file @
146326c4
# Copyright 2012 GRNET S.A. All rights reserved.
# Copyright 2012
, 2013
GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
...
...
@@ -34,26 +34,35 @@
from
django.core.management.base
import
BaseCommand
,
CommandError
from
astakos.im.api.callpoint
import
AstakosCallpoint
from
astakos.im.models
import
Service
class
Command
(
BaseCommand
):
args
=
"<name> <
api_url
>"
args
=
"<name> <
endpoint URL
>"
help
=
"Register a service"
def
handle
(
self
,
*
args
,
**
options
):
if
len
(
args
)
<
2
:
raise
CommandError
(
"Invalid number of arguments"
)
s
=
{
'name'
:
args
[
0
],
'api_url'
:
args
[
1
]}
if
len
(
args
)
==
3
:
s
[
'icon'
]
=
args
[
2
]
name
=
args
[
0
]
api_url
=
args
[
1
]
try
:
s
=
Service
.
objects
.
get
(
name
=
name
)
m
=
"There already exists service named '%s'."
%
name
raise
CommandError
(
m
)
except
Service
.
DoesNotExist
:
pass
services
=
list
(
Service
.
objects
.
filter
(
api_url
=
api_url
))
if
services
:
m
=
"URL '%s' is registered for another service."
%
api_url
raise
CommandError
(
m
)
try
:
c
=
AstakosCallpoint
()
r
=
c
.
add_services
((
s
,)).
next
()
except
Exception
,
e
:
raise
CommandError
(
e
)
s
=
Service
.
objects
.
create
(
name
=
name
,
api_url
=
api_url
)
except
BaseException
as
e
:
raise
CommandError
(
"Failed to create service."
)
else
:
if
r
.
is_success
:
self
.
stdout
.
write
(
'Service created successfully
\n
'
)
else
:
raise
CommandError
(
r
.
reason
)
self
.
stdout
.
write
(
'Token: %s
\n
'
%
s
.
auth_token
)
snf-astakos-app/astakos/im/management/commands/service-list.py
View file @
146326c4
# Copyright 2012 GRNET S.A. All rights reserved.
# Copyright 2012
, 2013
GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
...
...
@@ -31,44 +31,22 @@
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
from
optparse
import
make_option
from
django.core.management.base
import
NoArgsCommand
from
synnefo.webproject.management.commands
import
ListCommand
from
astakos.im.models
import
Service
class
Command
(
NoArgs
Command
):
class
Command
(
List
Command
):
help
=
"List services"
option_list
=
NoArgsCommand
.
option_list
+
(
make_option
(
'-c'
,
action
=
'store_true'
,
dest
=
'csv'
,
default
=
False
,
help
=
"Use pipes to separate values"
),
)
def
handle_noargs
(
self
,
**
options
):
services
=
Service
.
objects
.
all
().
order_by
(
'id'
)
labels
=
(
'id'
,
'name'
,
'API url'
,
'auth_token'
)
columns
=
(
3
,
12
,
70
,
20
)
if
not
options
[
'csv'
]:
line
=
' '
.
join
(
l
.
rjust
(
w
)
for
l
,
w
in
zip
(
labels
,
columns
))
self
.
stdout
.
write
(
line
+
'
\n
'
)
sep
=
'-'
*
len
(
line
)
self
.
stdout
.
write
(
sep
+
'
\n
'
)
for
service
in
services
:
fields
=
(
str
(
service
.
id
),
service
.
name
,
service
.
api_url
,
service
.
auth_token
or
''
)
if
options
[
'csv'
]:
line
=
'|'
.
join
(
fields
)
else
:
line
=
' '
.
join
(
f
.
rjust
(
w
)
for
f
,
w
in
zip
(
fields
,
columns
))
self
.
stdout
.
write
(
line
+
'
\n
'
)
object_class
=
Service
FIELDS
=
{
"id"
:
(
"id"
,
"ID"
),
"name"
:
(
"name"
,
"Service Name"
),
"url"
:
(
"api_url"
,
"Service API url"
),
"token"
:
(
"auth_token"
,
"Authentication token"
),
"created"
:
(
"auth_token_created"
,
"Token creation date"
),
"expires"
:
(
"auth_token_expires"
,
"Token expiration date"
),
}
fields
=
[
"id"
,
"name"
,
"url"
,
"token"
,
"created"
,
"expires"
]
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