+def _datacenter_to_switch_port(dc_id, port=None):
+ digits = 16
+ switch = ':'.join(wrap(('%0' + str(digits) + 'x') % int(dc_id), 2))
+ return (switch, str((port or int(dc_id)) + 1))
+
+
+def datacenter(identifier, external_ports_config=False):
+ config = '' if not external_ports_config else json.dumps({
+ 'external_connections': [
+ {'condition': {
+ 'provider:physical_network': 'provider',
+ 'encapsulation_type': 'vlan'},
+ 'vim_external_port':
+ dict(izip(('switch', 'port'),
+ _datacenter_to_switch_port(identifier)))}
+ ]})
+