Commit cace5cd1 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

Add --dry-run option to snf-manage network-create

parent 9336a38f
...@@ -35,6 +35,7 @@ from optparse import make_option ...@@ -35,6 +35,7 @@ from optparse import make_option
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
from synnefo.management.common import validate_network_info, get_backend from synnefo.management.common import validate_network_info, get_backend
from synnefo.management.common import pprint_table
from synnefo.db.models import Network from synnefo.db.models import Network
from synnefo.logic.backend import create_network from synnefo.logic.backend import create_network
...@@ -50,6 +51,12 @@ class Command(BaseCommand): ...@@ -50,6 +51,12 @@ class Command(BaseCommand):
help = "Create a new network" help = "Create a new network"
option_list = BaseCommand.option_list + ( option_list = BaseCommand.option_list + (
make_option(
"-n",
"--dry-run",
dest="dry_run",
default=False,
action="store_true"),
make_option( make_option(
'--name', '--name',
dest='name', dest='name',
...@@ -129,6 +136,7 @@ class Command(BaseCommand): ...@@ -129,6 +136,7 @@ class Command(BaseCommand):
if args: if args:
raise CommandError("Command doesn't accept any arguments") raise CommandError("Command doesn't accept any arguments")
dry_run = options["dry_run"]
name = options['name'] name = options['name']
subnet = options['subnet'] subnet = options['subnet']
backend_id = options['backend_id'] backend_id = options['backend_id']
...@@ -170,21 +178,28 @@ class Command(BaseCommand): ...@@ -170,21 +178,28 @@ class Command(BaseCommand):
if not link or not mode: if not link or not mode:
raise CommandError("Can not create network." raise CommandError("Can not create network."
" No connectivity link or mode") " No connectivity link or mode")
netinfo = {
network = Network.objects.create(name=name, "name": name,
userid=options['owner'], "userid": options["owner"],
subnet=subnet, "subnet": subnet,
gateway=gateway, "gateway": gateway,
gateway6=gateway6, "gateway6": gateway6,
subnet6=subnet6, "subnet6": subnet6,
dhcp=options['dhcp'], "dhcp": options["dhcp"],
flavor=flavor, "flavor": flavor,
public=public, "public": public,
mode=mode, "mode": mode,
link=link, "link": link,
mac_prefix=mac_prefix, "mac_prefix": mac_prefix,
tags=tags, "tags": tags,
state='PENDING') "state": "PENDING"}
if dry_run:
self.stdout.write("Creating network:\n")
pprint_table(self.stdout, tuple(netinfo.items()))
return
network = Network.objects.create(**netinfo)
if public: if public:
# Create BackendNetwork only to the specified Backend # Create BackendNetwork only to the specified Backend
......
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