'node_id': node['node_id']})
slice_node.sync()
+ def remove_node(self, node_filter, commit=True):
+ from PLC.Nodes import Nodes
+ assert 'slice_id' in self
+ nodes = Nodes(self.api, node_filter)
+ for node in nodes:
+ slice_node = SliceNode(self.api, {'slice_id': self['slice_id'],
+ 'node_id': node['node_id']})
+ slice_node.delete()
+
+
def spawn_instances(self, nodes):
# use the caller's nova keypair
keypairs = self.api.client_shell.nova.keypairs.list()
AlchemyObj.delete(SliceInstance, filter={'slice_id': self['slice_id'],
'instance_id': instance_id})
+
+ def create_network(self):
+ self.api.client_shell.quantum.create_network(name=self['name'],
+ admin_state_up=False)
+ def delete_network(self):
+ nets = self.api.client_shell.quantum.list_networks(name=self['name'],
+ tenant_id=self['tenant_id'])['networks']
+ for net in nets:
+ # delete all subnets:
+ #subnets = self.api.client_shell.quantum.list_subnets(network_id=net['network_id'])['subnets']
+ for subnet_id in net['subnets']:
+ self.delete_subnet(subnet_id)
+ self.api.client_shell.quantum.delete_network(net['id'])
+
- def remove_node(self, node_filter, commit=True):
- from PLC.Nodes import Nodes
- assert 'slice_id' in self
- nodes = Nodes(self.api, node_filter)
- for node in nodes:
- slice_node = SliceNode(self.api, {'slice_id': self['slice_id'],
- 'node_id': node['node_id']})
- slice_node.delete()
+ def create_subnet(self, cidr_ip, ip_version, start, end):
+ nets = self.api.client_shell.quantum.list_networks(name=self['name'],
+ tenant_id=self['tenant_id'])['networks']
+ # cannot create a subnet if there is no network
+ if not nets:
+ return
+ net = nets[0]
+ allocation_pools = [{'start': start, 'end': end}]
+ self.api.client_shell.quantum.create_subnet(network_id=net['id'],
+ ip_version=ip_version,
+ cidr=cidr_ip,
+ allocation_pools=allocation_pools)
+
+ def delete_subnet(self, id=None):
+ if id:
+ self.api.client_shell.quantum.delete_subnet(id=id)
+ else:
+ # delete all subnets
+ subnets = self.api.client_shell.quantum.list_subnets(name=self['name'],
+ tenant_id=self['tenant_id'])['subnets']
+ for subnet in subnets:
+ self.api.client_shell.quantum.delete_subnet(id=id)
+
+ def process_tags(self):
+ # create a subnet for each subnet tag if one doesn't alredy exist
+ tags = SliceTags(self.api, filter={'slice_id': self['slice_id']})
+ subnet_cidr = None
+ subnet_start = None
+ subnet_end = None
+
+ for tag in tags:
+ if tag['tagname'] == 'subnet_cidr':
+ subnet_cidr = tag['value']
+ elif tag['tagname'] == 'subnet_start':
+ subnet_start = tag['value']
+ elif tag['tagname'] == 'subnet_end':
+ subnet_end = tag['value']
+
+ if subnet_cidr and subnet_start and subnet_end:
+ allocation_pools = [{'start': subnet_start, 'end': subnet_end}]
+ subnets = self.api.client_shell.quantum.list_subnets(name=self['name'],
+ tenant_id=self['tenant_id'],
+ cidr=subnet_cidr,
+ allocation_pools=allocation_pools)
+
#add_to_node_whitelist = Row.add_object(Node, 'node_slice_whitelist')
#delete_from_node_whitelist = Row.remove_object(Node, 'node_slice_whitelist')
AlchemyObj.insert(self, dict(self))
slice = AlchemyObj.select(self, filter={'tenant_id': self['tenant_id']})[0]
self['slice_id'] = slice.slice_id
+
+ # create quantum network
+ self.create_network()
else:
self.object = self.api.client_shell.keystone.tenants.update(self['tenant_id'], **nova_slice)
AlchemyObj.updatedb(self, {'slice_id': self['slice_id']}, dict(self))
assert 'slice_id' in self
assert 'tenant_id' in self
+ # delete quantum networks
+ self.delete_network()
+
# delete the nova object
tenant = self.api.client_shell.keystone.tenants.find(id=self['tenant_id'])
self.api.client_shell.keystone.tenants.delete(tenant)