Created
October 10, 2014 01:05
-
-
Save vivek-bala/457147a9e94bad0c975d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""A kernel that creates a new ASCII file with a given size and name. | |
""" | |
__author__ = "Ole Weider <ole.weidner@rutgers.edu>" | |
__copyright__ = "Copyright 2014, http://radical.rutgers.edu" | |
__license__ = "MIT" | |
from copy import deepcopy | |
from radical.ensemblemd.exceptions import ArgumentError | |
from radical.ensemblemd.exceptions import NoKernelConfigurationError | |
from radical.ensemblemd.kernel_plugins.kernel_base import KernelBase | |
# ------------------------------------------------------------------------------ | |
# | |
_KERNEL_INFO = { | |
"name": "misc.mkfile", | |
"description": "Creates a new file of given size and fills it with random ASCII characters.", | |
"arguments": {"--size=": | |
{ | |
"mandatory": True, | |
"description": "File size in bytes." | |
}, | |
"--filename=": | |
{ | |
"mandatory": True, | |
"description": "Output filename." | |
} | |
}, | |
"machine_configs": | |
{ | |
"*": { | |
"environment" : {"FOO": "bar"}, | |
"pre_exec" : ['module load -intel intel/14.0.1.106','module load python','python -V'], | |
"executable" : "base64", | |
"uses_mpi" : False | |
} | |
} | |
} | |
# ------------------------------------------------------------------------------ | |
# | |
class Kernel(KernelBase): | |
# -------------------------------------------------------------------------- | |
# | |
def __init__(self): | |
"""Le constructor. | |
""" | |
super(Kernel, self).__init__(_KERNEL_INFO) | |
# -------------------------------------------------------------------------- | |
# | |
@staticmethod | |
def get_name(): | |
return _KERNEL_INFO["name"] | |
# -------------------------------------------------------------------------- | |
# | |
def _bind_to_resource(self, resource_key): | |
"""(PRIVATE) Implements parent class method. | |
""" | |
if resource_key not in _KERNEL_INFO["machine_configs"]: | |
if "*" in _KERNEL_INFO["machine_configs"]: | |
# Fall-back to generic resource key | |
resource_key = "*" | |
else: | |
raise NoKernelConfigurationError(kernel_name=_KERNEL_INFO["name"], resource_key=resource_key) | |
cfg = _KERNEL_INFO["machine_configs"][resource_key] | |
executable = "/bin/bash" | |
arguments = ['-l', '-c', '{0} /dev/urandom | head -c {1} > {2}'.format( | |
cfg["executable"], | |
self.get_arg("--size="), | |
self.get_arg("--filename=")) | |
] | |
self._executable = executable | |
self._arguments = arguments | |
self._environment = cfg["environment"] | |
self._uses_mpi = cfg["uses_mpi"] | |
self._pre_exec = cfg["pre_exec"] | |
self._post_exec = None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment