コード例 #1
0
    def _add_location(self, name, want_item, have_item):
        commands = []
        have_dict = {}
        have_ca = {}
        set_cmd = name + " location "
        want_location_type = want_item.get("location") or {}
        have_location_type = have_item.get("location") or {}

        if want_location_type["coordinate_based"]:
            want_dict = want_location_type.get("coordinate_based") or {}
            if is_dict_element_present(have_location_type, "coordinate_based"):
                have_dict = have_location_type.get("coordinate_based") or {}
            location_type = "coordinate-based"
            updates = dict_diff(have_dict, want_dict)
            for key, value in iteritems(updates):
                if value:
                    commands.append(
                        self._compute_command(set_cmd + location_type, key,
                                              str(value)))

        elif want_location_type["civic_based"]:
            location_type = "civic-based"
            want_dict = want_location_type.get("civic_based") or {}
            want_ca = want_dict.get("ca_info") or []
            if is_dict_element_present(have_location_type, "civic_based"):
                have_dict = have_location_type.get("civic_based") or {}
                have_ca = have_dict.get("ca_info") or []
                if want_dict["country_code"] != have_dict["country_code"]:
                    commands.append(
                        self._compute_command(
                            set_cmd + location_type,
                            "country-code",
                            str(want_dict["country_code"]),
                        ))
            else:
                commands.append(
                    self._compute_command(
                        set_cmd + location_type,
                        "country-code",
                        str(want_dict["country_code"]),
                    ))
            commands.extend(self._add_civic_address(name, want_ca, have_ca))

        elif want_location_type["elin"]:
            location_type = "elin"
            if is_dict_element_present(have_location_type, "elin"):
                if want_location_type.get("elin") != have_location_type.get(
                        "elin"):
                    commands.append(
                        self._compute_command(
                            set_cmd + location_type,
                            value=str(want_location_type["elin"]),
                        ))
            else:
                commands.append(
                    self._compute_command(
                        set_cmd + location_type,
                        value=str(want_location_type["elin"]),
                    ))
        return commands
コード例 #2
0
    def _add_location(self, name, want_item, have_item):
        commands = []
        have_dict = {}
        have_ca = {}
        set_cmd = name + ' location '
        want_location_type = want_item.get('location') or {}
        have_location_type = have_item.get('location') or {}

        if want_location_type['coordinate_based']:
            want_dict = want_location_type.get('coordinate_based') or {}
            if is_dict_element_present(have_location_type, 'coordinate_based'):
                have_dict = have_location_type.get('coordinate_based') or {}
            location_type = 'coordinate-based'
            updates = dict_diff(have_dict, want_dict)
            for key, value in iteritems(updates):
                if value:
                    commands.append(
                        self._compute_command(set_cmd + location_type, key, str(value))
                    )

        elif want_location_type['civic_based']:
            location_type = 'civic-based'
            want_dict = want_location_type.get('civic_based') or {}
            want_ca = want_dict.get('ca_info') or []
            if is_dict_element_present(have_location_type, 'civic_based'):
                have_dict = have_location_type.get('civic_based') or {}
                have_ca = have_dict.get('ca_info') or []
                if want_dict['country_code'] != have_dict['country_code']:
                    commands.append(
                        self._compute_command(
                            set_cmd + location_type, 'country-code', str(want_dict['country_code'])
                        )
                    )
            else:
                commands.append(
                    self._compute_command(
                        set_cmd + location_type, 'country-code', str(want_dict['country_code'])
                    )
                )
            commands.extend(self._add_civic_address(name, want_ca, have_ca))

        elif want_location_type['elin']:
            location_type = 'elin'
            if is_dict_element_present(have_location_type, 'elin'):
                if want_location_type.get('elin') != have_location_type.get('elin'):
                    commands.append(
                        self._compute_command(
                            set_cmd + location_type, value=str(want_location_type['elin'])
                        )
                    )
            else:
                commands.append(
                    self._compute_command(
                        set_cmd + location_type, value=str(want_location_type['elin'])
                    )
                )
        return commands
コード例 #3
0
    def _update_location(self, name, want_item, have_item):
        commands = []
        del_cmd = name + ' location'
        want_location_type = want_item.get('location') or {}
        have_location_type = have_item.get('location') or {}

        if want_location_type['coordinate_based']:
            want_dict = want_location_type.get('coordinate_based') or {}
            if is_dict_element_present(have_location_type, 'coordinate_based'):
                have_dict = have_location_type.get('coordinate_based') or {}
                location_type = 'coordinate-based'
                for key, value in iteritems(have_dict):
                    only_in_have = key_value_in_dict(key, value, want_dict)
                    if not only_in_have:
                        commands.append(
                            self._compute_command(del_cmd + location_type, key, str(value), True)
                        )
            else:
                commands.append(
                    self._compute_command(del_cmd, remove=True)
                )

        elif want_location_type['civic_based']:
            want_dict = want_location_type.get('civic_based') or {}
            want_ca = want_dict.get('ca_info') or []
            if is_dict_element_present(have_location_type, 'civic_based'):
                have_dict = have_location_type.get('civic_based') or {}
                have_ca = have_dict.get('ca_info')
                commands.extend(self._update_civic_address(name, want_ca, have_ca))
            else:
                commands.append(
                    self._compute_command(del_cmd, remove=True)
                )

        else:
            if is_dict_element_present(have_location_type, 'elin'):
                if want_location_type.get('elin') != have_location_type.get('elin'):
                    commands.append(
                        self._compute_command(del_cmd, remove=True)
                    )
            else:
                commands.append(
                    self._compute_command(del_cmd, remove=True)
                )
        return commands
コード例 #4
0
 def _configure_status(self, name, want_item, have_item):
     commands = []
     if is_dict_element_present(have_item, "enable"):
         temp_have_item = False
     else:
         temp_have_item = True
     if want_item["enable"] != temp_have_item:
         if want_item["enable"]:
             commands.append(
                 self._compute_command(name, value="disable", remove=True))
         else:
             commands.append(self._compute_command(name, value="disable"))
     return commands