def create(self, vals):
        """
        Override create to generate a random password for the passord option.

        :param vals: The values used to create the container.
        """
        if 'application_id' in vals and vals['application_id']:
            application = self.env['clouder.application'].browse(
                vals['application_id'])
            if application.type_id.name == 'openldap':
                if not 'option_ids' in vals:
                    vals['options_ids'] = []

                password_option = self.env.ref(
                    'clouder_ldap.apptype_openldap_option2').id
                flag = False
                for option in vals['option_ids']:
                    if option[2]['name'] == password_option:
                        if not option[2]['value']:
                            option[2]['value'] = \
                                clouder_model.generate_random_password(20)
                        flag = True

                if not flag:
                    vals['option_ids'].append((0, 0, {
                        'name': password_option,
                        'value': clouder_model.generate_random_password(20)}))
        return super(ClouderContainer, self).create_vals()
예제 #2
0
    def create(self, vals):
        """
        Override create to generate a random password for the passord option.

        :param vals: The values used to create the container.
        """
        if 'application_id' in vals and vals['application_id']:
            application = self.env['clouder.application'].browse(
                vals['application_id'])
            if application.type_id.name == 'openldap':
                if not 'option_ids' in vals:
                    vals['options_ids'] = []

                password_option = self.env.ref(
                    'clouder_ldap.apptype_openldap_option2').id
                flag = False
                for option in vals['option_ids']:
                    if option[2]['name'] == password_option:
                        if not option[2]['value']:
                            option[2]['value'] = \
                                clouder_model.generate_random_password(20)
                        flag = True

                if not flag:
                    vals['option_ids'].append((0, 0, {
                        'name':
                        password_option,
                        'value':
                        clouder_model.generate_random_password(20)
                    }))
        return super(ClouderContainer, self).create_vals()
예제 #3
0
    def deploy_post(self):
        """
        Update the root password after deployment.
        """
        super(ClouderContainer, self).deploy_post()

        if self.application_id.type_id.name == 'mysql':

            self.start()

            ssh = self.connect(self.fullname)
            self.execute(ssh, ['sed', '-i', '"/bind-address/d"',
                               '/etc/mysql/my.cnf'])
            if self.options['root_password']['value']:
                password = self.options['root_password']['value']
            else:
                password = clouder_model.generate_random_password(20)
                option_obj = self.env['clouder.container.option']
                options = option_obj.search([('container_id', '=', self),
                                             ('name', '=', 'root_password')])
                if options:
                    options.value = password
                else:
                    type_option_obj = self.env[
                        'clouder.application.type.option']
                    type_options = type_option_obj.search(
                        [('apptype_id.name', '=', 'mysql'),
                         ('name', '=', 'root_password')])
                    if type_options:
                        option_obj.create({'container_id': self,
                                           'name': type_options[0],
                                           'value': password})
            self.execute(ssh,
                         ['mysqladmin', '-u', 'root', 'password', password])