def update_conf_file(self, cf_rec): if not cf_rec['enabled']: return dest = cf_rec['dest'] err_cmd = cf_rec['error_cmd'] mode = string.atoi(cf_rec['file_permissions'], base=8) try: uid = pwd.getpwnam(cf_rec['file_owner'])[2] except: logger.log('conf_files: cannot find user %s -- %s not updated'%(cf_rec['file_owner'],dest)) return try: gid = grp.getgrnam(cf_rec['file_group'])[2] except: logger.log('conf_files: cannot find group %s -- %s not updated'%(cf_rec['file_group'],dest)) return url = 'https://%s/%s' % (self.config.PLC_BOOT_HOST, cf_rec['source']) # set node_id at the end of the request - hacky if tools.node_id(): if url.find('?') >0: url += '&' else: url += '?' url += "node_id=%d"%tools.node_id() else: logger.log('conf_files: %s -- WARNING, cannot add node_id to request'%dest) try: logger.verbose("conf_files: retrieving URL=%s"%url) contents = curlwrapper.retrieve(url, self.config.cacert) except xmlrpclib.ProtocolError,e: logger.log('conf_files: failed to retrieve %s from %s, skipping' % (dest, url)) return
def update_conf_file(self, cf_rec): if not cf_rec['enabled']: return dest = cf_rec['dest'] err_cmd = cf_rec['error_cmd'] mode = int(cf_rec['file_permissions'], base=8) try: uid = pwd.getpwnam(cf_rec['file_owner'])[2] except: logger.log('conf_files: cannot find user %s -- %s not updated' %(cf_rec['file_owner'], dest)) return try: gid = grp.getgrnam(cf_rec['file_group'])[2] except: logger.log('conf_files: cannot find group %s -- %s not updated' %(cf_rec['file_group'], dest)) return url = 'https://%s/%s' % (self.config.PLC_BOOT_HOST, cf_rec['source']) # set node_id at the end of the request - hacky if tools.node_id(): if url.find('?') > 0: url += '&' else: url += '?' url += "node_id=%d"%tools.node_id() else: logger.log('conf_files: %s -- WARNING, cannot add node_id to request' % dest) try: logger.verbose("conf_files: retrieving URL=%s"%url) contents = curlwrapper.retrieve(url, self.config.cacert) except xmlrpc.client.ProtocolError as e: logger.log('conf_files: failed to retrieve %s from %s, skipping' % (dest, url)) return if not cf_rec['always_update'] and sha(contents).digest() == self.checksum(dest): return if self.system(cf_rec['preinstall_cmd']): self.system(err_cmd) if not cf_rec['ignore_cmd_errors']: return logger.log('conf_files: installing file %s from %s' % (dest, url)) try: os.makedirs(os.path.dirname(dest)) except OSError: pass tools.write_file(dest, lambda f: f.write(contents.decode()), mode=mode, uidgid=(uid, gid)) if self.system(cf_rec['postinstall_cmd']): self.system(err_cmd)
def GetSlivers(data, conf = None, plc = None): node_id = tools.node_id() if 'slivers' not in data: logger.log_missing_data("privatebridge.GetSlivers",'slivers') return valid_bridges = [] for sliver in data['slivers']: sliver_name = sliver['name'] # build a dict of attributes, because it's more convenient attributes={} for attribute in sliver['attributes']: attributes[attribute['tagname']] = attribute['value'] bridge_name = attributes.get('slice_bridge_name',None) if bridge_name: configure_slicebridge(sliver, attributes) valid_bridges.append(bridge_name) # now, delete the bridges that we don't want bridges = ovs_listbridge() for bridge_name in bridges: if not bridge_name.startswith("br-slice-"): # ignore ones we didn't create continue if bridge_name in valid_bridges: # ignore ones we want to keep continue logger.log("privatebridge: deleting unused bridge %s" % bridge_name) ovs_delbridge(bridge_name)
def SetSliverTag(plc, slice, tagname, value): node_id = tools.node_id() slivertags=plc.GetSliceTags({"name":slice,"node_id":node_id,"tagname":tagname}) if len(slivertags)==0: # looks like GetSlivers reports about delegated/nm-controller slices that do *not* belong to this node # and this is something that AddSliceTag does not like try: slivertag_id=plc.AddSliceTag(slice,tagname,value,node_id) except: logger.log_exc ("sliverauth.SetSliverTag (probably delegated) slice=%(slice)s tag=%(tagname)s node_id=%(node_id)d"%locals()) pass else: slivertag_id=slivertags[0]['slice_tag_id'] plc.UpdateSliceTag(slivertag_id,value)
def GetSlivers(data, conf=None, plc=None): node_id = tools.node_id() if 'slivers' not in data: logger.log_missing_data("syndicate.GetSlivers", 'slivers') return syndicate_sliver = None for sliver in data['slivers']: if sliver['name'] == "princeton_syndicate": syndicate_sliver = sliver if not syndicate_sliver: logger.log( "Syndicate: no princeton_syndicate sliver on this node. aborting.") return syndicate_ip = tools.get_sliver_ip("princeton_syndicate") if not syndicate_ip: logger.log("Syndicate: unable to get syndicate sliver ip. aborting.") return for sliver in data['slivers']: enable_syndicate = False # build a dict of attributes, because it's more convenient attributes = {} for attribute in sliver['attributes']: attributes[attribute['tagname']] = attribute['value'] sliver_name = sliver['name'] syndicate_mountpoint = os.path.join("/vservers", sliver_name, "syndicate") enable_syndicate = attributes.get("enable_syndicate", False) has_syndicate = os.path.exists(syndicate_mountpoint) if enable_syndicate and (not has_syndicate): logger.log("Syndicate: enabling syndicate for %s" % sliver_name) #enable_syndicate_mount(sliver, syndicate_mountpoint, syndicate_ip) t = Thread(target=enable_syndicate_mount, args=(sliver, syndicate_mountpoint, syndicate_ip)) t.start() elif (not enable_syndicate) and (has_syndicate): logger.log("Syndicate: disabling syndicate for %s" % sliver_name) #disable_syndicate_mount(sliver, syndicate_mountpoint, syndicate_ip) t = Thread(target=disable_syndicate_mount, args=(sliver, syndicate_mountpoint, syndicate_ip)) t.start()
def GetSlivers(data, conf = None, plc = None): node_id = tools.node_id() if 'slivers' not in data: logger.log_missing_data("syndicate.GetSlivers",'slivers') return syndicate_sliver = None for sliver in data['slivers']: if sliver['name'] == "princeton_syndicate": syndicate_sliver = sliver if not syndicate_sliver: logger.log("Syndicate: no princeton_syndicate sliver on this node. aborting.") return syndicate_ip = tools.get_sliver_ip("princeton_syndicate") if not syndicate_ip: logger.log("Syndicate: unable to get syndicate sliver ip. aborting.") return for sliver in data['slivers']: enable_syndicate = False # build a dict of attributes, because it's more convenient attributes={} for attribute in sliver['attributes']: attributes[attribute['tagname']] = attribute['value'] sliver_name = sliver['name'] syndicate_mountpoint = os.path.join("/vservers", sliver_name, "syndicate") enable_syndicate = attributes.get("enable_syndicate", False) has_syndicate = os.path.exists(syndicate_mountpoint) if enable_syndicate and (not has_syndicate): logger.log("Syndicate: enabling syndicate for %s" % sliver_name) #enable_syndicate_mount(sliver, syndicate_mountpoint, syndicate_ip) t = Thread(target=enable_syndicate_mount, args=(sliver, syndicate_mountpoint, syndicate_ip)) t.start() elif (not enable_syndicate) and (has_syndicate): logger.log("Syndicate: disabling syndicate for %s" % sliver_name) #disable_syndicate_mount(sliver, syndicate_mountpoint, syndicate_ip) t = Thread(target=disable_syndicate_mount, args=(sliver, syndicate_mountpoint, syndicate_ip)) t.start()
def GetSlivers(data, conf = None, plc = None): DRL_SLICE_NAME = '' HAVE_DRL = 0 node_id = tools.node_id() if 'slivers' not in data: logger.log_missing_data("drl.GetSlivers",'slivers') return for sliver in data['slivers']: for attribute in sliver['attributes']: tag = attribute['tagname'] value = attribute['value'] if tag == 'drl' and value == '1': HAVE_DRL = 1 DRL_SLICE_NAME = sliver['name'] if HAVE_DRL: site_id = plc.GetNodes({'node_id': int(node_id) }, ['site_id']) site_id = site_id[0]['site_id'] q = plc.GetSites({'site_id': site_id, 'enabled': True, 'peer_site_id': None}, ['name', 'node_ids']) for i in q: if i['node_ids'] != [] and len(i['node_ids']) > 1: z = plc.GetInterfaces({'node_id': i['node_ids'], 'is_primary': True, '~bwlimit': None}, ['node_id', 'ip', 'bwlimit']) total_bwlimit = 0 peer = '' node_has_bwlimit = 0 for j in range(len(z)): total_bwlimit += z[j]['bwlimit'] if z[j]['node_id'] != int(node_id): peer += '\t<peer>%s</peer>\n' % z[j]['ip'] else: node_has_bwlimit = 1 if node_has_bwlimit: DRLSetup(i['name'], DRL_SLICE_NAME, site_id, total_bwlimit/1000, peer) else: logger.log('drl: This node has no bwlimit') else: logger.log('drl: This site has only %s node' % len(i['node_ids'])) else: logger.log('drl: This node has no drl slice!...')
def SetSliverTag(plc, slice, tagname, value): node_id = tools.node_id() slivertags = plc.GetSliceTags({ "name": slice, "node_id": node_id, "tagname": tagname }) if len(slivertags) == 0: # looks like GetSlivers reports about delegated/nm-controller slices that do *not* belong to this node # and this is something that AddSliceTag does not like try: slivertag_id = plc.AddSliceTag(slice, tagname, value, node_id) except: logger.log_exc( "sliverauth.SetSliverTag (probably delegated) slice=%(slice)s tag=%(tagname)s node_id=%(node_id)d" % locals()) pass else: slivertag_id = slivertags[0]['slice_tag_id'] plc.UpdateSliceTag(slivertag_id, value)
def SetSliverTag(plc, data, tagname): virt=tools.get_node_virt() if virt!='lxc': return for slice in data['slivers']: #logger.log("update_ipv6addr_slivertag: starting with slice={}".format(slice['name'])) # Check if the slice to be processed in a "system" slice # If so, just loop to the next slice system_slice = False for attribute in slice['attributes']: if attribute['tagname']=='system' and attribute['value']=='1': system_slice = True break if system_slice: continue # TODO: what about the prefixlen? Should we also inform the prefixlen? # here, I'm just taking the ipv6addr (value) value, prefixlen = tools.get_sliver_ipv6(slice['name']) node_id = tools.node_id() slivertags = plc.GetSliceTags({"name":slice['name'], "node_id":node_id, "tagname":tagname}) #logger.log(repr(str(slivertags))) #for tag in slivertags: # logger.log(repr(str(tag))) try: slivertag_id, ipv6addr = get_sliver_tag_id_value(slivertags) except: slivertag_id, ipv6addr = None, None if ipv6addr: logger.log("update_ipv6addr_slivertag: slice={} getSliceIPv6Address={}" .format(slice['name'], ipv6addr)) # if the value to set is null... if value is None: if ipv6addr is not None: # then, let's remove the slice tag if slivertag_id: try: plc.DeleteSliceTag(slivertag_id) logger.log("update_ipv6addr_slivertag: slice tag deleted for slice={}" .format(slice['name'])) except: logger.log("update_ipv6addr_slivertag: slice tag not deleted for slice={}" .format(slice['name'])) result = tools.search_ipv6addr_hosts(slice['name'], value) if result: # if there's any ipv6 address, then remove everything from the /etc/hosts tools.remove_all_ipv6addr_hosts(slice['name'], data['hostname']) else: # if the ipv6 addr set on the slice does not exist yet, so, let's add it if (ipv6addr is None) and len(value)>0: try: logger.log("update_ipv6addr_slivertag: slice name={}".format(slice['name'])) slivertag_id=plc.AddSliceTag(slice['name'], tagname, value, node_id) logger.log("update_ipv6addr_slivertag: slice tag added to slice {}" .format(slice['name'])) except: logger.log("update_ipv6addr_slivertag: could not set ipv6 addr tag to sliver. " "slice={} tag={} node_id={}".format(slice['name'], tagname, node_id)) # if the ipv6 addr set on the slice is different on the value provided, let's update it if (ipv6addr is not None) and (len(value) > 0) and (ipv6addr != value): plc.UpdateSliceTag(slivertag_id, value) # ipv6 entry on /etc/hosts of each slice result = tools.search_ipv6addr_hosts(slice['name'], value) if not result: tools.remove_all_ipv6addr_hosts(slice['name'], data['hostname']) tools.add_ipv6addr_hosts_line(slice['name'], data['hostname'], value)