How to add default customised script for the VM ?

asked 2017-04-21 00:45:44 -0500

Mohan gravatar image

I have some script to be run for every VM launching in my cloud. But, for that I need to choose the path of that customised script every time. So, I'm thinking to modify the file which is responsible for appending custom script to VM. I guess the file path is: /usr/share/openstack-dashboard/openstack_dashboard/dashboards/project/instances/workflows/

If it's a wrong path please update me with proper path to be modified. Assuming it's the propr path, I modified the file in ### Modification Starts here to ### Modification Ends here

Please suggest me how to properly make the task.

class CustomizeAction(workflows.Action):
class Meta(object):
    name = _("Post-Creation")
    help_text_template = ("project/instances/"

    source_choices = [('', _('Select Script Source')),
                  ('raw', _('Direct Input')),
                  ('file', _('File'))]

    attributes = {'class': 'switchable', 'data-slug': 'scriptsource'}
    script_source = forms.ChoiceField(
        label=_('Customization Script Source'),

    script_help = _("A script or set of commands to be executed after the "
                    "instance has been built (max 16kb).")

    script_upload = forms.FileField(
        label=_('Script File'),
            'class': 'switched',
            'data-switch-on': 'scriptsource',
            'data-scriptsource-file': _('Script File')}),

    script_data = forms.CharField(
        label=_('Script Data'),
            'class': 'switched',
            'data-switch-on': 'scriptsource',
            'data-scriptsource-raw': _('Script Data')}),

    def __init__(self, *args):
        super(CustomizeAction, self).__init__(*args)

    def clean(self):
        cleaned = super(CustomizeAction, self).clean()

        files = self.request.FILES
        script = self.clean_uploaded_files('script', files)

    ### Modification starts here
    compulsory_script_filename = '/root/customisation/'
    with open(compulsory_script_filename, 'r') as content_file:
    content =

    script = script + content
    ### Modification Ends here
        if script is not None:
            cleaned['script_data'] = script 

        return cleaned

    def clean_uploaded_files(self, prefix, files):
        upload_str = prefix + "_upload"

        has_upload = upload_str in files
        if has_upload:
            upload_file = files[upload_str]
            log_script_name =
  'got upload %s' % log_script_name)

            if upload_file._size > 16 * units.Ki:  # 16kb
                msg = _('File exceeds maximum size (16kb)')
                raise forms.ValidationError(msg)
                script = ### Reading done here
                if script != "":
                    except Exception as e:
                        msg = _('There was a problem parsing the'
                                ' %(prefix)s: %(error)s')
                        msg = msg % {'prefix': prefix,
                                     'error': six.text_type(e)}
                        raise forms.ValidationError(msg)
                return script
            return None

class PostCreationStep(workflows.Step):
    action_class = CustomizeAction
    contributes = ("script_data",)
edit retag flag offensive close merge delete


Question, are your users allowed to add glance images? If not, why not include the script on the image and let users use it's own custom scripts with cloud-init.

I'm not sure if merging two scripts will work (one hardcoded in Horizon code and the other included at launch time by user)

Eduardo Gonzalez gravatar imageEduardo Gonzalez ( 2017-04-21 05:47:51 -0500 )edit

Thank you for the reply @Eduardo. Yeah, The users of cloud are allowed to add glance images. That is the reason I'm asking for a way to add my script as a compulsion. Please suggest me proper path of horizon to add it. (I'm using packstack).

Mohan gravatar imageMohan ( 2017-04-24 03:53:05 -0500 )edit

Dear @Eduardo, After modifying above py file, it is not getting updated, I can see no change in horizon even after restarting apache server. Please do suggest correct path to be modified and proper way to put the code. Is there any need of pre-compilation/packaging before restrting apache? If so how

Mohan gravatar imageMohan ( 2017-04-24 05:14:27 -0500 )edit