[sdk]: compute service create_server method, how to create multiple servers

melanie witt melwittt at gmail.com
Mon Apr 26 23:42:14 UTC 2021


On 4/16/21 15:56, dmeng wrote:
> Hello there,
> Hope this email finds you well.
> We are currently using the openstacksdk for developing our product, and 
> have a question about the openstacksdk compute service create_server() 
> method. We are wondering if the "max_count" and "min_count" are 
> supported by openstackskd for creating multiple servers at once. I tried 
> both the max_count and the min_count, and they both only create one 
> server for me, but I'd like to create multiple servers at once. The code 
> I'm using is like the following:
> conn = connection.Connection(
> session=sess,
> region_name=None,
> compute_api_version='2')
> 
> nova = conn.compute
> 
> nova.create_server(
> name='sdk-test-create',
> image_id=image_id,
> flavor_id=flavor_id,
> key_name=my_key_name,
> networks=[{"uuid": network_id}],
> security_groups=[{'name':security_group_name}],
> min_count=3,
> )
> The above code will create one server "sdk-test-create", but I'm 
> assuming it should create three. Wondering did I miss anything, or if we 
> have any other option to archive this?

Hi, I was able to reproduce the behavior you describe on a local 
devstack and have proposed the following patch to fix it:

https://review.opendev.org/c/openstack/openstacksdk/+/788098

I was able to verify ^ works by doing the following hackaround for testing:

from openstack import connection
from openstack import resource


class MyServer(_server.Server):
     min_count = resource.Body('min_count')
     max_count = resource.Body('max_count')

conn = connection.Connection(region_name='RegionOne', 
auth=dict(auth_url='http://127.0.0.1/identity', username='demo', 
password='a', project_id='7c60976c662a414cb2661831ff41ee30', 
user_domain_id='default'), compute_api_version='2', 
identity_interface='internal')

conn.compute._create(MyServer, name='mult', 
image_id='23d8bca0-5dfa-4dd0-9267-368ce1e1e8a0', flavor_id=42, 
min_count=2, networks='none')

HTH,
-melanie




More information about the openstack-discuss mailing list