Skip to content

Commit

Permalink
add support for checking the compatibility of schema version and xcat…
Browse files Browse the repository at this point in the history
… release (#71)

* add support for checking the compatibility of schema version and xcat release

* add xcatversion in vutil

* correct some version in validation criteria
  • Loading branch information
immarvin authored and robin2008 committed Jul 25, 2018
1 parent 93d33ac commit e60d654
Show file tree
Hide file tree
Showing 31 changed files with 978 additions and 360 deletions.
35 changes: 26 additions & 9 deletions xcat-inventory/xcclient/inventory/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ def getvalidobjtypes(cls):
return cls.__InventoryClass__.keys()

@staticmethod
def createHandler(objtype,dbsession,schemaversion='latest'):
def createHandler(objtype,dbsession,schemaversion=None):
if schemaversion is None:
schemaversion='latest'
schemaversion=InventoryFactory.getValidSchemaVersion(objtype)
if schemaversion is None:
raise BadSchemaException("Error: no available schema of %s found!"%(objtype))

validversions=InventoryFactory.getAvailableSchemaVersions()
if schemaversion not in validversions:
raise BadSchemaException("Error: invalid schema version \""+schemaversion+"\", the valid schema versions: "+','.join(validversions))
Expand All @@ -61,11 +64,26 @@ def getAvailableSchemaVersions():
filepath = os.path.join(schemapath, item)
if os.path.isdir(filepath):
schemaversions.append(item)
schemaversions.sort(reverse = True)
return schemaversions

@staticmethod
def getValidSchemaVersion(objtype='node'):
schemavers=InventoryFactory.getAvailableSchemaVersions()
for ver in schemavers:
schemapath=os.path.join(os.path.dirname(__file__), 'schema/'+str(ver)+'/'+objtype+'.yaml')
try:
myclass = InventoryFactory.__InventoryClass__[objtype]
myclass.validate_schema_version(schemapath)
except Exception,e:
continue
return ver
return None

@staticmethod
def getLatestSchemaVersion():
schemapath=os.path.join(os.path.dirname(__file__), 'schema/latest')
latestver=InventoryFactory.getAvailableSchemaVersions()[0]
schemapath=os.path.join(os.path.dirname(__file__), 'schema/'+latestver)
realpath=os.path.realpath(schemapath)
return os.path.basename(realpath)

Expand All @@ -77,6 +95,7 @@ def getDBInst(self):
def exportObjs(self, objlist, location=None,fmt='json',comment=None):
myclass = InventoryFactory.__InventoryClass__[self.objtype]
myclass.loadschema(self.schemapath)
myclass.validate_schema_version(None,'export')
tabs=myclass.gettablist()
obj_attr_dict = self.getDBInst().gettab(tabs, objlist)
objdict={}
Expand Down Expand Up @@ -130,6 +149,7 @@ def validateObjLayout(cls,obj_attr_dict):
def importObjs(self, objlist, obj_attr_dict,update=True,envar=None):
myclass = InventoryFactory.__InventoryClass__[self.objtype]
myclass.loadschema(self.schemapath)
myclass.validate_schema_version(None,'import')
dbdict = {}
objfiles={}
exptmsglist=[]
Expand Down Expand Up @@ -159,9 +179,7 @@ def removeObjs(self):

def getcurschemaversion(self):
if self.schemapath:
return os.path.basename(os.path.dirname(os.path.realpath(self.schemapath)))
else:
return 'latest'
return os.path.basename(os.path.dirname(self.schemapath))

def dumpobj(objdict, fmt='json',location=None):
if not fmt or fmt.lower() == 'json':
Expand Down Expand Up @@ -269,6 +287,7 @@ def export_by_type(objtype, names, destfile=None, destdir=None, fmt='json',versi
if exclude and myobjtype in exclude:
continue
hdl = InventoryFactory.createHandler(myobjtype,dbsession,version)
schemaversion=hdl.getcurschemaversion()
if myobjtype == 'osimage' and destdir:
if exportall:
mylocation=os.path.join(destdir,myobjtype)
Expand All @@ -291,9 +310,7 @@ def export_by_type(objtype, names, destfile=None, destdir=None, fmt='json',versi
if not destdir or myobjtype!='osimage':
wholedict.update(typedict)

if version is None or version in ('latest'):
version=InventoryFactory.getLatestSchemaVersion()
wholedict['schema_version']=version
wholedict['schema_version']=schemaversion

if 'osimage' in objtypelist and destdir:
objtypelist.remove('osimage')
Expand Down
18 changes: 18 additions & 0 deletions xcat-inventory/xcclient/inventory/schema/0.1/credential.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
!!python/dict
credential:
CA:
private_key:
- "${{:'/etc/xcat/ca/private/ca-key.pem'}}"
- "F:${{:['/etc/xcat/ca/private/ca-key.pem']}}"
certificate:
- "${{:'/etc/xcat/ca/ca-cert.pem'}}"
- "F:${{:['/etc/xcat/ca/ca-cert.pem']}}"
server:
- "${{:'/etc/xcat/cert/server-cred.pem'}}"
- "F:${{:['/etc/xcat/cert/server-cred.pem']}}"
client:
root:
- "${{:'/root/.xcat/client-cred.pem'}}"
- "F:${{:['/root/.xcat/client-key.pem']}}"


32 changes: 32 additions & 0 deletions xcat-inventory/xcclient/inventory/schema/0.1/network.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
!!python/dict
network:
basic_attr:
net:
- "T{networks.net}"
- "C:${{value=V{basic_attr.net}: vutil.isIPaddr(value)}}"
mask:
- "T{networks.mask}"
- "C:${{value=V{basic_attr.mask}: vutil.isIPaddr(value)}}"
mgtifname: "T{networks.mgtifname}"
gateway:
- "T{networks.gateway}"
mtu: "T{networks.mtu}"
domain: "T{networks.domain}"
vlanid: "T{networks.vlanid}"
pool:
dynamicrange:
- "T{networks.dynamicrange}"
- "C:${{ value=V{pool.dynamicrange}: True if str(value) in [''] or vutil.isIPaddr(value) or vutil.isIPrange(value) else False}}"
staticrange:
- "T{networks.staticrange}"
- "C:${{ value=V{pool.staticrange}: True if str(value) in [''] or vutil.isIPrange(value) or vutil.isIPaddr(value) else False}}"
staticrangeincrement: "T{networks.staticrangeincrement}"
nodehostname: "T{networks.nodehostname}"
ddnsdomain: "T{networks.ddnsdomain}"
service:
dhcpserver: "T{networks.dhcpserver}"
tftpserver: "T{networks.tftpserver}"
ntpservers: "T{networks.ntpservers}"
logservers: "T{networks.logservers}"
nameservers: "T{networks.nameservers}"
usercomment: "T{networks.comments}"
Loading

0 comments on commit e60d654

Please sign in to comment.