class Division(Resource): """ Central resource for managing divisions. """ _URL = { 'query': '/divisions', 'get': '/divisions/{id}', } href = HrefField() id = StringField(read_only=True) name = StringField(read_only=True) def __str__(self): return six.text_type('<Division: id={id}>'.format(id=self.id)) def __eq__(self, other): if not hasattr(other, '__class__'): return False if not self.__class__ == other.__class__: return False return self is other or self.id == other.id def __ne__(self, other): return not self.__eq__(other) @classmethod def query(cls, offset=None, limit=None, api=None): """ Query (List) divisions. :param offset: Pagination offset. :param limit: Pagination limit. :param api: Api instance. :return: Collection object. """ api = api if api else cls._API return super(Division, cls)._query(url=cls._URL['query'], offset=offset, limit=limit, fields='_all', api=api) @classmethod def get(cls, id, api=None): return super(Division, cls).get(id) def reload(self): super(Division, self).reload() def get_teams(self, offset=None, limit=None): return self._api.teams.query(division=self.id, offset=offset, limit=limit) def get_members(self, role=None, offset=None, limit=None): return self._api.users.query(self, role=role, offset=offset, limit=limit)
class ExecutionStatus(Resource): """ Task execution status resource. Contains information about the number of completed task steps, total number of task steps, current execution message and information regarding computation limits. In case of a batch task it also contains the number of queued, running, completed, failed and aborted tasks. """ steps_completed = IntegerField(read_only=True) steps_total = IntegerField(read_only=True) message = StringField(read_only=True) message_code = StringField(read_only=True) queued = IntegerField(read_only=True) running = IntegerField(read_only=True) completed = IntegerField(read_only=True) failed = IntegerField(read_only=True) aborted = IntegerField(read_only=True) system_limit = BooleanField(read_only=True) account_limit = BooleanField(read_only=True) instance_init = BooleanField(read_only=True) queued_duration = IntegerField(read_only=True) running_duration = IntegerField(read_only=True) execution_duration = IntegerField(read_only=True) duration = IntegerField(read_only=True) def __str__(self): return '<ExecutionStatus>'
class EgressCost(Resource): """ EgressCost resource contains an information regarding the currency and the monet value of a egress cost. """ currency = StringField(read_only=True) amount = StringField(read_only=True) def __str__(self): return f'<EgressCost: currency={self.currency}, amount={self.amount}>'
class Disk(Resource): """ Disk resource contains information about EBS disk size. """ size = IntegerField(read_only=True) unit = StringField(read_only=True) type = StringField(read_only=True) def __str__(self): return f'<Disk size={self.size}, unit={self.unit}, type={self.type_}>'
class VolumePrefix(Resource): """ Volume prefix resource contains information about volume prefixes """ href = StringField(read_only=True) prefix = StringField(read_only=True) volume = StringField(read_only=True) def __str__(self): return f'<VolumePrefix: prefix={self.prefix}>'
class ImportDestination(Resource): """ ImportDestination resource describes the location of the file imported on to SevenBridges platform or related product. """ project = StringField(read_only=True) parent = StringField(read_only=True) name = StringField(read_only=True) def __str__(self): return f'<ImportDestination: project={self.project}, name={self.name}>'
class Link(Resource): """ Pagination links. """ href = HrefField(read_only=True) rel = StringField(read_only=True) method = StringField(read_only=True) def __str__(self): return ( f'<Link: method={self.method}, rel={self.rel}, href={self.href}>')
class FileStorage(Resource): """ File storage resource contains information about the storage location of the file if the file is imported on or exported to an external volume. """ type = StringField(read_only=True) volume = StringField(read_only=True) location = StringField(read_only=True) def __str__(self): return f'<FileStorage: type={self.type}, volume={self.volume}>'
class Breakdown(Resource): """ Breakdown resource contains price breakdown by storage and computation. """ storage = StringField(read_only=True) computation = StringField(read_only=True) def __str__(self): return six.text_type( '<Breakdown: storage={storage}, computation={computation}>'.format( storage=self.storage, computation=self.computation))
class AnalysisCost(Resource): """ AnalysisCost resource contains an information regarding the currency, the monet value and breakdown of a analysis cost. """ currency = StringField(read_only=True) amount = StringField(read_only=True) breakdown = CompoundField(AnalysisCostBreakdown, read_only=True) def __str__(self): return (f'<AnalysisCost: currency={self.currency}, ' f'amount={self.amount}>')
class VolumeFile(Resource): """ VolumeFile resource describes the location of the file on the external volume. """ volume = StringField(read_only=True) location = StringField(read_only=True) def __str__(self): return six.text_type( '<VolumeFile: volume={volume}, location={location}>'.format( volume=self.volume, location=self.location))
class Link(Resource): """ Pagination links. """ href = HrefField() rel = StringField(read_only=True) method = StringField(read_only=True) def __str__(self): return six.text_type( '<Link: method={method}, rel={rel}, href={href}>'.format( method=self.method, rel=self.rel, href=self.href))
class Instance(Resource): """ Instance resource contains information regarding the instance on which the job was executed. """ id = StringField(read_only=True) type = StringField(read_only=True) provider = StringField(read_only=True) def __str__(self): return six.text_type( '<Instance id={id}, type={type_}, provider={provider}>'.format( id=self.id, type_=self.type, provider=self.provider))
class Error(Resource): """ Error resource describes the error that happened and provides http status, custom codes and messages as well as the link to online resources. """ status = IntegerField(read_only=True) code = IntegerField(read_only=True) message = StringField(read_only=True) more_info = StringField(read_only=True) def __str__(self): return f'<Error: status={self.status}, code={self.code}>'
class VolumeObject(Resource): """ Volume object resource contains information about single file (object) entry in a specific volume. """ href = StringField(read_only=True) location = StringField(read_only=True) volume = StringField(read_only=True) type = StringField(read_only=True) metadata = DictField(read_only=True) def __str__(self): return f'<VolumeObject: location={self.location}>'
class ExecutionDetails(Resource): """ Task execution details. """ href = HrefField() start_time = DateTimeField(read_only=True) end_time = DateTimeField(read_only=True) status = StringField(read_only=True) message = StringField(read_only=True) jobs = CompoundListField(Job, read_only=True) @staticmethod def __str__(): return six.text_type('<Execution Details>')
class BillingGroupStorageBreakdown(Resource): _URL = {'query': '/billing/groups/{id}/breakdown/storage'} project_name = StringField(read_only=True) project_created_by = StringField(read_only=True) location = StringField(read_only=True) active = CompoundField(Measurement, read_only=True) archived = CompoundField(Measurement, read_only=True) project_locked = BooleanField(read_only=True) @classmethod def query(cls, bg_id, api=None, date_from=None, date_to=None, invoice_id=None, fields=None, offset=0, limit=50): """ Query (List) billing group storage breakdown. Date parameters must be string in format MM-DD-YYYY :param fields: :param invoice_id: :param date_to: include all storage transactions charged before and including date_to :param date_from: include all storage transactions charged after and including date_from :param bg_id: Billing Group ID :param offset: Pagination offset. :param limit: Pagination limit. :param api: Api instance. :return: Collection object. """ api = api or cls._API return super(BillingGroupStorageBreakdown, cls)._query(url=cls._URL['query'].format(id=bg_id), offset=offset, limit=limit, date_from=date_from, date_to=date_to, invoice_id=invoice_id, fields=fields, api=api) def __str__(self): return '<BillingGroupStorageBreakdown>'
class Breakdown(Resource): """ Breakdown resource contains price breakdown by storage and computation. """ storage = StringField(read_only=True) computation = StringField(read_only=True) data_transfer = StringField(read_only=True) def __str__(self): if self.data_transfer: return (f'<Breakdown: storage={self.storage}, ' f'computation={self.computation}, ' f'data_transfer={self.data_transfer}>') return (f'<Breakdown: storage={self.storage}, ' f'computation={self.computation}>')
class VolumeFile(Resource): """ VolumeFile resource describes the location of the file on the external volume. """ volume = StringField(read_only=True) location = StringField(read_only=True) def __str__(self): return f'<VolumeFile: volume={self.volume}, location={self.location}>' def __eq__(self, other): if type(other) is not type(self): return False return self is other or self.location == other.location
class BillingGroup(Resource): """ Central resource for managing billing groups. """ _URL = {'query': '/billing/groups', 'get': '/billing/groups/{id}'} href = HrefField() id = UuidField() owner = StringField(read_only=True) name = StringField(read_only=True) type = StringField(read_only=True) pending = BooleanField(read_only=True) disabled = BooleanField(read_only=False) balance = CompoundField(Price, read_only=True) def __str__(self): return six.text_type('<BillingGroup: id={id}>'.format(id=self.id)) def __eq__(self, other): if not hasattr(other, '__class__'): return False if not self.__class__ == other.__class__: return False return self is other or self.id == other.id def __ne__(self, other): return not self.__eq__(other) @classmethod def query(cls, offset=None, limit=None, api=None): """ Query (List) billing group. :param offset: Pagination offset. :param limit: Pagination limit. :return: Collection object. :param api: Api instance. """ api = api or cls._API return super(BillingGroup, cls)._query(url=cls._URL['query'], offset=offset, limit=limit, fields='_all', api=api) def breakdown(self): """ Get Billing group breakdown for the current billing group. """ return BillingGroupBreakdown.get(self.id, self._api)
class Division(Resource): """ Central resource for managing divisions. """ _URL = { 'query': '/divisions', 'get': '/divisions/{id}', } href = HrefField(read_only=True) id = StringField(read_only=True) name = StringField(read_only=True) def __str__(self): return f'<Division: id={self.id}>' def __eq__(self, other): if type(other) is not type(self): return False return self is other or self.id == other.id @classmethod def query(cls, offset=None, limit=None, api=None): """ Query (List) divisions. :param offset: Pagination offset. :param limit: Pagination limit. :param api: Api instance. :return: Collection object. """ api = api if api else cls._API return super()._query(url=cls._URL['query'], offset=offset, limit=limit, fields='_all', api=api) def get_teams(self, offset=None, limit=None): return self._api.teams.query(division=self.id, offset=offset, limit=limit) def get_members(self, role=None, offset=None, limit=None): return self._api.users.query(self, role=role, offset=offset, limit=limit)
class Member(Resource): """ Central resource for managing project members. """ _URL = {'permissions': '/permissions'} href = HrefField() username = StringField(read_only=False) permissions = CompoundField(Permissions) def __str__(self): return six.text_type( '<Member: username={username}>'.format(username=self.username)) def save(self): """ Saves modification to the api server. """ data = self._modified_data() try: data = data['permissions'] if bool(data): url = six.text_type(self.href) + self._URL['permissions'] self._api.patch(url=url, data=data, append_base=False) except KeyError: raise ResourceNotModified()
class Invoice(Resource): """ Central resource for managing invoices. """ _URL = {'query': '/billing/invoices', 'get': '/billing/invoices/{id}'} href = HrefField() id = StringField(read_only=True) pending = BooleanField(read_only=True) analysis_costs = CompoundField(Price, read_only=True) storage_costs = CompoundField(Price, read_only=True) total = CompoundField(Price, read_only=True) invoice_period = CompoundField(InvoicePeriod, read_only=True) def __str__(self): return six.text_type('<Invoice: id={id}>'.format(id=self.id)) @classmethod def query(cls, offset=None, limit=None, api=None): """ Query (List) invoices. :param offset: Pagination offset. :param limit: Pagination limit. :param api: Api instance. :return: Collection object. """ api = api if api else cls._API return super(Invoice, cls)._query(url=cls._URL['query'], offset=offset, limit=limit, fields='_all', api=api)
class Job(Resource): """ Job resource contains information for a single executed node in the analysis. """ name = StringField(read_only=True) start_time = DateTimeField(read_only=True) end_time = DateTimeField(read_only=True) status = StringField(read_only=True) command_line = StringField(read_only=True) instance = CompoundField(Instance, read_only=True) logs = CompoundField(Log, read_only=True) def __str__(self): return six.text_type('<Job: name={name}, status={status}>'.format( name=self.name, status=self.status))
class TeamMember(Resource): """ Central resource for managing team members. """ href = HrefField(read_only=True) id = StringField(read_only=True) username = StringField(read_only=False) role = StringField(read_only=True) def __eq__(self, other): if type(other) is not type(self): return False return self is other or self.id == other.id def __str__(self): return f'<Team member: username={self.username}>'
class Job(Resource): """ Job resource contains information for a single executed node in the analysis. """ name = StringField(read_only=True) start_time = DateTimeField(read_only=True) end_time = DateTimeField(read_only=True) status = StringField(read_only=True) command_line = StringField(read_only=True) retried = BooleanField(read_only=True) instance = CompoundField(Instance, read_only=True) docker = CompoundField(JobDocker, read_only=True) logs = CompoundField(Logs, read_only=True) def __str__(self): return f'<Job: name={self.name}, status={self.status}>'
class JobDocker(Resource): """ JobDocker resource contains information for a docker image that was used for execution of a single job. """ checksum = StringField(read_only=True) def __str__(self): return f'<Docker: checksum={self.checksum}'
class Member(Resource): """ Central resource for managing members. This resource is reused on both projects and volumes. """ _URL = { 'permissions': '/permissions' } href = HrefField() id = StringField(read_only=True) username = StringField(read_only=False) email = StringField(read_only=False) type = StringField(read_only=False) permissions = CompoundField(Permissions, read_only=False) def __str__(self): return six.text_type('<Member: id={id}>' .format(id=self.id)) def __eq__(self, other): if not hasattr(other, '__class__'): return False if not self.__class__ == other.__class__: return False return self is other or self.id == other.id def __ne__(self, other): return not self.__eq__(other) @inplace_reload def save(self, inplace=True): """ Saves modification to the api server. """ data = self._modified_data() data = data['permissions'] if bool(data): url = six.text_type(self.href) + self._URL['permissions'] extra = {'resource': self.__class__.__name__, 'query': data} logger.info('Modifying permissions', extra=extra) self._api.patch(url=url, data=data, append_base=False) else: raise ResourceNotModified()
class FileOrigin(Resource): """ File origin resource contains information about origin of a file. Among others it contains information about the task if the file was produced during executions of a analysis. """ task = StringField(read_only=True) def __str__(self): return f'<FileOrigin: task={self.task}>'
class BatchBy(Resource): """ Batch by tells the API what is the criteria for batching. It can be either item or criteria. """ type = StringField(read_only=False) criteria = BasicListField(read_only=False) @staticmethod def __str__(): return six.text_type('<Batch by>')