Merge "Add config setting to require keypair on instance create"
This commit is contained in:
commit
192a830b24
@ -568,7 +568,8 @@ Default::
|
||||
|
||||
{
|
||||
'can_set_mount_point': False,
|
||||
'can_set_password': False
|
||||
'can_set_password': False,
|
||||
'requires_keypair': False,
|
||||
}
|
||||
|
||||
A dictionary containing settings which can be used to identify the
|
||||
@ -582,6 +583,9 @@ from the UI.
|
||||
Setting ``can_set_password`` to ``True`` will enable the option to set
|
||||
an administrator password when launching or rebuilding an instance.
|
||||
|
||||
Setting ``requires_keypair`` to ``True`` will require users to select
|
||||
a key pair when launching an instance.
|
||||
|
||||
|
||||
``OPENSTACK_IMAGE_BACKEND``
|
||||
---------------------------
|
||||
|
@ -977,3 +977,8 @@ def can_set_mount_point():
|
||||
hypervisor_features = getattr(
|
||||
settings, "OPENSTACK_HYPERVISOR_FEATURES", {})
|
||||
return hypervisor_features.get("can_set_mount_point", False)
|
||||
|
||||
|
||||
def requires_keypair():
|
||||
features = getattr(settings, 'OPENSTACK_HYPERVISOR_FEATURES', {})
|
||||
return features.get('requires_keypair', False)
|
||||
|
@ -1482,6 +1482,16 @@ class InstanceTests(helpers.TestCase):
|
||||
def test_launch_instance_get_without_password(self):
|
||||
self.test_launch_instance_get(expect_password_fields=False)
|
||||
|
||||
@django.test.utils.override_settings(
|
||||
OPENSTACK_HYPERVISOR_FEATURES={'requires_keypair': True})
|
||||
def test_launch_instance_required_key(self):
|
||||
flavor = self.flavors.first()
|
||||
image = self.images.first()
|
||||
image.min_ram = flavor.ram
|
||||
image.min_disk = flavor.disk
|
||||
self._test_launch_form_instance_requirement_error(image, flavor,
|
||||
keypair_require=True)
|
||||
|
||||
def test_launch_instance_get_no_block_device_mapping_v2_supported(self):
|
||||
self.test_launch_instance_get(block_device_mapping_v2=False)
|
||||
|
||||
@ -2883,7 +2893,8 @@ class InstanceTests(helpers.TestCase):
|
||||
'volume_snapshot_list',),
|
||||
quotas: ('tenant_quota_usages',)})
|
||||
def _test_launch_form_instance_requirement_error(self, image, flavor,
|
||||
test_with_profile=False):
|
||||
test_with_profile=False,
|
||||
keypair_require=False):
|
||||
keypair = self.keypairs.first()
|
||||
server = self.servers.first()
|
||||
volume = self.volumes.first()
|
||||
@ -2954,7 +2965,6 @@ class InstanceTests(helpers.TestCase):
|
||||
'source_type': 'image_id',
|
||||
'image_id': image.id,
|
||||
'availability_zone': avail_zone.zoneName,
|
||||
'keypair': keypair.name,
|
||||
'name': server.name,
|
||||
'script_source': 'raw',
|
||||
'script_data': customization_script,
|
||||
@ -2965,11 +2975,17 @@ class InstanceTests(helpers.TestCase):
|
||||
'volume_id': volume_choice,
|
||||
'device_name': device_name,
|
||||
'count': 1}
|
||||
if not keypair_require:
|
||||
form_data['keypair'] = keypair.name
|
||||
|
||||
url = reverse('horizon:project:instances:launch')
|
||||
res = self.client.post(url, form_data)
|
||||
msg = "The flavor '%s' is too small" % flavor.name
|
||||
self.assertContains(res, msg)
|
||||
if keypair_require:
|
||||
msg = "This field is required"
|
||||
self.assertContains(res, msg)
|
||||
else:
|
||||
msg = "The flavor '%s' is too small" % flavor.name
|
||||
self.assertContains(res, msg)
|
||||
|
||||
def test_launch_form_instance_requirement_error_disk(
|
||||
self,
|
||||
|
@ -539,7 +539,6 @@ KEYPAIR_IMPORT_URL = "horizon:project:access_and_security:keypairs:import"
|
||||
|
||||
class SetAccessControlsAction(workflows.Action):
|
||||
keypair = forms.DynamicChoiceField(label=_("Key Pair"),
|
||||
required=False,
|
||||
help_text=_("Key pair to use for "
|
||||
"authentication."),
|
||||
add_item_link=KEYPAIR_IMPORT_URL)
|
||||
@ -570,6 +569,7 @@ class SetAccessControlsAction(workflows.Action):
|
||||
if not api.nova.can_set_server_password():
|
||||
del self.fields['admin_pass']
|
||||
del self.fields['confirm_admin_pass']
|
||||
self.fields['keypair'].required = api.nova.requires_keypair()
|
||||
|
||||
def populate_keypair_choices(self, request, context):
|
||||
keypairs = instance_utils.keypair_field_data(request, True)
|
||||
|
@ -203,6 +203,7 @@ OPENSTACK_KEYSTONE_BACKEND = {
|
||||
OPENSTACK_HYPERVISOR_FEATURES = {
|
||||
'can_set_mount_point': False,
|
||||
'can_set_password': False,
|
||||
'requires_keypair': False,
|
||||
}
|
||||
|
||||
# The OPENSTACK_CINDER_FEATURES settings can be used to enable optional
|
||||
|
Loading…
x
Reference in New Issue
Block a user