from PLC.InterfaceTags import InterfaceTag, InterfaceTags
from PLC.NodeTags import NodeTag, NodeTags
from PLC.InterfaceTags import InterfaceTag, InterfaceTags
from PLC.NodeTags import NodeTag, NodeTags
# could not define this in the class..
# create a dict with the allowed actions for each type of node
# reservable nodes being more recent, we do not support the floppy stuff anymore
allowed_actions = {
# could not define this in the class..
# create a dict with the allowed actions for each type of node
# reservable nodes being more recent, we do not support the floppy stuff anymore
allowed_actions = {
- (*) or regenerate the node config file for storage on a floppy
- that is, exactly what the ancestor method used todo,
+ (*) or regenerate the node config file for storage on a floppy
+ that is, exactly what the ancestor method used todo,
including renewing the node's key
(*) or regenerate the config file and bundle it inside an ISO or USB image
including renewing the node's key
(*) or regenerate the config file and bundle it inside an ISO or USB image
in which case of course the node_id_or_hostname parameter is not used
action is expected among the following string constants according the
in which case of course the node_id_or_hostname parameter is not used
action is expected among the following string constants according the
Apart for the preview mode, this method generates a new node key for the
specified node, effectively invalidating any old boot medium.
Apart for the preview mode, this method generates a new node key for the
specified node, effectively invalidating any old boot medium.
'generic-iso' nor 'generic-usb'.
In addition, two return mechanisms are supported.
'generic-iso' nor 'generic-usb'.
In addition, two return mechanisms are supported.
base64-encoded string. This is how the ancestor method used to work.
To use this method, pass an empty string as the file parameter.
base64-encoded string. This is how the ancestor method used to work.
To use this method, pass an empty string as the file parameter.
- (*) Or, for efficiency -- this makes sense only when the API is used
- by the web pages that run on the same host -- the caller may provide
- a filename, in which case the resulting file is stored in that location instead.
- The filename argument can use the following markers, that are expanded
+ (*) Or, for efficiency -- this makes sense only when the API is used
+ by the web pages that run on the same host -- the caller may provide
+ a filename, in which case the resulting file is stored in that location instead.
+ The filename argument can use the following markers, that are expanded
within the method
- %d : default root dir (some builtin dedicated area under /var/tmp/)
Using this is recommended, and enforced for non-admin users
within the method
- %d : default root dir (some builtin dedicated area under /var/tmp/)
Using this is recommended, and enforced for non-admin users
generic media is requested
- %s : a file suffix appropriate in the context (.txt, .iso or the like)
- %v : the bootcd version string (e.g. 4.0)
- %p : the PLC name
- %f : the nodefamily
- %a : arch
generic media is requested
- %s : a file suffix appropriate in the context (.txt, .iso or the like)
- %v : the bootcd version string (e.g. 4.0)
- %p : the PLC name
- %f : the nodefamily
- %a : arch
variants are used to run a different kernel on the bootCD
see kvariant.sh for how to create a variant
- 'no-hangcheck' - disable hangcheck
Tags: the following tags are taken into account when attached to the node:
'serial', 'cramfs', 'kvariant', 'kargs', 'no-hangcheck'
variants are used to run a different kernel on the bootCD
see kvariant.sh for how to create a variant
- 'no-hangcheck' - disable hangcheck
Tags: the following tags are taken into account when attached to the node:
'serial', 'cramfs', 'kvariant', 'kargs', 'no-hangcheck'
Security:
- Non-admins can only generate files for nodes at their sites.
- Non-admins, when they provide a filename, *must* specify it in the %d area
Security:
- Non-admins can only generate files for nodes at their sites.
- Non-admins, when they provide a filename, *must* specify it in the %d area
Whenever needed, the method stores intermediate files in a
private area, typically not located under the web server's
accessible area, and are cleaned up by the method.
Whenever needed, the method stores intermediate files in a
private area, typically not located under the web server's
accessible area, and are cleaned up by the method.
# Generate the node (plnode.txt) configuration content.
#
# This function will create the configuration file a node
# Generate the node (plnode.txt) configuration content.
#
# This function will create the configuration file a node
for category in categories:
category_settings = InterfaceTags(self.api,{'interface_id':interface['interface_id'],
'category':category})
for category in categories:
category_settings = InterfaceTags(self.api,{'interface_id':interface['interface_id'],
'category':category})
arch = self.api.config.PLC_FLAVOUR_NODE_ARCH
if not node:
return (pldistro,fcdistro,arch)
arch = self.api.config.PLC_FLAVOUR_NODE_ARCH
if not node:
return (pldistro,fcdistro,arch)
# no support for deployment-based BootCD's, use kvariants instead
node_pldistro = GetNodePldistro (self.api).call(auth, node_id)
if node_pldistro: pldistro = node_pldistro
# no support for deployment-based BootCD's, use kvariants instead
node_pldistro = GetNodePldistro (self.api).call(auth, node_id)
if node_pldistro: pldistro = node_pldistro
node_arch = GetNodeArch (self.api).call(auth,node_id)
if node_arch: arch = node_arch
node_arch = GetNodeArch (self.api).call(auth,node_id)
if node_arch: arch = node_arch
return (pldistro,fcdistro,arch)
def bootcd_version (self):
return (pldistro,fcdistro,arch)
def bootcd_version (self):
return file(self.BOOTCDDIR + "/build/version.txt").readline().strip()
except:
raise Exception,"Unknown boot cd version - probably wrong bootcd dir : %s"%self.BOOTCDDIR
return file(self.BOOTCDDIR + "/build/version.txt").readline().strip()
except:
raise Exception,"Unknown boot cd version - probably wrong bootcd dir : %s"%self.BOOTCDDIR
# check for permissions and concurrency
# returns the filename
def handle_filename (self, filename, nodename, suffix, arch):
# check for permissions and concurrency
# returns the filename
def handle_filename (self, filename, nodename, suffix, arch):
if os.path.exists(filename):
raise PLCInvalidArgument, "Resulting file %s already exists"%filename
if os.path.exists(filename):
raise PLCInvalidArgument, "Resulting file %s already exists"%filename
### either we are admin or under a controlled location
filedir=os.path.dirname(filename)
# dirname does not return "." for a local filename like its shell counterpart
### either we are admin or under a controlled location
filedir=os.path.dirname(filename)
# dirname does not return "." for a local filename like its shell counterpart
build_sh_options += " -s %s"%build_sh_spec['serial']
if "variant" in build_sh_spec:
build_sh_options += " -V %s"%build_sh_spec['variant']
build_sh_options += " -s %s"%build_sh_spec['serial']
if "variant" in build_sh_spec:
build_sh_options += " -V %s"%build_sh_spec['variant']
def call(self, auth, node_id_or_hostname, action, filename, options = []):
def call(self, auth, node_id_or_hostname, action, filename, options = []):
build_sh_spec={'kargs':[]}
# use node tags as defaults
# check for node tag equivalents
build_sh_spec={'kargs':[]}
# use node tags as defaults
# check for node tag equivalents
- tags = NodeTags(self.api,
- {'node_id': node['node_id'],
+ tags = NodeTags(self.api,
+ {'node_id': node['node_id'],
'tagname': ['serial', 'cramfs', 'kvariant', 'kargs', 'no-hangcheck']},
['tagname', 'value'])
if tags:
'tagname': ['serial', 'cramfs', 'kvariant', 'kargs', 'no-hangcheck']},
['tagname', 'value'])
if tags:
# apply on globals
for attr in [ "BOOTCDDIR", "BOOTCDBUILD", "GENERICDIR" ]:
setattr(self,attr,getattr(self,attr).replace("@NODEFAMILY@",self.nodefamily))
# apply on globals
for attr in [ "BOOTCDDIR", "BOOTCDBUILD", "GENERICDIR" ]:
setattr(self,attr,getattr(self,attr).replace("@NODEFAMILY@",self.nodefamily))
filename = self.handle_filename(filename, nodename, suffix, arch)
filename = self.handle_filename(filename, nodename, suffix, arch)
if not os.path.isfile(self.BOOTCDBUILD):
raise PLCAPIError, "Cannot locate bootcd/build.sh script %s"%self.BOOTCDBUILD
if not os.path.isfile(self.BOOTCDBUILD):
raise PLCAPIError, "Cannot locate bootcd/build.sh script %s"%self.BOOTCDBUILD
os.chmod(self.WORKDIR,0777)
except:
raise PLCPermissionDenied, "Could not create dir %s"%self.WORKDIR
os.chmod(self.WORKDIR,0777)
except:
raise PLCPermissionDenied, "Could not create dir %s"%self.WORKDIR
if not os.path.isfile (node_image):
raise PLCAPIError,"Unexpected location of build.sh output - %s"%node_image
if not os.path.isfile (node_image):
raise PLCAPIError,"Unexpected location of build.sh output - %s"%node_image
# we're done here, or we missed something
raise PLCAPIError,'Unhandled action %s'%action
# we're done here, or we missed something
raise PLCAPIError,'Unhandled action %s'%action