# TODO: Investigate ways to combine this with existing PLC API?
##
+### $Id$
+### $URL$
+
import xmlrpclib
from gid import *
pass
class ExceptionUnmarshaller(xmlrpclib.Unmarshaller):
- def close(self):\r
- try:\r
- return xmlrpclib.Unmarshaller.close(self)\r
- except xmlrpclib.Fault, e:\r
+ def close(self):
+ try:
+ return xmlrpclib.Unmarshaller.close(self)
+ except xmlrpclib.Fault, e:
raise ServerException(e.faultString)
##
class GeniTransport(xmlrpclib.Transport):
key_file = None
cert_file = None
- def make_connection(self, host):\r
- # create a HTTPS connection object from a host descriptor\r
- # host may be a string, or a (host, x509-dict) tuple\r
- import httplib\r
- host, extra_headers, x509 = self.get_host_info(host)\r
- try:\r
- HTTPS = httplib.HTTPS()\r
- except AttributeError:\r
- raise NotImplementedError(\r
- "your version of httplib doesn't support HTTPS"\r
- )\r
- else:\r
- return httplib.HTTPS(host, None, key_file=self.key_file, cert_file=self.cert_file) #**(x509 or {}))\r
-\r
- def getparser(self):\r
- unmarshaller = ExceptionUnmarshaller()\r
- parser = xmlrpclib.ExpatParser(unmarshaller)\r
- return parser, unmarshaller\r
-\r
-##\r
-# The GeniClient class provides stubs for executing Geni operations. A given\r
-# client object connects to one server. To connect to multiple servers, create\r
-# multiple GeniClient objects.\r
-#\r
-# The Geni protocol uses an HTTPS connection, and the client's side of the\r
-# connection uses his private key. Generally, this private key must match the\r
-# public key that is containing in the GID that the client is providing for\r
-# those functions that take a GID.\r
-\r
+ def make_connection(self, host):
+ # create a HTTPS connection object from a host descriptor
+ # host may be a string, or a (host, x509-dict) tuple
+ import httplib
+ host, extra_headers, x509 = self.get_host_info(host)
+ try:
+ HTTPS = httplib.HTTPS()
+ except AttributeError:
+ raise NotImplementedError(
+ "your version of httplib doesn't support HTTPS"
+ )
+ else:
+ return httplib.HTTPS(host, None, key_file=self.key_file, cert_file=self.cert_file) #**(x509 or {}))
+
+ def getparser(self):
+ unmarshaller = ExceptionUnmarshaller()
+ parser = xmlrpclib.ExpatParser(unmarshaller)
+ return parser, unmarshaller
+
+##
+# The GeniClient class provides stubs for executing Geni operations. A given
+# client object connects to one server. To connect to multiple servers, create
+# multiple GeniClient objects.
+#
+# The Geni protocol uses an HTTPS connection, and the client's side of the
+# connection uses his private key. Generally, this private key must match the
+# public key that is containing in the GID that the client is providing for
+# those functions that take a GID.
+
class GeniClient():
##
# Create a new GeniClient object.
# @return a credental object
def get_credential(self, cred, type, name):
- if cred == None:
- return self.get_self_credential(type, name)
- cred_str = self.server.get_credential(cred.save_to_string(save_parents=True), type, name)
+ if cred:
+ cred = cred.save_to_string(save_parents=True)
+ cred_str = self.server.get_credential(cred, type, name)
return Credential(string = cred_str)
##
# Geni database, the appropriate records will also be created in the
# PLC databases.
#
- # The geni_info and/or pl_info fields must in the record must be filled
- # out correctly depending on the type of record that is being registered.
#
- # TODO: The geni_info member of the record should be parsed and the pl_info
- # adjusted as necessary (add/remove users from a slice, etc)
#
# @param cred credential object specifying rights of the caller
# @return record to register
result_dict_list = self.server.resolve(cred.save_to_string(save_parents=True), name)
result_rec_list = []
for dict in result_dict_list:
- result_rec_list.append(GeniRecord(dict=dict))
+ if dict['type'] in ['authority']:
+ result_rec_list.append(AuthorityRecord(dict=dict))
+ elif dict['type'] in ['node']:
+ result_rec_list.append(NodeRecord(dict=dict))
+ elif dict['type'] in ['slice']:
+ result_rec_list.append(SliceRecord(dict=dict))
+ elif dict['type'] in ['user']:
+ result_rec_list.append(UserRecord(dict=dict))
+ else:
+ result_rec_list.append(GeniRecord(dict=dict))
return result_rec_list
##
# PLC information associated with the record. The Geni fields (name, type,
# GID) are fixed.
#
- # The record is expected to have the pl_info field filled in with the data
- # that should be updated.
#
- # TODO: The geni_info member of the record should be parsed and the pl_info
- # adjusted as necessary (add/remove users from a slice, etc)
#
# @param cred credential object specifying rights of the caller
# @param record a record object to be updated
# Aggregate Interface
#-------------------------------------------------------------------------
- ## list components
- #
- #
- def list_nodes(self, cred):
-
- result = self.server.list_nodes(cred.save_to_string(save_parents=True))
- return result
-
## list resources
#
# @param cred a credential
result = self.server.get_resources(cred.save_to_string(save_parents=True), hrn)
return result
+ def get_aggregates(self, cred, hrn=None):
+ result = self.server.get_resources(cred.save_to_string(save_parents=True), hrn)
+ return result
+
## get policy
#
# @param cred a credential
# @param cred a credential identifying the caller (callerGID) and the slice
# (objectGID)
- def start_slice(self, cred):
- result = self.server.start_slice(cred.save_to_string(save_parents=True))
+ def start_slice(self, cred, hrn):
+ result = self.server.start_slice(cred.save_to_string(save_parents=True), hrn)
return result
##
# @param cred a credential identifying the caller (callerGID) and the slice
# (objectGID)
- def stop_slice(self, cred):
- result = self.server.stop_slice(cred.save_to_string(save_parents=True))
+ def stop_slice(self, cred, hrn):
+ result = self.server.stop_slice(cred.save_to_string(save_parents=True), hrn)
return result
##
# @param cred a credential identifying the caller (callerGID) and the slice
# (objectGID)
- def reset_slice(self, cred):
- result = self.server.reset_slice(cred.save_to_string(save_parents=True))
+ def reset_slice(self, cred, hrn):
+ result = self.server.reset_slice(cred.save_to_string(save_parents=True), hrn)
return result
##
#
# @return a list of slice names
- def list_slices(self, cred):
- result = self.server.list_slices(cred.save_to_string(save_parents=True))
+ def get_slices(self, cred):
+ result = self.server.get_slices(cred.save_to_string(save_parents=True))
return result
##