Flavor is optional for creating instance

When creating replicas, flavor is not needed. Replica has the same
server settings as the primary.

Change-Id: Ia9b43a464763234b84ba163d8c773b21f53f4ee7
This commit is contained in:
Lingxian Kong 2020-07-26 00:40:12 +12:00
parent 40af556264
commit c23da586e9
4 changed files with 23 additions and 18 deletions

View File

@ -0,0 +1,4 @@
---
features:
- Change flavor as an optional parameter (``--flavor``) for creating
instance. When creating replicas, flavor is not requried.

View File

@ -227,7 +227,7 @@ class CreateDatabaseInstance(command.ShowOne):
help=_("Name of the instance."),
)
parser.add_argument(
'flavor',
'--flavor',
metavar='<flavor>',
type=str,
help=_("A flavor ID."),
@ -241,7 +241,7 @@ class CreateDatabaseInstance(command.ShowOne):
"Required when volume support is enabled."),
)
parser.add_argument(
'--volume_type',
'--volume-type',
metavar='<volume_type>',
type=str,
default=None,
@ -268,7 +268,7 @@ class CreateDatabaseInstance(command.ShowOne):
help=_("A backup name or ID."),
)
parser.add_argument(
'--availability_zone',
'--availability-zone',
metavar='<availability_zone>',
default=None,
help=_("The Zone hint to give to Nova."),
@ -280,7 +280,7 @@ class CreateDatabaseInstance(command.ShowOne):
help=_("A datastore name or ID."),
)
parser.add_argument(
'--datastore_version',
'--datastore-version',
metavar='<datastore_version>',
default=None,
help=_("A datastore version name or ID."),
@ -298,13 +298,13 @@ class CreateDatabaseInstance(command.ShowOne):
help=_("ID of the configuration group to attach to the instance."),
)
parser.add_argument(
'--replica_of',
'--replica-of',
metavar='<source_instance>',
default=None,
help=_("ID or name of an existing instance to replicate from."),
)
parser.add_argument(
'--replica_count',
'--replica-count',
metavar='<count>',
type=int,
default=None,
@ -353,7 +353,6 @@ class CreateDatabaseInstance(command.ShowOne):
def take_action(self, parsed_args):
database = self.app.client_manager.database
db_instances = database.instances
flavor_id = parsed_args.flavor
volume = None
if parsed_args.size is not None and parsed_args.size <= 0:
@ -409,7 +408,7 @@ class CreateDatabaseInstance(command.ShowOne):
instance = db_instances.create(
parsed_args.name,
flavor_id,
flavor_id=parsed_args.flavor,
volume=volume,
databases=databases,
users=users,

View File

@ -204,15 +204,15 @@ class TestDatabaseInstanceCreate(TestInstances):
@mock.patch.object(utils, 'find_resource')
def test_instance_create(self, mock_find):
mock_find.id.side_effect = ['test', 'mod_id']
args = ['test-name', '103',
args = ['test-name', '--flavor', '103',
'--size', '1',
'--databases', 'db1', 'db2',
'--users', 'u1:111', 'u2:111',
'--datastore', "datastore",
'--datastore_version', "datastore_version",
'--datastore-version', "datastore_version",
'--nic', 'net-id=net1',
'--replica_of', 'test',
'--replica_count', '4',
'--replica-of', 'test',
'--replica-count', '4',
'--module', 'mod_id',
'--is-public',
'--allowed-cidr', '10.0.0.1/24',

View File

@ -89,18 +89,20 @@ class Instances(base.ManagerWithFind):
auth_url, user, key, auth_version=auth_version,
os_options=os_options)
def create(self, name, flavor_id, volume=None, databases=None, users=None,
restorePoint=None, availability_zone=None, datastore=None,
datastore_version=None, nics=None, configuration=None,
replica_of=None, replica_count=None, modules=None,
locality=None, region_name=None, access=None, **kwargs):
def create(self, name, flavor_id=None, volume=None, databases=None,
users=None, restorePoint=None, availability_zone=None,
datastore=None, datastore_version=None, nics=None,
configuration=None, replica_of=None, replica_count=None,
modules=None, locality=None, region_name=None, access=None,
**kwargs):
"""Create (boot) a new instance."""
body = {"instance": {
"name": name,
"flavorRef": flavor_id
}}
datastore_obj = {}
if flavor_id:
body["instance"]["flavorRef"] = flavor_id
if volume:
body["instance"]["volume"] = volume
if databases: