Commit 82a59426 authored by Kostas Papadimitriou's avatar Kostas Papadimitriou
Browse files

Merge branch 'devel-0.12' into ui-0.11

parents 05ff5acc d3198147
......@@ -51,6 +51,9 @@ class Unauthorized(Fault):
class ResizeNotAllowed(Fault):
code = 403
class Forbidden(Fault):
code = 403
class ItemNotFound(Fault):
code = 404
......
......@@ -48,3 +48,10 @@ def format_date(d):
return timesince(d) + ' ago'
else:
return 'in ' + timeuntil(d)
def format_vm_state(vm):
if vm.operstate == "BUILD":
return "BUILD(" + str(vm.buildpercentage) + "%)"
else:
return vm.operstate
......@@ -40,6 +40,7 @@ from synnefo.api.util import get_image
from synnefo.lib.utils import merge_time
from synnefo.db.models import VirtualMachine
from synnefo.logic.rapi import GanetiApiError
from ._common import format_vm_state
# Fields to print from a gnt-instance info
......@@ -84,11 +85,11 @@ class Command(BaseCommand):
sep = '-' * 80 + '\n'
labels = ('name', 'owner', 'flavor', 'image', 'state', 'backend',
'deleted', 'action', 'backendjobid', 'backendopcodoe',
'deleted', 'action', 'backendjobid', 'backendopcode',
'backendjobstatus', 'backend_time')
fields = (vm.name, vm.userid, vm.flavor.name, image, vm.operstate,
str(vm.backend), str(vm.deleted), str(vm.action),
str(vm.backendjobid), str(vm.backendopcode),
fields = (vm.name, vm.userid, vm.flavor.name, image,
format_vm_state(vm), str(vm.backend), str(vm.deleted),
str(vm.action), str(vm.backendjobid), str(vm.backendopcode),
str(vm.backendjobstatus), str(vm.backendtime))
self.stdout.write(sep)
......
......@@ -37,6 +37,7 @@ from django.core.management.base import BaseCommand, CommandError
from synnefo.api.util import get_image
from synnefo.db.models import VirtualMachine, Backend
from ._common import format_vm_state
class Command(BaseCommand):
......@@ -101,7 +102,9 @@ class Command(BaseCommand):
image = cache.get_image(server.imageid, server.userid)['name']
except:
image = server.imageid
fields = (id, name, server.userid, flavor, image, server.operstate,
state = format_vm_state(server)
fields = (id, name, server.userid, flavor, image, state,
str(server.backend))
if options['csv']:
......
......@@ -36,7 +36,7 @@ from django.core.management.base import BaseCommand, CommandError
from synnefo.api.util import get_image
from synnefo.db.models import VirtualMachine
from ._common import format_bool, format_date
from ._common import format_bool, format_date, format_vm_state
class Command(BaseCommand):
......@@ -68,7 +68,7 @@ class Command(BaseCommand):
'flavor': flavor,
'deleted': format_bool(server.deleted),
'suspended': format_bool(server.suspended),
'state': server.operstate
'state': format_vm_state(server)
}
for key, val in sorted(kv.items()):
......
......@@ -44,7 +44,7 @@ from django.utils import simplejson as json
from synnefo.api import util
from synnefo.api.actions import network_actions
from synnefo.api.common import method_not_allowed
from synnefo.api.faults import (ServiceUnavailable, BadRequest, Unauthorized,
from synnefo.api.faults import (ServiceUnavailable, BadRequest, Forbidden,
NetworkInUse, OverLimit)
from synnefo.db.models import Network
from synnefo.db.pools import EmptyPool
......@@ -152,6 +152,7 @@ def create_network(request):
# unauthorized (401),
# badMediaType(415),
# badRequest (400),
# forbidden (403)
# overLimit (413)
req = util.get_request_dict(request)
......@@ -171,7 +172,7 @@ def create_network(request):
raise BadRequest('Malformed request.')
if net_type == 'PUBLIC_ROUTED':
raise Unauthorized('Can not create a public network.')
raise Forbidden('Can not create a public network.')
user_networks = len(Network.objects.filter(userid=request.user_uniq,
deleted=False))
......@@ -239,6 +240,7 @@ def update_network_name(request, network_id):
# serviceUnavailable (503),
# unauthorized (401),
# badRequest (400),
# forbidden (403)
# badMediaType(415),
# itemNotFound (404),
# overLimit (413)
......@@ -253,7 +255,7 @@ def update_network_name(request, network_id):
net = util.get_network(network_id, request.user_uniq)
if net.public:
raise Unauthorized('Can not rename the public network.')
raise Forbidden('Can not rename the public network.')
if net.deleted:
raise Network.DeletedError
net.name = name
......@@ -268,14 +270,14 @@ def delete_network(request, network_id):
# Error Response Codes: computeFault (400, 500),
# serviceUnavailable (503),
# unauthorized (401),
# forbidden (403)
# itemNotFound (404),
# unauthorized (401),
# overLimit (413)
log.info('delete_network %s', network_id)
net = util.get_network(network_id, request.user_uniq, for_update=True)
if net.public:
raise Unauthorized('Can not delete the public network.')
raise Forbidden('Can not delete the public network.')
if net.deleted:
raise Network.DeletedError
......@@ -300,7 +302,7 @@ def network_action(request, network_id):
net = util.get_network(network_id, request.user_uniq)
if net.public:
raise Unauthorized('Can not modify the public network.')
raise Forbidden('Can not modify the public network.')
if net.deleted:
raise Network.DeletedError
......
......@@ -57,7 +57,7 @@ from django.db.models import Q
from synnefo.api.faults import (Fault, BadRequest, BuildInProgress,
ItemNotFound, ServiceUnavailable, Unauthorized,
BadMediaType)
BadMediaType, Forbidden)
from synnefo.db.models import (Flavor, VirtualMachine, VirtualMachineMetadata,
Network, BackendNetwork, NetworkInterface,
BridgePoolTable, MacPrefixPoolTable)
......@@ -166,7 +166,8 @@ def get_vm(server_id, user_id, non_deleted=False, non_suspended=False):
if non_deleted and vm.deleted:
raise VirtualMachine.DeletedError
if non_suspended and vm.suspended:
raise Unauthorized("Administratively Suspended VM")
raise Forbidden("Administratively Suspended VM")
return vm
except ValueError:
raise BadRequest('Invalid server ID.')
except VirtualMachine.DoesNotExist:
......
......@@ -157,6 +157,11 @@ class Backend(models.Model):
else:
# ON_DELETE = SET NULL
self.virtual_machines.all().backend = None
# Remove BackendNetworks of this Backend.
# Do not use networks.all().delete(), since delete() method of
# BackendNetwork will not be called!
for net in self.networks.all():
net.delete()
super(Backend, self).delete(*args, **kwargs)
def __init__(self, *args, **kwargs):
......
......@@ -428,7 +428,11 @@ def _create_network(network, backend):
tags = network.backend_tag
if network.dhcp:
tags.append('nfdhcpd')
tags = ','.join(tags)
if network.public:
conflicts_check = True
else:
conflicts_check = False
try:
bn = BackendNetwork.objects.get(network=network, backend=backend)
......@@ -445,6 +449,7 @@ def _create_network(network, backend):
gateway6=network.gateway6,
network_type=network_type,
mac_prefix=mac_prefix,
conflicts_check=conflicts_check,
tags=tags)
......@@ -454,15 +459,21 @@ def connect_network(network, backend, depend_job=None, group=None):
mode = "routed" if "ROUTED" in network.type else "bridged"
if network.public:
conflicts_check = True
else:
conflicts_check = False
depend_jobs = [depend_job] if depend_job else []
with pooled_rapi_client(backend) as client:
if group:
client.ConnectNetwork(network.backend_id, group, mode,
network.link, depend_jobs)
network.link, conflicts_check, depend_jobs)
else:
for group in client.GetGroups():
client.ConnectNetwork(network.backend_id, group, mode,
network.link, depend_jobs)
network.link, conflicts_check,
depend_jobs)
def delete_network(network, backends=None, disconnect=True):
......
......@@ -256,6 +256,9 @@ def GenericCurlConfig(verbose=False, use_signal=False,
lcsslver = sslver.lower()
if lcsslver.startswith("openssl/"):
pass
elif lcsslver.startswith("nss/"):
# TODO: investigate compatibility beyond a simple test
pass
elif lcsslver.startswith("gnutls/"):
if capath:
raise Error("cURL linked against GnuTLS has no support for a"
......@@ -1659,7 +1662,8 @@ class GanetiRapiClient(object): # pylint: disable=R0904
def CreateNetwork(self, network_name, network, gateway=None, network6=None,
gateway6=None, mac_prefix=None, network_type=None,
tags=None, dry_run=False):
add_reserved_ips=None, tags=[],
conflicts_check=False, dry_run=False):
"""Creates a new network.
@type name: str
......@@ -1674,12 +1678,6 @@ class GanetiRapiClient(object): # pylint: disable=R0904
query = []
_AppendDryRunIf(query, dry_run)
if tags:
tags = tags.split(',')
else:
tags = []
body = {
"network_name": network_name,
"gateway": gateway,
......@@ -1688,20 +1686,24 @@ class GanetiRapiClient(object): # pylint: disable=R0904
"network6": network6,
"mac_prefix": mac_prefix,
"network_type": network_type,
"tags": tags
"add_reserved_ips": add_reserved_ips,
"conflicts_check": conflicts_check,
"tags": tags,
}
return self._SendRequest(HTTP_POST, "/%s/networks" % GANETI_RAPI_VERSION,
query, body)
def ConnectNetwork(self, network_name, group_name, mode, link, depends=None):
def ConnectNetwork(self, network_name, group_name, mode, link,
conflicts_check=False, depends=None, dry_run=False):
"""Connects a Network to a NodeGroup with the given netparams
"""
body = {
"group_name": group_name,
"network_mode": mode,
"network_link": link
"network_link": link,
"conflicts_check": conflicts_check,
}
if depends:
......@@ -1709,12 +1711,15 @@ class GanetiRapiClient(object): # pylint: disable=R0904
for d in depends:
body['depends'].append([d, ["success"]])
query = []
_AppendDryRunIf(query, dry_run)
return self._SendRequest(HTTP_PUT,
("/%s/networks/%s/connect" %
(GANETI_RAPI_VERSION, network_name)), None, body)
(GANETI_RAPI_VERSION, network_name)), query, body)
def DisconnectNetwork(self, network_name, group_name, depends=None):
def DisconnectNetwork(self, network_name, group_name,
depends=None, dry_run=False):
"""Connects a Network to a NodeGroup with the given netparams
"""
......@@ -1727,12 +1732,30 @@ class GanetiRapiClient(object): # pylint: disable=R0904
for d in depends:
body['depends'].append([d, ["success"]])
query = []
_AppendDryRunIf(query, dry_run)
return self._SendRequest(HTTP_PUT,
("/%s/networks/%s/disconnect" %
(GANETI_RAPI_VERSION, network_name)), None, body)
(GANETI_RAPI_VERSION, network_name)), query, body)
def ModifyNetwork(self, network, **kwargs):
"""Modifies a network.
More details for parameters can be found in the RAPI documentation.
@type network: string
@param network: Network name
@rtype: string
@return: job id
"""
return self._SendRequest(HTTP_PUT,
("/%s/networks/%s/modify" %
(GANETI_RAPI_VERSION, network)), None, kwargs)
def DeleteNetwork(self, network, depends=None):
def DeleteNetwork(self, network, depends=None, dry_run=False):
"""Deletes a network.
@type group: str
......@@ -1750,10 +1773,68 @@ class GanetiRapiClient(object): # pylint: disable=R0904
for d in depends:
body['depends'].append([d, ["success"]])
query = []
_AppendDryRunIf(query, dry_run)
return self._SendRequest(HTTP_DELETE,
("/%s/networks/%s" %
(GANETI_RAPI_VERSION, network)), None, body)
(GANETI_RAPI_VERSION, network)), query, body)
def GetNetworkTags(self, network):
"""Gets tags for a network.
@type network: string
@param network: Node group whose tags to return
@rtype: list of strings
@return: tags for the network
"""
return self._SendRequest(HTTP_GET,
("/%s/networks/%s/tags" %
(GANETI_RAPI_VERSION, network)), None, None)
def AddNetworkTags(self, network, tags, dry_run=False):
"""Adds tags to a network.
@type network: str
@param network: network to add tags to
@type tags: list of string
@param tags: tags to add to the network
@type dry_run: bool
@param dry_run: whether to perform a dry run
@rtype: string
@return: job id
"""
query = [("tag", t) for t in tags]
_AppendDryRunIf(query, dry_run)
return self._SendRequest(HTTP_PUT,
("/%s/networks/%s/tags" %
(GANETI_RAPI_VERSION, network)), query, None)
def DeleteNetworkTags(self, network, tags, dry_run=False):
"""Deletes tags from a network.
@type network: str
@param network: network to delete tags from
@type tags: list of string
@param tags: tags to delete
@type dry_run: bool
@param dry_run: whether to perform a dry run
@rtype: string
@return: job id
"""
query = [("tag", t) for t in tags]
_AppendDryRunIf(query, dry_run)
return self._SendRequest(HTTP_DELETE,
("/%s/networks/%s/tags" %
(GANETI_RAPI_VERSION, network)), query, None)
def GetGroups(self, bulk=False):
"""Gets all node groups in the cluster.
......
......@@ -68,9 +68,6 @@ eventd_start() {
case "$1" in
start)
# Check if we are on the Ganeti master node
check_ganeti_master
if "$SNF_EVENTD_ENABLE"; then
log_daemon_msg "Starting snf-ganeti-eventd daemon" "snf-ganeti-eventd"
if [ -s $SNF_EVENTD_PID_FILE ] && kill -0 $(cat $SNF_EVENTD_PID_FILE) >/dev/null 2>&1; then
......@@ -78,6 +75,8 @@ case "$1" in
log_end_msg 0
exit 0
fi
# Check if we are on the Ganeti master node
check_ganeti_master
eventd_start
else
if [ -s "$SNF_EVENTD_DEFAULTS" ]; then
......
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