Administrators - AVDeskAdmin class¶
Administrator pyavdesk resource described by AVDeskAdmin class exposes an interface to manipulate server administrators.
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 AVDeskAdmin class.
Basic class usage example:
# Setting up server connection parameters.
av_server = pyavdesk.AVDeskServer('admin', 'password', 'http://192.168.1.70')
# Get main administrator (his login is 'admin').
superadmin = av_server.get_administrator('admin')
print superadmin.name
# Create new administrator.
new_admin = av_server.new_administrator('my_new_admin')
new_admin.name = 'Fred'
new_admin.last_name = 'Colon'
new_admin.save()
print 'Password for Fred is "%s"' % new_admin.password
- class pyavdesk.pyavdesk.AVDeskAdmin(connector_resource, resource_id=None, predefined_handle=None)¶
AV-Desk administrator resource class is used to perform manipulations on administrators.
Parameters: - connector_resource – should be AVDeskServer instance.
- resource_id – if set server call is performed to get information for resource with given ID.
- predefined_handle – if set, resource data could be fetched from a resource at given handle.
Raises: AVDeskError on failure
- add_to_groups(groups_list)¶
Add groups to resource association by group IDs or objects.
Parameters: groups_list – list of AVDeskGroup instances, or a list of strings representing groups IDs Raises: AVDeskError on failure Note
Resource to group association is not sent to server until object’s save() is not called.
Warning
Some AV-Desk server versions (namely 6.2) might handle only one group per administrator. In that case only the first group from the given list is linked with the administrator.
Example:
resource_obj.add_to_groups(['my_group_id', my_another_group_obj]) resource_obj.save()
- create(auto_retrieve=True)¶
Performs a server call to create resource with properties defined in object.
Note
There is a convinience method save() to handle both create and update operations.
Parameters: auto_retrieve – boolean to specify whether an additional call to server is required after the update operation to retrieve full resource data. Default: True. Returns: True on success Raises: AVDeskError on failure Warning
Setting auto_retrieve to False may increase operation performance, but also may leave the resource object data in a not up-to-date state. It is advised that auto_retrieve set to False is only used when the resource object won’t be used further after the operation.
Example:
created = resource_obj.create()
- delete(**kwargs)¶
Performs server call in an attempt to delete the resource.
Returns: True on success Raises: AVDeskError on failure Example:
deleted = resource_obj.delete()
- delete_from_groups(groups_list)¶
Removes groups to resource association by group IDs or objects.
Parameters: groups_list – list of AVDeskGroup instances, or a list of strings representing groups IDs Raises: AVDeskError on failure Note
Resource to group association is not sent to server until object’s save() is not called.
Example:
resource_obj.delete_from_groups(['my_group_id', my_another_group_obj]) resource_obj.save()
- get_groups(as_id=True)¶
Performs a server call and returns a list of groups associated with the resource.
Parameters: as_id – boolean. If True list of AVDeskGroup instances is returned, if False - list of strings representing groups IDs Returns: list of objects which type is defined by as_id parameter Raises: AVDeskError on failure Note
Objects in the list returned have only basic information. To get full infomation use AVDeskGroup.retrieve_info().
Example:
groups = resource_obj.get_groups() for group in groups: print 'Group ID - %s' % group.id
- 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
- is_global_admin¶
This property is a boolen used to identify administrator as global (i.e. his powers are not restricted to certain group(s)).
- is_group_admin¶
This property is a boolen used to identify that administrator’s powers are restricted to certain group(s).
- last_name¶
This property is used to get or set administarator last name.
- login¶
This property is used to get or set administarator login.
- make_global_admin()¶
Shortcut method method that removes the administrator from all groups he is associated with, thus making him a global administrator.
Under the hood it utilizes get_groups() and delete_from_groups() methods.
Returns: None Raises: AVDeskError on failure Example:
my_admin.make_global_admin()
- middle_name¶
This property is used to get or set administarator middle name.
- password¶
This property is used to get or set administarator password.
- readonly¶
This property is used to get or set administarator readonly boolean restriction flag. If readonly flag is set to True administrator would be unable to perform create/update/delete actions on server resources.
- restrictions¶
This property is used to get or set restrictions for an administrator. Some operations on stations (e.g. changing expires, block period, parent group) will be restricted if True is passed. NOTE: This applies only to group administrators.
- retrieve_info(resource_id=None)¶
Performs a server call to retrieve complete resource information by its ID and puts it into object’s properties.
Parameters: resource_id – specific ID of the resource. If None, ID is taken from the object itself. Raises: AVDeskError on failure Example:
# resource_obj contains no additional info. assert resource_obj.name is None # After the following request resource_obj.retrieve_info('some_resource_id') # resource_obj contains additional info. assert resource_obj.name is not None
- right_create_admins¶
This property is used to get or set administarator’s right to create other administrators. NOTE: Only for group administrators.
- save(auto_retrieve=True)¶
A convinience method that automatically creates new resource on server if it doesn’t exists or updates it if it does.
Under the hood it switches between create() and update() methods.
Parameters: auto_retrieve – boolean to specify whether an additional call to server is required after the save operation to retrieve full resource data. Default: True. Returns: True on success Raises: AVDeskError on failure Warning
Setting auto_retrieve to False may increase operation performance, but also may leave the resource object data in a not up-to-date state. It is advised that auto_retrieve set to False is only used when the resource object won’t be used further after the operation.
Example:
saved = resource_obj.save()
- update(auto_retrieve=True)¶
Performs server call in attempt to update the resource with information from class properties.
Note
There is a convinience method save() to handle both create and update operations.
Parameters: auto_retrieve – boolean to specify whether an additional call to server is required after the update operation to retrieve full resource data. Default: True. Returns: True on success Raises: AVDeskError on failure Warning
Setting auto_retrieve to False may increase operation performance, but also may leave the resource object data in a not up-to-date state. It is advised that auto_retrieve set to False is only used when the resource object won’t be used further after the operation.
Example:
updated = resource_obj.update()