# -*-python-*-
-####################
+####################
import sys, os
g_url = ""
roles=['admin']
# just in case
if 'min_role_id' in tag_type:
- print "WARNING: ignoring deprecated field min_role_id for tagtype %s"%tagname
+ print("WARNING: ignoring deprecated field min_role_id for tagtype %s"%tagname)
del tag_type['min_role_id']
# Create/update default slice tag types
if tagname not in g_known_tag_types:
for plus_role in set(roles).difference(set(old_roles)):
AddRoleToTagType(plus_role,tagname)
except:
- # something went wrong for that tagname,
+ # something went wrong for that tagname,
# but don't want to break the whole startup sequence
- print "Could not enforce tagtype %s --- beg"%tagname
+ print("Could not enforce tagtype %s --- beg"%tagname)
import traceback
traceback.print_exc()
- print "Could not enforce tagtype %s --- end"%tagname
+ print("Could not enforce tagtype %s --- end"%tagname)
# Get list of existing (enabled, global) files
g_conf_files = GetConfFiles()
-g_conf_files = filter(lambda conf_file: conf_file['enabled'] and \
+g_conf_files = [conf_file for conf_file in g_conf_files if conf_file['enabled'] and \
not conf_file['node_ids'] and \
- not conf_file['nodegroup_ids'],
- g_conf_files)
+ not conf_file['nodegroup_ids']]
g_dests = [conf_file['dest'] for conf_file in g_conf_files]
-g_conf_files = dict(zip(g_dests, g_conf_files))
+g_conf_files = dict(list(zip(g_dests, g_conf_files)))
# Get list of existing initscripts
g_oldinitscripts = GetInitScripts()
g_oldinitscript_names = [script['name'] for script in g_oldinitscripts]
-g_oldinitscripts = dict(zip(g_oldinitscript_names, g_oldinitscripts))
+g_oldinitscripts = dict(list(zip(g_oldinitscript_names, g_oldinitscripts)))
def SetInitScript(initscript):
global g_oldinitscripts, g_oldinitscript_names
orig_initscript = g_oldinitscripts[initscript['name']]
initscript_id = orig_initscript['initscript_id']
UpdateInitScript(initscript_id, initscript)
-
+
def SetConfFile(conf_file):
global g_conf_files, g_dests
if conf_file['dest'] not in g_dests:
slices = GetSlices([slice_name])
if len(slices)==1:
slice_id = slices[0]['slice_id']
- if slice.has_key('name'):
+ if 'name' in slice:
del slice['name']
UpdateSlice(slice_id, slice)
slice['name']=slice_name
else:
expires = None
- if slice.has_key('expires'):
+ if 'expires' in slice:
expires = slice['expires']
del slice['expires']
slice_id = AddSlice(slice)
- if expires <> None:
+ if expires is not None:
UpdateSlice(slice_id, {'expires':expires})
-
+
# Get slice structure with all fields
slice = GetSlices([slice_name])[0]
-
+
# Create/delete all tags
- # NOTE: update is not needed, since unspecified tags are deleted,
+ # NOTE: update is not needed, since unspecified tags are deleted,
# and new tags are added
slice_tags = []
if slice['slice_tag_ids']:
# Delete unknown attributes
for slice_tag in GetSliceTags(slice['slice_tag_ids']):
# ignore sliver tags, as those are custom/run-time values
- if slice_tag['node_id'] <> None: continue
+ if slice_tag['node_id'] is not None:
+ continue
if (slice_tag['tagname'], slice_tag['value']) not in tags:
DeleteSliceTag(slice_tag['slice_tag_id'])
else:
slice_tags.append((slice_tag['tagname'],slice_tag['value']))
-
+
# only add slice tags that are new
for (name, value) in tags:
if (name,value) not in slice_tags:
- AddSliceTag(slice_name, name, value)
+ AddSliceTag(slice_name, name, value)
else:
- # NOTE: this confirms that the user-specified tag is
+ # NOTE: this confirms that the user-specified tag is
# returned by GetSliceTags
pass
except:
- # something went wrong for that tagname,
- print "Could not create init slice %s --- beg"%slice['name']
+ # something went wrong for that tagname,
+ print("Could not create init slice %s --- beg"%slice['name'])
import traceback
traceback.print_exc()
- print "Could not create init slice %s --- end"%slice['name']
+ print("Could not create init slice %s --- end"%slice['name'])
def SetMessage(message):
messages = GetMessages([message['message_id']])
# for each protocol, also add this.
for ptype in protocol_types:
AddPCUProtocolType(id, ptype)
-
# -*-python-*-
-#################### slice tag types
+# slice tag types
# xxx this should move to PLC/Accessors
# vref is now defined in an accessor
# initscript is now defined in an accessor
-
+
# Setup default slice tag types
slicetag_types = \
-[
-
-### this applies on Node, not on Slice
-### # Slice type (only vserver is supported)
-### {'tagname': "type",
-### 'description': "Type of slice (e.g. vserver)",
-### 'category' : 'slice/general',
-### 'roles': ['admin','pi']},
-
- # System slice
- {'tagname': "system",
- 'description': "Is a default system slice (1) or not (0 or unset)",
- 'category' : 'slice/general'},
-
- # Slice enabled (1) or suspended (0)
- {'tagname': "enabled",
- 'description': "Slice enabled (1 or unset) or suspended (0)",
- 'category' : 'slice/general'},
-
- # IP Addresses for a Slice
- {'tagname': "ip_addresses",
- 'description': "Add an ip address to a slice/sliver.",
- 'category' : 'slice/rspec'},
- {'tagname': "isolate_loopback",
- 'description': "Create an isolated loopback interface within the vserver rather than sharing with all vservers.",
- 'category' : 'slice/rspec'},
-
- # CPU share
- {'tagname': "cpu_pct",
- 'description': "Reserved CPU percent",
- 'category' : 'slice/rspec'},
- {'tagname': "cpu_share",
- 'description': "Number of CPU shares",
- 'category' : 'slice/rspec'},
- {'tagname': "cpu_cores",
- 'description': "Number of CPU cores",
- 'category': 'slice/rspec'},
- {'tagname': "cpu_freezable",
- 'description': "Slice processes should be frozen if cpu_cores is 0",
- 'category': 'slice/rspec'},
-
- # Bandwidth limits
- {'tagname': "net_min_rate",
- 'description': "Minimum bandwidth (kbps)",
- 'category' : 'slice/rspec'},
- {'tagname': "net_max_rate",
- 'description': "Maximum bandwidth (kbps)",
- 'category' : 'slice/rspec'},
- {'tagname': "net_i2_min_rate",
- 'description': "Minimum bandwidth over I2 routes (kbps)",
- 'category' : 'slice/rspec'},
- {'tagname': "net_i2_max_rate",
- 'description': "Maximum bandwidth over I2 routes (kbps)",
- 'category' : 'slice/rspec'},
- {'tagname': "net_max_kbyte",
- 'description': "Maximum daily network Tx KByte limit.",
- 'category' : 'slice/rspec'},
- {'tagname': "net_thresh_kbyte",
- 'description': "KByte limit before warning and throttling.",
- 'category' : 'slice/rspec'},
- {'tagname': "net_i2_max_kbyte",
- 'description': "Maximum daily network Tx KByte limit to I2 hosts.",
- 'category' : 'slice/rspec'},
- {'tagname': "net_i2_thresh_kbyte",
- 'description': "KByte limit to I2 hosts before warning and throttling.",
- 'category' : 'slice/rspec'},
- {'tagname': "net_share",
- 'description': "Number of bandwidth shares",
- 'category' : 'slice/rspec'},
- {'tagname': "net_i2_share",
- 'description': "Number of bandwidth shares over I2 routes",
- 'category' : 'slice/rspec'},
-
- # Disk quota
- {'tagname': "disk_max",
- 'description': "Disk quota (1k disk blocks)",
- 'category' : 'slice/rspec'},
-
- # deprecated in nov. 2010
- # Proper operations
- #{'tagname': "proper_op",
- # 'description': "Proper operation (e.g. bind_socket)",
- # 'category' : 'slice/rspec'},
-
- # VServer capabilities
- {'tagname': "capabilities",
- 'description': "VServer bcapabilities (separate by commas)",
- 'category' : 'slice/rspec'},
-
- # Vsys
- # need to allow this one so that slice can have that set from PLC_VSYS_DEFAULT
- {'tagname': "vsys",
- 'description': "Bind vsys script fd's to a slice's /vsys directory.",
- 'category' : 'slice/rspec',
- 'roles': AllPersonRoles()},
- {'tagname': "vsys_vnet",
- 'description': """Specify the IP range that can be used in a given slice
+ [
+
+ # this applies on Node, not on Slice
+ # Slice type (only vserver is supported)
+ # {'tagname': "type",
+ # 'description': "Type of slice (e.g. vserver)",
+ # 'category' : 'slice/general',
+ # 'roles': ['admin','pi']},
+
+ # System slice
+ {'tagname': "system",
+ 'description': "Is a default system slice (1) or not (0 or unset)",
+ 'category': 'slice/general'},
+
+ # Slice enabled (1) or suspended (0)
+ {'tagname': "enabled",
+ 'description': "Slice enabled (1 or unset) or suspended (0)",
+ 'category': 'slice/general'},
+
+ # IP Addresses for a Slice
+ {'tagname': "ip_addresses",
+ 'description': "Add an ip address to a slice/sliver.",
+ 'category': 'slice/rspec'},
+ {'tagname': "isolate_loopback",
+ 'description': "Create an isolated loopback interface within the vserver rather than sharing with all vservers.",
+ 'category': 'slice/rspec'},
+
+ # CPU share
+ {'tagname': "cpu_pct",
+ 'description': "Reserved CPU percent",
+ 'category': 'slice/rspec'},
+ {'tagname': "cpu_share",
+ 'description': "Number of CPU shares",
+ 'category': 'slice/rspec'},
+ {'tagname': "cpu_cores",
+ 'description': "Number of CPU cores",
+ 'category': 'slice/rspec'},
+ {'tagname': "cpu_freezable",
+ 'description': "Slice processes should be frozen if cpu_cores is 0",
+ 'category': 'slice/rspec'},
+
+ # Bandwidth limits
+ {'tagname': "net_min_rate",
+ 'description': "Minimum bandwidth (kbps)",
+ 'category': 'slice/rspec'},
+ {'tagname': "net_max_rate",
+ 'description': "Maximum bandwidth (kbps)",
+ 'category': 'slice/rspec'},
+ {'tagname': "net_i2_min_rate",
+ 'description': "Minimum bandwidth over I2 routes (kbps)",
+ 'category': 'slice/rspec'},
+ {'tagname': "net_i2_max_rate",
+ 'description': "Maximum bandwidth over I2 routes (kbps)",
+ 'category': 'slice/rspec'},
+ {'tagname': "net_max_kbyte",
+ 'description': "Maximum daily network Tx KByte limit.",
+ 'category': 'slice/rspec'},
+ {'tagname': "net_thresh_kbyte",
+ 'description': "KByte limit before warning and throttling.",
+ 'category': 'slice/rspec'},
+ {'tagname': "net_i2_max_kbyte",
+ 'description': "Maximum daily network Tx KByte limit to I2 hosts.",
+ 'category': 'slice/rspec'},
+ {'tagname': "net_i2_thresh_kbyte",
+ 'description': "KByte limit to I2 hosts before warning and throttling.",
+ 'category': 'slice/rspec'},
+ {'tagname': "net_share",
+ 'description': "Number of bandwidth shares",
+ 'category': 'slice/rspec'},
+ {'tagname': "net_i2_share",
+ 'description': "Number of bandwidth shares over I2 routes",
+ 'category': 'slice/rspec'},
+
+ # Disk quota
+ {'tagname': "disk_max",
+ 'description': "Disk quota (1k disk blocks)",
+ 'category': 'slice/rspec'},
+
+ # deprecated in nov. 2010
+ # Proper operations
+ # {'tagname': "proper_op",
+ # 'description': "Proper operation (e.g. bind_socket)",
+ # 'category' : 'slice/rspec'},
+
+ # VServer capabilities
+ {'tagname': "capabilities",
+ 'description': "VServer bcapabilities (separate by commas)",
+ 'category': 'slice/rspec'},
+
+ # Vsys
+ # need to allow this one so that slice can have that set from PLC_VSYS_DEFAULT
+ {'tagname': "vsys",
+ 'description': "Bind vsys script fd's to a slice's /vsys directory.",
+ 'category': 'slice/rspec',
+ 'roles': AllPersonRoles()},
+ {'tagname': "vsys_vnet",
+ 'description': """Specify the IP range that can be used in a given slice
for virtual devices involved in topologies, e.g. 192.168.100.0/24""",
- 'category': 'slice/rspec'},
-
- # CoDemux
- {'tagname': "codemux",
- 'description': "Demux HTTP between slices using localhost ports. Value in the form 'host, localhost port'.",
- 'category' : 'slice/rspec'},
-
- # Delegation
- {'tagname': "delegations",
- 'description': "Coma seperated list of slices to give delegation authority to.",
- 'category' : 'slice/rspec',
- 'roles' : ['admin','pi','user']},
-
- # Capability to give a sliver access to unused raw disk
- {'tagname': "rawdisk",
- 'description': "map unused raw disk devices into the slice",
- 'category' : 'slice/access', # we should get rid of this category thing
- 'roles': ['admin','pi']},
-
- { 'tagname' : 'exempt_slice_until',
- 'description' : 'Exclude this slice from MyOps until given date (YYYYMMDD)',
- 'category' : 'slice/myops'},
-
- # DistributedRateLimiting slice
- {'tagname': "drl",
- 'description': "Is a default Distributed Rate Limiting slice (1) or not (0 or unset)",
- 'category' : 'slice/general'},
-
- {'tagname' : 'interface',
- 'description' : 'The interface tag holds network configuration information until VirtualInterface objects are in PLCAPI',
- 'category' : 'slice/network'},
-
-]
+ 'category': 'slice/rspec'},
+
+ # CoDemux
+ {'tagname': "codemux",
+ 'description': "Demux HTTP between slices using localhost ports. Value in the form 'host, localhost port'.",
+ 'category': 'slice/rspec'},
+
+ # Delegation
+ {'tagname': "delegations",
+ 'description': "Coma seperated list of slices to give delegation authority to.",
+ 'category': 'slice/rspec',
+ 'roles': ['admin', 'pi', 'user']},
+
+ # Capability to give a sliver access to unused raw disk
+ {'tagname': "rawdisk",
+ 'description': "map unused raw disk devices into the slice",
+ 'category': 'slice/access', # we should get rid of this category thing
+ 'roles': ['admin', 'pi']},
+
+ {'tagname': 'exempt_slice_until',
+ 'description': 'Exclude this slice from MyOps until given date (YYYYMMDD)',
+ 'category': 'slice/myops'},
+
+ # DistributedRateLimiting slice
+ {'tagname': "drl",
+ 'description': "Is a default Distributed Rate Limiting slice (1) or not (0 or unset)",
+ 'category': 'slice/general'},
+
+ {'tagname': 'interface',
+ 'description': 'The interface tag holds network configuration information until VirtualInterface objects are in PLCAPI',
+ 'category': 'slice/network'},
+
+ ]
import resource
# add in the platform supported rlimits to the default_attribute_types
-for entry in resource.__dict__.keys() + ["VLIMIT_OPENFD"]:
- if entry.find("LIMIT_")==1:
+for entry in list(resource.__dict__.keys()) + ["VLIMIT_OPENFD"]:
+ if entry.find("LIMIT_") == 1:
rlim = entry[len("RLIMIT_"):]
rlim = rlim.lower()
- for ty in ("min","soft","hard"):
+ for ty in ("min", "soft", "hard"):
attribute = {
- 'tagname': "%s_%s"%(rlim,ty),
- 'description': "Per sliver RLIMIT %s_%s."%(rlim,ty),
+ 'tagname': "%s_%s" % (rlim, ty),
+ 'description': "Per sliver RLIMIT %s_%s." % (rlim, ty),
'category': 'slice/limit',
- }
+ }
slicetag_types.append(attribute)
for slicetag_type in slicetag_types: