How to add default customised script for every VM ?

asked 2017-04-26 01:16:01 -0600

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