Skip to content

Instantly share code, notes, and snippets.

@otherwiseguy
otherwiseguy / deathsig
Created July 15, 2014 21:40
An example how in python on linux you can ensure that a signal gets passed to a child on its parent's death
#!/usr/bin/env python
from prctl import prctl, PDEATHSIG # https://pypi.python.org/pypi/prctl/1.0.1
import signal as sig
import subprocess
p = subprocess.Popen(['yes'], preexec_fn=lambda: prctl(PDEATHSIG, sig.SIGTERM))
p.communicate()
def autocommit(fn):
def wrapper(*args, **kwargs):
self = args[0]
cmd = fn(*args, **kwargs)
if isinstance(self, Transaction):
self.commands.append(cmd)
return cmd
else:
return cmd.execute()
return wrapper
import abc
import six
@six.add_metaclass(abc.ABCMeta)
class NotifyDict(dict):
NOT_FOUND = object()
@abc.abstractmethod
def on_create(self, key, val):
class AddLogicalPortCommand(BaseCommand):
# required values or values that need processing enumerated, optional
# columns as kwargs
def __init__(self, api, lswitch_name, lport_name, may_exist, **columns):
super(AddLogicalPortCommand, self).__init__(api)
self.lswitch_name = lswitch_name
self.lport_name = lport_name
self.may_exist = may_exist
self.columns == columns
import eventlet
eventlet.monkey_patch()
import os
import time
def fun():
num = 0
while True:
print num
#!/bin/bash
set -x
set -e
IMAGE=rhel
# Create private network
neutron net-create privateA
neutron subnet-create --ip_version 4 --gateway 10.1.0.1 --name privateA privateA 10.1.0.0/24
class FakeSchemaHelper(object):
def register_table(self, table):
print "register_table(%s)" % table
def register_columns(self, table, columns, read_only=None):
print "register_column(%s, %s, %s)" % (table, str(columns),
str(read_only))
def register_all(self):
print "register_all"
@otherwiseguy
otherwiseguy / test.py
Created August 31, 2016 23:48
test replace_port
import time
from neutron.agent.common import ovs_lib
from neutron.agent.linux import ip_lib
# import sys
# from oslo_config import cfg
# from neutron.common import config
#
# config.init(sys.argv[1:])
%{!?upstream_version: %global upstream_version %{version}%{?milestone}}
# Python3 support in OpenStack starts with version 3.5,
# which is only in Fedora 24+
%if 0%{?fedora} >= 24
%global with_python3 1
%endif
%global library ovsdbapp
diff --git a/neutron/agent/common/ovs_lib.py b/neutron/agent/common/ovs_lib.py
index f96e31c..aee88d6 100644
--- a/neutron/agent/common/ovs_lib.py
+++ b/neutron/agent/common/ovs_lib.py
@@ -87,12 +87,13 @@ def _ovsdb_retry(fn):
class VifPort(object):
- def __init__(self, port_name, ofport, vif_id, vif_mac, switch):
+ def __init__(self, port_name, ofport, vif_id, vif_mac, switch, other=None):