Commit 42090b30 authored by Ilias Tsitsimpis's avatar Ilias Tsitsimpis
Browse files

snf-ci: Use the new Network API

Update snf-ci to use the new Synnefo's Network API.
This means that we have to create a floating IP and a
port to attach our server.
parent e13dbdd6
......@@ -64,7 +64,7 @@ cmd_options = --images "name:.*" --flavors "name:C1R512D2file" --no-ipv6
# Kamaki version to be used (leave empty for default)
# In some cases there is the need for a specific version
# of kamaki to be used.
kamaki_version = 0.11next-1858-1d7368b
kamaki_version = 0.12rc2
[Unit Tests]
......
......@@ -16,7 +16,7 @@ from ConfigParser import ConfigParser, DuplicateSectionError
from kamaki.cli import config as kamaki_config
from kamaki.clients.astakos import AstakosClient
from kamaki.clients.cyclades import CycladesClient
from kamaki.clients.cyclades import CycladesClient, CycladesNetworkClient
from kamaki.clients.image import ImageClient
from kamaki.clients.compute import ComputeClient
import filelocker
......@@ -92,13 +92,13 @@ class _MyFormatter(logging.Formatter):
def format(self, record):
format_orig = self._fmt
if record.levelno == logging.DEBUG:
self._fmt = " %(msg)s"
self._fmt = " %(message)s"
elif record.levelno == logging.INFO:
self._fmt = "%(msg)s"
self._fmt = "%(message)s"
elif record.levelno == logging.WARNING:
self._fmt = _yellow("[W] %(msg)s")
self._fmt = _yellow("[W] %(message)s")
elif record.levelno == logging.ERROR:
self._fmt = _red("[E] %(msg)s")
self._fmt = _red("[E] %(message)s")
result = logging.Formatter.format(self, record)
self._fmt = format_orig
return result
......@@ -173,6 +173,7 @@ class SynnefoCI(object):
self.fabric_installed = False
self.kamaki_installed = False
self.cyclades_client = None
self.network_client = None
self.compute_client = None
self.image_client = None
self.astakos_client = None
......@@ -189,7 +190,7 @@ class SynnefoCI(object):
self.kamaki_cloud = config.get("global", "default_cloud")
except AttributeError:
# Compatibility with kamaki version <=0.10
self.kamaki_cloud = config.get_global("default_cloud")
self.kamaki_cloud = config.get("global", "default_cloud")
self.logger.info("Setup kamaki client, using cloud '%s'.." %
self.kamaki_cloud)
......@@ -206,6 +207,12 @@ class SynnefoCI(object):
self.cyclades_client = CycladesClient(cyclades_url, token)
self.cyclades_client.CONNECTION_RETRY_LIMIT = 2
network_url = \
self.astakos_client.get_service_endpoints('network')['publicURL']
self.logger.debug("Network API url is %s" % _green(network_url))
self.network_client = CycladesNetworkClient(network_url, token)
self.network_client.CONNECTION_RETRY_LIMIT = 2
image_url = \
self.astakos_client.get_service_endpoints('image')['publicURL']
self.logger.debug("Images API url is %s" % _green(image_url))
......@@ -251,6 +258,26 @@ class SynnefoCI(object):
if wait:
self._wait_transition(server_id, "ACTIVE", "DELETED")
def _create_floating_ip(self):
"""Create a new floating ip"""
networks = self.network_client.list_networks(detail=True)
pub_net = [n for n in networks
if n['SNF:floating_ip_pool'] and n['public']]
pub_net = pub_net[0]
fip = self.network_client.create_floatingip(pub_net['id'])
self.logger.debug("Floating IP %s with id %s created",
fip['floating_ip_address'], fip['id'])
return fip
def _create_port(self, floating_ip):
"""Create a new port for our floating IP"""
net_id = floating_ip['floating_network_id']
self.logger.debug("Creating a new port to network with id %s", net_id)
fixed_ips = [{'ip_address': floating_ip['floating_ip_address']}]
port = self.network_client.create_port(
net_id, device_id=None, fixed_ips=fixed_ips)
return port
@_check_kamaki
def create_server(self, image=None, flavor=None, ssh_keys=None,
server_name=None):
......@@ -266,11 +293,14 @@ class SynnefoCI(object):
flavor_id = self._find_flavor(flavor)
# Create Server
fip = self._create_floating_ip()
port = self._create_port(fip)
networks = [{'port': port['id']}]
if server_name is None:
server_name = self.config.get("Deployment", "server_name")
server_name = "%s(BID: %s)" % (server_name, self.build_id)
server = self.cyclades_client.create_server(server_name, flavor_id,
image_id)
server = self.cyclades_client.create_server(
server_name, flavor_id, image_id, networks=networks)
server_id = server['id']
self.write_temp_config('server_id', server_id)
self.logger.debug("Server got id %s" % _green(server_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