'Add one or more subports to trunk.'

@db_base_plugin_common.convert_result_to_dict
def add_subports(self, context, trunk_id, subports):

    with db_api.context_manager.writer.using(context):
        trunk = self._get_trunk(context, trunk_id)
        subports = subports['sub_ports']
        subports_validator = rules.SubPortsValidator(self._segmentation_types, subports, trunk['port_id'])
        subports = subports_validator.validate(context, basic_validation=True)
        added_subports = []
        rules.trunk_can_be_managed(context, trunk)
        original_trunk = copy.deepcopy(trunk)
        if (trunk.status == constants.ERROR_STATUS):
            raise trunk_exc.TrunkInErrorState(trunk_id=trunk_id)
        else:
            trunk.update(status=constants.DOWN_STATUS)
        for subport in subports:
            obj = trunk_objects.SubPort(context=context, trunk_id=trunk_id, port_id=subport['port_id'], segmentation_type=subport['segmentation_type'], segmentation_id=subport['segmentation_id'])
            obj.create()
            trunk['sub_ports'].append(obj)
            added_subports.append(obj)
        payload = callbacks.TrunkPayload(context, trunk_id, current_trunk=trunk, original_trunk=original_trunk, subports=added_subports)
        if added_subports:
            registry.notify(constants.SUBPORTS, events.PRECOMMIT_CREATE, self, payload=payload)
    if added_subports:
        registry.notify(constants.SUBPORTS, events.AFTER_CREATE, self, payload=payload)
    return trunk
