Fix: failed to create the replicas

guest-agent should get the user-defined port's ip for primay instance
rather than the management ip when network_isolation is set to true.

Change-Id: I6f24cf623aa2836517dffda99305d127413d9df2
This commit is contained in:
wu.chunyang 2023-08-17 02:50:21 +00:00
parent 4288b8f782
commit ae3c0a225a
2 changed files with 27 additions and 2 deletions

View File

@ -15,12 +15,15 @@
#
import abc
import json
import os
import uuid
from oslo_log import log as logging
from oslo_utils import netutils
from trove.common import cfg
from trove.common import constants
from trove.common.db.mysql import models
from trove.common import exception
from trove.common import utils
@ -35,8 +38,18 @@ class MysqlReplicationBase(base.Replication):
"""Base class for MySql Replication strategies."""
def get_master_ref(self, service, snapshot_info):
ip_address = None
if CONF.network_isolation and \
os.path.exists(constants.ETH1_CONFIG_PATH):
# Get IP_address from eth1.json, ipv4 address was preferred.
with open(constants.ETH1_CONFIG_PATH) as fd:
eth1_config = json.load(fd)
ip_address = eth1_config.get("ipv4_address", None) or \
eth1_config.get("ipv6_address", None)
if not ip_address:
ip_address = netutils.get_my_ipv4()
master_ref = {
'host': netutils.get_my_ipv4(),
'host': ip_address,
'port': service.get_port()
}
return master_ref

View File

@ -11,12 +11,14 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json
import os
from oslo_log import log as logging
from oslo_utils import netutils
from trove.common import cfg
from trove.common import constants
from trove.common.db.postgresql import models
from trove.common import exception
from trove.common import utils
@ -143,8 +145,18 @@ class PostgresqlReplicationStreaming(base.Replication):
return snapshot_info['id'], replica_conf
def get_master_ref(self, service, snapshot_info):
ip_address = None
if CONF.network_isolation and \
os.path.exists(constants.ETH1_CONFIG_PATH):
# Get IP_address from eth1.json, ipv4 address was preferred.
with open(constants.ETH1_CONFIG_PATH) as fd:
eth1_config = json.load(fd)
ip_address = eth1_config.get("ipv4_address", None) or \
eth1_config.get("ipv6_address", None)
if not ip_address:
ip_address = netutils.get_my_ipv4()
master_ref = {
'host': netutils.get_my_ipv4(),
'host': ip_address,
'port': cfg.get_configuration_property('postgresql_port')
}
return master_ref