Commit ae644a7a authored by Giorgos Verigakis's avatar Giorgos Verigakis
Browse files

Merge branch 'api-current' of https://code.grnet.gr/git/synnefo into api-tests

parents 0ea2052a 35d0674b
......@@ -2,6 +2,8 @@
# Copyright (c) 2010 Greek Research and Technology Network
#
from socket import getfqdn
from django.conf import settings
from django.http import HttpResponse
from django.template.loader import render_to_string
......@@ -74,10 +76,10 @@ def get_console(request, vm, args):
passwd = random_password()
request_vnc_forwarding(sport, daddr, dport, passwd)
vnc = { 'host': '62.217.120.67', 'port': sport, 'password': passwd }
vnc = { 'host': socket.getfqdn(), 'port': sport, 'password': passwd }
# Format to be reviewed by [verigak], FIXME
if request.type == 'xml':
if request.serialization == 'xml':
mimetype = 'application/xml'
data = render_to_string('vnc.xml', {'vnc': vnc})
else:
......
......@@ -169,29 +169,39 @@ def create_server(request):
ipfour='0.0.0.0',
ipsix='::1',
flavor=flavor)
# Pick a random password for the VM.
# FIXME: This must be passed to the Ganeti OS provider via CreateInstance()
passwd = random_password()
# We *must* save the VM instance now,
# so that it gets a vm.id and vm.backend_id is valid.
vm.save()
if request.META.get('SERVER_NAME', None) == 'testserver':
name = 'test-server'
backend_name = 'test-server'
dry_run = True
else:
name = vm.backend_id
backend_name = vm.backend_id
dry_run = False
jobId = rapi.CreateInstance(
mode='create',
name=name,
disk_template='plain',
disks=[{"size": 2000}], #FIXME: Always ask for a 2GB disk for now
nics=[{}],
os='debootstrap+default', #TODO: select OS from imageRef
ip_check=False,
name_check=False,
pnode=rapi.GetNodes()[0], #TODO: verify if this is necessary
dry_run=dry_run,
beparams=dict(auto_balance=True, vcpus=flavor.cpu, memory=flavor.ram))
vm.save()
try:
jobId = rapi.CreateInstance(
mode='create',
name=backend_name,
disk_template='plain',
disks=[{"size": 2000}], #FIXME: Always ask for a 2GB disk for now
nics=[{}],
os='debootstrap+default', #TODO: select OS from imageRef
ip_check=False,
name_check=False,
pnode=rapi.GetNodes()[0], #TODO: verify if this is necessary
dry_run=dry_run,
beparams=dict(auto_balance=True, vcpus=flavor.cpu, memory=flavor.ram))
except Exception, e:
vm.delete()
raise e
for key, val in metadata.items():
VirtualMachineMetadata.objects.create(meta_key=key, meta_value=val, vm=vm)
......@@ -199,7 +209,7 @@ def create_server(request):
server = vm_to_dict(vm, detail=True)
server['status'] = 'BUILD'
server['adminPass'] = random_password()
server['adminPass'] = passwd
return render_server(request, server, status=202)
@api_method('GET')
......
......@@ -56,7 +56,7 @@ def isoparse(s):
if now - utc_since > timedelta(seconds=settings.POLL_LIMIT):
raise BadRequest('Too old changes-since value.')
return since
return utc_since
def random_password(length=8):
pool = ascii_letters + digits
......
......@@ -6,8 +6,7 @@
"name": "Debian Squeeze",
"created": "2011-02-06 00:00:00",
"updated": "2011-02-06 00:00:00",
"state": "ACTIVE",
"size": 5678
"state": "ACTIVE"
}
},
{
......@@ -96,7 +95,6 @@
"created": "2011-02-10 00:00:00",
"updated": "2011-02-10 00:00:00",
"state": "ACTIVE",
"size": 1234,
"owner": 1,
"sourcevm": 1001
}
......
......@@ -274,6 +274,8 @@ class VirtualMachine(models.Model):
def _get_backend_id(self):
"""Returns the backend id for this VM by prepending backend-prefix."""
if not self.id:
raise VirtualMachine.InvalidBackendIdError("self.id is None")
return '%s%s' % (settings.BACKEND_PREFIX_ID, str(self.id))
backend_id = property(_get_backend_id)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment