from sfa.util.sfalogging import logger
from sfa.util.defaultdict import defaultdict
from sfa.util.sfatime import utcparse, datetime_to_string, datetime_to_epoch
-from sfa.util.xrn import Xrn, hrn_to_urn, get_leaf, urn_to_sliver_id
+from sfa.util.xrn import Xrn, hrn_to_urn, get_leaf
from sfa.openstack.osxrn import OSXrn, hrn_to_os_slicename, hrn_to_os_tenant_name
from sfa.util.cache import Cache
from sfa.trust.credential import Credential
raise SliverDoesNotExist("You have not allocated any slivers here")
result = {}
- top_level_status = 'unknown'
- if instances:
- top_level_status = 'ready'
+ top_level_status = 'ready'
result['geni_urn'] = slice_urn
result['plos_login'] = 'root'
# do we need real dates here?
res['plos_created_at'] = datetime_to_string(utcparse(instance.created))
res['plos_boot_state'] = instance.status
res['plos_sliver_type'] = self.shell.nova_manager.flavors.find(id=instance.flavor['id']).name
- sliver_id = Xrn(slice_urn).get_sliver_id(instance.id)
- res['geni_urn'] = sliver_id
+ res['geni_urn'] = Xrn(slice_urn, type='slice', id=instance.id).get_urn()
if instance.status.lower() == 'active':
res['boot_state'] = 'ready'
else:
res['boot_state'] = 'unknown'
res['geni_status'] = 'unknown'
+ top_level_status = 'unknown'
resources.append(res)
result['geni_status'] = top_level_status
def instance_to_sliver(instance, slice_xrn=None):
sliver_id = None
- if slice_xrn:
- xrn = Xrn(slice_xrn, 'slice')
- sliver_id = xrn.get_sliver_id(instance.project_id, instance.hostname, instance.id)
-
- sliver = Sliver({'slice_id': sliver_id,
- 'name': instance.name,
+ sliver = Sliver({'name': instance.name,
'type': instance.name,
'cpus': str(instance.vcpus),
'memory': str(instance.ram),
flavor = self.driver.shell.nova_manager.flavors.find(id=instance.flavor['id'])
sliver = instance_to_sliver(flavor)
rspec_node['slivers'].append(sliver)
+ sliver_xrn = OSXrn(xrn=slice_xrn, type='slice', id=instance.id)
+ rspec_node['sliver_id'] = sliver_xrn.get_urn()
image = self.driver.shell.image_manager.get_images(id=instance.image['id'])
if isinstance(image, list) and len(image) > 0:
image = image[0]
for private_ip in addresses.get('private', []):
if_xrn = PlXrn(auth=self.driver.hrn,
- interface='node%s:eth0' % (instance.hostId))
- interface = Interface({'component_id': if_xrn.urn})
+ interface='node%s' % (instance.hostId))
+ if_client_id = Xrn(if_xrn.urn, type='interface', id="eth%s" %if_index).urn
+ interface = Interface({'component_id': if_xrn.urn,
+ 'client_id': if_client_id})
interface['ips'] = [{'address': private_ip['addr'],
#'netmask': private_ip['network'],
- 'type': private_ip['version']}]
+ 'type': 'ipv%s' % str(private_ip['version'])}]
rspec_node['interfaces'].append(interface)
# slivers always provide the ssh service
from copy import deepcopy
from StringIO import StringIO
-from sfa.util.xrn import Xrn, urn_to_sliver_id
+from sfa.util.xrn import Xrn
from sfa.rspecs.version import RSpecVersion
from sfa.rspecs.elements.versions.pgv2Link import PGv2Link
from sfa.rspecs.elements.versions.pgv2Node import PGv2Node
# set the sliver id
#slice_id = sliver_info.get('slice_id', -1)
#node_id = sliver_info.get('node_id', -1)
- #sliver_id = urn_to_sliver_id(sliver_urn, slice_id, node_id)
+ #sliver_id = Xrn(xrn=sliver_urn, type='slice', id=str(node_id)).get_urn()
#node_elem.set('sliver_id', sliver_id)
# add the sliver type elemnt
def hrn_to_urn(hrn,type): return Xrn(hrn, type=type).urn\r
def hrn_authfor_hrn(parenthrn, hrn): return Xrn.hrn_is_auth_for_hrn(parenthrn, hrn)\r
\r
-def urn_to_sliver_id(urn, slice_id, node_id, index=0, authority=None):\r
- return Xrn(urn).get_sliver_id(slice_id, node_id, index, authority)\r
-\r
class Xrn:\r
\r
########## basic tools on HRNs\r
# self.type\r
# self.path\r
# provide either urn, or (hrn + type)\r
- def __init__ (self, xrn, type=None):\r
+ def __init__ (self, xrn, type=None, id=None):\r
if not xrn: xrn = ""\r
# user has specified xrn : guess if urn or hrn\r
+ self.id = id\r
if Xrn.is_urn(xrn):\r
self.hrn=None\r
self.urn=xrn\r
+ if id:\r
+ self.urn = "%s:%s" % (self.urn, str(id))\r
self.urn_to_hrn()\r
else:\r
self.urn=None\r
self._normalize()\r
return ':'.join( [Xrn.unescape(x) for x in self.authority] )\r
\r
- def get_sliver_id(self, slice_id, node_id=None, index=0, authority=None):\r
+ def set_authority(self, authority):\r
+ """\r
+ update the authority section of an existing urn\r
+ """\r
+ authority_hrn = self.get_authority_hrn()\r
+ if not authority_hrn.startswith(authority):\r
+ hrn = ".".join([authority,authority_hrn, self.get_leaf()])\r
+ else:\r
+ hrn = ".".join([authority_hrn, self.get_leaf()])\r
+ \r
+ self.hrn = hrn \r
+ self.hrn_to_urn()\r
self._normalize()\r
- urn = self.get_urn()\r
- if authority:\r
- authority_hrn = self.get_authority_hrn()\r
- if not authority_hrn.startswith(authority):\r
- hrn = ".".join([authority,authority_hrn, self.get_leaf()])\r
- else:\r
- hrn = ".".join([authority_hrn, self.get_leaf()])\r
- urn = Xrn(hrn, self.get_type()).get_urn()\r
- parts = [part for part in [urn, slice_id, node_id, index] if part is not None]\r
- return ":".join(map(str, [parts]))\r
-\r
+ \r
def urn_to_hrn(self):\r
"""\r
compute tuple (hrn, type) from urn\r
hrn = '.'.join([Xrn.escape(part).replace(':','.') for part in parts if part])\r
# dont replace ':' in the name section\r
if name:\r
+ parts = name.split(':')\r
+ if len(parts) > 1:\r
+ self.id = ":".join(parts[1:])\r
+ name = parts[0] \r
hrn += '.%s' % Xrn.escape(name) \r
\r
self.hrn=str(hrn)\r
urn = "+".join(['',authority_string,Xrn.unescape(name)])\r
else:\r
urn = "+".join(['',authority_string,self.type,Xrn.unescape(name)])\r
- \r
+\r
+ if hasattr(self, 'id') and self.id:\r
+ urn = "%s:%s" % (urn, self.id) \r
+\r
self.urn = Xrn.URN_PREFIX + urn\r
\r
def dump_string(self):\r