Skip to content

Commit

Permalink
Flavor is optional for creating instance
Browse files Browse the repository at this point in the history
When creating replicas, flavor is not needed. Replica has the same
server settings as the primary.

Change-Id: Ia9b43a464763234b84ba163d8c773b21f53f4ee7
  • Loading branch information
lingxiankong committed Jul 26, 2020
1 parent 40af556 commit c23da58
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
4 changes: 4 additions & 0 deletions releasenotes/notes/victoria-flavor-optional.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
features:
- Change flavor as an optional parameter (``--flavor``) for creating
instance. When creating replicas, flavor is not requried.
15 changes: 7 additions & 8 deletions troveclient/osc/v1/database_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def get_parser(self, prog_name):
help=_("Name of the instance."),
)
parser.add_argument(
'flavor',
'--flavor',
metavar='<flavor>',
type=str,
help=_("A flavor ID."),
Expand All @@ -241,7 +241,7 @@ def get_parser(self, prog_name):
"Required when volume support is enabled."),
)
parser.add_argument(
'--volume_type',
'--volume-type',
metavar='<volume_type>',
type=str,
default=None,
Expand All @@ -268,7 +268,7 @@ def get_parser(self, prog_name):
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."),
Expand All @@ -280,7 +280,7 @@ def get_parser(self, prog_name):
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."),
Expand All @@ -298,13 +298,13 @@ def get_parser(self, prog_name):
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,
Expand Down Expand Up @@ -353,7 +353,6 @@ def get_parser(self, prog_name):
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:
Expand Down Expand Up @@ -409,7 +408,7 @@ def take_action(self, parsed_args):

instance = db_instances.create(
parsed_args.name,
flavor_id,
flavor_id=parsed_args.flavor,
volume=volume,
databases=databases,
users=users,
Expand Down
8 changes: 4 additions & 4 deletions troveclient/tests/osc/v1/test_database_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,15 @@ def setUp(self):
@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',
Expand Down
14 changes: 8 additions & 6 deletions troveclient/v1/instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,20 @@ def _get_swift_client(self):
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:
Expand Down

0 comments on commit c23da58

Please sign in to comment.