Exemplo n.º 1
0
def test_compare_org_hierarchy():
    from ucsmsdk.mometa.org.OrgOrg import OrgOrg
    from ucsmsdk.mometa.ls.LsServer import LsServer
    static_setup()

    ref_org = OrgOrg(parent_mo_or_dn="org-root", name="org_same", descr="")
    ref_org._handle = ref_handle
    ref_same_sp = LsServer(ref_org, name="same")
    ref_same_sp._handle = ref_handle
    ref_remove = LsServer(ref_org, name="remove_from_ref")
    ref_remove._handle = ref_handle
    ref_mos = [ref_org, ref_same_sp, ref_remove]

    diff_org = OrgOrg(parent_mo_or_dn="org-root",
                      name="org_same",
                      descr="diff")
    diff_org._handle = diff_handle
    diff_same_sp = LsServer(diff_org, name="same", usr_lbl="diff")
    diff_same_sp._handle = diff_handle
    diff_add = LsServer(diff_org, name="add_to_ref")
    diff_add._handle = diff_handle
    diff_mos = [diff_org, diff_same_sp, diff_add]

    difference = compare_ucs_mo(ref_mos, diff_mos)
    write_mo_diff(difference)
    assert_equal(len(difference), 4)
Exemplo n.º 2
0
def test_compare_org_hierarchy():
    from ucsmsdk.mometa.org.OrgOrg import OrgOrg
    from ucsmsdk.mometa.ls.LsServer import LsServer
    static_setup()

    ref_org = OrgOrg(parent_mo_or_dn="org-root", name="org_same", descr="")
    ref_org._handle = ref_handle
    ref_same_sp = LsServer(ref_org, name="same")
    ref_same_sp._handle = ref_handle
    ref_remove = LsServer(ref_org, name="remove_from_ref")
    ref_remove._handle = ref_handle
    ref_mos = [ref_org, ref_same_sp, ref_remove]

    diff_org = OrgOrg(parent_mo_or_dn="org-root", name="org_same",
                      descr="diff")
    diff_org._handle = diff_handle
    diff_same_sp = LsServer(diff_org, name="same", usr_lbl="diff")
    diff_same_sp._handle = diff_handle
    diff_add = LsServer(diff_org, name="add_to_ref")
    diff_add._handle = diff_handle
    diff_mos = [diff_org, diff_same_sp, diff_add]

    difference = compare_ucs_mo(ref_mos, diff_mos)
    write_mo_diff(difference)
    assert_equal(len(difference), 4)
Exemplo n.º 3
0
def main():
    src_ucs_params = get_parameters('Source', default_src_ip, default_username)
    dst_ucs_params = get_parameters('Destination', default_dst_ip,
                                    default_username)
    src_handle = ucshandle.UcsHandle(src_ucs_params['ip'],
                                     src_ucs_params['user'],
                                     src_ucs_params['password'],
                                     secure=True)
    dst_handle = ucshandle.UcsHandle(dst_ucs_params['ip'],
                                     dst_ucs_params['user'],
                                     dst_ucs_params['password'],
                                     secure=True)
    src_handle.login()
    dst_handle.login()
    src_vlans = get_vlans(src_handle)
    dst_vlans = get_vlans(dst_handle)
    diff_vlans = comparesyncmo.compare_ucs_mo(dst_vlans, src_vlans)
    if diff_vlans:
        print 'Following VLANs will be synced:\n'
        comparesyncmo.write_mo_diff(diff_vlans)
        print '\nSyncing VLANs...\n'
        comparesyncmo.sync_ucs_mo(dst_handle,
                                  diff_vlans,
                                  delete_not_present=True)
    else:
        print 'VLANs are already in sync.'
    src_handle.logout()
    dst_handle.logout()
Exemplo n.º 4
0
def test_compare_remove_obj_from_ref_exist_only_in_ref():
    from ucsmsdk.mometa.ls.LsServer import LsServer
    static_setup()

    ref_mo = LsServer(parent_mo_or_dn="org-root", name="remove_from_ref",
                      usr_lbl="")
    ref_mo._handle = ref_handle
    ref_mos = [ref_mo]

    diff_mos = []

    difference = compare_ucs_mo(ref_mos, diff_mos)
    write_mo_diff(difference)
    assert_equal(len(difference), 1)
Exemplo n.º 5
0
def test_compare_remove_obj_from_ref_exist_only_in_ref():
    from ucsmsdk.mometa.ls.LsServer import LsServer
    static_setup()

    ref_mo = LsServer(parent_mo_or_dn="org-root", name="remove_from_ref",
                      usr_lbl="")
    ref_mo._handle = ref_handle
    ref_mos = [ref_mo]

    diff_mos = []

    difference = compare_ucs_mo(ref_mos, diff_mos)
    write_mo_diff(difference)
    assert_equal(len(difference), 1)
Exemplo n.º 6
0
def test_unknown_mo():
    from ucsmsdk.ucsmo import GenericMo
    static_setup()

    ref_mo = GenericMo(class_id="unknown", parent_mo_or_dn="parent_dn",
                       dn="sys/unknown", unknown="")
    ref_mo._handle = ref_handle
    ref_mos = [ref_mo]

    diff_mo = GenericMo(class_id="unknown", parent_mo_or_dn="parent_dn",
                        dn="sys/unknown", unknown="yyy")
    diff_mo._handle = diff_handle
    diff_mos = [diff_mo]

    difference = compare_ucs_mo(ref_mos, diff_mos)
    write_mo_diff(difference)
    assert_equal(len(difference), 0)
Exemplo n.º 7
0
def test_unknown_mo():
    from ucsmsdk.ucsmo import GenericMo
    static_setup()

    ref_mo = GenericMo(class_id="unknown", parent_mo_or_dn="parent_dn",
                       dn="sys/unknown", unknown="")
    ref_mo._handle = ref_handle
    ref_mos = [ref_mo]

    diff_mo = GenericMo(class_id="unknown", parent_mo_or_dn="parent_dn",
                        dn="sys/unknown", unknown="yyy")
    diff_mo._handle = diff_handle
    diff_mos = [diff_mo]

    difference = compare_ucs_mo(ref_mos, diff_mos)
    write_mo_diff(difference)
    assert_equal(len(difference), 0)
Exemplo n.º 8
0
def test_compare_same_obj_with_diff_props_include_operational():
    from ucsmsdk.mometa.ls.LsServer import LsServer
    static_setup()

    ref_mo = LsServer(parent_mo_or_dn="org-root", name="same", usr_lbl="")
    ref_mo.__dict__['config_state'] = "applied"
    ref_mo._handle = ref_handle
    ref_mos = [ref_mo]

    diff_mo = LsServer(parent_mo_or_dn="org-root", name="same", usr_lbl="xxx")
    diff_mo.__dict__['config_state'] = "applying"
    diff_mo._handle = diff_handle
    diff_mos = [diff_mo]

    difference = compare_ucs_mo(ref_mos, diff_mos, include_operational=True)
    write_mo_diff(difference)
    assert_equal(len(difference), 1)
    assert_equal(len(difference[0].diff_property), 2)
Exemplo n.º 9
0
def test_unknown_mo_noversionfilter():
    from ucsmsdk.ucsmo import GenericMo
    static_setup()

    ref_mo = GenericMo(class_id="unknown", parent_mo_or_dn="parent_dn",
                       dn="sys/unknown", unknown="")
    ref_mo._handle = ref_handle
    ref_mos = [ref_mo]

    diff_mo = GenericMo(class_id="unknown", parent_mo_or_dn="parent_dn",
                        dn="sys/unknown", unknown="yyy")
    diff_mo._handle = diff_handle
    diff_mos = [diff_mo]

    difference = compare_ucs_mo(ref_mos, diff_mos, version_filter=False)
    write_mo_diff(difference)
    assert_equal(len(difference), 1)
    assert_equal(len(difference[0].diff_property), 1)
Exemplo n.º 10
0
def test_compare_same_obj_with_diff_props_include_operational():
    from ucsmsdk.mometa.ls.LsServer import LsServer
    static_setup()

    ref_mo = LsServer(parent_mo_or_dn="org-root", name="same", usr_lbl="")
    ref_mo.__dict__['config_state'] = "applied"
    ref_mo._handle = ref_handle
    ref_mos = [ref_mo]

    diff_mo = LsServer(parent_mo_or_dn="org-root", name="same", usr_lbl="xxx")
    diff_mo.__dict__['config_state'] = "applying"
    diff_mo._handle = diff_handle
    diff_mos = [diff_mo]

    difference = compare_ucs_mo(ref_mos, diff_mos, include_operational=True)
    write_mo_diff(difference)
    assert_equal(len(difference), 1)
    assert_equal(len(difference[0].diff_property), 2)
Exemplo n.º 11
0
def test_unknown_mo_noversionfilter():
    from ucsmsdk.ucsmo import GenericMo
    static_setup()

    ref_mo = GenericMo(class_id="unknown", parent_mo_or_dn="parent_dn",
                       dn="sys/unknown", unknown="")
    ref_mo._handle = ref_handle
    ref_mos = [ref_mo]

    diff_mo = GenericMo(class_id="unknown", parent_mo_or_dn="parent_dn",
                        dn="sys/unknown", unknown="yyy")
    diff_mo._handle = diff_handle
    diff_mos = [diff_mo]

    difference = compare_ucs_mo(ref_mos, diff_mos, version_filter=False)
    write_mo_diff(difference)
    assert_equal(len(difference), 1)
    assert_equal(len(difference[0].diff_property), 1)
Exemplo n.º 12
0
def test_unknown_property_noversionfilter():
    from ucsmsdk.mometa.ls.LsServer import LsServer
    static_setup()

    ref_mo = LsServer(parent_mo_or_dn="org-root", name="ra_ref", usr_lbl="")
    ref_mo._handle = ref_handle
    ref_mo.unknown = ""
    ref_mos = [ref_mo]

    diff_mo = LsServer(parent_mo_or_dn="org-root", name="ra_ref",
                       usr_lbl="xxx")
    diff_mo._handle = diff_handle
    diff_mo.unknown = "yyy"
    diff_mos = [diff_mo]

    difference = compare_ucs_mo(ref_mos, diff_mos, version_filter=False)
    write_mo_diff(difference)
    assert_equal(len(difference), 1)
    assert_equal(len(difference[0].diff_property), 2)
Exemplo n.º 13
0
def test_unknown_property_noversionfilter():
    from ucsmsdk.mometa.ls.LsServer import LsServer
    static_setup()

    ref_mo = LsServer(parent_mo_or_dn="org-root", name="ra_ref", usr_lbl="")
    ref_mo._handle = ref_handle
    ref_mo.unknown = ""
    ref_mos = [ref_mo]

    diff_mo = LsServer(parent_mo_or_dn="org-root", name="ra_ref",
                       usr_lbl="xxx")
    diff_mo._handle = diff_handle
    diff_mo.unknown = "yyy"
    diff_mos = [diff_mo]

    difference = compare_ucs_mo(ref_mos, diff_mos, version_filter=False)
    write_mo_diff(difference)
    assert_equal(len(difference), 1)
    assert_equal(len(difference[0].diff_property), 2)
Exemplo n.º 14
0
# Login to a SOURCE UCS and a TARGET UCS
SOURCE_UCS = UcsHandle("13.58.22.56", "admin", "password")
TARGET_UCS = UcsHandle("18.217.19.216", "admin", "password")
SOURCE_UCS.login()
TARGET_UCS.login()

# Query the SOURCE UCS VLANS and the TARGET UCS VLANS
SOURCE_UCS_VLANS = SOURCE_UCS.query_classid("fabricVlan")
TARGET_UCS_VLANS = TARGET_UCS.query_classid("fabricVlan")

# Compare the TARGET VLANS with the SOURCE VLANS
DIFFERENCE_VLANS = comparesyncmo.compare_ucs_mo(TARGET_UCS_VLANS,
                                                SOURCE_UCS_VLANS)

print("difference is %s" % DIFFERENCE_VLANS)

if DIFFERENCE_VLANS:
    # Display the difference
    comparesyncmo.write_mo_diff(DIFFERENCE_VLANS)

    # Sync - apply the difference to the TARGET_UCS, remove from the
    # TARGET_UCS any objects that are not present on the SOURCE_UCS
    # This action is not done through the HANDLE, the commit() is implicit
    comparesyncmo.sync_ucs_mo(TARGET_UCS,
                              DIFFERENCE_VLANS,
                              delete_not_present=True)

# Logout
SOURCE_UCS.logout()
TARGET_UCS.logout()