-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* virtual machine update * style fix * bump version * add code for compare vm configurations * move virtual machine tasks file to folder * fix bug in get property and deep search in dictionary keys * remove comments and style fixes * add tests * fix log message * __NODOCS__ * added comment regarding upgrade of the api version
- Loading branch information
1 parent
f82f5ef
commit 424636e
Showing
12 changed files
with
341 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
cloudify_azure/resources/compute/virtualmachine/virtualmachine_utils.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# ####### | ||
# Copyright (c) 2016-2020 Cloudify Platform Ltd. All rights reserved | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from cloudify import ctx | ||
|
||
|
||
def check_if_configuration_changed(ctx, update_payload, current_vm): | ||
for prop in ['location', 'tags', 'plan', 'availability_set', | ||
'eviction_policy', 'billing_profile', 'priority', | ||
'hardware_profile']: | ||
update_property_value = update_payload.get(prop) | ||
current_vm_property_value = current_vm.get(prop) | ||
if update_property_value and ordered( | ||
update_property_value) != ordered(current_vm_property_value): | ||
ctx.logger.info("{prop} changed.".format(prop=prop)) | ||
ctx.logger.info("update payload: {content}.".format( | ||
content=update_property_value)) | ||
ctx.logger.info("current configuration: {content}.".format( | ||
content=current_vm_property_value)) | ||
return True | ||
|
||
for prop in ['os_profile', 'storage_profile', 'network_profile']: | ||
if prop == 'network_profile' and update_payload.get(prop): | ||
update_property_value = update_payload.get(prop).as_dict() | ||
else: | ||
update_property_value = update_payload.get(prop, {}) | ||
|
||
current_vm_property_value = current_vm.get(prop, {}) | ||
if diff_dictionaries(update_property_value, current_vm_property_value): | ||
ctx.logger.info("{prop} changed.".format(prop=prop)) | ||
return True | ||
|
||
return False | ||
|
||
|
||
def diff_dictionaries(update_dict, current_conf_dict): | ||
""" | ||
Returns True if update_dict has changes in a key that doesn't appear in | ||
current_conf_dict. | ||
current_conf_dict can have additional keys and its not considered as a | ||
diff. | ||
""" | ||
for key in update_dict: | ||
if isinstance(update_dict.get(key), dict): | ||
res = diff_dictionaries(update_dict.get(key), | ||
current_conf_dict.get(key, {})) | ||
if res: | ||
return True | ||
elif ordered(update_dict.get(key)) != ordered( | ||
current_conf_dict.get(key)): | ||
ctx.logger.info( | ||
'Changes found in diff_dictionaries: key={key}\n'.format( | ||
key=key)) | ||
ctx.logger.info( | ||
'update_dict: {}'.format(ordered(update_dict.get(key)))) | ||
ctx.logger.info( | ||
'current_conf_dict: {}'.format(ordered( | ||
current_conf_dict.get(key)))) | ||
return True | ||
return False | ||
|
||
|
||
def ordered(obj): | ||
""" | ||
This function will recursively sort any lists it finds | ||
(and convert dictionaries to lists of (key, value) pairs so that they're | ||
orderable) | ||
""" | ||
if isinstance(obj, dict): | ||
return sorted((k, ordered(v)) for k, v in obj.items()) | ||
if isinstance(obj, list): | ||
return sorted(ordered(x) for x in obj) | ||
if isinstance(obj, str): | ||
return obj.lower() | ||
if isinstance(obj, (int, float)): | ||
return str(obj) | ||
else: | ||
return obj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.