From 275fce4c9457786788d85482e7efa0fa807da3ef Mon Sep 17 00:00:00 2001 From: Giulio Fidente Date: Thu, 8 Aug 2013 18:41:23 +0200 Subject: [PATCH] adds support for configuration of cinder nfs backend driver a new config options is added: CONFIG_CINDER_NFS_MOUNTS , also adds validate_multi_regepx for use with both NFS mounts and GlusterFS mounts Change-Id: I5cf0ef0114c7eaa0bedd8528e6b1fe805221443a --- docs/packstack.rst | 17 +++++- packstack/installer/processors.py | 16 ++++++ packstack/installer/validators.py | 10 ++++ packstack/plugins/cinder_250.py | 54 ++++++++++++++++---- packstack/plugins/nova_300.py | 2 + packstack/puppet/templates/cinder_gluster.pp | 2 +- packstack/puppet/templates/cinder_nfs.pp | 6 +++ packstack/puppet/templates/nova_nfs.pp | 1 + 8 files changed, 96 insertions(+), 12 deletions(-) create mode 100644 packstack/puppet/templates/cinder_nfs.pp create mode 100644 packstack/puppet/templates/nova_nfs.pp diff --git a/docs/packstack.rst b/docs/packstack.rst index ccb23725a..d0954de44 100644 --- a/docs/packstack.rst +++ b/docs/packstack.rst @@ -86,13 +86,28 @@ Cinder Config parameters **CONFIG_CINDER_KS_PW** : The password to use for the Cinder to authenticate with Keystone -**CONFIG_CINDER_VOLUMES_CREATE** : Create Cinder's volumes group ['y', 'n'] +**CONFIG_CINDER_BACKEND** : The Cinder backend to use ['lvm', 'gluster', 'nfs'] Cinder volume create Config parameters -------------------------------------- +**CONFIG_CINDER_VOLUMES_CREATE** : Create Cinder's volumes group ['y', 'n'] + +Cinder volume size Config parameters +------------------------------------ + **CONFIG_CINDER_VOLUMES_SIZE** : Cinder's volumes group size +Cinder gluster Config parameters +-------------------------------- + +**CONFIG_CINDER_GLUSTER_MOUNTS** : A single or comma separated list of gluster volume shares + +Cinder NFS Config parameters +---------------------------- + +**CONFIG_CINDER_NFS_MOUNTS** : A single or comma seprated list of NFS exports to mount + Nova Options ------------ diff --git a/packstack/installer/processors.py b/packstack/installer/processors.py index 1355452a4..04188fb46 100644 --- a/packstack/installer/processors.py +++ b/packstack/installer/processors.py @@ -46,3 +46,19 @@ def process_ssh_key(param, process_args=None): param = param.endswith('.pub') and param or ('%s.pub' % param) create_key(key_file) return param + + +def process_add_quotes_around_values(param, process_args=None): + """ + Add a single quote character around each element of a comma + separated list of values + """ + params_list = param.split(',') + for index, elem in enumerate(params_list): + if not elem.startswith("'"): + elem = "'" + elem + if not elem.endswith("'"): + elem = elem + "'" + params_list[index] = elem + param = ','.join(params_list) + return param diff --git a/packstack/installer/validators.py b/packstack/installer/validators.py index 60e85171b..35dd4fc6b 100644 --- a/packstack/installer/validators.py +++ b/packstack/installer/validators.py @@ -69,6 +69,16 @@ def validate_regexp(param, options=None): raise ParamValidationError(msg % param) +def validate_multi_regexp(param, options=None): + """ + Raises ParamValidationError if any of the comma separated values given + in param doesn't match one of the regular expressions given in options. + """ + options = options or [] + for i in param.split(','): + validate_regexp(i.strip(), options=options) + + def validate_port(param, options=None): """ Raises ParamValidationError if given param is not a decimal number diff --git a/packstack/plugins/cinder_250.py b/packstack/plugins/cinder_250.py index 607b0acbc..a6876b6e6 100644 --- a/packstack/plugins/cinder_250.py +++ b/packstack/plugins/cinder_250.py @@ -7,6 +7,7 @@ import uuid import logging from packstack.installer import exceptions +from packstack.installer import processors from packstack.installer import validators from packstack.installer import basedefs @@ -70,9 +71,9 @@ def initConfig(controllerObject): "CONDITION" : False }, {"CMD_OPTION" : "cinder-backend", "USAGE" : ("The Cinder backend to use, valid options are: " - "lvm, gluster"), + "lvm, gluster, nfs"), "PROMPT" : "Enter the Cinder backend to be configured", - "OPTION_LIST" : ["lvm", "gluster"], + "OPTION_LIST" : ["lvm", "gluster", "nfs"], "VALIDATORS" : [validators.validate_options], "DEFAULT_VALUE" : "lvm", "MASK_INPUT" : False, @@ -159,13 +160,13 @@ def initConfig(controllerObject): paramsList = [ {"CMD_OPTION" : "cinder-gluster-mounts", - "USAGE" : ("A gluster volume to mount, eg: " - "ip-address:/vol-name " - "You don't need to create a local volume group when " - "using gluster."), - "PROMPT" : "Enter a gluster volume for use with Cinder", - "OPTION_LIST" : ["^([\d]{1,3}\.){3}[\d]{1,3}:/.*"], - "VALIDATORS" : [validators.validate_regexp], + "USAGE" : ("A single or comma separated list of gluster volume shares " + "to mount, eg: ip-address:/vol-name "), + "PROMPT" : ("Enter a single or comma separated list of gluster volume " + "shares to use with Cinder"), + "OPTION_LIST" : ["^'([\d]{1,3}\.){3}[\d]{1,3}:/.*'"], + "VALIDATORS" : [validators.validate_multi_regexp], + "PROCESSORS" : [processors.process_add_quotes_around_values], "DEFAULT_VALUE" : "", "MASK_INPUT" : False, "LOOSE_VALIDATION": True, @@ -176,7 +177,7 @@ def initConfig(controllerObject): ] groupDict = { "GROUP_NAME" : "CINDERGLUSTERMOUNTS", - "DESCRIPTION" : "Cinder gluster mounts", + "DESCRIPTION" : "Cinder gluster Config parameters", "PRE_CONDITION" : check_gluster_options, "PRE_CONDITION_MATCH" : True, "POST_CONDITION" : False, @@ -184,6 +185,37 @@ def initConfig(controllerObject): controller.addGroup(groupDict, paramsList) + def check_nfs_options(config): + return (config.get('CONFIG_CINDER_INSTALL', 'n') == 'y' and + config.get('CONFIG_CINDER_BACKEND', 'lvm') == 'nfs') + + paramsList = [ + {"CMD_OPTION" : "cinder-nfs-mounts", + "USAGE" : ("A single or comma seprated list of NFS exports to mount, " + "eg: ip-address:/export-name "), + "PROMPT" : ("Enter a single or comma seprated list of NFS exports to " + "use with Cinder"), + "OPTION_LIST" : ["^'([\d]{1,3}\.){3}[\d]{1,3}:/.*'"], + "VALIDATORS" : [validators.validate_multi_regexp], + "PROCESSORS" : [processors.process_add_quotes_around_values], + "DEFAULT_VALUE" : "", + "MASK_INPUT" : False, + "LOOSE_VALIDATION": True, + "CONF_NAME" : "CONFIG_CINDER_NFS_MOUNTS", + "USE_DEFAULT" : False, + "NEED_CONFIRM" : False, + "CONDITION" : False }, + ] + + groupDict = { "GROUP_NAME" : "CINDERNFSMOUNTS", + "DESCRIPTION" : "Cinder NFS Config parameters", + "PRE_CONDITION" : check_nfs_options, + "PRE_CONDITION_MATCH" : True, + "POST_CONDITION" : False, + "POST_CONDITION_MATCH" : True} + + controller.addGroup(groupDict, paramsList) + def initSequences(controller): if controller.CONF['CONFIG_CINDER_INSTALL'] != 'y': @@ -316,5 +348,7 @@ def create_manifest(config): if controller.CONF['CONFIG_CINDER_BACKEND'] == "gluster": manifestdata += getManifestTemplate("cinder_gluster.pp") + if controller.CONF['CONFIG_CINDER_BACKEND'] == "nfs": + manifestdata += getManifestTemplate("cinder_nfs.pp") appendManifestFile(manifestfile, manifestdata) diff --git a/packstack/plugins/nova_300.py b/packstack/plugins/nova_300.py index 1580f7683..127b6349e 100644 --- a/packstack/plugins/nova_300.py +++ b/packstack/plugins/nova_300.py @@ -370,6 +370,8 @@ def createcomputemanifest(config): manifestdata = getManifestTemplate("nova_compute.pp") if controller.CONF['CONFIG_CINDER_INSTALL'] == 'y' and controller.CONF['CONFIG_CINDER_BACKEND'] == 'gluster': manifestdata += getManifestTemplate("nova_gluster.pp") + if controller.CONF['CONFIG_CINDER_INSTALL'] == 'y' and controller.CONF['CONFIG_CINDER_BACKEND'] == 'nfs': + manifestdata += getManifestTemplate("nova_nfs.pp") manifestfile = "%s_nova.pp"%host nova_config_options = NovaConfig() diff --git a/packstack/puppet/templates/cinder_gluster.pp b/packstack/puppet/templates/cinder_gluster.pp index c51670b66..e3621f789 100644 --- a/packstack/puppet/templates/cinder_gluster.pp +++ b/packstack/puppet/templates/cinder_gluster.pp @@ -1,6 +1,6 @@ package { 'glusterfs-fuse': ensure => present } class { 'cinder::volume::glusterfs': - glusterfs_shares => ['%(CONFIG_CINDER_GLUSTER_MOUNTS)s'], + glusterfs_shares => [%(CONFIG_CINDER_GLUSTER_MOUNTS)s], require => Package['glusterfs-fuse'], } diff --git a/packstack/puppet/templates/cinder_nfs.pp b/packstack/puppet/templates/cinder_nfs.pp new file mode 100644 index 000000000..d6f4c376f --- /dev/null +++ b/packstack/puppet/templates/cinder_nfs.pp @@ -0,0 +1,6 @@ +package { 'nfs-utils': ensure => present } + +class { 'cinder::volume::nfs': + nfs_servers => [%(CONFIG_CINDER_NFS_MOUNTS)s], + require => Package['nfs-utils'], +} diff --git a/packstack/puppet/templates/nova_nfs.pp b/packstack/puppet/templates/nova_nfs.pp new file mode 100644 index 000000000..25e4c3c84 --- /dev/null +++ b/packstack/puppet/templates/nova_nfs.pp @@ -0,0 +1 @@ +package { 'nfs-utils': ensure => present } \ No newline at end of file