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
ef52da70
Commit
ef52da70
authored
Apr 01, 2011
by
Georgios Gousios
Browse files
Merge branch 'master' of
https://code.grnet.gr/git/synnefo
parents
f5e24ad4
491ba48a
Changes
7
Hide whitespace changes
Inline
Side-by-side
api/actions.py
View file @
ef52da70
...
...
@@ -2,12 +2,13 @@
# Copyright (c) 2010 Greek Research and Technology Network
#
from
synnefo.api.errors
import
*
from
synnefo.util.rapi
import
GanetiRapiClient
from
django.conf
import
settings
from
django.http
import
HttpResponse
from
synnefo.api.errors
import
*
from
synnefo.util.rapi
import
GanetiRapiClient
from
synnefo.logic
import
backend
,
utils
server_actions
=
{}
rapi
=
GanetiRapiClient
(
*
settings
.
GANETI_CLUSTER_INFO
)
...
...
@@ -51,12 +52,12 @@ def reboot(server, args):
# buildInProgress (409),
# overLimit (413)
type
=
args
.
get
(
'type'
,
''
)
if
type
not
in
(
'SOFT'
,
'HARD'
):
reboot_
type
=
args
.
get
(
'type'
,
''
)
if
reboot_
type
not
in
(
'SOFT'
,
'HARD'
):
raise
BadRequest
()
server
.
start_action
(
'REBOOT'
)
rapi
.
RebootInstance
(
server
.
backend_id
,
type
.
lower
())
backend
.
start_action
(
server
,
'REBOOT'
)
rapi
.
RebootInstance
(
server
.
backend_id
,
reboot_
type
.
lower
())
return
HttpResponse
(
status
=
202
)
@
server_action
(
'start'
)
...
...
@@ -64,7 +65,7 @@ def start(server, args):
# Normal Response Code: 202
# Error Response Codes: serviceUnavailable (503), itemNotFound (404)
server
.
start_action
(
'START'
)
backend
.
start_action
(
server
,
'START'
)
rapi
.
StartupInstance
(
server
.
backend_id
)
return
HttpResponse
(
status
=
202
)
...
...
@@ -73,7 +74,7 @@ def shutdown(server, args):
# Normal Response Code: 202
# Error Response Codes: serviceUnavailable (503), itemNotFound (404)
server
.
start_action
(
'STOP'
)
backend
.
start_action
(
server
,
'STOP'
)
rapi
.
ShutdownInstance
(
server
.
backend_id
)
return
HttpResponse
(
status
=
202
)
...
...
api/flavors.py
View file @
ef52da70
...
...
@@ -23,6 +23,7 @@ def flavor_to_dict(flavor, detail=True):
if
detail
:
d
[
'ram'
]
=
flavor
.
ram
d
[
'disk'
]
=
flavor
.
disk
d
[
'cpu'
]
=
flavor
.
cpu
return
d
...
...
api/servers.py
View file @
ef52da70
...
...
@@ -2,11 +2,7 @@
# Copyright (c) 2010 Greek Research and Technology Network
#
from
synnefo.api.actions
import
server_actions
from
synnefo.api.errors
import
*
from
synnefo.api.util
import
*
from
synnefo.db.models
import
*
from
synnefo.util.rapi
import
GanetiRapiClient
from
logging
import
getLogger
from
django.conf
import
settings
from
django.conf.urls.defaults
import
*
...
...
@@ -14,9 +10,12 @@ from django.http import HttpResponse
from
django.template.loader
import
render_to_string
from
django.utils
import
simplejson
as
json
from
logging
import
getLogger
from
logic
import
utils
from
synnefo.api.actions
import
server_actions
from
synnefo.api.errors
import
*
from
synnefo.api.util
import
*
from
synnefo.db.models
import
*
from
synnefo.util.rapi
import
GanetiRapiClient
from
synnefo.logic
import
backend
,
utils
log
=
getLogger
(
'synnefo.api.servers'
)
rapi
=
GanetiRapiClient
(
*
settings
.
GANETI_CLUSTER_INFO
)
...
...
@@ -232,7 +231,7 @@ def delete_server(request, server_id):
except
VirtualMachine
.
DoesNotExist
:
raise
ItemNotFound
server
.
start_action
(
'DESTROY'
)
backend
.
start_action
(
server
,
'DESTROY'
)
rapi
.
DeleteInstance
(
server
.
backend_id
)
return
HttpResponse
(
status
=
204
)
...
...
api/templates/flavor.xml
View file @
ef52da70
<?xml version="1.0" encoding="UTF-8"?>
<flavor
xmlns=
"http://docs.openstack.org/compute/api/v1.1"
xmlns:atom=
"http://www.w3.org/2005/Atom"
id=
"{{ flavor.id }}"
name=
"{{ flavor.name }}"
ram=
"{{ flavor.ram }}"
disk=
"{{ flavor.disk }}"
>
<flavor
xmlns=
"http://docs.openstack.org/compute/api/v1.1"
xmlns:atom=
"http://www.w3.org/2005/Atom"
id=
"{{ flavor.id }}"
name=
"{{ flavor.name }}"
ram=
"{{ flavor.ram }}"
cpu=
"{{ flavor.cpu }}"
disk=
"{{ flavor.disk }}"
>
</flavor>
api/templates/list_flavors.xml
View file @
ef52da70
...
...
@@ -2,7 +2,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<flavors
xmlns=
"http://docs.openstack.org/compute/api/v1.1"
xmlns:atom=
"http://www.w3.org/2005/Atom"
>
{% for flavor in flavors %}
<flavor
id=
"{{ flavor.id}}"
name=
"{{ flavor.name }}"
{%
if
detail
%}
ram=
"{{ flavor.ram }}"
disk=
"{{ flavor.disk }}"
{%
endif
%}
>
<flavor
id=
"{{ flavor.id}}"
name=
"{{ flavor.name }}"
{%
if
detail
%}
ram=
"{{ flavor.ram }}"
cpu=
"{{ flavor.cpu }}"
disk=
"{{ flavor.disk }}"
{%
endif
%}
>
</flavor>
{% endfor %}
</flavors>
...
...
ui/static/synnefo.js
View file @
ef52da70
var
flavors
=
[],
images
=
[],
servers
=
[],
disks
=
[],
cpus
=
[],
ram
=
[];
var
changes_since
=
0
,
deferred
=
0
,
update_request
=
false
,
load_request
=
false
,
pending_actions
=
[];
var
API_URL
=
"
/api/v1.1redux
"
;
function
ISODateString
(
d
){
//return a date in an ISO 8601 format using UTC.
...
...
@@ -336,7 +337,7 @@ Array.prototype.unique = function () {
// get and configure flavor selection
function
update_flavors
()
{
$
.
ajax
({
url
:
'
/api/v1.0
/flavors/detail
'
,
url
:
API_URL
+
'
/flavors/detail
'
,
type
:
"
GET
"
,
//async: false,
dataType
:
"
json
"
,
...
...
@@ -349,7 +350,7 @@ function update_flavors() {
}
},
success
:
function
(
data
,
textStatus
,
jqXHR
)
{
flavors
=
data
.
flavors
;
flavors
=
data
.
flavors
.
values
;
$
.
each
(
flavors
,
function
(
i
,
flavor
)
{
cpus
[
i
]
=
flavor
[
'
cpu
'
];
disks
[
i
]
=
flavor
[
'
disk
'
];
...
...
@@ -416,6 +417,39 @@ function updateActions() {
}
}
//create server action
function
create_vm
(
machineName
,
imageRef
,
flavorRef
){
var
payload
=
{
"
server
"
:
{
"
name
"
:
machineName
,
"
imageRef
"
:
imageRef
,
"
flavorRef
"
:
flavorRef
,
"
metadata
"
:
{
"
My Server Name
"
:
machineName
},
}
};
$
.
ajax
({
url
:
"
/api/v1.0/servers
"
,
type
:
"
POST
"
,
dataType
:
"
json
"
,
data
:
JSON
.
stringify
(
payload
),
timeout
:
TIMEOUT
,
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
ajax_error
(
jqXHR
.
status
);
},
success
:
function
(
data
,
textStatus
,
jqXHR
)
{
if
(
jqXHR
.
status
==
'
202
'
)
{
ajax_success
(
"
CREATE_VM_SUCCESS
"
,
data
.
server
.
adminPass
);
}
else
{
ajax_error
(
jqXHR
.
status
);
}
}
});
}
// reboot action
function
reboot
(
serverIDs
){
if
(
!
serverIDs
.
length
){
...
...
@@ -429,7 +463,7 @@ function reboot(serverIDs){
var
serverID
=
serverIDs
.
pop
();
$
.
ajax
({
url
:
'
/api/v1.0
/servers/
'
+
serverID
+
'
/action
'
,
url
:
API_URL
+
'
/servers/
'
+
serverID
+
'
/action
'
,
type
:
"
POST
"
,
dataType
:
"
json
"
,
data
:
JSON
.
stringify
(
payload
),
...
...
@@ -468,7 +502,7 @@ function shutdown(serverIDs) {
var
serverID
=
serverIDs
.
pop
()
$
.
ajax
({
url
:
'
/api/v1.0
/servers/
'
+
serverID
+
'
/action
'
,
url
:
API_URL
+
'
/servers/
'
+
serverID
+
'
/action
'
,
type
:
"
POST
"
,
dataType
:
"
json
"
,
data
:
JSON
.
stringify
(
payload
),
...
...
@@ -505,7 +539,7 @@ function destroy(serverIDs) {
serverID
=
serverIDs
.
pop
()
$
.
ajax
({
url
:
'
/api/v1.0
/servers/
'
+
serverID
,
url
:
API_URL
+
'
/servers/
'
+
serverID
,
type
:
"
DELETE
"
,
dataType
:
"
json
"
,
data
:
JSON
.
stringify
(
payload
),
...
...
@@ -544,7 +578,7 @@ function start(serverIDs){
var
serverID
=
serverIDs
.
pop
()
$
.
ajax
({
url
:
'
/api/v1.0
/servers/
'
+
serverID
+
'
/action
'
,
url
:
API_URL
+
'
/servers/
'
+
serverID
+
'
/action
'
,
type
:
"
POST
"
,
dataType
:
"
json
"
,
data
:
JSON
.
stringify
(
payload
),
...
...
ui/templates/machines.html
View file @
ef52da70
...
...
@@ -168,8 +168,8 @@
<div
class=
"confirm_multiple"
>
<p>
{% trans "Your actions will affect" %}
<span
class=
"actionLen"
>
XX
</span>
{% trans "machines" %}
</p>
<button
class=
"yes"
>
{% trans "Confirm
Α
ll" %}
</button>
<button
class=
"no"
>
{% trans "Cancel
Α
ll" %}
</button>
<button
class=
"yes"
>
{% trans "Confirm
A
ll" %}
</button>
<button
class=
"no"
>
{% trans "Cancel
A
ll" %}
</button>
</div>
<div
id=
"machines"
class=
"separator"
></div>
...
...
@@ -423,35 +423,10 @@ $("#start").click(function(){
var
imageRef
=
$
(
'
input[type=radio][name=image-id]:checked
'
)[
0
].
id
.
replace
(
'
img-radio-
'
,
''
);
var
flavorRef
=
identify_flavor
(
$
(
"
#cpu-indicator
"
)[
0
].
value
,
$
(
"
#storage-indicator
"
)[
0
].
value
,
$
(
"
#ram-indicator
"
)[
0
].
value
);
var
machineName
=
$
(
'
input[name=machine_name]
'
)[
0
].
value
;
var
payload
=
{
"
server
"
:
{
"
name
"
:
machineName
,
"
imageRef
"
:
imageRef
,
"
flavorRef
"
:
flavorRef
,
"
metadata
"
:
{
"
My Server Name
"
:
machineName
},
}
};
create_vm
(
machineName
,
imageRef
,
flavorRef
);
$
(
'
a#create
'
).
data
(
'
overlay
'
).
close
();
$
.
ajax
({
url
:
"
/api/v1.0/servers
"
,
type
:
"
POST
"
,
dataType
:
"
json
"
,
data
:
JSON
.
stringify
(
payload
),
timeout
:
TIMEOUT
,
error
:
function
(
jqXHR
,
textStatus
,
errorThrown
)
{
ajax_error
(
jqXHR
.
status
);
},
success
:
function
(
data
,
textStatus
,
jqXHR
)
{
if
(
jqXHR
.
status
==
'
202
'
)
{
ajax_success
(
"
CREATE_VM_SUCCESS
"
,
data
.
server
.
adminPass
);
}
else
{
ajax_error
(
jqXHR
.
status
);
}
}
});
$
(
"
#emptymachineslist
"
).
hide
();
try
{
console
.
warn
(
'
creating
'
+
$
(
"
input[name=machine_name]
"
)[
0
].
value
)}
catch
(
err
){}
...
...
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