Revision 9621c777 snf-cyclades-app/synnefo/api/management/commands/network-create.py
b/snf-cyclades-app/synnefo/api/management/commands/network-create.py | ||
---|---|---|
50 | 50 |
help = "Create a new network" |
51 | 51 |
|
52 | 52 |
option_list = BaseCommand.option_list + ( |
53 |
make_option('--name', |
|
53 |
make_option( |
|
54 |
'--name', |
|
54 | 55 |
dest='name', |
55 | 56 |
help="Name of network"), |
56 |
make_option('--owner', |
|
57 |
make_option( |
|
58 |
'--owner', |
|
57 | 59 |
dest='owner', |
58 | 60 |
help="The owner of the network"), |
59 |
make_option('--subnet', |
|
61 |
make_option( |
|
62 |
'--subnet', |
|
60 | 63 |
dest='subnet', |
61 | 64 |
default=None, |
62 | 65 |
# required=True, |
63 | 66 |
help='Subnet of the network'), |
64 |
make_option('--gateway', |
|
67 |
make_option( |
|
68 |
'--gateway', |
|
65 | 69 |
dest='gateway', |
66 | 70 |
default=None, |
67 | 71 |
help='Gateway of the network'), |
68 |
make_option('--subnet6', |
|
72 |
make_option( |
|
73 |
'--subnet6', |
|
69 | 74 |
dest='subnet6', |
70 | 75 |
default=None, |
71 | 76 |
help='IPv6 subnet of the network'), |
72 |
make_option('--gateway6', |
|
77 |
make_option( |
|
78 |
'--gateway6', |
|
73 | 79 |
dest='gateway6', |
74 | 80 |
default=None, |
75 | 81 |
help='IPv6 gateway of the network'), |
76 |
make_option('--dhcp', |
|
82 |
make_option( |
|
83 |
'--dhcp', |
|
77 | 84 |
dest='dhcp', |
78 | 85 |
action='store_true', |
79 | 86 |
default=False, |
80 | 87 |
help='Automatically assign IPs'), |
81 |
make_option('--public', |
|
88 |
make_option( |
|
89 |
'--public', |
|
82 | 90 |
dest='public', |
83 | 91 |
action='store_true', |
84 | 92 |
default=False, |
85 | 93 |
help='Network is public'), |
86 |
make_option('--flavor', |
|
94 |
make_option( |
|
95 |
'--flavor', |
|
87 | 96 |
dest='flavor', |
88 | 97 |
default=None, |
89 | 98 |
choices=NETWORK_FLAVORS, |
90 | 99 |
help='Network flavor. Choices: ' + ', '.join(NETWORK_FLAVORS)), |
91 |
make_option('--mode', |
|
100 |
make_option( |
|
101 |
'--mode', |
|
92 | 102 |
dest='mode', |
93 | 103 |
default=None, |
94 | 104 |
help="Overwrite flavor connectivity mode."), |
95 |
make_option('--link', |
|
105 |
make_option( |
|
106 |
'--link', |
|
96 | 107 |
dest='link', |
97 | 108 |
default=None, |
98 | 109 |
help="Overwrite flavor connectivity link."), |
99 |
make_option('--mac-prefix', |
|
110 |
make_option( |
|
111 |
'--mac-prefix', |
|
100 | 112 |
dest='mac_prefix', |
101 | 113 |
default=None, |
102 | 114 |
help="Overwrite flavor connectivity MAC prefix"), |
103 |
make_option('--tags', |
|
115 |
make_option( |
|
116 |
'--tags', |
|
104 | 117 |
dest='tags', |
105 | 118 |
default=None, |
106 | 119 |
help='The tags of the Network (comma separated strings)'), |
107 |
make_option('--backend-id', |
|
120 |
make_option( |
|
121 |
'--backend-id', |
|
108 | 122 |
dest='backend_id', |
109 | 123 |
default=None, |
110 | 124 |
help='ID of the backend that the network will be created. Only for' |
111 | 125 |
' public networks'), |
112 |
)
|
|
126 |
) |
|
113 | 127 |
|
114 | 128 |
def handle(self, *args, **options): |
115 | 129 |
if args: |
... | ... | |
154 | 168 |
subnet, gateway, subnet6, gateway6 = validate_network_info(options) |
155 | 169 |
|
156 | 170 |
if not link or not mode: |
157 |
raise CommandError("Can not create network. No connectivity link or mode")
|
|
158 |
|
|
159 |
network = Network.objects.create( |
|
160 |
name=name,
|
|
161 |
userid=options['owner'], |
|
162 |
subnet=subnet, |
|
163 |
gateway=gateway, |
|
164 |
gateway6=gateway6, |
|
165 |
subnet6=subnet6, |
|
166 |
dhcp=options['dhcp'], |
|
167 |
flavor=flavor, |
|
168 |
public=public, |
|
169 |
mode=mode, |
|
170 |
link=link, |
|
171 |
mac_prefix=mac_prefix, |
|
172 |
tags=tags, |
|
173 |
state='PENDING') |
|
171 |
raise CommandError("Can not create network."
|
|
172 |
" No connectivity link or mode") |
|
173 |
|
|
174 |
network = Network.objects.create(name=name,
|
|
175 |
userid=options['owner'],
|
|
176 |
subnet=subnet,
|
|
177 |
gateway=gateway,
|
|
178 |
gateway6=gateway6,
|
|
179 |
subnet6=subnet6,
|
|
180 |
dhcp=options['dhcp'],
|
|
181 |
flavor=flavor,
|
|
182 |
public=public,
|
|
183 |
mode=mode,
|
|
184 |
link=link,
|
|
185 |
mac_prefix=mac_prefix,
|
|
186 |
tags=tags,
|
|
187 |
state='PENDING')
|
|
174 | 188 |
|
175 | 189 |
if public: |
176 | 190 |
# Create BackendNetwork only to the specified Backend |
Also available in: Unified diff