Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
snf-ganeti
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
itminedu
snf-ganeti
Commits
264bb3c5
Commit
264bb3c5
authored
17 years ago
by
Michael Hanselmann
Browse files
Options
Downloads
Patches
Plain Diff
Get ports from configuration if there are some.
Reviewed-by: iustinp
parent
821afb13
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/config.py
+36
-9
36 additions, 9 deletions
lib/config.py
lib/objects.py
+4
-1
4 additions, 1 deletion
lib/objects.py
with
40 additions
and
10 deletions
lib/config.py
+
36
−
9
View file @
264bb3c5
...
...
@@ -53,6 +53,8 @@ class ConfigWriter:
def
__init__
(
self
,
cfg_file
=
None
,
offline
=
False
):
self
.
_config_data
=
None
self
.
_config_time
=
None
self
.
_config_size
=
None
self
.
_config_inode
=
None
self
.
_offline
=
offline
if
cfg_file
is
None
:
self
.
_cfg_file
=
constants
.
CLUSTER_CONF_FILE
...
...
@@ -167,6 +169,22 @@ class ConfigWriter:
disk
.
physical_id
=
disk
.
logical_id
return
def
AddTcpIpPort
(
self
,
port
):
if
not
isinstance
(
port
,
int
):
raise
errors
.
ProgrammerError
(
"
Invalid type passed for port
"
)
self
.
_OpenConfig
()
self
.
_config_data
.
tcpudp_port_pool
.
add
(
port
)
self
.
_WriteConfig
()
def
GetPortList
():
"""
Returns a copy of the current port list.
"""
self
.
_OpenConfig
()
self
.
_ReleaseLock
()
return
self
.
_config_data
.
tcpudp_port_pool
.
copy
()
def
AllocatePort
(
self
):
"""
Allocate a port.
...
...
@@ -175,12 +193,16 @@ class ConfigWriter:
"""
self
.
_OpenConfig
()
self
.
_config_data
.
cluster
.
highest_used_port
+=
1
if
self
.
_config_data
.
cluster
.
highest_used_port
>=
constants
.
LAST_DRBD_PORT
:
raise
errors
.
ConfigurationError
,
(
"
The highest used port is greater
"
"
than %s. Aborting.
"
%
constants
.
LAST_DRBD_PORT
)
port
=
self
.
_config_data
.
cluster
.
highest_used_port
# If there are TCP/IP ports configured, we use them first.
if
self
.
_config_data
.
tcpudp_port_pool
:
port
=
self
.
_config_data
.
tcpudp_port_pool
.
pop
()
else
:
port
=
self
.
_config_data
.
cluster
.
highest_used_port
+
1
if
port
>=
constants
.
LAST_DRBD_PORT
:
raise
errors
.
ConfigurationError
,
(
"
The highest used port is greater
"
"
than %s. Aborting.
"
%
constants
.
LAST_DRBD_PORT
)
self
.
_config_data
.
cluster
.
highest_used_port
=
port
self
.
_WriteConfig
()
return
port
...
...
@@ -377,7 +399,9 @@ class ConfigWriter:
raise
errors
.
ConfigurationError
,
"
Can
'
t stat config file: %s
"
%
err
if
(
self
.
_config_data
is
not
None
and
self
.
_config_time
is
not
None
and
self
.
_config_time
==
st
.
st_mtime
):
self
.
_config_time
==
st
.
st_mtime
and
self
.
_config_size
==
st
.
st_size
and
self
.
_config_inode
==
st
.
st_ino
):
# data is current, so skip loading of config file
return
f
=
open
(
self
.
_cfg_file
,
'
r
'
)
...
...
@@ -399,6 +423,8 @@ class ConfigWriter:
constants
.
CONFIG_VERSION
))
self
.
_config_data
=
data
self
.
_config_time
=
st
.
st_mtime
self
.
_config_size
=
st
.
st_size
self
.
_config_inode
=
st
.
st_ino
def
_ReleaseLock
(
self
):
"""
xxxx
...
...
@@ -464,8 +490,8 @@ class ConfigWriter:
secondary_ip: the secondary IP of the current host or None
clustername: the name of the cluster
hostkeypub: the public hostkey of this host
"""
"""
hu_port
=
constants
.
FIRST_DRBD_PORT
-
1
globalconfig
=
objects
.
Cluster
(
config_version
=
constants
.
CONFIG_VERSION
,
serial_no
=
1
,
master_node
=
node
,
...
...
@@ -482,7 +508,8 @@ class ConfigWriter:
self
.
_config_data
=
objects
.
ConfigData
(
nodes
=
{
node
:
nodeconfig
},
instances
=
{},
cluster
=
globalconfig
)
cluster
=
globalconfig
,
tcpudp_port_pool
=
set
())
self
.
_WriteConfig
()
def
GetClusterName
(
self
):
...
...
This diff is collapsed.
Click to expand it.
lib/objects.py
+
4
−
1
View file @
264bb3c5
...
...
@@ -100,6 +100,9 @@ class ConfigObject(object):
cls
=
Node
elif
name
==
"
Cluster
"
:
cls
=
Cluster
elif
module
==
"
__builtin__
"
:
if
name
==
"
set
"
:
cls
=
set
if
cls
is
None
:
raise
cPickle
.
UnpicklingError
,
(
"
Class %s.%s not allowed due to
"
"
security concerns
"
%
(
module
,
name
))
...
...
@@ -140,7 +143,7 @@ class ConfigObject(object):
class
ConfigData
(
ConfigObject
):
"""
Top-level config object.
"""
__slots__
=
[
"
cluster
"
,
"
nodes
"
,
"
instances
"
]
__slots__
=
[
"
cluster
"
,
"
nodes
"
,
"
instances
"
,
"
tcpudp_port_pool
"
]
class
NIC
(
ConfigObject
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment