This package covers basic Jerasoft VCS API functions to integrate it with external services.
In settings.py under default section one can setup some sane defaults that would be
used when not set explicitly. The token and endpoint parameters should be set to actual
Jerasoft VCS API token and full API url respectfully.
Fill those values in settings.py and then just import jerasoft package with:
import jerasoftto start working.
Print an Client object with id 68:
>>> jerasoft.Clients(68)
<Clients: 68 CF: Тестеренко А.Пи. 0.0>Print client name:
>>> print(jerasoft.Clients(68).name)
CF: Тестеренко А.Пи.Get client balance:
>>> jerasoft.Clients(68).balance()
0.0Get client status:
>>> jerasoft.Clients(68).status
u'active'Get credit balance:
>>> jerasoft.Clients(68).credit
0.0Get client email:
>>> jerasoft.Clients(68).c_email_billing
u'chop@chop.ch'All the fields of Client entity returned by Jerasoft VCS may be requested this way. There is also possibility to request raw data for custom interactions:
>>> jerasoft.Clients(68).get()
{u'balance_accountant': 0.0, u'low_balance_capacity': None, u'autoinvoice_enabled': False,
u'invoice_no_tpl': u'invoice-%N-%X', u'orig_capacity': ............ }>>> client = jerasoft.Clients(68)
>>> client.delete()
(True, '')>>> client = jerasoft.Clients(68)
>>> client.archive()
(True, '')>>> params = {"name": "Тестеренко А.Пи. 47"}
>>> client = jerasoft.Clients(68)
>>> client.update(**params)
(True, '')
>>> client.name
u'\u0422\u0435\u0441\u0442\u0435\u0440\u0435\u043d\u043a\u043e \u0410.\u041f\u0438. 47'
>>> print(client.name)
Тестеренко А.Пи. 47or just
>>> client = jerasoft.Clients(68)
>>> client.update(name="Тестеренко А.Пи. 47")
(True, '')
>>> print(client.name)
Тестеренко А.Пи. 47Multiple attributes may be updated in single client.update() call.
>>> params = {"name": u"Тестеренко А.Пи. Esq", "c_company": "Defaults", "c_email_billing":
"chop@chop.ch"}
>>> client = jerasoft.Clients()
>>> client.create(**params)
(True, 69)
>>> client.id
69
>>> print(client.name)
CF: Тестеренко А.Пи. EsqOther Client entity attributes (like rate id, currency id, start balance etc) may be passed in params too, sane defaults from settings.py would be used if they are not set.
>>> client = jerasoft.Clients(69)
>>> params = {"stop_days": 30, "packages_id": 6}
>>> client.add_package(**params)
(True, '')If one wants to set the default package to Client, passing params to client.add_package() may be skipped:
>>> client = jerasoft.Clients(69)
>>> client.add_package()
(True, '')>>> import jerasoft, uuid
>>> params = {"clients_id": 69, "ipaddr": "127.0.0.69", "ani": uuid.uuid4().hex, "name": "my-server"}
>>> account = jerasoft.Accounts()
>>> account.create(**params)
(True, 242)
>>> account.id
242
>>> account.name
u'127.0.0.69 my-server'
>>> account.clients_id
69
>>> print(account.clients_name)
CF: Тестеренко А.Пи. EsqOther Account entity attributes (like rate id, authentication type etc) may be passed in params too, sane defaults from settings.py would be used if they are not set.
Print an Account object with id 242:
>>> jerasoft.Accounts(242)
<Accounts: 242 127.0.0.69 my-server>Print account name:
>>> jerasoft.Accounts(242).name
u'127.0.0.69 my-server'Print account rate id:
>>> jerasoft.Accounts(242).orig_rate_table
19Print client name and id, associated with this account:
>>> jerasoft.Accounts(242).clients_id
69
>>> print(jerasoft.Accounts(242).clients_name)
CF: Тестеренко А.Пи. EsqAll the fields of Account entity returned by Jerasoft VCS may be requested this way. There is also possibility to request raw data for custom interactions:
>>> jerasoft.Accounts(242).get()
{u'auth_type': u'ani', u'protocol': None, u'dr_plans_id': None, u'ani':
u'52add16b1d4f4ee987fc9c2b05c64a7f', u'orig_capacity': None, u'ips': [], u'term_tags': [],
u'term_capacity': None, u'id': 242, u'orig_enabled': True, u'clients_id': 69, u' ............ }>>> jerasoft.Accounts(242).delete()
(True, '')>>> jerasoft.Accounts(242).ani
u'52add16b1d4f4ee987fc9c2b05c64a7f'
>>> params = {"ani": uuid.uuid4().hex}
>>> jerasoft.Accounts(242).update(**params)
(True, '')
>>> jerasoft.Accounts(242).ani
u'f086a5a04a534ac58b4ffb2621b71c49'or
>>> jerasoft.Accounts(242).update(ani=uuid.uuid4().hex)
(True, '')
>>> print(account.ani)
u'f086a5a04a534ac58b4ffb2621b71c49'Multiple attributes may be updated in single Accounts update() call.
>>> jerasoft.Rates(19).get()
[{u'status': u'active', u'effective_till': u'9999-12-31 23:59:59', u'code': u'cpu_fix', u'rate_tables_id': 19,
u'end_date': None, u'currencies_id': 27, ............ }>>> jerasoft.Rates(19).codes()
[u'cpu_fix', u'cpu_scale', u'ram_fix', u'ram_scale', u'hdd_150', u'hdd_1500', u'cpu_fix_off',
u'cpu_scale_off', u'ram_fix_off', u'ram_scale_off', u'hdd_150_off', u'hdd_1500_off', u'ip_setup',
u'ip_usage', u'network', u'internet']>>> from pprint import pprint
>>> pprint(jerasoft.Rates(19).by_code("cpu_fix"))
{u'code': u'cpu_fix',
u'code_name': u'CPU utilization',
u'currencies_id': 27,
u'effective_from': u'2017-07-14 00:00:00+0300',
u'effective_till': u'9999-12-31 23:59:59',
u'end_date': None,
u'grace_volume': 0,
u'id': 1122989,
u'min_volume': 3600,
u'notes': None,
u'pay_interval': 3600,
u'pay_setup': 0.0,
u'policy': u'regular',
u'rate_tables_id': 19,
u'services_id': 1,
u'status': u'active',
u'tag': u'@',
u'time_profiles_id': 1,
u'value': 0.406090902}For example, selecting the service unit cost for service with code cpu_fix:
>>> jerasoft.Rates(19).by_code("cpu_fix").get("value")
0.406090902Example of getting charges list for account id 242 using date interval:
>>> report = jerasoft.Reports(242)
>>> report
<Reports: 242>
>>> report.get("2017-10-16", "2017-10-16")
[]Calling report.get() without arguments will select charges at current date:
>>> report = jerasoft.Reports(242)
>>> report.get()
[]Example of getting transactions for client id 69:
>>> trans = jerasoft.Transactions(69)Get the sum of all transactions:
>>> trans.counted
-200.0Get the list of transactions:
>>> trans.charges
[{'date': u'2017-10-17 16:48:50+0300', 'comment': u'Package pending payment: test', 'amount':
-100.0}, {'date': u'2017-10-17 16:51:42+0300', 'comment': u'Package pending payment: test',
'amount': -100.0}]Raw response from Jerasoft VCS:
>>> trans.raw_charges
[{u'status': u'pending', u'c_dt': u'2017-10-17 16:48:50+0300', u'companies_id': 24, u'clients_id': 69,
u'currencies_id': 27, u'type': u'charge', u'notes': u'P ............... }Jerasoft VCS vendor web-site all the product info and documentation
python-digitalocean was a package design influence.