Add nic to cluster grow

Added nic field to grow add instance form, the summary added instance
table, cached object and the api.

Change-Id: I927b3a233f9e6a97535dd9882d23393e8197b75a
Closes-bug: #1613449
This commit is contained in:
Ali Adil 2016-08-16 16:35:25 -04:00
parent 4d55652543
commit d53d2efbc6
5 changed files with 49 additions and 12 deletions

View File

@ -89,6 +89,8 @@ def cluster_grow(request, cluster_id, new_instances):
instance["type"] = new_instance.type
if new_instance.related_to:
instance["related_to"] = new_instance.related_to
if new_instance.nics:
instance["nics"] = [{'net-id': new_instance.nics}]
instances.append(instance)
return troveclient(request).clusters.grow(cluster_id, instances)

View File

@ -58,9 +58,9 @@ class ClusterInstanceManager(object):
return None
def add_instance(self, id, name, flavor_id,
flavor, volume, type, related_to):
flavor, volume, type, related_to, nics):
instance = ClusterInstance(id, name, flavor_id, flavor,
volume, type, related_to)
volume, type, related_to, nics)
self.instances.append(instance)
update(self.cluster_id, self)
return self.instances
@ -76,7 +76,8 @@ class ClusterInstanceManager(object):
class ClusterInstance(object):
def __init__(self, id, name, flavor_id, flavor, volume, type, related_to):
def __init__(self, id, name, flavor_id, flavor, volume, type,
related_to, nics):
self.id = id
self.name = name
self.flavor_id = flavor_id
@ -84,3 +85,4 @@ class ClusterInstance(object):
self.volume = volume
self.type = type
self.related_to = related_to
self.nics = nics

View File

@ -343,11 +343,17 @@ class ClusterAddInstanceForm(forms.SelfHandlingForm):
help_text=_("Optional datastore specific value that defines the "
"relationship from one instance in the cluster to "
"another."))
network = forms.ChoiceField(
label=_("Network"),
help_text=_("Network attached to instance."),
required=False)
def __init__(self, request, *args, **kwargs):
super(ClusterAddInstanceForm, self).__init__(request, *args, **kwargs)
self.fields['flavor'].choices = self.populate_flavor_choices(request)
self.fields['network'].choices = self.populate_network_choices(
request)
@memoized.memoized_method
def flavors(self, request):
@ -374,6 +380,26 @@ class ClusterAddInstanceForm(forms.SelfHandlingForm):
flavor_list = [(f.id, "%s" % f.name) for f in self.flavors(request)]
return sorted(flavor_list)
@memoized.memoized_method
def populate_network_choices(self, request):
network_list = []
try:
if api.base.is_service_enabled(request, 'network'):
tenant_id = self.request.user.tenant_id
networks = api.neutron.network_list_for_tenant(request,
tenant_id)
network_list = [(network.id, network.name_or_id)
for network in networks]
else:
self.fields['network'].widget = forms.HiddenInput()
except exceptions.ServiceCatalogException:
network_list = []
redirect = reverse('horizon:project:database_clusters:index')
exceptions.handle(request,
_('Unable to retrieve networks.'),
redirect=redirect)
return network_list
def handle(self, request, data):
try:
flavor = trove_api.trove.flavor_get(request, data['flavor'])
@ -384,7 +410,8 @@ class ClusterAddInstanceForm(forms.SelfHandlingForm):
flavor.name,
data['volume'],
data.get('type', None),
data.get('related_to', None))
data.get('related_to', None),
data.get('network', None))
except Exception as e:
redirect = reverse("horizon:project:database_clusters:index")
exceptions.handle(request,

View File

@ -389,10 +389,11 @@ class ClusterGrowAction(tables.Action):
datum_display_objs = []
for instance in table.data:
msg = _("[flavor=%(flavor)s, volume=%(volume)s, name=%(name)s, "
"type=%(type)s, related_to=%(related_to)s]")
"type=%(type)s, related_to=%(related_to)s, "
"nics=%(nics)s]")
params = {"flavor": instance.flavor_id, "volume": instance.volume,
"name": instance.name, "type": instance.type,
"related_to": instance.related_to}
"related_to": instance.related_to, "nics": instance.nics}
datum_display_objs.append(msg % params)
display_str = functions.lazy_join(", ", datum_display_objs)
@ -423,6 +424,7 @@ class ClusterGrowInstancesTable(tables.DataTable):
volume = tables.Column("volume", verbose_name=_("Volume"))
type = tables.Column("type", verbose_name=_("Instance Type"))
related_to = tables.Column("related_to", verbose_name=_("Related To"))
nics = tables.Column("nics", verbose_name=_("Network"))
class Meta(object):
name = "cluster_grow_instances_table"

View File

@ -395,13 +395,15 @@ class ClustersTests(test.TestCase):
instances = [
cluster_manager.ClusterInstance("id1", "name1", cluster_flavor,
cluster_flavor_name,
cluster_volume, "master", None),
cluster_volume, "master", None,
None),
cluster_manager.ClusterInstance("id2", "name2", cluster_flavor,
cluster_flavor_name,
cluster_volume, "slave", "master"),
cluster_volume, "slave",
"master", None),
cluster_manager.ClusterInstance("id3", None, cluster_flavor,
cluster_flavor_name,
cluster_volume, None, None),
cluster_volume, None, None, None),
]
manager = cluster_manager.ClusterInstanceManager(cluster.id)
@ -468,13 +470,15 @@ class ClustersTests(test.TestCase):
instances = [
cluster_manager.ClusterInstance("id1", "name1", cluster_flavor,
cluster_flavor_name,
cluster_volume, "master", None),
cluster_volume, "master", None,
None),
cluster_manager.ClusterInstance("id2", "name2", cluster_flavor,
cluster_flavor_name,
cluster_volume, "slave", "master"),
cluster_volume, "slave",
"master", None),
cluster_manager.ClusterInstance("id3", None, cluster_flavor,
cluster_flavor_name,
cluster_volume, None, None),
cluster_volume, None, None, None),
]
manager = cluster_manager.ClusterInstanceManager(cluster.id)