'Create a trunk.'

@db_base_plugin_common.convert_result_to_dict
def create_trunk(self, context, trunk):

    trunk = self.validate(context, trunk['trunk'])
    sub_ports = [trunk_objects.SubPort(context=context, port_id=p['port_id'], segmentation_id=p['segmentation_id'], segmentation_type=p['segmentation_type']) for p in trunk['sub_ports']]
    admin_state_up = trunk.get('admin_state_up', True)
    trunk_description = trunk.get('description', '')
    trunk_obj = trunk_objects.Trunk(context=context, admin_state_up=admin_state_up, id=uuidutils.generate_uuid(), name=trunk.get('name', ''), description=trunk_description, project_id=trunk['tenant_id'], port_id=trunk['port_id'], status=constants.DOWN_STATUS, sub_ports=sub_ports)
    with db_api.context_manager.writer.using(context):
        trunk_obj.create()
        payload = callbacks.TrunkPayload(context, trunk_obj.id, current_trunk=trunk_obj)
        registry.notify(constants.TRUNK, events.PRECOMMIT_CREATE, self, payload=payload)
    registry.notify(constants.TRUNK, events.AFTER_CREATE, self, payload=payload)
    return trunk_obj
