def assign_hostname(self, user, asset_id, asset_id_type_name, persistent=False): """ set the status of this host to 'assigned' """ if not self.get_manageability(user): raise UserNotAuthorized( "{} is not authorized to manage this hostname".format(user)) if not self.active: raise HostnameInactive("{} is currently inactive".format( self.hostname)) if self.status not in ['available', 'reserved']: raise InvalidStateTransition( "{} has a status of {}; can not transition to 'assigned". format(self.hostname, self.status)) if not asset_id: raise AssetIdRequired("asset ID required to assign a hostname") asset_id_type_obj = AssetIdType.objects.get_object_or_none( name=asset_id_type_name) if not asset_id_type_obj: raise InvalidAssetIdType( "{} is not a valid asset ID type".format(asset_id_type_name)) self.asset_id = asset_id self.asset_id_type = asset_id_type_obj if persistent in [True, 'true', 'True']: self.persistent = True self.status = "assigned" self.save() return 0
def reassign_hostname(self, user, asset_id, asset_id_type_name): """ assign this hostname to a different asset """ if not self.get_manageability(user): raise UserNotAuthorized( "{} is not authorized to manage this hostname".format(user)) if not self.active: raise HostnameInactive("{} is currently inactive".format( self.hostname)) if self.status not in ['assigned']: raise InvalidStateTransition( "{} has a status of {}; can not transition to 'assigned". format(self.hostname, self.status)) if self.persistent: raise HostnamePersistent( "{} is set to persistent and can not be released".format( self.hostname)) asset_id_type_obj = AssetIdType.objects.get_object_or_none( name=asset_id_type_name) if not asset_id_type_obj: raise InvalidAssetIdType( "{} is not a valid asset ID type".format(asset_id_type_name)) self.asset_id = asset_id self.asset_id_type = asset_id_type_obj self.status = "assigned" self.save() return 0
def disable_hostname(self, user): """ set this hostname to active = False """ if not self.get_manageability(user): raise UserNotAuthorized( "{} is not authorized to manage this hostname".format(user)) self.active = False self.save()
def disable_pattern(self, user): """ set this pattern to active = False """ if not self.get_manageability(user): raise UserNotAuthorized( "{} is not authorized to disable this pattern".format(user)) self.active = False self.save()
def disable_project(self, user): """ set this project to active = False """ if not self.get_manageability(user): raise UserNotAuthorized( "{} is not authorized to manage this lock".format(user)) self.active = False self.save()
def reserve_next_hostname(self, user, count=1, consecutive=False): """ get and reserve the next available hostname(s) for this pattern :param count: (int) number of hostnames to find and return :param consecutive: (bool) set True if hostnames must be consecutive :return: (list) list of hostname objects """ if not self.get_manageability(): raise UserNotAuthorized( "user '{}' is not authorized to reserve this hostname".format( user)) hostname_list = self.get_next_hostname(count=count, consecutive=consecutive) hostname_list.update(status="reserved")
def reserve_hostname(self, user): """ set the status of this host to 'reserved' """ if not self.get_manageability(user): raise UserNotAuthorized( "{} is not authorized to manage this hostname".format(user)) if not self.active: raise HostnameInactive("{} is currently inactive".format( self.hostname)) if self.status not in ['available', 'assigned']: raise InvalidStateTransition( "{} has a status of {}; can not transition to 'reserved". format(self.hostname, self.status)) self.status = "reserved" self.save() return 0
def release_hostname(self, user): """ set the status of this host to 'available' """ if not self.get_manageability(user): raise UserNotAuthorized( "{} is not authorized to manage this hostname".format(user)) if not self.active: raise HostnameInactive("{} is currently inactive".format( self.hostname)) if self.persistent: raise HostnamePersistent( "{} is set to persistent and can not be released".format( self.hostname)) self.status = "available" self.asset_id_type = None self.asset_id = None self.save() return 0