AddressPool object
diff --git a/xos/configurations/cord/cord.yaml b/xos/configurations/cord/cord.yaml
index df13312..ec2cd6f 100644
--- a/xos/configurations/cord/cord.yaml
+++ b/xos/configurations/cord/cord.yaml
@@ -24,6 +24,11 @@
view_url: /admin/cord/voltservice/$id$/
kind: vOLT
+ public_addresses:
+ type: tosca.nodes.AddressPool
+ properties:
+ addresses: 10.123.0.0/24 10.124.0.0/24
+
service_vsg:
type: tosca.nodes.VSGService
requirements:
diff --git a/xos/core/models/__init__.py b/xos/core/models/__init__.py
index a022cae..628a3bb 100644
--- a/xos/core/models/__init__.py
+++ b/xos/core/models/__init__.py
@@ -26,7 +26,7 @@
from .instance import Instance
from .reservation import ReservedResource
from .reservation import Reservation
-from .network import Network, NetworkParameterType, NetworkParameter, Port, NetworkTemplate, Router, NetworkSlice, ControllerNetwork
+from .network import Network, NetworkParameterType, NetworkParameter, Port, NetworkTemplate, Router, NetworkSlice, ControllerNetwork, AddressPool
from .billing import Account, Invoice, Charge, UsableObject, Payment
from .program import Program
diff --git a/xos/core/models/network.py b/xos/core/models/network.py
index a019091..8dd0b17 100644
--- a/xos/core/models/network.py
+++ b/xos/core/models/network.py
@@ -337,4 +337,30 @@
def __unicode__(self):
return self.parameter.name
+class AddressPool(PlCoreBase):
+ name = models.CharField(max_length=32)
+ addresses = models.TextField(blank=True, null=True)
+
+ def __unicode__(self): return u'%s' % (self.name)
+
+ def get_address(self):
+ with transaction.atomic():
+ ap = AddressPool.objects.get(pk=self.pk)
+ if ap.addresses:
+ parts = ap.addresses.split()
+ addr = parts.pop()
+ ap.addresses = " ".join(parts)
+ ap.save()
+ else:
+ addr = None
+ return addr
+
+ def put_address(self, addr):
+ with transaction.atomic():
+ ap = AddressPool.objects.get(pk=self.pk)
+ parts = ap.address.split()
+ if addr not in parts:
+ parts.push(addr)
+ ap.addresses = " ".join(parts)
+ ap.save()
diff --git a/xos/tosca/custom_types/xos.m4 b/xos/tosca/custom_types/xos.m4
index 92f8cc1..c9cea49 100644
--- a/xos/tosca/custom_types/xos.m4
+++ b/xos/tosca/custom_types/xos.m4
@@ -522,6 +522,17 @@
required: false
description: Comma-separated list of flavors that this deployment supports.
+ tosca.nodes.AddressPool:
+ derived_from: tosca.nodes.Root
+ description: >
+ A pool of addresses
+ properties:
+ xos_base_props
+ addresses:
+ type: string
+ required: false
+ description: space-separated list of addresses
+
tosca.nodes.Image:
derived_from: tosca.nodes.Root
description: >
diff --git a/xos/tosca/custom_types/xos.yaml b/xos/tosca/custom_types/xos.yaml
index dfb9481..ce8a1ac 100644
--- a/xos/tosca/custom_types/xos.yaml
+++ b/xos/tosca/custom_types/xos.yaml
@@ -160,7 +160,7 @@
no_container:
type: boolean
default: false
- key_fn:
+ node_key:
type: string
required: false
@@ -746,6 +746,28 @@
required: false
description: Comma-separated list of flavors that this deployment supports.
+ tosca.nodes.AddressPool:
+ derived_from: tosca.nodes.Root
+ description: >
+ A pool of addresses
+ properties:
+ no-delete:
+ type: boolean
+ default: false
+ description: Do not allow Tosca to delete this object
+ no-create:
+ type: boolean
+ default: false
+ description: Do not allow Tosca to create this object
+ no-update:
+ type: boolean
+ default: false
+ description: Do not allow Tosca to update this object
+ addresses:
+ type: string
+ required: false
+ description: space-separated list of addresses
+
tosca.nodes.Image:
derived_from: tosca.nodes.Root
description: >
diff --git a/xos/tosca/resources/addresspool.py b/xos/tosca/resources/addresspool.py
new file mode 100644
index 0000000..e8577a2
--- /dev/null
+++ b/xos/tosca/resources/addresspool.py
@@ -0,0 +1,53 @@
+import os
+import pdb
+import socket
+import sys
+import struct
+import tempfile
+sys.path.append("/opt/tosca")
+from translator.toscalib.tosca_template import ToscaTemplate
+
+from core.models import AddressPool
+
+from xosresource import XOSResource
+
+class XOSAddressPool(XOSResource):
+ provides = "tosca.nodes.AddressPool"
+ xos_model = AddressPool
+ copyin_props = ["addresses"]
+
+ def expand_cidr(self, cidr):
+ (network, bits) = cidr.split("/")
+ network=network.strip()
+ bits=int(bits.strip())
+
+ dest = []
+
+ netmask = (~(pow(2,32-bits)-1) & 0xFFFFFFFF)
+
+ count = pow(2, 32-bits)
+ for i in range(2, count-1):
+ ip = struct.unpack("!L", socket.inet_aton(network))[0]
+ ip = ip & netmask | i
+ dest.append( socket.inet_ntoa(struct.pack("!L", ip)) )
+
+ return dest
+
+ def get_xos_args(self):
+ args = super(XOSAddressPool, self).get_xos_args()
+
+ if "addresses" in args:
+ dest = []
+ for addr in args["addresses"].split():
+ addr=addr.strip()
+ if "/" in addr:
+ dest.extend(self.expand_cidr(addr))
+ else:
+ dest.append(addr)
+ args["addresses"] = " ".join(dest)
+
+ return args
+
+
+
+