Server - AVDeskServer class

Server resource is a basic resource of pyavdesk. It gives an access both to server properties (statistics, key, etc.) and other resources manipulation means (creating and fetching server groups, tariffs, stations, etc.).

Note

It is advised to use server resource class AVDeskServer as a single entry point for every server resource manipulation instead of direct instantiation of other resources classes (AVDeskGroup, AVDeskStation, etc.).

Basic class usage example:

# Setting up server connection parameters.
av_server = pyavdesk.AVDeskServer('admin', 'password', 'http://192.168.1.70')

# Printing out server OS.
info = av_server.get_info()
print 'OS used - %s' % info['os']

# Printing out names of tariffs available at server.
tariffs = av_server.get_tariffs()
for tariff in tariffs:
    print 'Tariff "%s" is available' % tariff.name

# Getting server groups and printing out their IDs.
groups = av_server.get_groups()
for group in groups:
    print 'A group with ID - %s' % group.id

# Creating a new group.
my_group = av_server.new_group('My Group')
my_group.save()
print 'Server generated group ID - "%s"' % my_group.id

# Getting server stations ID printed out.
# Note though that some AV-Desk versions may return an empty list here.
stations = av_server.get_stations()
for station in stations:
    print 'Station found - %s' % station
class pyavdesk.pyavdesk.AVDeskServer(login, password, url='http://127.0.0.1', port=9080, connection_timeout=2)

This is a basic pyavdesk class, providing server connection handle, and essential methods to manipulate server resources.

Note

If url parameter value contains https dwavdapi library will try to verify connection certificate automatically. This behavior can be changed with verify_connection_certificate().

Parameters:
  • login – is the login of user from whose name module issues connection
  • password – user password used for connection
  • url – should be set to AV-Desk web-server URL
  • port – should be set to AV-Desk web-server port
  • connection_timeout – connection timeout in seconds
Returns:

AVDeskServer instance

Raises:

AVDeskError on failure

Example:

# Setting up the connection data with timeout equal to 5 seconds.
av_server = pyavdesk.AVDeskServer('admin', 'password', 'http://192.168.1.70', connection_timeout=5)
get_administrator(administrator_login)

Returns administrator resource object from server by login.

Parameters:administrator_login – administrator login to retrieve information for
Returns:AVDeskAdmin instance
Raises:AVDeskError on failure

Example:

admin_fred = av_server.get_administrator('fred_colon')
print 'Admin ID - %s' % admin_fred.id
get_administrators()

Returns a list of administator objects registered at server, performing server call.

Note

Objects in the list returned have only basic information. To get full infomation use AVDeskAdmin.retrieve_info().

Returns:list of AVDeskAdmin instances
Raises:AVDeskError on failure

Example:

administrators = av_server.get_administrators()
for administrator in administrators:
    print 'An administrator with login - %s' % administrator.login
get_group(group_id)

Returns group resource object from server by ID.

Parameters:group_id – group ID to retrieve information for
Returns:AVDeskGroup instance
Raises:AVDeskError on failure

Example:

everyone = av_server.get_group(pyavdesk.META_GROUP_IDS['EVERYONE'])

In this example we use META_GROUP_IDS dictionary defined in the module to get ‘EVERYONE’ meta-group ID from to pass it to the method.

get_groups()

Returns a list of groups objects registered at server, performing server call.

Note

Objects in the list returned have only basic information. To get full infomation use AVDeskGroup.retrieve_info().

Returns:list of AVDeskGroup instances
Raises:AVDeskError on failure

Example:

groups = av_server.get_groups()
for group in groups:
    print 'A group with ID - %s' % group.id
get_info()

Makes request to a server and returns a dictionary with basic information about server.

Example:

info = av_server.get_info()

An extract from dictionary returned:

{
    'api_build': '201110201',
    'groups_system': 85,
    'uptime': 98544,
    'tariffs_total': 25,
    'stations_total': 283,
    'os': 'Linux',
     ...
}
Returns:dictionary
Raises:AVDeskError on failure
get_key_info()

Makes request to a server and returns a dictionary with information about AV-Desk server key.

Example:

info = av_server.get_key_info()

An extract from dictionary returned:

{
    'expires_ts': 1341867133,
    'created_ts': 1310158333,
    'servers': 1,
    'sn': None,
    'md5': '6036761418df7065dab1518afd2cf1e7'
    ...
}
Returns:dictionary
Raises:AVDeskError on failure
get_repositories()

Makes request to a server and returns a dictionary with data about repositories used by server.

Returns:list of dictionaries
Raises:AVDeskError on failure

An extract from repositories data list:

[
    {
        'state': 'ok',
        'code': '20-drwwince',
        'name': 'Mobile Dr.Web AV-Desk Agent',
        'rev_date_ts': 1311239190,
        'rev_id': 1311239190
    },
    ...
]

Code sample:

repositories = av_server.get_repositories()
for repository in repositories:
    print 'Repository "%s" -> "%s"' % (repository['code'], repository['state'])
get_resource_id()

Helper method to get resource identifier, which can be passed to such resource manipulation methods as get_info() and delete().

Returns:resource identifier as string
get_station(station_id)

Returns station resource object from server by ID.

Parameters:station_id – station ID to retrieve information for
Returns:AVDeskStation instance
Raises:AVDeskError on failure

Example:

station = avdesk.get_station('my_station')
print station.name
get_stations(as_id=True)

Shortcut method that returns a list of stations registered at server through Everyone system group quering.

Parameters:as_id – boolean flag. If True list of AVDeskStation instances is returned, if False - list of strings representing station IDs.
Returns:list of objects which type is defined by as_id parameter
Raises:AVDeskError on failure

Warning

Setting as_id parameter to False may lead to considerable server load, since separate server call is performed to retrieve full station information. One should bear it in mind when querying servers with large amount of stations.

Example:

stations = av_server.get_stations()
for station in stations:
    print 'Station ID - %s' % station.id
get_statistics(ts_from=0, ts_till=0, virus_limit=10)

Makes request to a server and returns a dictionary with overall server statistics.

Parameters:
  • ts_from – timestamp of when statistics starts. If 0 - statistics starts at year 1970. Default 0.
  • ts_till – timestamp of when staristics ends. If 0 - statistics ends today. Default 0.
  • virus_limit – virus statistics limiter, to return no more than a given number of viruses. Default 10.
Returns:

dictionary

Raises:

AVDeskError on failure

Example:

stats = av_server.get_statistics()

An extract from dictionary returned:

{
    'groups_system': 85,
    'tariffs_total': 25,
    'traffic': {
        'total': 1140022.0,
        'out': 322671.0,
        'in': 817351.0
    },
    'stations_total': 283,
    'stations_state': {
        'unactivated': 270,
        'activated': 13,
        'deinstalled': 0,
        ...
    },
    ...
}
get_tariff(tariff_id)

Returns tariff group resource object from server by ID.

Parameters:tariff_id – tariff group ID to retrieve information for
Returns:AVDeskTariff instance
Raises:AVDeskError on failure

Example:

tariff_group = avdesk.get_tariff('my_tariff')
print tariff_group.name
get_tariffs()

Returns a list of tariff group objects registered at server, performing server call.

Note

Objects in the list returned have only basic information. To get full infomation use AVDeskTariff.retrieve_info().

Returns:list of AVDeskTariff instances
Raises:AVDeskError on failure

Example:

tariffs = av_server.get_tariffs()
for tariff in tariffs:
    print 'Tariff named "%s"' % tariff.name
new_administrator(administrator_login, password=None)

Initializes new AVDeskAdmin object with given parameters and returns it for further usage.

Parameters:
  • administrator_login – login for new administrator
  • password – password for new administrator. If None password is generated by server and available from AVDeskAdmin.password after object is saved.
Returns:

AVDeskAdmin

Example:

administrator = avdesk.new_administrator('fred_colon')
administrator.save()
print 'Server generated password - "%s"' % administrator.password
new_group(group_name, id=None, parent_group=None)

Initializes new AVDeskGroup object with given parameters and returns it for further usage.

Parameters:
  • group_name – name for the group
  • id – group ID. If None group ID is generated by server and available from AVDeskGroup.id after object is saved
  • parent_group – parent group ID or object. Note: parent group must already exist on server.
Returns:

AVDeskGroup

Example:

group = avdesk.new_group('My Group', parent_group=my_parent_group)
group.save()
print 'Server generated group ID - "%s"' % group.id
new_station(id=None, parent_group=None, tariff=None)

Initializes new AVDeskStation object with given parameters and returns it for further usage.

Parameters:
  • id – station ID. If None station ID is generated by server and available from AVDeskStation.id after object is saved.
  • parent_group – parent group ID or object. Note: parent group must already exist on server.
  • tariff – tariff group ID or object. Note: tariff group must already exist on server.
Returns:

AVDeskStation

Example:

station = avdesk.new_station('My Station', parent_group=my_parent_group, tariff='tariff_id')
station.save()
print 'Server generated station ID - "%s"' % station.id
new_tariff(tariff_name, id=None, parent_tariff=None, grace_period=None)

Initializes new AVDeskTariff object with given parameters and returns it for further usage.

Parameters:
  • tariff_name – name for the tariff group
  • id – tariff group ID. If None tariff group ID is generated by server and available from AVDeskTariff.id after object is saved.
  • parent_tariff – parent tariff group ID or object. Note: parent tariff group must already exist on server.
  • grace_period – grace period rot this tariff in days.
Returns:

AVDeskTariff

Example:

tariff = avdesk.new_tariff('My Tariff', parent_tariff='my_parent_tariff_id')
tariff.save()
print 'Server generated tariff ID - "%s"' % tariff.id
run_task(task_id)

Requests a server to execute the task defined by its ID string.

Parameters:task_id – task identifier string.
Raises:AVDeskError on failure
set_user_agent(title)

Instructs dwavdapi library to use the given User Agent string on server requests.

Parameters:title – User Agent string.
Returns:boolean. True on success, overwise - False
Raises:AVDeskError on failure
switch_to_debug_mode(log_filepath=None)

Permanently switches dwavdapi library into debug mode when debugging information including server responses is written into a file.

Parameters:log_filepath – absolute path to file to write logs into. If None libdwavdapi.log in module’s directory will be used.
Returns:boolean. True if successfully switched, overwise - False
Raises:AVDeskError on failure
verify_connection_certificate(do_verify, certificate_path=None)

Gives dwavdapi library an instruction to verify or not to verify connection certificate.

Parameters:
  • do_verify – boolean. If True connection certificate will be verified.
  • certificate_path – expects full path to root certificate to verify connection validity against, or None is system certificates should be used.
Raises:

AVDeskError on failure