Revision f5174d2c image_creator/dialog_menu.py

b/image_creator/dialog_menu.py
108 108

  
109 109
def upload_image(session):
110 110
    d = session["dialog"]
111
    dev = session['device']
111
    image = session['image']
112 112
    meta = session['metadata']
113
    size = dev.size
113
    size = image.size
114 114

  
115 115
    if "account" not in session:
116 116
        d.msgbox("You need to provide your ~okeanos credentials before you "
......
139 139

  
140 140
    gauge = GaugeOutput(d, "Image Upload", "Uploading...")
141 141
    try:
142
        out = dev.out
142
        out = image.out
143 143
        out.add(gauge)
144 144
        try:
145 145
            if 'checksum' not in session:
146 146
                md5 = MD5(out)
147
                session['checksum'] = md5.compute(session['snapshot'], size)
147
                session['checksum'] = md5.compute(image.device, size)
148 148

  
149 149
            kamaki = Kamaki(session['account'], out)
150 150
            try:
151 151
                # Upload image file
152
                with open(session['snapshot'], 'rb') as f:
152
                with open(image.device, 'rb') as f:
153 153
                    session["pithos_uri"] = \
154 154
                        kamaki.upload(f, size, filename,
155 155
                                      "Calculating block hashes",
......
188 188

  
189 189
def register_image(session):
190 190
    d = session["dialog"]
191
    dev = session['device']
192 191

  
193 192
    is_public = False
194 193

  
195 194
    if "account" not in session:
196 195
        d.msgbox("You need to provide your ~okeanos credentians before you "
197
                 "can register an images with cyclades",
198
                 width=SMALL_WIDTH)
196
                 "can register an images with cyclades", width=SMALL_WIDTH)
199 197
        return False
200 198

  
201 199
    if "pithos_uri" not in session:
......
233 231
    img_type = "public" if is_public else "private"
234 232
    gauge = GaugeOutput(d, "Image Registration", "Registering image...")
235 233
    try:
236
        out = dev.out
234
        out = session['image'].out
237 235
        out.add(gauge)
238 236
        try:
239 237
            out.output("Registering %s image with Cyclades..." % img_type)
......
481 479

  
482 480
def sysprep(session):
483 481
    d = session['dialog']
484
    image_os = session['image_os']
482
    image = session['image']
485 483

  
486 484
    # Is the image already shrinked?
487 485
    if 'shrinked' in session and session['shrinked']:
......
500 498
    if 'exec_syspreps' not in session:
501 499
        session['exec_syspreps'] = []
502 500

  
503
    all_syspreps = image_os.list_syspreps()
501
    all_syspreps = image.os.list_syspreps()
504 502
    # Only give the user the choice between syspreps that have not ran yet
505 503
    syspreps = [s for s in all_syspreps if s not in session['exec_syspreps']]
506 504

  
......
513 511
        choices = []
514 512
        index = 0
515 513
        for sysprep in syspreps:
516
            name, descr = image_os.sysprep_info(sysprep)
514
            name, descr = image.os.sysprep_info(sysprep)
517 515
            display_name = name.replace('-', ' ').capitalize()
518 516
            sysprep_help += "%s\n" % display_name
519 517
            sysprep_help += "%s\n" % ('-' * len(display_name))
......
536 534
            # Enable selected syspreps and disable the rest
537 535
            for i in range(len(syspreps)):
538 536
                if str(i + 1) in tags:
539
                    image_os.enable_sysprep(syspreps[i])
537
                    image.os.enable_sysprep(syspreps[i])
540 538
                    session['exec_syspreps'].append(syspreps[i])
541 539
                else:
542
                    image_os.disable_sysprep(syspreps[i])
540
                    image.os.disable_sysprep(syspreps[i])
543 541

  
544 542
            infobox = InfoBoxOutput(d, "Image Configuration")
545 543
            try:
546
                dev = session['device']
547
                dev.out.add(infobox)
544
                image.out.add(infobox)
548 545
                try:
549
                    dev.mount(readonly=False)
546
                    image.mount(readonly=False)
550 547
                    try:
551 548
                        # The checksum is invalid. We have mounted the image rw
552 549
                        if 'checksum' in session:
553 550
                            del session['checksum']
554 551

  
555 552
                        # Monitor the metadata changes during syspreps
556
                        with MetadataMonitor(session, image_os.meta):
557
                            image_os.do_sysprep()
553
                        with MetadataMonitor(session, image.os.meta):
554
                            image.os.do_sysprep()
558 555
                            infobox.finalize()
559 556

  
560 557
                        # Disable syspreps that have ran
561 558
                        for sysprep in session['exec_syspreps']:
562
                            image_os.disable_sysprep(sysprep)
559
                            image.os.disable_sysprep(sysprep)
563 560
                    finally:
564
                        dev.umount()
561
                        image.umount()
565 562
                finally:
566
                    dev.out.remove(infobox)
563
                    image.out.remove(infobox)
567 564
            finally:
568 565
                infobox.cleanup()
569 566
            break
......
572 569

  
573 570
def shrink(session):
574 571
    d = session['dialog']
575
    dev = session['device']
572
    image = session['image']
576 573

  
577 574
    shrinked = 'shrinked' in session and session['shrinked']
578 575

  
......
589 586

  
590 587
    if not d.yesno("%s\n\nDo you want to continue?" % msg, width=WIDTH,
591 588
                   height=12, title="Image Shrinking"):
592
        with MetadataMonitor(session, dev.meta):
589
        with MetadataMonitor(session, image.meta):
593 590
            infobox = InfoBoxOutput(d, "Image Shrinking", height=4)
594
            dev.out.add(infobox)
591
            image.out.add(infobox)
595 592
            try:
596
                dev.shrink()
593
                image.shrink()
597 594
                infobox.finalize()
598 595
            finally:
599
                dev.out.remove(infobox)
596
                image.out.remove(infobox)
600 597

  
601 598
        session['shrinked'] = True
602 599
        update_background_title(session)

Also available in: Unified diff