<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def register_vm(datacenter, name, vmx_path, resourcepool_object, host_object=None):
    '''
    Registers a virtual machine to the inventory with the given vmx file, on success
    it returns the vim.VirtualMachine managed object reference

    datacenter
        Datacenter object of the virtual machine, vim.Datacenter object

    name
        Name of the virtual machine

    vmx_path:
        Full path to the vmx file, datastore name should be included

    resourcepool
        Placement resource pool of the virtual machine, vim.ResourcePool object

    host
        Placement host of the virtual machine, vim.HostSystem object
    '''
    try:
        if host_object:
            task = datacenter.vmFolder.RegisterVM_Task(path=vmx_path, name=name,
                                                       asTemplate=False,
                                                       host=host_object,
                                                       pool=resourcepool_object)
        else:
            task = datacenter.vmFolder.RegisterVM_Task(path=vmx_path, name=name,
                                                       asTemplate=False,
                                                       pool=resourcepool_object)
    except vim.fault.NoPermission as exc:
        log.exception(exc)
        raise salt.exceptions.VMwareApiError(
            'Not enough permissions. Required privilege: '
            '{}'.format(exc.privilegeId))
    except vim.fault.VimFault as exc:
        log.exception(exc)
        raise salt.exceptions.VMwareApiError(exc.msg)
    except vmodl.RuntimeFault as exc:
        log.exception(exc)
        raise salt.exceptions.VMwareRuntimeError(exc.msg)
    try:
        vm_ref = wait_for_task(task, name, 'RegisterVM Task')
    except salt.exceptions.VMwareFileNotFoundError as exc:
        raise salt.exceptions.VMwareVmRegisterError(
            'An error occurred during registration operation, the '
            'configuration file was not found: {0}'.format(exc))
    return vm_ref