Revision b82c93a5 kamaki/clients/cyclades/__init__.py
b/kamaki/clients/cyclades/__init__.py | ||
---|---|---|
234 | 234 |
def create_port( |
235 | 235 |
self, network_id, |
236 | 236 |
device_id=None, security_groups=None, name=None, fixed_ips=None): |
237 |
""" |
|
238 |
:param fixed_ips: (list of dicts) [{"ip_address": IPv4}, ...] |
|
239 |
""" |
|
237 | 240 |
port = dict(network_id=network_id) |
238 | 241 |
if device_id: |
239 | 242 |
port['device_id'] = device_id |
... | ... | |
241 | 244 |
port['security_groups'] = security_groups |
242 | 245 |
if name: |
243 | 246 |
port['name'] = name |
244 |
for fixed_ip in fixed_ips or []: |
|
245 |
diff = set(['subnet_id', 'ip_address']).difference(fixed_ip) |
|
246 |
if diff: |
|
247 |
raise ValueError( |
|
248 |
'Invalid format for "fixed_ips", %s missing' % diff) |
|
249 | 247 |
if fixed_ips: |
248 |
for fixed_ip in fixed_ips or []: |
|
249 |
if not 'ip_address' in fixed_ip: |
|
250 |
raise ValueError( |
|
251 |
'Invalid format for "fixed_ips"', details=[ |
|
252 |
'fixed_ips format: [{"ip_address": IPv4}, ...]']) |
|
250 | 253 |
port['fixed_ips'] = fixed_ips |
251 | 254 |
r = self.ports_post(json_data=dict(port=port), success=201) |
252 | 255 |
return r.json['port'] |
Also available in: Unified diff