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()
def createMachine(self, args): """ Create a physical machine in abiquo. This method uses configurable constats for default values.""" parser = OptionParser(usage="machine create --host <host> <options>") # create options parser.add_option("-i","--host", help="ip or hostname from machine to create in abiquo [required]",action="store",dest="host") parser.add_option("-u","--user",help="user to loggin in the machine",action="store",dest="user") parser.add_option("-p","--psswd",help="password to loggin in the machine",action="store",dest="psswd") # parser.add_option("-c","--port",help="port from machine",action="store",dest="port") parser.add_option("-t","--type",help="hypervisor type of the machine",action="store",dest="hypervisor") parser.add_option("-r","--rsip",help="ip from remote services",action="store",dest="remoteservicesip") parser.add_option("-d","--datastore", help="datastore to enable on physical machine",action="store",dest="datastore") parser.add_option("-s","--vswitch", help="virtual switch to select on physical machine",action="store",dest="vswitch") (options, args) = parser.parse_args(args) # parse options host = options.host if not host: parser.print_help() return user = self._getConfig(options,host,"user") psswd = self._getConfig(options,host,"psswd") rsip = self._getConfig(options,host,"remoteservicesip") dsname = self._getConfig(options,host,"datastore") vswitch = self._getConfig(options,host,"vswitch") hypervisor = options.hypervisor context = ContextLoader().load() try: admin = context.getAdministrationService() # search or create datacenter log.debug("Searching for the datacenter 'kahuna'.") dc = admin.findDatacenter(DatacenterPredicates.name('kahuna')) if not dc: log.debug("No datacenter 'kahuna' found.") dc = Datacenter.builder(context) \ .name('kahuna') \ .location('terrassa') \ .remoteServices(rsip,AbiquoEdition.ENTERPRISE) \ .build() try: dc.save() except (AbiquoException), ex: if ex.hasError("RS-3"): print "ip %s to create remote services has been used yet, try with another one" % rsip dc.delete() return else: raise ex rack = Rack.builder(context,dc).name('rack').build() rack.save() log.debug("New datacenter 'kahuna' created.") else:
def create(self, args): """ Create a physical machine in abiquo """ parser = OptionParser(usage="machine create --host <host> <options>") # create options parser.add_option('-i', '--host', help='ip or hostname from machine to ' 'create in abiquo [required]', action='store', dest='host') parser.add_option('-u', '--user', help='user to loggin in the machine', action='store', dest='user') parser.add_option('-p', '--psswd', help='password to loggin in the machine', action='store', dest='psswd') parser.add_option('-t', '--type', help='hypervisor type of the machine', action='store', dest='hypervisor') parser.add_option('-r', '--rsip', help='ip from remote services', action='store', dest='remoteservicesip') parser.add_option('-d', '--datastore', help='datastore to enable on physical machine', action='store', dest='datastore') parser.add_option('-s', '--vswitch', help='virtual switch to select on physical machine', action='store', dest='vswitch') (options, args) = parser.parse_args(args) # parse options host = options.host if not host: parser.print_help() return user = self._getConfig(options, host, "user") psswd = self._getConfig(options, host, "psswd") rsip = self._getConfig(options, host, "remoteservicesip") dsname = self._getConfig(options, host, "datastore") vswitch = self._getConfig(options, host, "vswitch") hypervisor = options.hypervisor try: api_context = self._context.getApiContext() admin = self._context.getAdministrationService() # search or create datacenter log.debug("Searching for the datacenter 'kahuna'.") dc = admin.findDatacenter(DatacenterPredicates.name('kahuna')) if not dc: log.debug("No datacenter 'kahuna' found.") dc = Datacenter.builder(api_context) \ .name('kahuna') \ .location('terrassa') \ .remoteServices(rsip, AbiquoEdition.ENTERPRISE) \ .build() try: dc.save() except (AbiquoException), ex: if ex.hasError('RS-3'): print ('ip %s to create remote services has been used ' 'yet, try with another one' % rsip) dc.delete() return else: raise ex rack = Rack.builder(api_context, dc).name('rack').build() rack.save() log.debug("New datacenter 'kahuna' created.") else:
def create(self, args): """ Create a physical machine in abiquo """ parser = OptionParser(usage="machine create --host <host> <options>") # create options parser.add_option('-i', '--host', help='ip or hostname from machine to ' 'create in abiquo [required]', action='store', dest='host') parser.add_option('-u', '--user', help='user to loggin in the machine', action='store', dest='user') parser.add_option('-p', '--psswd', help='password to loggin in the machine', action='store', dest='psswd') parser.add_option('-t', '--type', help='hypervisor type of the machine', action='store', dest='hypervisor') parser.add_option('-r', '--rsip', help='ip from remote services', action='store', dest='remoteservicesip') parser.add_option('-d', '--datastore', help='datastore to enable on physical machine', action='store', dest='datastore') parser.add_option('-s', '--vswitch', help='virtual switch to select on physical machine', action='store', dest='vswitch') (options, args) = parser.parse_args(args) # parse options host = options.host if not host: parser.print_help() return user = self._getConfig(options, host, "user") psswd = self._getConfig(options, host, "psswd") rsip = self._getConfig(options, host, "remoteservicesip") dsname = self._getConfig(options, host, "datastore") vswitch = self._getConfig(options, host, "vswitch") hypervisor = options.hypervisor try: api_context = self._context.getApiContext() admin = self._context.getAdministrationService() # search or create datacenter log.debug("Searching for the datacenter 'kahuna'.") dc = admin.findDatacenter(DatacenterPredicates.name('kahuna')) if not dc: log.debug("No datacenter 'kahuna' found.") dc = Datacenter.builder(api_context) \ .name('kahuna') \ .location('terrassa') \ .remoteServices(rsip, AbiquoEdition.ENTERPRISE) \ .build() try: dc.save() except (AbiquoException), ex: if ex.hasError('RS-3'): print( 'ip %s to create remote services has been used ' 'yet, try with another one' % rsip) dc.delete() return else: raise ex rack = Rack.builder(api_context, dc).name('rack').build() rack.save() log.debug("New datacenter 'kahuna' created.") else:
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()