Openstack SDK,仅创建新服务器的IPv4。

huangapple go评论67阅读模式
英文:

Openstack SDK, create new server only IPV4

问题

conn: Connection = create_connection()

nics = [{'net-id': '`net_id`', 'subnet-id': '`subnet_id`'}]

params = {
    'name': 'Instance_app_2',
    'networks': [{'uuid': 'net_id'}],
    'nics': nics,
    'security_groups': [{'name': 'GroupName'}],
    'user_data': create_user_data(),  # 编码后的 user_data
    'flavor_id': '`flavor_id`',
    'image_id': '`image_id`',
    'ipv6_address_mode': None,
    'ipv6_ra_mode': None,
}

server = conn.compute.create_server(**params)
英文:
conn: Connection = create_connection()

nics = [{'net-id': '`net_id`', 'subnet-id': '`subnet_id`'}]

params = {
    'name': 'Instance_app_2',
    'networks': [{'uuid': 'net_id'}],
    'nics': nics,
    'security_groups': [{'name': 'GroupName'}],
    'user_data': create_user_data(), # encoded user_data
    'flavor_id': '`flavor_id`'
    'image_id': '`image_id`',
    'ipv6_address_mode': None,
    'ipv6_ra_mode': None,
}

server = conn.compute.create_server(**params)

I run the code and create a server have both IPv4 and IPv6.
How can I create a new server with only IPv4 ? please  

答案1

得分: 1

首先,ipv6_address_modeipv6_ra_mode 用于 network.create_subnet 方法,而不是 compute.create_server 方法,它们的有效值为:'dhcpv6-stateful'、'dhcpv6-stateless' 或 'slaac'。

其次,在 create_server 方法中,networks 参数与 nics 参数是互斥的。

最后,在您的情况下,创建一个同时具有IPv4和IPv6的服务器,我猜您已经在 net_id 中定义了 ipv6_address_scope 或在 subnet_id 中定义了 ipv6_*_mode,因此它将自动创建IPv6地址。

尝试创建一个仅具有IPv4地址的 port_id,然后只需使用 {'nics': port_id} 来创建服务器。

另请参考:https://docs.openstack.org/openstacksdk/latest/user/connection.html

英文:

Firstly, ipv6_address_mode and ipv6_ra_mode are used by network.create_subnet rather than compute.create_server method, and their Valid values are: 'dhcpv6-stateful', 'dhcpv6-stateless', or 'slaac'.

Secondly, the networks parameter Mutually exclusive with the nics parameter in create_server method.

Lastly, in your case create a server have both IPv4 and IPv6, I guess that you had already defined the ipv6_address_scope in net_id or ipv6_*_mode in subnet_id, so it would auto create ipv6 address.

Try to create a port_id which port only with ipv4 address, and just use 'nics': port_id, to create_server.

see also: https://docs.openstack.org/openstacksdk/latest/user/connection.html

huangapple
  • 本文由 发表于 2023年3月3日 18:18:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/75625795.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定