Changeset 6778


Ignore:
Timestamp:
Feb 7, 2018, 1:23:57 PM (19 months ago)
Author:
kbut
Message:

script to delay working ok

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lmd/trunk/fuentes/lmd-server.install/usr/sbin/lmd-update-image-delay

    r6762 r6778  
    66import os
    77import xmlrpc.client
     8import ssl
    89
    910class UpdateLTSPImage:
    10     def __init__(self, arch, identifier):
     11    def __init__(self, identifier):
    1112
    12         self.arch = arch
    1313        self.identifier = identifier
    1414
     
    1919        self.CHROOT_BASE = '/opt/ltsp'
    2020        self.LMD_CONFIG_BASE = '/etc/ltsp/images'
    21         self.n4d = xmlrpc.client.ServerProxy('https://localhost:9779')
     21        context = ssl._create_unverified_context()
     22        self.n4d = xmlrpc.client.ServerProxy('https://localhost:9779',context=context)
     23        command = "ltsp-chroot -a {chroot} dpkg-architecture | grep DEB_BUILD_ARCH_CPU | awk -F'[/=]' {{'print $2'}}".format(chroot=self.identifier)
     24        p = subprocess.Popen([command],shell=True,stdout=subprocess.PIPE)
     25        self.arch = p.communicate()[0].strip().decode('utf-8')
    2226
    2327    def get_unique_identifier(self):
     
    2832        '''
    2933        counter = 1
    30         while not os.path.exists(os.path.join(self.CHROOT_BASE,self.new_identifier)):
     34        while os.path.exists(os.path.join(self.CHROOT_BASE,'images',self.new_identifier) + ".img"):
    3135            self.new_identifier = "{identifier}_{date_string}_{counter}".format(
    3236                                                                identifier=self.identifier,
     
    4145            On file change id and name.
    4246        '''
    43         with open(os.path.join(self.LMD_CONFIG_BASE, self.identifier + ".conf"), 'r') as data_file:
     47        with open(os.path.join(self.LMD_CONFIG_BASE, self.identifier + ".json"), 'r') as data_file:
    4448            lmd_config = json.load(data_file)
    4549        lmd_config['id'] = self.new_identifier
    4650        lmd_config['name'] = "{name} ({date_string})".format(name=lmd_config['name'], date_string=self.TODAY.strftime("%d-%m-%Y"))
    47         with open(os.path.join(self.LMD_CONFIG_BASE, self.new_identifier + ".conf"), 'w') as data_file:
     51        lmd_config['status'] = "enabled-non-editable"
     52        with open(os.path.join(self.LMD_CONFIG_BASE, self.new_identifier + ".json"), 'w') as data_file:
    4853            json.dump(lmd_config, data_file, indent=4)
    4954        print("Created config for Lmd")
    5055
    5156    def ltsp_update_image(self):
     57        arch_build = 'linux32'
     58        if self.arch == 'amd64':
     59            arch_build = 'linux64'
    5260        options = {
    5361            "original_chroot" : os.path.join(self.CHROOT_BASE,self.identifier),
    5462            "new_chroot": os.path.join(self.CHROOT_BASE,self.new_identifier),
    5563            "new_identifier" : self.new_identifier,
    56             "arch" : self.arch
     64            "arch" : arch_build
    5765        }
    58         command = "mount --bind {original_chroot} {new_chroot} && {arch} ltsp-update-image {new_identifier} && umount {new_chroot}".format(**options)
     66        command = "mount --bind {original_chroot} {new_chroot} && {arch} ltsp-update-image {new_identifier}".format(**options)
    5967        process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
    6068        while True:
    61             output = process.stdout.readline()
    62             if output == '' and process.poll() is not None:
     69            output = os.read(process.stdout.fileno(),1024).decode('utf-8')
     70            if output.strip() == '' and process.poll() is not None:
    6371                break
    6472            if output:
    6573                print(output.strip())
    66        
     74        command = "umount -l {new_chroot}".format(**options)
     75        result = subprocess.Popen([command],shell=True).communicate()
    6776
    6877
     
    7887        self.ltsp_update_image()
    7988        os.rmdir(os.path.join(self.CHROOT_BASE, self.new_identifier))
    80 
     89        masterkey = ''
    8190        with open('/etc/n4d/key') as file_data:
    82             masterkey = file_data.readlines()
    83         self.n4d.pushToBootList(masterkey,'LlxBootManager', "ltsp_label{new_identifier}".format(self.new_identifier))
     91            masterkey = file_data.readlines()[0].strip()
     92        self.n4d.pushToBootList(masterkey,'LlxBootManager', "ltsp_label{new_identifier}".format(new_identifier=self.new_identifier))
    8493        print("Finish update image. New image available")
    8594
    8695def main():
    87     p = UpdateLTSPImage(sys.argv[0],sys.argv[1])
     96    p = UpdateLTSPImage(sys.argv[1])
    8897    p.run()
    8998
Note: See TracChangeset for help on using the changeset viewer.