Exemple #1
0
def manage_org(org_op, org_name, org_descr=None):
    from ucsmsdk.mometa.org.OrgOrg import OrgOrg

    handle = ucs_login()

    if org_op.lower() == "add":
        mo = OrgOrg(parent_mo_or_dn='org-root', name=org_name, descr=org_descr)
        handle.add_mo(mo, modify_present=True)
        handle.commit()
        response = "Org: " + org_name + " Added/Updated."
    elif org_op.lower() == "remove":
        mo = handle.query_dn("org-root/org-" + org_name)
        if mo:
            handle.remove_mo(mo)
            handle.commit()
            response = "Org: " + org_name + " Removed."
        else:
            response = "Org: " + org_name + " Not Found."
    elif org_op.lower() == "update":
        mo = handle.query_dn("org-root/org-" + org_name)
        if mo:
            mo.descr = org_descr
            handle.add_mo(mo, modify_present=True)
            handle.commit()
            response = "Org: " + org_name + " Updated."
        else:
            response = "Org: " + org_name + " Not Found: could not update."

    ucs_logout(handle)

    print(response)
    return response
def manage_org(inputs):
    """ Manage UCS Organizations """

    from ucsmsdk.mometa.org.OrgOrg import OrgOrg

    handle = ucs_login()

    object_op = inputs[0]
    org_parent = inputs[1]
    org_name = inputs[2]
    if len(inputs) == 4:
        org_descr = inputs[3]

    if object_op == "add":
        parent_org_dn = 'org-' + org_parent.replace('/', '/org-')
        parent_org = handle.query_dn(parent_org_dn)
        if parent_org:
            ucs_mo = OrgOrg(parent_mo_or_dn=parent_org_dn,
                            name=org_name,
                            descr=org_descr)
            handle.add_mo(ucs_mo, modify_present=True)
            handle.commit()
            response = "Org: " + (parent_org_dn + "/org-" + org_name).replace(
                '/org-', '/').replace('org-', '') + " - Added."
        else:
            response = "Org: " + (parent_org_dn).replace('/org-', '/').replace(
                'org-', '') + " - Parent Org Not Found: could not Add."
    elif object_op == "remove":
        parent_org_dn = 'org-' + org_parent.replace('/', '/org-')
        ucs_mo = handle.query_dn(parent_org_dn + "/org-" + org_name)
        if ucs_mo:
            handle.remove_mo(ucs_mo)
            handle.commit()
            response = "Org: " + (parent_org_dn + "/org-" + org_name).replace(
                '/org-', '/').replace('org-', '') + " - Removed."
        else:
            response = "Org: " + (parent_org_dn + "/org-" + org_name).replace(
                '/org-', '/').replace('org-',
                                      '') + " - Not Found: could not remove."
    elif object_op == "update":
        parent_org_dn = 'org-' + org_parent.replace('/', '/org-')
        ucs_mo = handle.query_dn(parent_org_dn + "/org-" + org_name)
        if ucs_mo:
            ucs_mo.descr = org_descr
            handle.add_mo(ucs_mo, modify_present=True)
            handle.commit()
            response = "Org: " + (parent_org_dn + "/org-" + org_name).replace(
                '/org-', '/').replace('org-', '') + " - Updated."
        else:
            response = "Org: " + (parent_org_dn + "/org-" + org_name).replace(
                '/org-', '/').replace('org-',
                                      '') + " - Not Found: could not update."

    ucs_logout(handle)

    print(response)
    return response