Skip to content

Commit

Permalink
Merge pull request #1 from daedalus/master
Browse files Browse the repository at this point in the history
mergeback
  • Loading branch information
FlorianHeigl authored Jun 20, 2022
2 parents 6804c7f + a49f418 commit aaec027
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 30 deletions.
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ Example:
`python zoning.py example/zonedata.json`
```
cfgclear
alicreate SRV_P0, 00:00:00:00:00:00:00:01
alicreate SRV_P1, 00:00:00:00:00:00:00:02
alicreate CLI_PA, 00:00:00:00:00:00:00:03
alicreate CLI_PB, 00:00:00:00:00:00:00:04
zonecreate SRV_CLI1, "SRV_P0; CLI_PA"
zonecreate SRV_CLI2, "SRV_P1; CLI_PB"
alicreate SRV_P0, "00:00:00:00:00:00:00:01"
alicreate SRV_P1, "00:00:00:00:00:00:00:02"
alicreate CLI_PA, "00:00:00:00:00:00:00:03"
alicreate CLI_PB, "00:00:00:00:00:00:00:04"
alicreate STOR2, "00:00:00:00:00:01:00:05;00:00:00:00:00:02:00:05"
zonecreate "SRV_CLI1", "SRV_P0;CLI_PA"
zonecreate "SRV_CLI2", "SRV_P1;CLI_PB"
zonecreate "SRV_P0_STOR2", "SRV_P0;STOR2"
zonecreate "SRV_P1_STOR2", "SRV_P1;STOR2"
cfgcreate FABRIC_1, SRV_CLI1
cfgadd FABRIC_1, SRV_CLI2
cfgadd FABRIC_1, SRV_P0_STOR2
cfgadd FABRIC_1, SRV_P1_STOR2
cfgenable FABRIC_1
```
15 changes: 9 additions & 6 deletions example/zonedata.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
{
"ALIAS": [
{"SRV_P0":"00:00:00:00:00:00:00:01"},
{"SRV_P1":"00:00:00:00:00:00:00:02"},
{"CLI_PA":"00:00:00:00:00:00:00:03"},
{"CLI_PB":"00:00:00:00:00:00:00:04"}
{"SRV_P0":["00:00:00:00:00:00:00:01"]},
{"SRV_P1":["00:00:00:00:00:00:00:02"]},
{"CLI_PA":["00:00:00:00:00:00:00:03"]},
{"CLI_PB":["00:00:00:00:00:00:00:04"]},
{"STOR2" :["00:00:00:00:00:01:00:05","00:00:00:00:00:02:00:05"]}
],
"ZONES": [
{"SRV_CLI1":["SRV_P0","CLI_PA"]},
{"SRV_CLI2":["SRV_P1","CLI_PB"]}
{"SRV_CLI2":["SRV_P1","CLI_PB"]},
{"SRV_P0_STOR2":["SRV_P0","STOR2"]},
{"SRV_P1_STOR2":["SRV_P1","STOR2"]}
],
"CFGS": {
"FABRIC_1":["SRV_CLI1","SRV_CLI2"]
"FABRIC_1":["SRV_CLI1","SRV_CLI2","SRV_P0_STOR2","SRV_P1_STOR2" ]
}
}
43 changes: 25 additions & 18 deletions zoning.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,49 @@

def proc_json(filename):
json_data = ''
f = open(filename)
fp = open(filename,"r")
#import ast
import json
#j = ast.literal_eval(json_data)
j = json.load(f)
j = json.load(fp)
fp.close()
return j

def mkcfg(wwns,zoning,cfgs):

txt = "cfgclear\n"

def mkcfg(wwns,zoning,cfgs,clear=True)
if clear:
txt = "cfgclear\n"
else:
txt = ""

for wwn in wwns:
k = wwn.keys()
v = wwn.values()
alias = "alicreate %s, %s" % (k[0],v[0])
alias = """alicreate %s, "%s" """ % (k[0],(";").join(v[0]))
txt = txt + alias + "\n"

for zone in zoning:
k = zone.keys()
v = zone.values()
zone = 'zonecreate %s, "%s; %s"' % (k[0],v[0][0],v[0][1])
zone = """zonecreate "%s", "%s" """ % (k[0],(";").join(v[0]))
txt = txt + zone + "\n"

i = 0

cfgname = cfgs.keys()[0]
members = cfgs.values()[0]

for member in members:
if i == 0:
cfg = "cfgcreate %s, %s" % (cfgname,member)
else:
if clear == True:
i = 0
for member in members:
if i == 0:
cfg = "cfgcreate %s, %s" % (cfgname,member)
else:
cfg = "cfgadd %s, %s" % (cfgname,member)
i+=1
txt = txt + cfg + "\n"
else:
for member in members:
cfg = "cfgadd %s, %s" % (cfgname,member)
i+=1
txt = txt + cfg + "\n"

txt = txt + cfg + "\n"

txt = txt + "cfgenable %s" % cfgname

return txt
Expand All @@ -52,4 +59,4 @@ def mkcfg(wwns,zoning,cfgs):
zoning = json['ZONES']
cfgs = json['CFGS']

print mkcfg(wwns,zoning,cfgs)
print (mkcfg(wwns,zoning,cfgs))

0 comments on commit aaec027

Please sign in to comment.