'Update licenses'

def update_licenses(self):

    if self.remove_unused:
        self.remove_unused_licenses()
    if self.remove_expired:
        self.remove_expired_licenses()
    license_add = netapp_utils.zapi.NaElement('license-v2-add')
    codes = netapp_utils.zapi.NaElement('codes')
    remove_list = []
    for (key, value) in self.licenses.items():
        str_value = str(value)
        if (str_value and str_value.strip()):
            if (str_value.lower() == 'remove'):
                remove_list.append(str(key).lower())
            else:
                codes.add_new_child('license-code-v2', str_value)
    if (not (len(remove_list) == 0)):
        self.remove_licenses(remove_list)
    if (not (len(codes.get_children()) == 0)):
        license_add.add_child_elem(codes)
        try:
            self.server.invoke_successfully(license_add, enable_tunneling=False)
        except netapp_utils.zapi.NaApiError as e:
            self.module.fail_json(msg=('Error    adding    licenses:    %s' % to_native(e)), exception=traceback.format_exc())
