Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nicolas Wavrant
slapos.core
Commits
67e6b1c4
Commit
67e6b1c4
authored
May 25, 2016
by
Rafael Monnerat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos.format: Get and upload public ipv4.
parent
d62fa8e3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
1 deletion
+26
-1
slapos/format.py
slapos/format.py
+26
-1
No files found.
slapos/format.py
View file @
67e6b1c4
...
...
@@ -49,6 +49,7 @@ import threading
import
time
import
traceback
import
zipfile
from
urllib2
import
urlopen
import
lxml.etree
import
xml_marshaller.xml_marshaller
...
...
@@ -124,6 +125,23 @@ class AddressGenerationError(Exception):
)
def
getPublicIPv4Address
():
test_list
=
[
{
"url"
:
'https://api.ipify.org/?format=json'
,
"json_key"
:
"ip"
},
{
"url"
:
'http://httpbin.org/ip'
,
"json_key"
:
"origin"
},
{
"url"
:
'http://jsonip.com'
,
"json_key"
:
"ip"
}]
previous
=
None
ipv4
=
None
for
test
in
test_list
:
if
ipv4
is
not
None
:
previous
=
ipv4
try
:
ipv4
=
json
.
load
(
urlopen
(
test
[
"url"
]))[
test
[
"json_key"
]]
except
:
ipv4
=
None
if
ipv4
is
not
None
and
ipv4
==
previous
:
return
ipv4
def
callAndRead
(
argument_list
,
raise_on_error
=
True
):
popen
=
subprocess
.
Popen
(
argument_list
,
stdout
=
subprocess
.
PIPE
,
...
...
@@ -237,6 +255,7 @@ class Computer(object):
self
.
ipv6_interface
=
ipv6_interface
self
.
software_user
=
software_user
self
.
tap_gateway_interface
=
tap_gateway_interface
self
.
public_ipv4_address
=
None
def
__getinitargs__
(
self
):
return
(
self
.
reference
,
self
.
interface
)
...
...
@@ -273,11 +292,16 @@ class Computer(object):
# Can't find address
raise
NoAddressOnInterface
(
'No valid IPv6 found on %s.'
%
self
.
interface
.
name
)
def
update
(
self
):
"""
Collect environmental hardware/network information.
"""
self
.
public_ipv4_address
=
getPublicIPv4Address
()
def
send
(
self
,
conf
):
"""
Send a marshalled dictionary of the computer object serialized via_getDict.
"""
slap_instance
=
slap
.
slap
()
connection_dict
=
{}
if
conf
.
key_file
and
conf
.
cert_file
:
...
...
@@ -1227,6 +1251,7 @@ def do_format(conf):
if
getattr
(
conf
,
'certificate_repository_path'
,
None
):
mkdir_p
(
conf
.
certificate_repository_path
,
mode
=
0o700
)
computer
.
update
()
# Dumping and sending to the erp5 the current configuration
if
not
conf
.
dry_run
:
computer
.
dump
(
path_to_xml
=
conf
.
computer_xml
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment