def create_datacenter(self, datacenter):
server_items = []<EOL>volume_items = []<EOL>lan_items = []<EOL>loadbalancer_items = []<EOL>entities = dict()<EOL>properties = {<EOL>"<STR_LIT:name>": datacenter.name<EOL>}<EOL>if datacenter.location:<EOL><INDENT>properties['<STR_LIT:location>'] = datacenter.location<EOL><DEDENT>if datacenter.description:<EOL><INDENT>properties['<STR_LIT:description>'] = datacenter.description<EOL><DEDENT>if datacenter.servers:<EOL><INDENT>for server in datacenter.servers:<EOL><INDENT>server_items.append(self._create_server_dict(server))<EOL><DEDENT>servers = {<EOL>"<STR_LIT>": server_items<EOL>}<EOL>server_entities = {<EOL>"<STR_LIT>": servers<EOL>}<EOL>entities.update(server_entities)<EOL><DEDENT>if datacenter.volumes:<EOL><INDENT>for volume in datacenter.volumes:<EOL><INDENT>volume_items.append(self._create_volume_dict(volume))<EOL><DEDENT>volumes = {<EOL>"<STR_LIT>": volume_items<EOL>}<EOL>volume_entities = {<EOL>"<STR_LIT>": volumes<EOL>}<EOL>entities.update(volume_entities)<EOL><DEDENT>if datacenter.loadbalancers:<EOL><INDENT>for loadbalancer in datacenter.loadbalancers:<EOL><INDENT>loadbalancer_items.append(<EOL>self._create_loadbalancer_dict(<EOL>loadbalancer<EOL>)<EOL>)<EOL><DEDENT>loadbalancers = {<EOL>"<STR_LIT>": loadbalancer_items<EOL>}<EOL>loadbalancer_entities = {<EOL>"<STR_LIT>": loadbalancers<EOL>}<EOL>entities.update(loadbalancer_entities)<EOL><DEDENT>if datacenter.lans:<EOL><INDENT>for lan in datacenter.lans:<EOL><INDENT>lan_items.append(<EOL>self._create_lan_dict(lan)<EOL>)<EOL><DEDENT>lans = {<EOL>"<STR_LIT>": lan_items<EOL>}<EOL>lan_entities = {<EOL>"<STR_LIT>": lans<EOL>}<EOL>entities.update(lan_entities)<EOL><DEDENT>if not entities:<EOL><INDENT>raw = {<EOL>"<STR_LIT>": properties,<EOL>}<EOL><DEDENT>else:<EOL><INDENT>raw = {<EOL>"<STR_LIT>": properties,<EOL>"<STR_LIT>": entities<EOL>}<EOL><DEDENT>data = json.dumps(raw)<EOL>response = self._perform_request(<EOL>url='<STR_LIT>',<EOL>method='<STR_LIT:POST>',<EOL>data=data)<EOL>return response<EOL>
Creates a data center -- both simple and complex are supported.