Don't go fishing in the stack for the KeyName

The KeyName should be a property of the Instance, and need not have the
same name in the stack parameters.

Change-Id: I05dcfd9aa6f92bc7aaa2dbc594062984ac074b7e
Signed-off-by: Zane Bitter <zbitter@redhat.com>
This commit is contained in:
Zane Bitter 2012-06-27 11:47:30 +02:00
parent b942be0e36
commit 2c15f8e1b3
2 changed files with 13 additions and 10 deletions

View File

@ -241,17 +241,20 @@ class Instance(Resource):
res = Resource.validate(self)
if res:
return res
#check validity of key
if self.stack.parms['KeyName']:
try:
key_name = self.properties['KeyName']
except ValueError:
return
else:
keypairs = self.nova().keypairs.list()
valid_key = False
for k in keypairs:
if k.name == self.stack.parms['KeyName']:
valid_key = True
if not valid_key:
return {'Error':
'Provided KeyName is not registered with nova'}
return None
if k.name == key_name:
return
return {'Error':
'Provided KeyName is not registered with nova'}
def handle_delete(self):
try:

View File

@ -71,7 +71,7 @@ test_template_ref = '''
"Properties": {
"ImageId": "image_name",
"InstanceType": "m1.large",
"KeyName": "test_KeyName"
"KeyName": { "Ref" : "KeyName" }
}
},
"DataVolume" : {
@ -112,7 +112,7 @@ test_template_findinmap_valid = '''
"Properties": {
"ImageId": "image_name",
"InstanceType": "m1.large",
"KeyName": "test_KeyName"
"KeyName": { "Ref" : "KeyName" }
}
},
"DataVolume" : {
@ -176,7 +176,7 @@ test_template_findinmap_invalid = '''
'"InstanceType" }, "Arch" ] } ] },' + \
'''
"InstanceType": "m1.large",
"KeyName": "test_KeyName"
"KeyName": { "Ref" : "KeyName"}
}
},
"DataVolume" : {