Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Add support to Unit resource
Browse files Browse the repository at this point in the history
  • Loading branch information
joaodaher committed Jun 28, 2019
1 parent 60e098f commit b2f4462
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tsuru/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Plan,
Platform,
Team,
Unit,
)
from tsuru.exceptions import (
DoesNotExist,
Expand All @@ -27,6 +28,8 @@
'Plan',
'Platform',
'Team',
'Unit',

'DoesNotExist',
'UnexpectedDataFormat',
'UnsupportedModelException',
Expand Down
4 changes: 4 additions & 0 deletions tsuru/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from tsuru.models.plan import Plan
from tsuru.models.platform import Platform
from tsuru.models.team import Team
from tsuru.models.unit import Unit


__all__ = (
'App',
'Deploy',
Expand All @@ -15,4 +18,5 @@
'Plan',
'Platform',
'Team',
'Unit',
)
53 changes: 53 additions & 0 deletions tsuru/models/unit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from tsuru.models.base import BaseModel


class Unit(BaseModel):
_RESOURCE_NAME = 'units'

@property
def name(self):
return self._get('Name')

@property
def process_name(self):
return self._get('ProcessName')

@property
def app_name(self):
return self._get('AppName')

@property
def type(self):
return self._get('Type')

@property
def ip(self):
return self._get('IP')

@property
def status(self):
return self._get('Status')

@property
def address(self):
data = self._get('Address')
scheme = data['Scheme']
user = data['User']
host = data['Host']
path = data['Path']
raw_query = data['RawQuery']

auth = f'{user}@' if user else ''
query = f'?{raw_query}' if raw_query else ''
return f"{scheme}://{auth}{host}{path}{query}"

@property
def host_(self):
address = self._get('HostAddr')
port = self._get('HostPort')
return f"{address}:{port}"

def app(self):
from tsuru import App

return App(data={'name': self.app_name})

0 comments on commit b2f4462

Please sign in to comment.