-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/billing-breakdown' into 'develop'
Add support for billing breakdown See merge request core/sevenbridges-python!70
- Loading branch information
Showing
10 changed files
with
261 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from sevenbridges.meta.resource import Resource | ||
from sevenbridges.meta.fields import ( | ||
UuidField, CompoundField, StringField, | ||
DateTimeField, FloatField, BooleanField | ||
) | ||
from sevenbridges.models.compound.analysis_cost import AnalysisCost | ||
|
||
|
||
class BillingGroupAnalysisBreakdown(Resource): | ||
_URL = { | ||
'query': '/billing/groups/{id}/breakdown/analysis' | ||
} | ||
|
||
project_name = StringField(read_only=True) | ||
analysis_app_name = StringField(read_only=True) | ||
analysis_name = StringField(read_only=True) | ||
analysis_type = StringField(read_only=True) | ||
analysis_id = UuidField(read_only=True) | ||
ran_by = StringField(read_only=True) | ||
analysis_status = StringField(read_only=True) | ||
analysis_cost = CompoundField(AnalysisCost, read_only=True) | ||
refunded_amount = FloatField(read_only=True) | ||
time_started = DateTimeField(read_only=True) | ||
time_finished = DateTimeField(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 analysis breakdown. Date parameters must be | ||
string in format MM-DD-YYYY | ||
:param fields: | ||
:param invoice_id: | ||
:param date_to: include all analysis transactions charged before and | ||
including date_to | ||
:param date_from: include all analysis 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(BillingGroupAnalysisBreakdown, 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 '<BillingGroupAnalysisBreakdown>' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from sevenbridges.meta.resource import Resource | ||
from sevenbridges.meta.fields import ( | ||
StringField, CompoundField, BooleanField | ||
) | ||
from sevenbridges.models.compound.measurement import Measurement | ||
from sevenbridges.models.compound.egress_cost import EgressCost | ||
|
||
|
||
class BillingGroupEgressBreakdown(Resource): | ||
_URL = { | ||
'query': '/billing/groups/{id}/breakdown/egress' | ||
} | ||
|
||
project_name = StringField(read_only=True) | ||
downloaded_by = StringField(read_only=True) | ||
downloaded = CompoundField(Measurement, read_only=True) | ||
egress_cost = CompoundField(EgressCost, 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 egress breakdown. Date parameters must be | ||
string in format MM-DD-YYYY | ||
:param fields: | ||
:param invoice_id: | ||
:param date_to: include all egress transactions charged before and | ||
including date_to | ||
:param date_from: include all egress 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(BillingGroupEgressBreakdown, 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 '<BillingGroupEgressBreakdown>' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from sevenbridges.meta.resource import Resource | ||
from sevenbridges.meta.fields import ( | ||
CompoundField, StringField, BooleanField | ||
) | ||
from sevenbridges.models.compound.measurement import Measurement | ||
|
||
|
||
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>' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from sevenbridges.meta.resource import Resource | ||
from sevenbridges.meta.fields import StringField, CompoundField | ||
from sevenbridges.models.compound.analysis_cost_breakdown import ( | ||
AnalysisCostBreakdown | ||
) | ||
|
||
|
||
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}>' | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from sevenbridges.meta.resource import Resource | ||
from sevenbridges.meta.fields import FloatField | ||
|
||
|
||
class AnalysisCostBreakdown(Resource): | ||
""" | ||
AnalysisCostBreakdown resource contains price breakdown by storage and | ||
computation. | ||
""" | ||
storage = FloatField(read_only=True) | ||
computation = FloatField(read_only=True) | ||
data_transfer_in = FloatField(read_only=True) | ||
|
||
def __str__(self): | ||
return ( | ||
f'<AnalysisCostBreakdown: storage={self.storage}, ' | ||
f'computation={self.computation}, ' | ||
f'data_transfer_in={self.data_transfer_in}' | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from sevenbridges.meta.resource import Resource | ||
from sevenbridges.meta.fields import StringField | ||
|
||
|
||
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}>' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from sevenbridges.meta.resource import Resource | ||
from sevenbridges.meta.fields import StringField, FloatField | ||
|
||
|
||
class Measurement(Resource): | ||
""" | ||
Measurement resource contains an information regarding the size and the | ||
unit of a certain resource. | ||
""" | ||
size = FloatField(read_only=True) | ||
unit = StringField(read_only=True) | ||
|
||
def __str__(self): | ||
return f'<Measurement size={self.size}, unit={self.unit}>' |