Example #1
0
 def deploy(self, cr, uid, vals, context={}):
     context.update({'saas-self': self, 'saas-cr': cr, 'saas-uid': uid})
     self.purge(cr, uid, vals, context=context)
     key_file = vals['config_home_directory'] + '/.ssh/keys/' + vals[
         'server_domain']
     execute.execute_write_file(key_file, vals['server_private_key'],
                                context)
     execute.execute_local(['chmod', '700', key_file], context)
     execute.execute_write_file(
         vals['config_home_directory'] + '/.ssh/config',
         'Host ' + vals['server_domain'], context)
     execute.execute_write_file(
         vals['config_home_directory'] + '/.ssh/config',
         '\n  HostName ' + vals['server_domain'], context)
     execute.execute_write_file(
         vals['config_home_directory'] + '/.ssh/config',
         '\n  Port ' + str(vals['server_ssh_port']), context)
     execute.execute_write_file(
         vals['config_home_directory'] + '/.ssh/config', '\n  User root',
         context)
     execute.execute_write_file(
         vals['config_home_directory'] + '/.ssh/config',
         '\n  IdentityFile ~/.ssh/keys/' + vals['server_domain'], context)
     execute.execute_write_file(
         vals['config_home_directory'] + '/.ssh/config',
         '\n#END ' + vals['server_domain'] + '\n', context)
Example #2
0
 def purge(self, cr, uid, vals, context={}):
     context.update({'saas-self': self, 'saas-cr': cr, 'saas-uid': uid})
     execute.execute_local(
         ['sudo', 'rm', '-rf', vals['app_version_full_archivepath']],
         context)
     execute.execute_local(
         ['sudo', 'rm', vals['app_version_full_archivepath_targz']],
         context)
Example #3
0
    def purge(self, cr, uid, vals, context={}):
        context.update({'saas-self': self, 'saas-cr': cr, 'saas-uid': uid})

        #TODO we need to launch a direct command, without ssh
        ssh, sftp = execute.connect('localhost', 22, 'saas-conductor', context)
        execute.execute(ssh, ['sed', '-i', "'/Host " + vals['server_domain'] + "/,/END " + vals['server_domain'] + "/d'", vals['config_home_directory'] + '/.ssh/config'], context)
        ssh.close()
        sftp.close()
        execute.execute_local(['rm', '-rf', vals['config_home_directory'] + '/.ssh/keys/' + vals['server_domain']], context)
Example #4
0
 def _create_key(self, cr, uid, context=None):
     vals = self.pool.get('saas.config.settings').get_vals(cr,
                                                           int(uid),
                                                           context=context)
     execute.execute_local(['mkdir', '/tmp/key_' + uid], context)
     execute.execute_local([
         'ssh-keygen', '-t', 'rsa', '-C', vals['config_email_sysadmin'],
         '-f', '/tmp/key_' + uid + '/key', '-N', ''
     ], context)
     return True
 def purge_key(self, cr, uid, vals, context={}):
     ssh, sftp = execute.connect('localhost', 22, 'saas-conductor', context)
     execute.execute(ssh, ['sed', '-i', "'/Host " + vals['container_fullname'] + "/,/END " + vals['container_fullname'] + "/d'", vals['config_home_directory'] + '/.ssh/config'], context)
     ssh.close()
     sftp.close()
     execute.execute_local(['rm', '-rf', vals['config_home_directory'] + '/.ssh/keys/' + vals['container_fullname']], context)
     execute.execute_local(['rm', '-rf', vals['config_home_directory'] + '/.ssh/keys/' + vals['container_fullname'] + '.pub'], context)
     ssh, sftp = execute.connect(vals['server_domain'], vals['server_ssh_port'], 'root', context)
     execute.execute(ssh, ['rm', '-rf', '/opt/keys/' + vals['container_fullname'] + '/authorized_keys'], context)
     ssh.close()
     sftp.close()
Example #6
0
 def deploy(self, cr, uid, vals, context):
     context.update({'saas-self': self, 'saas-cr': cr, 'saas-uid': uid})
     if not execute.local_dir_exist(vals['app_full_archivepath']):
         execute.execute_local(['mkdir', vals['app_full_archivepath']], context)
     if execute.local_dir_exist(vals['app_version_full_archivepath']):
         execute.execute_local(['rm', '-rf', vals['app_version_full_archivepath']], context)
     execute.execute_local(['mkdir', vals['app_version_full_archivepath']], context)
     self.build_application(cr, uid, vals, context)
     execute.execute_write_file(vals['app_version_full_archivepath'] + '/VERSION.txt', vals['app_version_name'], context)
     execute.execute_local(['pwd'], context, path=vals['app_version_full_archivepath'])
     execute.execute_local(['tar', 'czf', vals['app_version_full_archivepath_targz'], '-C', vals['app_full_archivepath'] + '/' + vals['app_version_name'], '.'], context)
Example #7
0
    def purge(self, cr, uid, vals, context={}):
        context.update({'saas-self': self, 'saas-cr': cr, 'saas-uid': uid})

        execute.execute_local([
            vals['config_conductor_path'] + '/saas/saas/shell/sed.sh',
            vals['server_domain'],
            vals['config_home_directory'] + '/.ssh/config'
        ], context)
        execute.execute_local([
            'rm', '-rf', vals['config_home_directory'] + '/.ssh/keys/' +
            vals['server_domain']
        ], context)
Example #8
0
 def deploy(self, cr, uid, vals, context={}):
     context.update({'saas-self': self, 'saas-cr': cr, 'saas-uid': uid})
     self.purge(cr, uid, vals, context=context)
     key_file = vals['config_home_directory'] + '/.ssh/keys/' + vals['server_domain']
     execute.execute_write_file(key_file, vals['server_private_key'], context)
     execute.execute_local(['chmod', '700', key_file], context)
     execute.execute_write_file(vals['config_home_directory'] + '/.ssh/config', 'Host ' + vals['server_domain'], context)
     execute.execute_write_file(vals['config_home_directory'] + '/.ssh/config', '\n  HostName ' + vals['server_domain'], context)
     execute.execute_write_file(vals['config_home_directory'] + '/.ssh/config', '\n  Port ' + str(vals['server_ssh_port']), context)
     execute.execute_write_file(vals['config_home_directory'] + '/.ssh/config', '\n  User root', context)
     execute.execute_write_file(vals['config_home_directory'] + '/.ssh/config', '\n  IdentityFile ~/.ssh/keys/' + vals['server_domain'], context)
     execute.execute_write_file(vals['config_home_directory'] + '/.ssh/config', '\n#END ' + vals['server_domain'] + '\n', context)
Example #9
0
    def deploy_key(self, cr, uid, vals, context={}):
        context.update({'saas-self': self, 'saas-cr': cr, 'saas-uid': uid})
        # restart_required = False
        # try:
        #     ssh_container, sftp_container = execute.connect(vals['container_fullname'], context=context)
        # except:
        #     restart_required = True
        #     pass

        self.purge_key(cr, uid, vals, context=context)
        execute.execute_local(['ssh-keygen', '-t', 'rsa', '-C', '*****@*****.**', '-f', vals['config_home_directory'] + '/.ssh/keys/' + vals['container_fullname'], '-N', ''], context)
        execute.execute_write_file(vals['config_home_directory'] + '/.ssh/config', 'Host ' + vals['container_fullname'], context)
        execute.execute_write_file(vals['config_home_directory'] + '/.ssh/config', '\n  HostName ' + vals['server_domain'], context)
        execute.execute_write_file(vals['config_home_directory'] + '/.ssh/config', '\n  Port ' + str(vals['container_ssh_port']), context)
        execute.execute_write_file(vals['config_home_directory'] + '/.ssh/config', '\n  User root', context)
        execute.execute_write_file(vals['config_home_directory'] + '/.ssh/config', '\n  IdentityFile ~/.ssh/keys/' + vals['container_fullname'], context)
        execute.execute_write_file(vals['config_home_directory'] + '/.ssh/config', '\n#END ' + vals['container_fullname'] + '\n', context)
        ssh, sftp = execute.connect(vals['server_domain'], vals['server_ssh_port'], 'root', context)
        execute.execute(ssh, ['mkdir', '/opt/keys/' + vals['container_fullname']], context)
        sftp.put(vals['config_home_directory'] + '/.ssh/keys/' + vals['container_fullname'] + '.pub', '/opt/keys/' + vals['container_fullname'] + '/authorized_keys')
        ssh.close()
        sftp.close()

        # _logger.info('restart required %s', restart_required)
        # if not restart_required:
        #     execute.execute(ssh_container, ['supervisorctl', 'restart', 'sshd'], context)
        #     ssh_container.close()
        #     sftp_container.close()
        # else:
        #     self.start(cr, uid, vals, context=context)


        if vals['apptype_name'] == 'backup':
            shinken_ids = self.search(cr, uid, [('application_id.type_id.name', '=','shinken')], context=context)
            if not shinken_ids:
                execute.log('The shinken isnt configured in conf, skipping deploying backup keys in shinken', context)
                return
            for shinken in self.browse(cr, uid, shinken_ids, context=context):
                shinken_vals = self.get_vals(cr, uid, shinken.id, context=context)
                ssh, sftp = execute.connect(shinken_vals['container_fullname'], username='******', context=context)
                execute.execute(ssh, ['rm', '-rf', '/home/shinken/.ssh/keys/' + vals['container_fullname'] + '*'], context)
                execute.send(sftp, vals['config_home_directory'] + '/.ssh/keys/' + vals['container_fullname'] + '.pub', '/home/shinken/.ssh/keys/' + vals['container_fullname'] + '.pub', context)
                execute.send(sftp, vals['config_home_directory'] + '/.ssh/keys/' + vals['container_fullname'], '/home/shinken/.ssh/keys/' + vals['container_fullname'], context)
                execute.execute(ssh, ['chmod', '-R', '700', '/home/shinken/.ssh'], context)
                execute.execute(ssh, ['sed', '-i', "'/Host " + vals['container_fullname'] + "/,/END " + vals['container_fullname'] + "/d'", '/home/shinken/.ssh/config'], context)
                execute.execute(ssh, ['echo "Host ' + vals['container_fullname'] + '" >> /home/shinken/.ssh/config'], context)
                execute.execute(ssh, ['echo "    Hostname ' + vals['server_domain'] + '" >> /home/shinken/.ssh/config'], context)
                execute.execute(ssh, ['echo "    Port ' + str(vals['container_ssh_port']) + '" >> /home/shinken/.ssh/config'], context)
                execute.execute(ssh, ['echo "    User backup" >> /home/shinken/.ssh/config'], context)
                execute.execute(ssh, ['echo "    IdentityFile  ~/.ssh/keys/' + vals['container_fullname'] + '" >> /home/shinken/.ssh/config'], context)
                execute.execute(ssh, ['echo "#END ' + vals['container_fullname'] +'" >> ~/.ssh/config'], context)
    def deploy(self, cr, uid, vals, context={}):
        context.update({'saas-self': self, 'saas-cr': cr, 'saas-uid': uid})
        execute.execute_local(['mkdir', '-p','/opt/build/saas-conductor'], context)
        execute.execute_local(['cp', '-R', vals['config_conductor_path'] + '/saas', '/opt/build/saas-conductor/saas'], context)

        dockerfile = vals['image_dockerfile']
        for key, volume in vals['image_volumes'].iteritems():
            dockerfile += '\nVOLUME ' + volume['name']

        ports = ''
        for key, port in vals['image_ports'].iteritems():
            ports += port['localport'] + ' '
        if ports:
            dockerfile += '\nEXPOSE ' + ports

        execute.execute_write_file('/opt/build/saas-conductor/Dockerfile', dockerfile, context)
        execute.execute_local(['sudo','docker', 'build', '-t', vals['image_version_fullname'],'/opt/build/saas-conductor'], context)
        execute.execute_local(['sudo','docker', 'tag', vals['image_version_fullname'], vals['image_name'] + ':latest'], context)
        execute.execute_local(['rm', '-rf', '/opt/build/saas-conductor'], context)
        return
Example #11
0
 def deploy(self, cr, uid, vals, context):
     context.update({'saas-self': self, 'saas-cr': cr, 'saas-uid': uid})
     if not execute.local_dir_exist(vals['app_full_archivepath']):
         execute.execute_local(['mkdir', vals['app_full_archivepath']],
                               context)
     if execute.local_dir_exist(vals['app_version_full_archivepath']):
         execute.execute_local(
             ['rm', '-rf', vals['app_version_full_archivepath']], context)
     execute.execute_local(['mkdir', vals['app_version_full_archivepath']],
                           context)
     self.build_application(cr, uid, vals, context)
     execute.execute_write_file(
         vals['app_version_full_archivepath'] + '/VERSION.txt',
         vals['app_version_name'], context)
     execute.execute_local(['pwd'],
                           context,
                           path=vals['app_version_full_archivepath'])
     execute.execute_local([
         'tar', 'czf', vals['app_version_full_archivepath_targz'], '-C',
         vals['app_full_archivepath'] + '/' + vals['app_version_name'], '.'
     ], context)
Example #12
0
    def _default_private_key(self, cr, uid, context=None):
        context.update({'saas-self': self, 'saas-cr': cr, 'saas-uid': uid})
        uid = str(uid)

        destroy = True
        if not execute.local_dir_exist('/tmp/key_' + uid):
            self._create_key(cr, uid, context=context)
            destroy = False

        key = execute.execute_local(['cat', '/tmp/key_' + uid + '/key'], context)

        if destroy:
            self._destroy_key(cr, uid, context=context)
        return key
Example #13
0
    def _default_public_key(self, cr, uid, context=None):
        context.update({'saas-self': self, 'saas-cr': cr, 'saas-uid': uid})
        uid = str(uid)

        destroy = True
        if not execute.local_dir_exist('/tmp/key_' + uid):
            self._create_key(cr, uid, context=context)
            destroy = False

        key = execute.execute_local(['cat', '/tmp/key_' + uid + '/key.pub'],
                                    context)

        if destroy:
            self._destroy_key(cr, uid, context=context)
        return key
Example #14
0
 def purge_key(self, cr, uid, vals, context={}):
     execute.execute_local([
         vals['config_conductor_path'] + '/saas/saas/shell/sed.sh',
         vals['container_fullname'],
         vals['config_home_directory'] + '/.ssh/config'
     ], context)
     execute.execute_local([
         'rm', '-rf', vals['config_home_directory'] + '/.ssh/keys/' +
         vals['container_fullname']
     ], context)
     execute.execute_local([
         'rm', '-rf', vals['config_home_directory'] + '/.ssh/keys/' +
         vals['container_fullname'] + '.pub'
     ], context)
     ssh, sftp = execute.connect(vals['server_domain'],
                                 vals['server_ssh_port'], 'root', context)
     execute.execute(ssh, [
         'rm', '-rf',
         '/opt/keys/' + vals['container_fullname'] + '/authorized_keys'
     ], context)
     ssh.close()
     sftp.close()
Example #15
0
    def deploy_key(self, cr, uid, vals, context={}):
        context.update({'saas-self': self, 'saas-cr': cr, 'saas-uid': uid})
        # restart_required = False
        # try:
        #     ssh_container, sftp_container = execute.connect(vals['container_fullname'], context=context)
        # except:
        #     restart_required = True
        #     pass

        self.purge_key(cr, uid, vals, context=context)
        execute.execute_local([
            'ssh-keygen', '-t', 'rsa', '-C', '*****@*****.**', '-f',
            vals['config_home_directory'] + '/.ssh/keys/' +
            vals['container_fullname'], '-N', ''
        ], context)
        execute.execute_write_file(
            vals['config_home_directory'] + '/.ssh/config',
            'Host ' + vals['container_fullname'], context)
        execute.execute_write_file(
            vals['config_home_directory'] + '/.ssh/config',
            '\n  HostName ' + vals['server_domain'], context)
        execute.execute_write_file(
            vals['config_home_directory'] + '/.ssh/config',
            '\n  Port ' + str(vals['container_ssh_port']), context)
        execute.execute_write_file(
            vals['config_home_directory'] + '/.ssh/config', '\n  User root',
            context)
        execute.execute_write_file(
            vals['config_home_directory'] + '/.ssh/config',
            '\n  IdentityFile ~/.ssh/keys/' + vals['container_fullname'],
            context)
        execute.execute_write_file(
            vals['config_home_directory'] + '/.ssh/config',
            '\n#END ' + vals['container_fullname'] + '\n', context)
        ssh, sftp = execute.connect(vals['server_domain'],
                                    vals['server_ssh_port'], 'root', context)
        execute.execute(ssh,
                        ['mkdir', '/opt/keys/' + vals['container_fullname']],
                        context)
        sftp.put(
            vals['config_home_directory'] + '/.ssh/keys/' +
            vals['container_fullname'] + '.pub',
            '/opt/keys/' + vals['container_fullname'] + '/authorized_keys')
        ssh.close()
        sftp.close()

        # _logger.info('restart required %s', restart_required)
        # if not restart_required:
        #     execute.execute(ssh_container, ['supervisorctl', 'restart', 'sshd'], context)
        #     ssh_container.close()
        #     sftp_container.close()
        # else:
        #     self.start(cr, uid, vals, context=context)

        if vals['apptype_name'] == 'backup':
            shinken_ids = self.search(
                cr,
                uid, [('application_id.type_id.name', '=', 'shinken')],
                context=context)
            if not shinken_ids:
                execute.log(
                    'The shinken isnt configured in conf, skipping deploying backup keys in shinken',
                    context)
                return
            for shinken in self.browse(cr, uid, shinken_ids, context=context):
                shinken_vals = self.get_vals(cr,
                                             uid,
                                             shinken.id,
                                             context=context)
                ssh, sftp = execute.connect(shinken_vals['container_fullname'],
                                            username='******',
                                            context=context)
                execute.execute(ssh, [
                    'rm', '-rf', '/home/shinken/.ssh/keys/' +
                    vals['container_fullname'] + '*'
                ], context)
                execute.send(
                    sftp, vals['config_home_directory'] + '/.ssh/keys/' +
                    vals['container_fullname'] + '.pub',
                    '/home/shinken/.ssh/keys/' + vals['container_fullname'] +
                    '.pub', context)
                execute.send(
                    sftp, vals['config_home_directory'] + '/.ssh/keys/' +
                    vals['container_fullname'],
                    '/home/shinken/.ssh/keys/' + vals['container_fullname'],
                    context)
                execute.execute(ssh,
                                ['chmod', '-R', '700', '/home/shinken/.ssh'],
                                context)
                execute.execute(ssh, [
                    'sed', '-i', "'/Host " + vals['container_fullname'] +
                    "/,/END " + vals['container_fullname'] + "/d'",
                    '/home/shinken/.ssh/config'
                ], context)
                execute.execute(ssh, [
                    'echo "Host ' + vals['container_fullname'] +
                    '" >> /home/shinken/.ssh/config'
                ], context)
                execute.execute(ssh, [
                    'echo "    Hostname ' + vals['server_domain'] +
                    '" >> /home/shinken/.ssh/config'
                ], context)
                execute.execute(ssh, [
                    'echo "    Port ' + str(vals['container_ssh_port']) +
                    '" >> /home/shinken/.ssh/config'
                ], context)
                execute.execute(
                    ssh,
                    ['echo "    User backup" >> /home/shinken/.ssh/config'],
                    context)
                execute.execute(ssh, [
                    'echo "    IdentityFile  ~/.ssh/keys/' +
                    vals['container_fullname'] +
                    '" >> /home/shinken/.ssh/config'
                ], context)
                execute.execute(ssh, [
                    'echo "#END ' + vals['container_fullname'] +
                    '" >> ~/.ssh/config'
                ], context)
Example #16
0
 def purge(self, cr, uid, vals, context={}):
     context.update({'saas-self': self, 'saas-cr': cr, 'saas-uid': uid})
     execute.execute_local(['sudo','rm', '-rf', vals['app_version_full_archivepath']], context)
     execute.execute_local(['sudo','rm', vals['app_version_full_archivepath_targz']], context)
Example #17
0
 def _destroy_key(self, cr, uid, context=None):
     execute.execute_local(['rm', '-rf', '/tmp/key_' + uid], context)
     return True
Example #18
0
 def _destroy_key(self, cr, uid, context=None):
     execute.execute_local(['rm', '-rf', '/tmp/key_' + uid], context)
     return True
Example #19
0
 def _create_key(self, cr, uid, context=None):
     vals = self.pool.get('saas.config.settings').get_vals(cr, int(uid), context=context)
     execute.execute_local(['mkdir', '/tmp/key_' + uid], context)
     execute.execute_local(['ssh-keygen', '-t', 'rsa', '-C', vals['config_email_sysadmin'], '-f', '/tmp/key_' + uid + '/key', '-N', ''], context)
     return True
 def purge(self, cr, uid, vals, context={}):
     context.update({'saas-self': self, 'saas-cr': cr, 'saas-uid': uid})
     execute.execute_local(['sudo','docker', 'rmi', vals['image_name'] + ':latest'], context)