'Extended API:  New style object manipulations, 2.0 and later
Prefered over using new_, modify_, save_ directly.
Though we must preserve the old ways for backwards compatibility these
cause much less XMLRPC traffic.
edit_type - One of \'add\', \'rename\', \'copy\', \'remove\'
Ex: xapi_object_edit("distro","el5","add",{"kernel":"/tmp/foo","initrd":"/tmp/foo"},token)'

def xapi_object_edit(self, object_type, object_name, edit_type, attributes, token):

    if (object_name.strip() == ''):
        raise CX('xapi_object_edit()    called    without    an    object    name')
    self.check_access(token, ('xedit_%s' % object_type), token)
    if (edit_type == 'add'):
        handle = 0
        try:
            handle = self.get_item_handle(object_type, object_name)
        except:
            pass
        if (handle != 0):
            raise CX("it    seems    unwise    to    overwrite    this    object,    try    'edit'")
    if (edit_type == 'add'):
        is_subobject = ((object_type == 'profile') and ('parent' in attributes))
        if (is_subobject and ('distro' in attributes)):
            raise CX("You    can't    change    both    'parent'    and    'distro'")
        if (object_type == 'system'):
            if (('profile' not in attributes) and ('image' not in attributes)):
                raise CX("You    must    specify    a    'profile'    or    'image'    for    new    systems")
        handle = self.new_item(object_type, token, is_subobject=is_subobject)
    else:
        handle = self.get_item_handle(object_type, object_name)
    if (edit_type == 'rename'):
        self.rename_item(object_type, handle, attributes['newname'], token)
        handle = self.get_item_handle(object_type, attributes['newname'], token)
    if (edit_type == 'copy'):
        is_subobject = ((object_type == 'profile') and ('parent' in attributes))
        if is_subobject:
            if ('distro' in attributes):
                raise CX("You    can't    change    both    'parent'    and    'distro'")
            self.copy_item(object_type, handle, attributes['newname'], token)
            handle = self.get_item_handle('profile', attributes['newname'], token)
            self.modify_item('profile', handle, 'parent', attributes['parent'], token)
        else:
            self.copy_item(object_type, handle, attributes['newname'], token)
            handle = self.get_item_handle(object_type, attributes['newname'], token)
    if (edit_type in ['copy', 'rename']):
        del attributes['name']
        del attributes['newname']
    if (edit_type != 'remove'):
        imods = {}
        for (k, v) in attributes.iteritems():
            if ((object_type != 'system') or (not self.__is_interface_field(k))):
                if ((k in ['autoinstall_meta', 'kernel_options', 'kernel_options_post', 'template_files', 'boot_files', 'fetchable_files', 'params']) and ('in_place' in attributes) and attributes['in_place']):
                    details = self.get_item(object_type, object_name)
                    v2 = details[k]
                    (ok, input) = utils.input_string_or_dict(v)
                    for (a, b) in input.iteritems():
                        if (a.startswith('~') and (len(a) > 1)):
                            del v2[a[1:]]
                        else:
                            v2[a] = b
                    v = v2
                self.modify_item(object_type, handle, k, v, token)
            else:
                modkey = ('%s-%s' % (k, attributes.get('interface', '')))
                imods[modkey] = v
        if (object_type == 'system'):
            if (('delete_interface' not in attributes) and ('rename_interface' not in attributes)):
                self.modify_system(handle, 'modify_interface', imods, token)
            elif ('delete_interface' in attributes):
                self.modify_system(handle, 'delete_interface', attributes.get('interface', ''), token)
            elif ('rename_interface' in attributes):
                ifargs = [attributes.get('interface', ''), attributes.get('rename_interface', '')]
                self.modify_system(handle, 'rename_interface', ifargs, token)
    else:
        recursive = attributes.get('recursive', False)
        if ((object_type == 'profile') and (recursive is False)):
            childs = len(self.api.find_items(object_type, criteria={'parent': attributes['name']}))
            if (childs > 0):
                raise CX(("Can't    delete    this    profile    there    are    %s    subprofiles    and    'recursive'    is    set    to    'False'" % childs))
        self.remove_item(object_type, object_name, token, recursive=recursive)
        return True
    self.save_item(object_type, handle, token)
    return True
