本文整理汇总了Python中utils.get_ip函数的典型用法代码示例。如果您正苦于以下问题:Python get_ip函数的具体用法?Python get_ip怎么用?Python get_ip使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_ip函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, name, start_calico=True, dind=True,
additional_docker_options="",
post_docker_commands=["docker load -i /code/calico-node.tar",
"docker load -i /code/busybox.tar"]):
self.name = name
self.dind = dind
self.workloads = set()
# This variable is used to assert on destruction that this object was
# cleaned up. If not used as a context manager, users of this object
self._cleaned = False
if dind:
log_and_run("docker rm -f %s || true" % self.name)
log_and_run("docker run --privileged -tid "
"-v %s/docker:/usr/local/bin/docker "
"-v %s:/code --name %s "
"calico/dind:latest docker daemon --storage-driver=aufs %s" %
(CHECKOUT_DIR, CHECKOUT_DIR, self.name, additional_docker_options))
self.ip = log_and_run("docker inspect --format "
"'{{.NetworkSettings.Networks.bridge.IPAddress}}' %s" % self.name)
# Make sure docker is up
docker_ps = partial(self.execute, "docker ps")
retry_until_success(docker_ps, ex_class=CalledProcessError,
retries=10)
for command in post_docker_commands:
self.execute(command)
else:
self.ip = get_ip(v6=False)
self.ip6 = get_ip(v6=True)
if start_calico:
self.start_calico_node()
示例2: r_3login_callback
def r_3login_callback(src):
"""
第3方登录-的回调
"""
args = casts(request.args, code=str, callUrl=str)
if not args.code:
abort(403, '缺少参数code')
code = args.code
callUrl = args.callUrl
is_wxpaper = False #是否来自wxpaper.ldbcom.com
is_wxpaper_need_data = False
if callUrl.find("wxpaper.ldbcom.com") != -1:
is_wxpaper = True
if callUrl.find("auth_back") != -1:
is_wxpaper_need_data = True
#print('r_3login_callback:', code)
user_id = 0
if src == 'weibo':
token_info = weibo_login.get_access_token(code)
#print('r_3login_callback1:', token_info)
if not token_info:
abort(403, 'no token')
user = weibo_login.get_user_info(token_info.access_token, token_info.uid)
#print('r_3login_callback2:', user)
ip = get_ip()
user_id = api_user.reg_or_log_weibo(user, ip)
elif src == 'qq':
pass #改在r_3login_callback_qq中处理了.
elif src == 'wx_gzh':
token_info = wx_gzh_login.get_access_token(code)
# print('r_3login_callback11:', token_info)
if not token_info:
abort(403, 'no token')
if not is_wxpaper: # 正常请求
user = wx_gzh_login.get_user_info(token_info.access_token, token_info.openid)
# print('r_3login_callback12:', user)
ip = get_ip()
user_id = api_user.reg_or_log_wx(user, ip)
else: #来自wxpaper.ldbcom.com
user_json = wx_gzh_login.get_user_info(token_info.access_token, token_info.openid, True)
api_user.set_wxpaper_cookie(user_json)
if is_wxpaper_need_data:
import urllib.parse
data_args = urllib.parse.urlencode({'data': user_json})
return redirect(callUrl+'&'+data_args)
else:
return redirect(callUrl)
if user_id:
sess_result = api_user.set_sess(user_id)
if sess_result == -1:
return redirect('/feedback/?f=user_baned')
if callUrl:
return redirect(callUrl)
else:
return redirect('/')
else:
abort(403, "args err")
示例3: __enter__
def __enter__(self):
"""
Set up the route reflector clusters when entering context.
:return: self.
"""
# Construct the common environment variables passed in when starting
# the route reflector.
etcd_auth = "-e ETCD_AUTHORITY=%s:2379" % get_ip()
# Create the route reflector hosts, grouped by redundancy.
for ii in range(self.num_redundancy_groups):
cluster_id = str(IPAddress(0xFF000001 + ii))
redundancy_group = []
for jj in range(self.num_in_redundancy_group):
rr = DockerHost('RR.%d.%d' % (ii, jj), start_calico=False)
ip = "-e IP=%s" % rr.ip
rr.execute("docker load --input /code/routereflector.tar")
# Check which type of etcd is being run, then invoke the
# suggested curl command to add the RR entry to etcd.
#
# See https://github.com/projectcalico/calico-bird/tree/feature-ipinip/build_routereflector
# for details.
if os.getenv("ETCD_SCHEME", None) == "https":
# Etcd is running with SSL/TLS, pass the key values
rr.execute("docker run --privileged --net=host -d "
"--name rr %s "
"-e ETCD_AUTHORITY=%s:2379 "
"-e ETCD_CA_CERT_FILE=%s "
"-e ETCD_CERT_FILE=%s "
"-e ETCD_KEY_FILE=%s "
"-e ETCD_SCHEME=https "
"-v %s/certs:%s/certs "
"calico/routereflector" %
(ip, ETCD_HOSTNAME_SSL, ETCD_CA, ETCD_CERT,
ETCD_KEY, CHECKOUT_DIR,CHECKOUT_DIR))
rr.execute(r'curl --cacert %s --cert %s --key %s '
r'-L https://%s:2379/v2/keys/calico/bgp/v1/rr_v4/%s '
r'-XPUT -d value="{'
r'\"ip\":\"%s\",'
r'\"cluster_id\":\"%s\"'
r'}"' % (ETCD_CA, ETCD_CERT, ETCD_KEY,
ETCD_HOSTNAME_SSL, rr.ip, rr.ip,
cluster_id))
else:
rr.execute("docker run --privileged --net=host -d "
"--name rr %s %s "
"calico/routereflector" % (etcd_auth, ip))
rr.execute(r'curl -L http://%s:2379/v2/keys/calico/bgp/v1/rr_v4/%s '
r'-XPUT -d value="{'
r'\"ip\":\"%s\",'
r'\"cluster_id\":\"%s\"'
r'}"' % (get_ip(), rr.ip, rr.ip, cluster_id))
# Store the redundancy group.
redundancy_group.append(rr)
self.redundancy_groups.append(redundancy_group)
return self
示例4: __init__
def __init__(self, name, start_calico=True, dind=True,
additional_docker_options="",
post_docker_commands=["docker load -i /code/calico-node.tar",
"docker load -i /code/busybox.tar"],
calico_node_autodetect_ip=False):
self.name = name
self.dind = dind
self.workloads = set()
self.ip = None
"""
An IP address value to pass to calicoctl as `--ip`. If left as None, no value will be passed,
forcing calicoctl to do auto-detection.
"""
self.ip6 = None
"""
An IPv6 address value to pass to calicoctl as `--ipv6`. If left as None, no value will be passed.
"""
# This variable is used to assert on destruction that this object was
# cleaned up. If not used as a context manager, users of this object
self._cleaned = False
docker_args = "--privileged -tid " \
"-v /lib/modules:/lib/modules " \
"-v %s/certs:%s/certs -v %s:/code --name %s" % \
(CHECKOUT_DIR, CHECKOUT_DIR, CHECKOUT_DIR,
self.name)
if ETCD_SCHEME == "https":
docker_args += " --add-host %s:%s" % (ETCD_HOSTNAME_SSL, get_ip())
if dind:
log_and_run("docker rm -f %s || true" % self.name)
# Pass the certs directory as a volume since the etcd SSL/TLS
# environment variables use the full path on the host.
# Set iptables=false to prevent iptables error when using dind libnetwork
log_and_run("docker run %s "
"calico/dind:latest "
" --storage-driver=aufs "
"--iptables=false "
"%s" %
(docker_args, additional_docker_options))
self.ip = log_and_run("docker inspect --format "
"'{{.NetworkSettings.Networks.bridge.IPAddress}}' %s" % self.name)
# Make sure docker is up
docker_ps = partial(self.execute, "docker ps")
retry_until_success(docker_ps, ex_class=CalledProcessError,
retries=10)
for command in post_docker_commands:
self.execute(command)
elif not calico_node_autodetect_ip:
# Find the IP so it can be specified as `--ip` when launching node later.
self.ip = get_ip(v6=False)
self.ip6 = get_ip(v6=True)
if start_calico:
self.start_calico_node()
示例5: set_ip_address
def set_ip_address(options):
utils.log('Setting IP Address')
wireless_ip = utils.get_ip('10.{0}.{1}.42', options.team_number)
ethernet_ip = utils.get_ip('10.{0}.{1}.6', options.team_number)
if options.wireless_mac_address != '[None]':
configure_ip.switch_to_robot(
options.wireless_mac_address,
wireless_ip)
if options.ethernet_mac_address != '[None]':
configure_ip.switch_to_robot(
options.ethernet_mac_address,
ethernet_ip)
示例6: share
def share(filename, forever):
"""Share a file in the local network."""
ip = utils.get_ip()
# port = get_port()
# Bind to port 0. OS assigns a random open port.
server = httpserver.HTTPServer((ip, 0), utils.LocalFileHandler)
port = server.server_port
server.filename = filename
zc_info = zeroconf.ServiceInfo(
"_http._tcp.local.",
"%s._http._tcp.local." % filename,
utils.ip_to_bytes(ip), port, 0, 0,
{'filename': filename}
)
url = "http://" + ip + ":" + str(port) + "/" + urllib.pathname2url(filename)
zc_instance = zeroconf.Zeroconf()
try:
zc_instance.register_service(zc_info)
click.echo('Sharing %s at %s' % (filename, url))
if forever:
server.serve_forever(poll_interval=0.5)
else:
server.handle_request()
click.echo('File downloaded by peer. Exiting')
sys.exit(0)
except KeyboardInterrupt:
pass
示例7: signup
def signup():
error = None
form = SignUpForm()
if form.validate_on_submit():
user = User(
name=form.username.data,
email=form.email.data,
password=form.password.data,
ip=get_ip())
try:
db.session.add(user)
db.session.commit()
login_user(user)
flash("You just added user <strong>%s</strong>" % user.name, "success")
next = request.args.get("next")
if not is_safe_url(next):
return flask.abort(400)
return redirect(next or url_for("index"))
except:
flash("That username already exists", "danger")
return redirect(url_for("signup"))
return render_template(
"signup.html",
error=error,
form=form
)
示例8: calicoctl
def calicoctl(self, command):
"""
Convenience function for abstracting away calling the calicoctl
command.
Raises a CommandExecError() if the command returns a non-zero
return code.
:param command: The calicoctl command line parms as a single string.
:return: The output from the command with leading and trailing
whitespace removed.
"""
if os.environ.get("CALICOCTL"):
calicoctl = os.environ["CALICOCTL"]
else:
if self.dind:
calicoctl = "/code/dist/calicoctl"
else:
calicoctl = "dist/calicoctl"
etcd_auth = "ETCD_AUTHORITY=%s:2379" % get_ip()
# Export the environment, in case the command has multiple parts, e.g.
# use of | or ;
calicoctl = "export %s; %s" % (etcd_auth, calicoctl)
return self.execute(calicoctl + " " + command)
示例9: start_calico_node_with_docker
def start_calico_node_with_docker(self):
"""
Start calico in a container inside a host by calling docker directly.
"""
if ETCD_SCHEME == "https":
etcd_auth = "%s:2379" % ETCD_HOSTNAME_SSL
ssl_args = "-e ETCD_CA_CERT_FILE=%s " \
"-e ETCD_CERT_FILE=%s " \
"-e ETCD_KEY_FILE=%s " \
"-v %s/certs:%s/certs " \
% (ETCD_CA, ETCD_CERT, ETCD_KEY,
CHECKOUT_DIR, CHECKOUT_DIR)
else:
etcd_auth = "%s:2379" % get_ip()
ssl_args = ""
# If the hostname has been overridden on this host, then pass it in
# as an environment variable.
if self.override_hostname:
hostname_args = "-e HOSTNAME=%s" % self.override_hostname
else:
hostname_args = ""
self.execute("docker run -d --net=host --privileged "
"--name=calico-node "
"%s "
"-e IP=%s "
"-e ETCD_AUTHORITY=%s -e ETCD_SCHEME=%s %s "
"-v /var/log/calico:/var/log/calico "
"-v /var/run/calico:/var/run/calico "
"calico/node:latest" % (hostname_args,
self.ip,
etcd_auth, ETCD_SCHEME, ssl_args))
示例10: post
def post(self):
db = SETTINGS['db']
body = json.loads(self.request.body)
item = body['image']
ip = utils.get_ip(self.request)
# Get item
db_item = yield motor.Op(db.images.find_one, {'unixtime': item['unixtime']})
_id = db_item['_id']
# Save like/unlike on item
if ip in db_item['likes']['data']:
db_item['likes']['data'].remove(ip)
db_item['likes']['count'] -= 1
else:
db_item['likes']['data'].append(ip)
db_item['likes']['count'] += 1
# Update item
update_command = {'$set': {'likes': db_item['likes']}}
yield motor.Op(db.images.update, {'_id': _id}, update_command)
data = {'likes': db_item['likes']}
self.finish(data)
示例11: calicoctl
def calicoctl(self, command):
"""
Convenience function for abstracting away calling the calicoctl
command.
Raises a CommandExecError() if the command returns a non-zero
return code.
:param command: The calicoctl command line parms as a single string.
:return: The output from the command with leading and trailing
whitespace removed.
"""
calicoctl = os.environ.get("CALICOCTL", "/code/dist/calicoctl")
if ETCD_SCHEME == "https":
etcd_auth = "%s:2379" % ETCD_HOSTNAME_SSL
else:
etcd_auth = "%s:2379" % get_ip()
# Export the environment, in case the command has multiple parts, e.g.
# use of | or ;
#
# Pass in all etcd params, the values will be empty if not set anyway
calicoctl = "export ETCD_AUTHORITY=%s; " \
"export ETCD_SCHEME=%s; " \
"export ETCD_CA_CERT_FILE=%s; " \
"export ETCD_CERT_FILE=%s; " \
"export ETCD_KEY_FILE=%s; %s" % \
(etcd_auth, ETCD_SCHEME, ETCD_CA, ETCD_CERT, ETCD_KEY,
calicoctl)
return self.execute(calicoctl + " " + command)
示例12: start_calico_node_with_docker
def start_calico_node_with_docker(self):
"""
Start calico in a container inside a host by calling docker directly.
"""
if ETCD_SCHEME == "https":
etcd_auth = "%s:2379" % ETCD_HOSTNAME_SSL
ssl_args = "-e ETCD_CA_CERT_FILE=%s " \
"-e ETCD_CERT_FILE=%s " \
"-e ETCD_KEY_FILE=%s " \
"-v %s/certs:%s/certs " \
% (ETCD_CA, ETCD_CERT, ETCD_KEY,
CHECKOUT_DIR, CHECKOUT_DIR)
else:
etcd_auth = "%s:2379" % get_ip()
ssl_args = ""
self.execute("docker run -d --net=host --privileged "
"--name=calico-node "
"-e IP=%s -e ETCD_AUTHORITY=%s "
"-e ETCD_SCHEME=%s %s "
"-v /var/log/calico:/var/log/calico "
"-v /var/run/calico:/var/run/calico "
"calico/node:latest" % (self.ip, etcd_auth,
ETCD_SCHEME, ssl_args))
示例13: r_3login_callback_qq
def r_3login_callback_qq():
args = casts(request.args, code=str, callUrl=str)
if not args.code:
abort(403, '缺少参数code')
code = args.code
callUrl = args.callUrl
# print('r_3login_callback:', code)
user_id = 0
token_info = qq_login.get_access_token(code)
# print('r_3login_callback11:', token_info)
if not token_info:
abort(403, 'no token')
openid_info = qq_login.get_openid(token_info.access_token)
if not openid_info:
abort(403, "no openid")
user = qq_login.get_user_info(token_info.access_token, openid_info.openid)
# print('r_3login_callback12:', user)
ip = get_ip()
user_id = api_user.reg_or_log_qq(user, ip, openid_info.openid)
if user_id:
sess_result = api_user.set_sess(user_id)
if sess_result == -1:
return redirect('/feedback/?f=user_baned')
if callUrl:
return redirect(callUrl)
else:
return redirect('/')
else:
abort(403, "args err")
示例14: server_connect
def server_connect(self):
if self.ip:
return False
self.ip = str(utils.get_ip())
if (not self.ip) or self.ip == SERVER_IP or self.connectedToServer:
print "no connection to the network"
return False
d = self.connect_end_point()
def c(ampProto):
return ampProto.callRemote(Connect, ip=self.ip)
d.addCallback(c)
d.addErrback(err)
reactor.callLater(10, d.cancel)
def connected_server(args):
pid = args['id']
otherPids = args['cur']
mapName = args['map']
# callback for after connection, arg:pid of self and server
if pid != -1: # check no error
print "my pid is ", pid
self.pid = pid
self.playerList = otherPids
self.map = self._init_map_and_cm(mapName)
else:
print "Connected server but can't play game, map is full or game already started"
d.addCallback(connected_server)
d.addErrback(err)
reactor.callLater(10, d.cancel)
return True
示例15: hola
def hola(solicitud):
if solicitud.method == 'POST' and solicitud.POST.get('email') and solicitud.POST.get('nombre'):
pais = get_pais(solicitud.META)
email = solicitud.POST['email']
nombre = solicitud.POST['nombre']
payload = {
'email_address': email,
'apikey': settings.MAILCHIMP_APIKEY,
'merge_vars': {
'FNAME': nombre,
'OPTINIP': get_ip(solicitud.META),
'OPTIN_TIME': time.time(),
'PAIS': pais
},
'id': settings.MAILCHIMP_LISTID,
'email_type': 'html'
}
r = requests.post('http://us4.api.mailchimp.com/1.3/?method=listSubscribe', simplejson.dumps(payload))
return HttpResponse(r.text)
return render_to_response('./hola.html')