Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Sep 30, 2020. It is now read-only.

Commit b812fd4

Browse files
committed
Fixed some sloppy suborg stuff
Now, suborg is created (if doesn't exist) upon initialization of the functions class. All non sub-org related functions should refer to self.orgNameDN, and not self.orgName. In the future I may rename self.orgNameDN to be more specific to it's purpose.
1 parent 52219e5 commit b812fd4

1 file changed

Lines changed: 35 additions & 34 deletions

File tree

functions/newfunctions_ucs.py

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,53 +21,51 @@ def __init__(self, handle, orgName): #TODO: Currently requiring org info at star
2121
#TODO: is there a way to check to make sure this is a valid handle? I.e. logged in?
2222
self.handle = handle
2323

24+
#Some functions refer directly to root (i.e. VLANs) self.orgroot represents this
2425
self.orgroot = self.handle.GetManagedObject(None, None, {"Dn":"org-root/"})
2526

26-
#TODO: Need to re-implement this so you can use root orgs. Currently only suborgs supported
27-
#Set DN string for org
28-
#if newfxns.orgName == "root":
29-
# newfxns.orgNameDN = "org-root/"
30-
#else:
31-
# newfxns.orgNameDN = "org-root/org-" + newfxns.orgName + "/"
32-
33-
self.orgName = orgName
34-
self.orgNameDN = "org-root/org-" + orgName #TODO: Would prefer to get this more dynamically (i.e. self.org.Dn)
35-
36-
#TODO: Would prefer to reference the getSubOrg method, but is this possible in __init__? Getting a "getSubOrg is not defined" error
37-
self.org = self.handle.GetManagedObject(None, OrgOrg.ClassId(),
38-
{
39-
OrgOrg.DN : self.orgNameDN
40-
})
27+
#Set self.org object. This is referred to throughout the various functions.
28+
if orgName != "root":
29+
self.org = self.getSubOrg(orgName)
30+
else:
31+
self.org = self.orgroot
32+
33+
#For some reason, org objects are stored as lists
34+
for item in self.org:
35+
36+
#Sets other org-related properties. Functions should refer directly
37+
#to self.orgNameDN - self.orgName is used only by suborg functions
38+
self.orgName = item.Name
39+
self.orgNameDN = item.Dn
40+
41+
#Create requested suborg
42+
self.createSubOrg(self.orgName)
4143

4244
print "Instantiated New Functions"
4345

4446
def getSubOrg(self, orgName):
45-
self.org = self.handle.GetManagedObject(None, OrgOrg.ClassId(),
47+
suborg = self.handle.GetManagedObject(None, OrgOrg.ClassId(),
4648
{
4749
OrgOrg.DN : "org-root/org-" + orgName
4850
})
51+
return suborg
4952

5053
def createSubOrg(self, orgName):
51-
if self.orgName != "root" :
52-
try:
53-
self.handle.AddManagedObject(self.rootorg, OrgOrg.ClassId(),
54-
{
55-
OrgOrg.DESCR:self.orgName,
56-
OrgOrg.NAME:self.orgName,
57-
OrgOrg.DN:"org-root/org-" + self.orgName
58-
})
59-
except UcsException:
60-
print "Sub-organization already exists" #convert to logging and TODO: need to handle this better. Need to poke around at the possible exception types
61-
62-
self.org = self.handle.GetManagedObject(None, OrgOrg.ClassId(),
63-
{
64-
OrgOrg.DN : self.orgNameDN
65-
})
66-
else:
67-
self.org = self.handle.GetManagedObject(None, OrgOrg.ClassId(),
54+
try:
55+
self.handle.AddManagedObject(self.orgroot, OrgOrg.ClassId(),
6856
{
69-
OrgOrg.DN : "org-root/"
57+
"Dn":"org-root/org-" + self.orgName,
58+
"Desc":self.orgName,
59+
"Name":self.orgName
7060
})
61+
except UcsException:
62+
print "Sub-organization already exists" #convert to logging and TODO: need to handle this better. Need to poke around at the possible exception types
63+
64+
self.org = self.handle.GetManagedObject(None, OrgOrg.ClassId(),
65+
{
66+
OrgOrg.DN : self.orgNameDN
67+
})
68+
7169

7270

7371
###########
@@ -189,3 +187,6 @@ def removeMacPool(self, mo):
189187

190188

191189

190+
191+
192+

0 commit comments

Comments
 (0)