Ejemplo n.º 1
0
Archivo: volume.py Proyecto: 9apps/9tk
    def mount(self):
        #loop through the volumes
        volumes = self.config.userData["volumes"]
        for volumeId in volumes:
            volume = self.ec2.get_all_volumes([volumeId])[0]
            print "Volume {0} status: {1}".format(volume.id, volume.status)

            device = volumes[volumeId]["device"]
            mountpoint = volumes[volumeId]["mountpoint"]

            # attach the volume to the instance in case is not in use
            if volume.status == "available":
                print "Attaching volume to device {0} ...".format(device)
                self.ec2.attach_volume(volume.id, self.config.instanceId, device)
                #wait untill the volume is attached
                volume.update()
                while volume.attachment_state() != "attached":
                    time.sleep(3)
                    volume.update()
                    print "volume status: {0}".format(volume.attachment_state())

            #HACK to make it work on Ubuntu 12.04
            dev = device.replace("/dev/s", "/dev/xv")

            # mount the volume to the mountpoint
            print "Mounting {0} @ {1} ...".format(dev, mountpoint)
            BashCmd([ "mkdir", "-p", mountpoint ]).execute()
            mount = BashCmd([ "mount", "-t", "xfs", "-o", "defaults", dev, mountpoint ])
            mount.execute()
            if mount.isOk():
                print "Mountpoint {0} ready".format(mountpoint)
            else:
                print "ERROR - Problem mounting {0}".format(mountpoint)
Ejemplo n.º 2
0
Archivo: volume.py Proyecto: 9apps/9tk
    def umount(self):
        #loop through the volumes
        volumes = self.config.userData["volumes"]
        for volumeId in volumes:
            volume = self.ec2.get_all_volumes([volumeId])[0]
            print "Volume {0} status: {1}".format(volume.id, volume.status)

            device = volumes[volumeId]["device"]
            mountpoint = volumes[volumeId]["mountpoint"]

            # umount the volume and detach the volume if is in use
            print("Umounting {0} ...".format(mountpoint))
            umount = BashCmd( ["umount", "-t", "xfs", mountpoint] )
            umount.execute()
            if umount.isOk():
                if volume.status == "in-use":
                    print "Detaching volume {0} ...".format(volume.id)
                    self.ec2.detach_volume(volume.id, self.config.instanceId, device)
                else:
                    print "Volume {0} already detached".format(volume.id)
            else:
                print "ERROR - Problem umounting {0}".format(mountpoint)