def UpdateGridServicesToRevision(self, revision): """ Update the target to the revision specified. """ if (self.aperture_service.IsRunning()): raise ServiceError("Update: Cannot update, aperture is running.") if (self.messaging_service.IsRunning()): raise ServiceError( "Update: Cannot update, messaging service is running.") if (self.user_service.IsRunning()): raise ServiceError( "Update: Cannot update, user service is running.") try: target = provision.GetServiceBaseDir() gridshare_path = self.props.getValue("gridshare_path") (username, password) = self.props.getGridShareCredentials() ConnectUNCShare(gridshare_path, username, password) return (provision.ProvisionFromRevision(gridshare_path, target, revision)) except: import traceback exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback) raise ServiceError(exc_value)
def __init__(self, uuid, record={}): ServiceBase.__init__(self, uuid, record) self.props = DefaultProperties.instance() dbconfig = self.props.getCoreDbConfig() self.exe_name = "OpenSim.exe" # self.exe_args = "--console rest" self.exe_args = "" if ((not 'sim_name' in record) or (not 'sim_location_x' in record) or (not 'sim_location_y' in record) or (not 'estate_id' in record) or (not 'master_avatar_uuid' in record)): raise ServiceError("Region: Invalid Region Information provided") self.regionEntry = None self.sim_uuid = uuid self.estate_id = record['estate_id'] self.syncEstateInfoToEstateId() self.master_avatar_uuid = record['master_avatar_uuid'] self.syncOwnerInfoToMasterAvatarId() self.sim_name = record.get("sim_name") self.set_sim_location(record.get("sim_location_x"), record.get("sim_location_y")) if ('slot_number' in record): self.slot_number = int(record.get('slot_number')) self.slot_directory = provision.GetSlotDirectory(self.slot_number) else: raise ServiceError("Create failed. No Slot Number Specified") rdbHost = GetRdbHost(dbconfig, uuid) if not rdbHost: # no info? that's ok in this case we assign print "RDB server not assigned for {0}, assigning new slot".format(uuid) rdbHost = AssignBestRdbHost(dbconfig, uuid) from inworldz.maestro.RegionHost import RegionHost self.regionHost = RegionHost.instance() self.set_external_host_name(record.get('external_host_name')) self.set_outside_ip(record.get('outside_ip')) self.set_internal_ip_address(record.get('internal_ip_address')) self.set_internal_ip_port(record.get('internal_ip_port')) self.set_allow_alternate_ports(record.get('allow_alternate_ports')) self.set_lastmap_uuid(record.get("lastmap_uuid")) self.set_lastmap_refresh(record.get("lastmap_refresh")) self.set_nonphysical_prim_max(record.get("nonphysical_prim_max")) self.set_physical_prim_max(record.get("physical_prim_max")) self.set_clamp_prim_size(record.get("clamp_prim_size")) self.set_object_capacity(record.get("object_capacity")) self.set_region_product(record.get("region_product")) self.set_remoteadmin_url(record.get("remoteadmin_url")) self.remoteadmin_session = Session(self.get_remoteadmin_url()) self.remoteadmin_sessionid = None
def ReconfigureGridServices(self): """ Retrieves the most up to date configuration templates, and regenerates configuration files. The grid services must be down for this to succeed. """ if (self.aperture_service.IsRunning()): raise ServiceError( "Reconfigure: Cannot reconfigure, aperture is running.") if (self.messaging_service.IsRunning()): raise ServiceError( "Reconfigure: Cannot reconfigure, messaging service is running." ) if (self.user_service.IsRunning()): raise ServiceError( "Reconfigure: Cannot reconfigure, user service is running.") if (self.grid_service != None and self.grid_service.IsRunning()): raise ServiceError( "Reconfigure: Cannot reconfigure, grid service is running.") serviceBaseDir = os.path.join(provision.GetServiceBaseDir(), "bin") try: os.makedirs(serviceBaseDir) except OSError as exc: if exc.errno == errno.EEXIST and os.path.isdir(serviceBaseDir): pass else: raise ServiceError( "Grid Services destination directory doesn't exist") defaults = {} defaults['http_listener_port'] = str( self.props.getInteger('starting_http_port')) defaults['internal_ip_port'] = str( self.props.getInteger('starting_udp_port')) keys = dict(self.props.getItems(vars=defaults)) # Map the source drive and figure out if its on GridShare (username, password) = self.props.getGridShareCredentials() templateBaseDir = self.props.getValue("template_basedir") try: ConnectUNCShare(templateBaseDir, username, password) """ Read in Region Config Settings """ keys = provision.GetConfiguration(templateBaseDir, "simulation.config", "simulation", keys) provision.ReconfigureSimulator(templateBaseDir, serviceBaseDir, keys) """ Done""" return True except Exception: import traceback exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback) return False
def recreate(cls, record, uuid): if (not 'user_id' in record): raise ServiceError("Recreate: user_id not provided") result = user.LookupUserNameById(record['user_id']) if (result == None): raise ServiceError("Recreate failed. user id not found '" + record['user_id'] + "'") record['first_name'] = result[0] record['last_name'] = result[1] userobj = User(uuid, record) return userobj.get_uuid()
def recreate(cls, record, uuid): if (not 'estate_id' in record): raise ServiceError("Recreate: Invalid Estate Information provided") # make sure the estate owner is valid estate_entry = estate.LookupEstateById(record['estate_id']) if (estate_entry == None): raise ServiceError("Recreate: Invalid Estate Information provided") record['estate_name'] = estate_entry[1] record['estate_owner'] = estate_entry[2] record['parent_estate_id'] = estate_entry[3] uuid = genuuid.createString() new_estate = Estate(uuid, record) return new_estate.get_uuid()
def Backup(self, regionName, fileName, storeAssets): """ Saves a region to disk """ if (not self.IsRunning()): raise ServiceError("SaveOar: Region Process Not Running") self.establishRemoteAdminApiCredentials() return self.remoteadmin_session.api.Region.Backup(regionName, fileName, storeAssets)
def Restore(self, regionName, filename, allowUserReassignment, skipErrorGroups): """ Restores a region backup from disk """ if (not self.IsRunning()): raise ServiceError("RestoreOar: Region Process Not Running") self.establishRemoteAdminApiCredentials() return self.remoteadmin_session.api.Region.Restore(regionName, filename, allowUserReassignment, skipErrorGroups)
def SaveOarBackup(self, owner_id): """ Saves a region to disk """ if (not self.IsRunning()): raise ServiceError("SaveOar: Region Process Not Running") self.establishRemoteAdminApiCredentials() return self.remoteadmin_session.api.Region.SaveOAR(owner_id)
def RestoreOarBackup(self, owner_id, filename): """ Restores a region backup from disk """ if (not self.IsRunning()): raise ServiceError("RestoreOar: Region Process Not Running") self.establishRemoteAdminApiCredentials() return self.remoteadmin_session.api.Region.RestoreOAR(owner_id, filename)
def AssignEstate(self, estate_uuid): estate = store.get(estate_uuid, "Estate") if (estate == None): ServiceError("AssignEstate: Invalid Estate Reference") estate.AssignRegion(self.get_sim_uuid()) self.estate = estate self.estate_id = self.estate.get_estate_id()
def verifyRecord(cls, record, verifyEstate=True): if ((not 'sim_name' in record) or (not 'sim_location_x' in record) or (not 'sim_location_y' in record) or (verifyEstate and not 'estate_id' in record) or (not 'region_product' in record) or (not 'master_avatar_uuid' in record)): raise ServiceError("Create: Invalid Region Information provided")
def create(cls, record): if ((not 'estate_name' in record) or (not 'estate_owner' in record)): raise ServiceError("Create: Invalid Estate Information provided") # make sure the estate owner is valid if (user.LookupUserNameById(record['estate_owner']) == None): raise ServiceError("Create failed. Invalid estate owner specified") record['estate_id'] = estate.CreateNewEstate(record['estate_name'], record['estate_owner']) if (record['estate_id'] == None): raise ServiceError("Create: Cannot create new Estate") record['parent_estate_id'] = record['estate_id'] uuid = genuuid.createString() new_estate = Estate(uuid, record) return new_estate.get_uuid()
def __init__(self, uuid, record={}): ServiceBase.__init__(self, uuid, record) self.props = DefaultProperties.instance() if ('user_id' in record): self.user_id = str(record.get('user_id')) else: raise ServiceError("Create failed. No user id specified") self.first_name = str(record['first_name'] if 'first_name' in record else "") self.last_name = str(record['last_name'] if 'last_name' in record else "")
def UpdateRegionToLatest(self, region_uuid): """ Update the region to the latest revision. """ region = store.get(region_uuid, Region.getClass()) if (region == None): raise ServiceError("Invalid Region Specified") if (region.IsRunning()): raise ServiceError("Cannot update a running region.") try: target = region.get_slot_directory() gridshare_path = self.props.getValue("gridshare_path") (username, password) = self.props.getGridShareCredentials() ConnectUNCShare(gridshare_path, username, password) return (provision.ProvisionFromLatest(gridshare_path, target)) except: import traceback exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback) raise ServiceError(exc_value)
def login_with_password(self, username, password): """Returns a session UUID if valid, otherwise raises an error. @raises ServiceError: If login fails. @rtype: string @return: Session UUID """ authInfo = self.try_authorize(username, password) if authInfo[0]: return self.login_unconditionally(username, password, authInfo[1]) raise ServiceError("Login failed")
def recreate(cls, record, uuid): if ('estate_id' not in record): estate_id = estate.FindEstateIDForRegion(uuid) if (estate_id == None): raise ServiceError("Recreate: No estate assigned for region " + uuid) record['estate_id'] = estate_id cls.verifyRecord(record,False) region = Region(uuid, record) region.associateWithRegionEntry() return region.get_uuid()
def GetAvailableReleases(cls): try: props = DefaultProperties.instance() gridshare_path = props.getValue("gridshare_path") (username, password) = props.getGridShareCredentials() ConnectUNCShare(gridshare_path, username, password) return (provision.GetRevisions(gridshare_path)) except: import traceback exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback) raise ServiceError(exc_value)
def ProvisionRegion(self, record): """ Set up a new region in the resource pool provided by this host sim_name - The name of the new region to provision sim_location_x - The x location on the map for the new region sim_location_y - The y location on the map for the new region master_avatar_uuid - The user that owns this new region """ for slotnum in range(self.maxRegionSlots): if (self.IsSlotFree(slotnum)): record['slot_number'] = slotnum try: region = Region.create(record) #also record this provisioning to the environment regEntry = RegionEntry(region.sim_uuid, region.sim_name, region.master_avatar_uuid, \ region.estate_id, region.get_region_product(), \ region.sim_location_x, region.sim_location_y, \ self.props.hostingResource.dbid, \ RegionState.SetupInProgress) self.props.hostingResource.registerNewRegion(regEntry) region.associateWithRegionEntry() self.region_add(region.get_uuid()) return region.get_uuid() except: import traceback exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback) raise ServiceError(exc_value) """ No slots found available. tell them """ raise ServiceError("No region slot is available")
def destroy(self): p = provision._findRegionProcess(self.slot_number) if p: raise ServiceError("Cannot destroy a running region") """ Zap the config file """ regionDir = os.path.join(provision.GetSlotDirectory(self.slot_number), "bin", "Regions") configFile = os.path.join(regionDir, self.get_name_label() + ".xml") if (os.path.exists(configFile)): os.remove(configFile) self.regionEntry.unprovision() """ Remove our Entry in the Host """ self.regionHost.region_del(self.get_uuid()) ServiceBase.destroy(self)
def ConsoleCommand(self, command): """ Runs the given console command """ if (not self.IsRunning()): raise ServiceError("ConsoleCommand: Process Not Running") ServiceBase.ConsoleCommand(self, command)
def ReconfigureRegion(self, region_uuid): """ Retrieves the most up to date configuration templates, and regenerates configuration files. The region must be down for this to succeed. """ region = store.get(region_uuid, Region.getClass()) if (region == None): raise ServiceError("Invalid Region Specified") if (region.IsRunning()): raise ServiceError("Cannot reconfigure a running region.") region_record = region.get_record() slotnum = region.get_slot_number() regionBaseDir = os.path.join(region.get_slot_directory(), "bin") regionConfigDir = os.path.join(region.get_slot_directory(), "bin", "Regions") try: os.makedirs(regionConfigDir) except OSError as exc: if exc.errno == errno.EEXIST and os.path.isdir(regionConfigDir): pass else: raise ServiceError( "Region destination directory doesn't exist") dbconfig = self.props.getCoreDbConfig() region_uuid = region.get_sim_uuid() rdbHost = GetRdbHost(dbconfig, region_uuid) if (rdbHost == None): # no info? that's ok in this case we assign print "RDB server not assigned for {0}, assigning new slot".format( region_uuid) rdbHost = AssignBestRdbHost(dbconfig, region_uuid) if ((not 'http_listener_port' in region_record) or (region_record['http_listener_port'] == "{REQUIRE}")): region_record['http_listener_port'] = str( self.props.getInteger('starting_http_port') + slotnum) if ((not 'internal_ip_port' in region_record) or (region_record['internal_ip_port'] == "{REQUIRE}")): region_record['internal_ip_port'] = str( self.props.getInteger('starting_udp_port') + slotnum) if ((not 'rdb_host' in region_record) or (region_record['rdb_host'] == "{REQUIRE}")): region_record['rdb_host'] = rdbHost # Check for REQUIRE items and do the replacements if needed keys = dict(self.props.getItems(vars=region_record)) # Map the source drive and figure out if its on GridShare regionConfigName = region.get_name_label() + ".xml" (username, password) = self.props.getGridShareCredentials() templateBaseDir = self.props.getValue("template_basedir") try: ConnectUNCShare(templateBaseDir, username, password) """ Read in Region Config Settings """ keys = provision.GetConfiguration(templateBaseDir, "simulation.config", "simulation", keys) """ Update the Region Configuration First """ provision.ReconfigureRegion(templateBaseDir, regionConfigDir, regionConfigName, keys) """ Now do the Simulator Configuration Files """ provision.ReconfigureSimulator(templateBaseDir, regionBaseDir, keys) """ Done""" return True except Exception, e: raise ServiceError("Reconfiguration failed: " + str(e))