Example #1
0
    def upload(self, args):
        """ Upload a template to a repository """
        parser = OptionParser(usage="template upload <options>")
        parser.add_option('-a', '--bind-address',
                help='The bind address fot the local repository'
                'By default the public IP will be detected and used',
                action='store', dest='address')
        parser.add_option('-p', '--port',
                help='The port to open locally for the repository',
                action='store', dest='port', type='int', default=8888)
        parser.add_option('-f', '--disk-file',
                help='The disk file to be uploaded',
                action='store', dest='disk')
        parser.add_option('-c', '--config',
                help='Path to a json configuration file for the template',
                action='store', dest='config')
        parser.add_option('-d', '--datacenter',
                help='The name of the datacenter where the template '
                'will be downloaded', action='store', dest='datacenter')
        (options, args) = parser.parse_args(args)

        if not options.disk or not options.datacenter:
            parser.print_help()
            return

        # Read OVF values from json file
        if options.config:
            with open(options.config, "r") as f:
                config = json.loads(f.read())
        else:
            config = {}

        # Find the public bind address if not provided
        if not options.address:
            options.address = self._get_public_address()

        repo = TransientRepository(options.address, options.port)
        try:
            log.info("Creating temporal OVF repository")
            repo.create()
            definition = repo.add_definition(self._context,
                options.disk, config)
            repo.start()

            log.info("Loading destination repository: %s" % options.datacenter)
            admin = self._context.getAdministrationService()
            dc = admin.findDatacenter(
                DatacenterPredicates.name(options.datacenter))

            log.info("Uploading template. This may take some time...")
            definition.save()

            monitor = self._context.getMonitoringService() \
                .getAsyncTaskMonitor()
            task = definition.downloadToRepository(dc)
            monitor.awaitCompletion(task)

            pprint_templates([task.getResult()])
        except (AbiquoException, AuthorizationException), ex:
            print "Error: %s" % ex.getMessage()
Example #2
0
    def find(self, args):
        """ Find a template given its name. """
        # Parse user input to get the name of the template
        parser = OptionParser(usage="template find <options>")
        parser.add_option("-n", "--name", help="The name of the template to find",
                action="store", dest="name")
        (options, args) = parser.parse_args(args)
        name = options.name
        if not name:
            parser.print_help()
            return

        # Once user input has been read, find the template 
        context = ContextLoader().load_context()
        try:
            admin = context.getAdministrationService()
            user = admin.getCurrentUserInfo()
            enterprise = user.getEnterprise()
            template = enterprise.findTemplate(VirtualMachineTemplatePredicates.name(name))
            if template:
                pprint_templates([template])
            else:
                print "No template found with name: %s" % name
        except (AbiquoException, AuthorizationException), ex:
            print "Error: %s" % ex.getMessage()
Example #3
0
    def find(self, args):
        """ Find a template given its name """
        # Parse user input to get the name of the template
        parser = OptionParser(usage="template find <options>")
        parser.add_option("-n",
                          "--name",
                          deswt="name",
                          help="The name of the template to find")
        (options, args) = parser.parse_args(args)
        name = options.name
        if not name:
            parser.print_help()
            return

        # Once user input has been read, find the template
        try:
            admin = self._context.getAdministrationService()
            enterprise = admin.getCurrentEnterprise()
            template = enterprise.findTemplate(
                VirtualMachineTemplatePredicates.name(name))
            if template:
                pprint_templates([template])
            else:
                print "No template found with name: %s" % name
        except (AbiquoException, AuthorizationException), ex:
            print "Error: %s" % ex.getMessage()
Example #4
0
 def list(self, args):
     """ List all available templates """
     try:
         admin = self._context.getAdministrationService()
         enterprise = admin.getCurrentEnterprise()
         templates = enterprise.listTemplates()
         pprint_templates(templates)
     except (AbiquoException, AuthorizationException), ex:
         print "Error: %s" % ex.getMessage()
Example #5
0
 def list_templates(self, args):
     """ List all available templates """
     try:
         admin = self._context.getAdministrationService()
         enterprise = admin.getCurrentEnterprise()
         templates = enterprise.listTemplates()
         pprint_templates(templates)
     except (AbiquoException, AuthorizationException), ex:
         print "Error: %s" % ex.getMessage()
Example #6
0
 def list(self, args):
     """ List all available templates. """
     context = ContextLoader().load_context()
     try:
         admin = context.getAdministrationService()
         user = admin.getCurrentUserInfo()
         enterprise = user.getEnterprise()
         templates = enterprise.listTemplates()
         pprint_templates(templates)
     except (AbiquoException, AuthorizationException), ex:
         print "Error: %s" % ex.getMessage()
    def upload(self, args):
        """ Upload a template to a repository """
        parser = OptionParser(usage="template upload <options>")
        parser.add_option('-a',
                          '--bind-address',
                          help='The bind address fot the local repository'
                          'By default the public IP will be detected and used',
                          action='store',
                          dest='address')
        parser.add_option('-p',
                          '--port',
                          help='The port to open locally for the repository',
                          action='store',
                          dest='port',
                          type='int',
                          default=8888)
        parser.add_option('-f',
                          '--disk-file',
                          help='The disk file to be uploaded',
                          action='store',
                          dest='disk')
        parser.add_option(
            '-c',
            '--config',
            help='Path to a json configuration file for the template',
            action='store',
            dest='config')
        parser.add_option('-d',
                          '--datacenter',
                          help='The name of the datacenter where the template '
                          'will be downloaded',
                          action='store',
                          dest='datacenter')
        (options, args) = parser.parse_args(args)

        if not options.disk or not options.datacenter:
            parser.print_help()
            return

        # Read OVF values from json file
        if options.config:
            with open(options.config, "r") as f:
                config = json.loads(f.read())
        else:
            config = {}

        # Find the public bind address if not provided
        if not options.address:
            options.address = self._get_public_address()

        repo = TransientRepository(options.address, options.port)
        try:
            log.info("Creating temporal OVF repository")
            repo.create()
            definition = repo.add_definition(self._context, options.disk,
                                             config)
            repo.start()

            log.info("Loading destination repository: %s" % options.datacenter)
            admin = self._context.getAdministrationService()
            dc = admin.findDatacenter(
                DatacenterPredicates.name(options.datacenter))

            log.info("Uploading template. This may take some time...")
            definition.save()

            monitor = self._context.getMonitoringService() \
                .getAsyncTaskMonitor()
            task = definition.downloadToRepository(dc)
            monitor.awaitCompletion(task)

            pprint_templates([task.getResult()])
        except (AbiquoException, AuthorizationException), ex:
            print "Error: %s" % ex.getMessage()