def __init__(self, server, host): """.. function:: init(server, host) Setup communication channel for CRUD operations against cvbn-guest-agent via CvBB/CvBN. CvBB - HTTP protocol and REST syntax with default CvBB port (8280) CvBN - HTTP protocol and RPC specific syntax with default CvBN port (26265) Autodiscovery of CvBB vs. CvBN There is no authentication. :param server: FQDN/IP of the server CvBB/CvBN :param host: if 'server' is CvBB, then 'host' must be UUID of the CvBN server. Otherwise it can be anything >>> import cvbn_server >>> server=cvbn_server.vbn("localhost","none") """ port = self._determine_rpc_port(server) factory = RpcMethodFactory.factory( '{}:{}'.format(server, str(port)) ) self._walk_method = factory.method('walk') self._get_method = factory.method('get') self._set_method = factory.method('set') self._delete_method = factory.method('delete') self.agent = host + '/cvbn-guest-agent' self.cid = 'magic'
def _determine_rpc_port(server): '''check for qvbb rest interface present or not''' factory = RpcMethodFactory.factory('{}:26265'.format(server)) try: factory.method('get').invoke( 'cvbn-service-agent', 'magic', { 'tid': 'website', 'name': 'cvbb-rest-interface', }) except (RpcMethodError): return 26265 else: return 8280