Example #1
0
    def __call__(self, args):
        if not args.force:
            if not yes_or_no():
                print "Aborting group deletion"
                return

        try:
            self.get_repoman_client(args).remove_group(args.group)
            print "[OK]     Removed group %s." % (args.group)
        except RepomanError, e:
            raise SubcommandFailure(self, "Could not remove group '%s'" % (args.group), e)
Example #2
0
 def __call__(self, args):
     if not args.force:
         print ("WARNING:\n"
                 "\tAll images owned by the user will be removed.\n"
                 "\tThis operation cannot be undone!")
         if not yes_or_no():
             print "Aborting user deletion"
             return
     try:
         self.get_repoman_client(args).remove_user(args.user)
         print "[OK]     Removed user %s." % (args.user)
     except RepomanError, e:
         raise SubcommandFailure(self, "Could not remove user '%s'" % (args.user), e)
Example #3
0
    def __call__(self, args, extra_args=None):
        log = logging.getLogger('RemoveGroup')
        log.debug("args: '%s' extra_args: '%s'" % (args, extra_args))
    
        repo = RepomanClient(config.host, config.port, config.proxy)
        if not args.force:
            if not yes_or_no():
                print "Aborting group deletion"
                return

        try:
            repo.remove_group(args.group)
        except RepomanError, e:
            print e
            sys.exit(1)
Example #4
0
    def __call__(self, args, extra_args=None):
        log = logging.getLogger('RemoveGroup')
        log.debug("args: '%s' extra_args: '%s'" % (args, extra_args))

        repo = RepomanClient(config.host, config.port, config.proxy)
        if not args.force:
            if not yes_or_no():
                print "Aborting group deletion"
                return

        try:
            repo.remove_group(args.group)
        except RepomanError, e:
            print e
            sys.exit(1)
Example #5
0
    def __call__(self, args, extra_args=None):
        log = logging.getLogger('RemoveImage')
        log.debug("args: '%s' extra_args: '%s'" % (args, extra_args))

        repo = RepomanClient(config.host, config.port, config.proxy)
        if not args.force:
            print("WARNING:\n" "\tdeleting an image cannot be undone.\n")
            if not yes_or_no():
                print "Aborting user deletion"
                return

        try:
            repo.remove_image(args.image)
        except RepomanError, e:
            print e
            sys.exit(1)
Example #6
0
    def __call__(self, args):
        if not args.force:
            print ("WARNING:\n"
                    "\tdeleting an image cannot be undone.\n")
            if not yes_or_no():
                print "Aborting user deletion"
                return

        image_name = args.image
        if args.owner:
            image_name = '%s/%s' % (args.owner, args.image
)
        try:
            self.get_repoman_client(args).remove_image(image_name)
            print "[OK]     Removed image %s." % (args.image)
        except RepomanError, e:
            raise SubcommandFailure(self, "Could not remove image '%s'" % (args.image), e)
Example #7
0
    def __call__(self, args, extra_args=None):
        log = logging.getLogger('RemoveImage')
        log.debug("args: '%s' extra_args: '%s'" % (args, extra_args))
    
        repo = RepomanClient(config.host, config.port, config.proxy)
        if not args.force:
            print ("WARNING:\n"
                    "\tdeleting an image cannot be undone.\n")
            if not yes_or_no():
                print "Aborting user deletion"
                return

        try:
            repo.remove_image(args.image)
        except RepomanError, e:
            print e
            sys.exit(1)
Example #8
0
 def __call__(self, args, extra_args=None):
     log = logging.getLogger('RemoveUser')
     log.debug("args: '%s' extra_args: '%s'" % (args, extra_args))
 
     repo = RepomanClient(config.host, config.port, config.proxy)
     if not args.force:
         print ("WARNING:\n"
                 "\tAll images owned by the user will be removed.\n"
                 "\tThis operation cannot be undone!")
         if not yes_or_no():
             print "Aborting user deletion"
             return
     try:
         repo.remove_user(args.user)
     except RepomanError, e:
         print e
         sys.exit(1)
Example #9
0
    def __call__(self, args, extra_args=None):
        log = logging.getLogger('RemoveUser')
        log.debug("args: '%s' extra_args: '%s'" % (args, extra_args))

        repo = RepomanClient(config.host, config.port, config.proxy)
        if not args.force:
            print(
                "WARNING:\n"
                "\tAll images owned by the user will be removed.\n"
                "\tThis operation cannot be undone!")
            if not yes_or_no():
                print "Aborting user deletion"
                return
        try:
            repo.remove_user(args.user)
        except RepomanError, e:
            print e
            sys.exit(1)
Example #10
0
    def __call__(self, args):
        # Check if sudo...
        if os.getuid() != 0:
            raise SubcommandFailure(self, "Error.  This command requires root privileges, try again with sudo.")

        kwargs={}

        name = args.image
        # Check for proper Gzip extension (if needed)
        if args.gzip:
            if name and name.endswith('.gz'):
                pass
            else:
                log.info("Enforcing '.gz' extension.")
                name += '.gz'
                print ("WARNING: gzip option found, but your image name does not"
                       " end in '.gz'.  Modifying image name to enforce this.")
                print "New image name: '%s'" % (name)

        kwargs['name'] = name

        # Check to see if the image name has the '.gz' suffix and
        # compression not enabled.  Having uncompressed images named with
        # a '.gz' suffix will break things in Nimbus.
        if (not args.gzip) and name.endswith('.gz'):
            print ("WARNING: The image name you gave ends with '.gz' but you did not enable image compression with the --gzip command line argument.  Having uncompressed images with a '.gz' suffix to the image name can cause problems in some cloud frameworks.")
            if not yes_or_no('Do you want to continue? [yes]/[n]o: '):
                print "Aborting.  Please select a new image name or enable compression via the --gzip command line argument."
                return

        exists = False
        try:
            image = self.get_repoman_client(args).describe_image(name, args.owner)
            if image:
                log.info("Found existing image")
                exists = True
        except RepomanError,e:
            if e.status == 404:
                log.debug("Did not find an existing image in repository with same name.")
                pass
            else:
                log.error("Unexpected response occurred when testing if image exists.")
                log.error("%s" % e)
                raise SubcommandFailure(self, "Unexpected response from server occurred when testing if image exists.", e)
Example #11
0
    def __call__(self, args):
        hypervisor = None
        try:
            image_name = args.image
            if args.owner:
                image_name = "%s/%s" % (args.owner, args.image)

            image = self.get_repoman_client(args).describe_image(image_name)

            # Check if image is multi-hypervisor.  If yes, then make sure the user specified
            # the hypervisor at command line.
            if (len(image['hypervisor'].split(',')) > 1) and (not args.hypervisor):
                print "ERROR:  This %s image is a multi-hypervisor image.  You must specify an hypervisor using the --hypervisor command line argument.  Do a 'repoman help put-image' for more information." % args.image
                return

            # If the image is multi-hypervisor and an hypervisor was given at command line,
            # check to make sure it is in the list of hypervisors of that image.
            if args.hypervisor and (args.hypervisor not in image['hypervisor'].split(',')):
                print "ERROR:  The given hypervisor is not supported by this image.  Supported hypervisors for this image are: %s" % (image['hypervisor'])
                return

            if args.hypervisor:
                hypervisor = args.hypervisor
            else:
                hypervisor = image['hypervisor'].strip()

            # Check if destination image already contains an image.
            if self.get_repoman_client(args).uploaded_image_exist(args.image, args.owner, hypervisor=hypervisor) == True and not args.force:
                if not yes_or_no("Image '%s' already contains an image file for hypervisor %s.  Overwrite? [yes]/[n]o:" % (args.image, hypervisor)):
                    return

            print "Uploading %s to image '%s', hypervisor %s ..." % (args.file, args.image, hypervisor)
            self.get_repoman_client(args).upload_image(args.image, args.owner, args.file, hypervisor=hypervisor)
            print "[OK]     %s uploaded to image '%s', hypervisor %s" % (args.file, args.image, hypervisor)
        except RepomanError, e:
            raise SubcommandFailure(self, "Could not upload %s to image '%s', hypervisor %s" % (args.file, args.image, hypervisor), e)
Example #12
0
                log.info("Enforcing '.gz' extension.")
                kwargs.update({"name": name + ".gz"})
                print (
                    "WARNING: gzip option found, but your image name does not"
                    " end in '.gz'.  Modifying image name to enforce this."
                )
                print "New image name: '%s'" % (name + ".gz")

        # this is a bit messy.  Maybe return conflict object from server?
        try:
            image = repo.create_image_metadata(**kwargs)
            print "[OK]     Creating new image meatadata."
        except RepomanError, e:
            if e.status == 409 and not args.force:
                print "An image with that name already exists."
                if not yes_or_no("Do you want to overwrite? [yes]/[n]o: "):
                    print "Aborting.  Please select a new image name or force overwrite"
                    sys.exit(1)
                else:
                    log.info("User has confirmed overwritting existing image.")
                    print "Image will be overwritten."
                    try:
                        # update metedata here!
                        image = repo.describe_image(kwargs["name"])
                    except RepomanError, e:
                        log.error("%s" % e)
                        print e
                        sys.exit(1)
            elif e.status == 409 and args.force:
                log.info("'--force' option found.  Image is being overwritten")
                print "Image will be overwritten."
Example #13
0
            else:
                log.info("Enforcing '.gz' extension.")
                kwargs.update({'name': name + '.gz'})
                print(
                    "WARNING: gzip option found, but your image name does not"
                    " end in '.gz'.  Modifying image name to enforce this.")
                print "New image name: '%s'" % (name + '.gz')

        # this is a bit messy.  Maybe return conflict object from server?
        try:
            image = repo.create_image_metadata(**kwargs)
            print "[OK]     Creating new image meatadata."
        except RepomanError, e:
            if e.status == 409 and not args.force:
                print "An image with that name already exists."
                if not yes_or_no('Do you want to overwrite? [yes]/[n]o: '):
                    print "Aborting.  Please select a new image name or force overwrite"
                    sys.exit(1)
                else:
                    log.info("User has confirmed overwritting existing image.")
                    print "Image will be overwritten."
                    try:
                        # update metedata here!
                        image = repo.describe_image(kwargs['name'])
                    except RepomanError, e:
                        log.error("%s" % e)
                        print e
                        sys.exit(1)
            elif e.status == 409 and args.force:
                log.info("'--force' option found.  Image is being overwritten")
                print "Image will be overwritten."
Example #14
0
 except RepomanError,e:
     if e.status == 404:
         log.debug("Did not find an existing image in repository with same name.")
         pass
     else:
         log.error("Unexpected response occurred when testing if image exists.")
         log.error("%s" % e)
         print "Unexpected response from server.  exiting."
         sys.exit(1)
 
 if exists:
     if args.force:       
         log.info("User is forcing the overwriting of existing image.")
     else:
         print "An image with that name already exists."
         if not yes_or_no('Do you want to overwrite? [yes]/[n]o: '):
             print "Aborting.  Please select a new image name or force overwrite"
             sys.exit(1)
         else:
             log.info("User has confirmed overwritting existing image.")
             print "Image will be overwritten."
             
 image_utils = ImageUtils(config.lockfile,
                          config.snapshot,
                          config.mountpoint,
                          config.exclude_dirs.split(),
                          size=args.resize*1024*1024)
 
 try:
     self.write_metadata(kwargs, self.metadata_file)
 except IOError, e: