Revision 938adc87 lib/bdev.py
b/lib/bdev.py | ||
---|---|---|
2802 | 2802 |
raise ValueError("Invalid configuration data %s" % str(unique_id)) |
2803 | 2803 |
|
2804 | 2804 |
self.driver, self.vol_name = unique_id |
2805 |
self.ext_params = params |
|
2805 | 2806 |
|
2806 | 2807 |
self.major = self.minor = None |
2807 | 2808 |
self.Attach() |
... | ... | |
2820 | 2821 |
|
2821 | 2822 |
# Call the External Storage's create script, |
2822 | 2823 |
# to provision a new Volume inside the External Storage |
2823 |
_ExtStorageAction(constants.ES_ACTION_CREATE, unique_id, str(size)) |
|
2824 |
_ExtStorageAction(constants.ES_ACTION_CREATE, unique_id, |
|
2825 |
params, str(size)) |
|
2824 | 2826 |
|
2825 | 2827 |
return ExtStorageDevice(unique_id, children, size, params) |
2826 | 2828 |
|
... | ... | |
2837 | 2839 |
|
2838 | 2840 |
# Call the External Storage's remove script, |
2839 | 2841 |
# to remove the Volume from the External Storage |
2840 |
_ExtStorageAction(constants.ES_ACTION_REMOVE, self.unique_id) |
|
2842 |
_ExtStorageAction(constants.ES_ACTION_REMOVE, self.unique_id, |
|
2843 |
self.ext_params) |
|
2841 | 2844 |
|
2842 | 2845 |
def Rename(self, new_id): |
2843 | 2846 |
"""Rename this device. |
... | ... | |
2857 | 2860 |
# Call the External Storage's attach script, |
2858 | 2861 |
# to attach an existing Volume to a block device under /dev |
2859 | 2862 |
self.dev_path = _ExtStorageAction(constants.ES_ACTION_ATTACH, |
2860 |
self.unique_id) |
|
2863 |
self.unique_id, self.ext_params)
|
|
2861 | 2864 |
|
2862 | 2865 |
try: |
2863 | 2866 |
st = os.stat(self.dev_path) |
... | ... | |
2891 | 2894 |
|
2892 | 2895 |
# Call the External Storage's detach script, |
2893 | 2896 |
# to detach an existing Volume from it's block device under /dev |
2894 |
_ExtStorageAction(constants.ES_ACTION_DETACH, self.unique_id) |
|
2897 |
_ExtStorageAction(constants.ES_ACTION_DETACH, self.unique_id, |
|
2898 |
self.ext_params) |
|
2895 | 2899 |
|
2896 | 2900 |
self.minor = None |
2897 | 2901 |
self.dev_path = None |
... | ... | |
2932 | 2936 |
# Call the External Storage's grow script, |
2933 | 2937 |
# to grow an existing Volume inside the External Storage |
2934 | 2938 |
_ExtStorageAction(constants.ES_ACTION_GROW, self.unique_id, |
2935 |
str(self.size), grow=str(new_size)) |
|
2939 |
self.ext_params, str(self.size), grow=str(new_size))
|
|
2936 | 2940 |
|
2937 | 2941 |
def SetInfo(self, text): |
2938 | 2942 |
"""Update metadata with info text. |
... | ... | |
2948 | 2952 |
# Call the External Storage's setinfo script, |
2949 | 2953 |
# to set metadata for an existing Volume inside the External Storage |
2950 | 2954 |
_ExtStorageAction(constants.ES_ACTION_SETINFO, self.unique_id, |
2951 |
metadata=text) |
|
2955 |
self.ext_params, metadata=text)
|
|
2952 | 2956 |
|
2953 | 2957 |
|
2954 |
def _ExtStorageAction(action, unique_id, size=None, grow=None, metadata=None): |
|
2958 |
def _ExtStorageAction(action, unique_id, ext_params, |
|
2959 |
size=None, grow=None, metadata=None): |
|
2955 | 2960 |
"""Take an External Storage action. |
2956 | 2961 |
|
2957 | 2962 |
Take an External Storage action concerning or affecting |
... | ... | |
2963 | 2968 |
@type unique_id: tuple (driver, vol_name) |
2964 | 2969 |
@param unique_id: a tuple containing the type of ExtStorage (driver) |
2965 | 2970 |
and the Volume name |
2971 |
@type ext_params: dict |
|
2972 |
@param ext_params: ExtStorage parameters |
|
2966 | 2973 |
@type size: integer |
2967 | 2974 |
@param size: the size of the Volume in mebibytes |
2968 | 2975 |
@type grow: integer |
... | ... | |
2980 | 2987 |
_ThrowError("%s" % inst_es) |
2981 | 2988 |
|
2982 | 2989 |
# Create the basic environment for the driver's scripts |
2983 |
create_env = _ExtStorageEnvironment(unique_id, size, grow, metadata) |
|
2990 |
create_env = _ExtStorageEnvironment(unique_id, ext_params, size, |
|
2991 |
grow, metadata) |
|
2984 | 2992 |
|
2985 | 2993 |
# Do not use log file for action `attach' as we need |
2986 | 2994 |
# to get the output from RunResult |
... | ... | |
3053 | 3061 |
# an optional one |
3054 | 3062 |
es_files = dict.fromkeys(constants.ES_SCRIPTS, True) |
3055 | 3063 |
|
3056 |
for filename in es_files: |
|
3064 |
es_files[constants.ES_PARAMETERS_FILE] = True |
|
3065 |
|
|
3066 |
for (filename, _) in es_files.items(): |
|
3057 | 3067 |
es_files[filename] = utils.PathJoin(es_dir, filename) |
3058 | 3068 |
|
3059 | 3069 |
try: |
... | ... | |
3071 | 3081 |
return False, ("File '%s' under path '%s' is not executable" % |
3072 | 3082 |
(filename, es_dir)) |
3073 | 3083 |
|
3084 |
parameters = [] |
|
3085 |
if constants.ES_PARAMETERS_FILE in es_files: |
|
3086 |
parameters_file = es_files[constants.ES_PARAMETERS_FILE] |
|
3087 |
try: |
|
3088 |
parameters = utils.ReadFile(parameters_file).splitlines() |
|
3089 |
except EnvironmentError, err: |
|
3090 |
return False, ("Error while reading the EXT parameters file at %s: %s" % |
|
3091 |
(parameters_file, utils.ErrnoOrStr(err))) |
|
3092 |
parameters = [v.split(None, 1) for v in parameters] |
|
3093 |
|
|
3074 | 3094 |
es_obj = \ |
3075 | 3095 |
objects.ExtStorage(name=name, path=es_dir, |
3076 | 3096 |
create_script=es_files[constants.ES_SCRIPT_CREATE], |
... | ... | |
3078 | 3098 |
grow_script=es_files[constants.ES_SCRIPT_GROW], |
3079 | 3099 |
attach_script=es_files[constants.ES_SCRIPT_ATTACH], |
3080 | 3100 |
detach_script=es_files[constants.ES_SCRIPT_DETACH], |
3081 |
setinfo_script=es_files[constants.ES_SCRIPT_SETINFO]) |
|
3101 |
setinfo_script=es_files[constants.ES_SCRIPT_SETINFO], |
|
3102 |
verify_script=es_files[constants.ES_SCRIPT_VERIFY], |
|
3103 |
supported_parameters=parameters) |
|
3082 | 3104 |
return True, es_obj |
3083 | 3105 |
|
3084 | 3106 |
|
3085 |
def _ExtStorageEnvironment(unique_id, size=None, grow=None, metadata=None): |
|
3107 |
def _ExtStorageEnvironment(unique_id, ext_params, |
|
3108 |
size=None, grow=None, metadata=None): |
|
3086 | 3109 |
"""Calculate the environment for an External Storage script. |
3087 | 3110 |
|
3088 | 3111 |
@type unique_id: tuple (driver, vol_name) |
3089 | 3112 |
@param unique_id: ExtStorage pool and name of the Volume |
3113 |
@type ext_params: dict |
|
3114 |
@param ext_params: the EXT parameters |
|
3090 | 3115 |
@type size: string |
3091 | 3116 |
@param size: size of the Volume (in mebibytes) |
3092 | 3117 |
@type grow: string |
... | ... | |
3102 | 3127 |
result = {} |
3103 | 3128 |
result["VOL_NAME"] = vol_name |
3104 | 3129 |
|
3130 |
# EXT params |
|
3131 |
for pname, pvalue in ext_params.items(): |
|
3132 |
result["EXTP_%s" % pname.upper()] = str(pvalue) |
|
3133 |
|
|
3105 | 3134 |
if size is not None: |
3106 | 3135 |
result["VOL_SIZE"] = size |
3107 | 3136 |
|
Also available in: Unified diff