def create_app_catalog_subscription(compute_client, module): existing_app_catalog_subscription = get_app_catalog_subscription( compute_client, module) if existing_app_catalog_subscription: return dict(changed=False, app_catalog_subscription=existing_app_catalog_subscription) create_app_catalog_subscription_details = CreateAppCatalogSubscriptionDetails( ) for attr in six.iterkeys( create_app_catalog_subscription_details.swagger_types): setattr(create_app_catalog_subscription_details, attr, module.params.get(attr)) # sanitize time_retrieved parameter create_app_catalog_subscription_details.time_retrieved = _sanitize_time_retrieved( create_app_catalog_subscription_details.time_retrieved) oci_utils.to_dict( oci_utils.call_with_backoff( compute_client.create_app_catalog_subscription, create_app_catalog_subscription_details= create_app_catalog_subscription_details, ).data) app_catalog_subscription = get_app_catalog_subscription( compute_client, module) return dict(changed=True, app_catalog_subscription=app_catalog_subscription)
def run(self, ib_spec): state = self.module.params["state"] if state not in ("present", "absent"): self.module.fail_json( msg="state must be one of `present`, `absent`, got `%s`" % state) result = {"changed": False} obj_filter = dict([(k, self.module.params[k]) for k, v in iteritems(ib_spec) if v.get("ib_req")]) proposed_object = {} for key in iterkeys(ib_spec): if self.module.params[key] is not None: proposed_object[key] = self.module.params[key] if obj_filter["query"]: cature_query = obj_filter["query"] elif obj_filter["interface_name"] and obj_filter["type"]: cature_query = ( SKYDIVE_GREMLIN_QUERY + "('Name', '{0}', 'Type', '{1}')".format( obj_filter["interface_name"], obj_filter["type"])) else: raise self.module.fail_json( msg= "Interface name and Type is required if gremlin query is not defined!" ) # to check current object ref for idempotency captured_list_objs = self.restclient_object.capture_list() current_ref_uuid = None for each_capture in captured_list_objs: if cature_query == each_capture.__dict__["query"]: current_ref_uuid = each_capture.__dict__["uuid"] break if state == "present": if not current_ref_uuid: try: self.restclient_object.capture_create( cature_query, obj_filter["capture_name"], obj_filter["description"], obj_filter["extra_tcp_metric"], obj_filter["ip_defrag"], obj_filter["reassemble_tcp"], obj_filter["layer_key_mode"], ) except Exception as e: self.module.fail_json(msg=to_text(e)) result["changed"] = True if state == "absent": if current_ref_uuid: try: self.restclient_object.capture_delete(current_ref_uuid) except Exception as e: self.module.fail_json(msg=to_text(e)) result["changed"] = True return result
def convert_keys(data): for key in iterkeys(data): new_key = key.replace("-", "") if new_key != key: data[new_key] = data[key] del data[key] return data
def __init__(self, result): self.data = [] self.k = set() self.d = {} if isinstance(result, dict): self.data = [result] elif isinstance(result, list): self.data = result for d in self.data: self.k.update(iterkeys(d)) for k, v in iteritems(d): if k not in iterkeys(self.d): self.d.update({k: [v]}) else: self.d[k].append(v)
def filter_object(self, obj1, obj2, check_only=False): changed_flag = False try: for k in list(iterkeys(obj1)): if k in list(iterkeys(obj2)): if type(obj1[k]) is dict: if cmp(obj1[k], obj2[k]) != 0: changed_flag = True elif obj1[k] != obj2[k]: changed_flag = True if not changed_flag and not check_only: del obj1[k] else: changed_flag = True return changed_flag except AttributeError: changed_flag = True return changed_flag
def run(self, ib_spec): state = self.module.params['state'] if state not in ('present', 'absent'): self.module.fail_json( msg='state must be one of `present`, `absent`, got `%s`' % state) result = {'changed': False} obj_filter = dict([(k, self.module.params[k]) for k, v in iteritems(ib_spec) if v.get('ib_req')]) proposed_object = {} for key in iterkeys(ib_spec): if self.module.params[key] is not None: proposed_object[key] = self.module.params[key] if obj_filter['query']: cature_query = obj_filter['query'] elif obj_filter['interface_name'] and obj_filter['type']: cature_query = SKYDIVE_GREMLIN_QUERY + "('Name', '{0}', 'Type', '{1}')".format( obj_filter['interface_name'], obj_filter['type']) else: raise self.module.fail_json( msg= "Interface name and Type is required if gremlin query is not defined!" ) # to check current object ref for idempotency captured_list_objs = self.restclient_object.capture_list() current_ref_uuid = None for each_capture in captured_list_objs: if cature_query == each_capture.__dict__['query']: current_ref_uuid = each_capture.__dict__['uuid'] break if state == 'present': if not current_ref_uuid: try: self.restclient_object.capture_create( cature_query, obj_filter['capture_name'], obj_filter['description'], obj_filter['extra_tcp_metric'], obj_filter['ip_defrag'], obj_filter['reassemble_tcp'], obj_filter['layer_key_mode']) except Exception as e: self.module.fail_json(msg=to_text(e)) result['changed'] = True if state == 'absent': if current_ref_uuid: try: self.restclient_object.capture_delete(current_ref_uuid) except Exception as e: self.module.fail_json(msg=to_text(e)) result['changed'] = True return result
def missing_required_params(rq_set, params): key_set = set(list(iterkeys(params))) required_minus_received = rq_set - key_set if required_minus_received != set(): return list(required_minus_received)
def clear_values(self, obj): for k in list(iterkeys(obj)): obj[k] = ''
def compare_keys(self, obj1, obj2): unknown_keys = [] for k in list(iterkeys(obj1)): if k not in list(iterkeys(obj2)): unknown_keys.append(k) return unknown_keys