def request(self, format='xml', default_operation=None, target='running', config=None): node = new_ele('edit-config') config_node = new_ele('config') if default_operation is not None: # TODO: check if it is a valid default-operation sub_ele(node, "default-operation").text = default_operation if config is not None: if format == 'xml': node.append( util.datastore_or_url('target', target, self._assert)) config_node.append(config) if format == 'cli': node.append( util.datastore_or_url('target', 'running', self._assert)) sub_ele(config_node, 'config-format-cli-block').text = config node.append(config_node) return self._request(node)
def request(self, source, target): """Create or replace an entire configuration datastore with the contents of another complete configuration datastore. *source* is the name of the configuration datastore to use as the source of the copy operation or `config` element containing the configuration subtree to copy *target* is the name of the configuration datastore to use as the destination of the copy operation :seealso: :ref:`srctarget_params`""" node = new_ele("copy-config") node.append(util.datastore_or_url("target", target, self._assert)) node.append(util.datastore_or_url("source", source, self._assert)) return self._request(node)
def request(self, content='xml', filter=None, detail=False): """Get config from Alu router *content* Content layer. cli or xml *filter* specifies the portion of the configuration to retrieve (by default entire configuration is retrieved) *detail* Show detailed config in CLI -layer""" node = new_ele('get-config') node.append(util.datastore_or_url('source', 'running', self._assert)) if filter is not None: if content == 'xml': node.append(util.build_filter(('subtree', filter))) elif content == 'cli': rep = new_ele('filter') sub_filter = sub_ele(rep, 'config-format-cli-block') if filter is not None: for item in filter: if detail: sub_ele(sub_filter, 'cli-info-detail').text = item else: sub_ele(sub_filter, 'cli-info').text = item else: if detail: sub_ele(sub_filter, 'cli-info-detail') else: sub_ele(sub_filter, 'cli-info') node.append(validated_element(rep)) return self._request(node)
def request(self, rpc_command, source=None, filter=None): """ *rpc_command* specifies rpc command to be dispatched either in plain text or in xml element format (depending on command) *source* name of the configuration datastore being queried *filter* specifies the portion of the configuration to retrieve (by default entire configuration is retrieved) :seealso: :ref:`filter_params` Examples of usage:: dispatch('clear-arp-table') or dispatch element like :: xsd_fetch = new_ele('get-xnm-information') sub_ele(xsd_fetch, 'type').text="xml-schema" sub_ele(xsd_fetch, 'namespace').text="junos-configuration" dispatch(xsd_fetch) """ if etree.iselement(rpc_command): node = rpc_command else: node = new_ele(rpc_command) if source is not None: node.append(util.datastore_or_url("source", source, self._assert)) if filter is not None: node.append(util.build_filter(filter)) return self._request(node)
def request(self, rpc_command, source=None, filter=None, config=None, target=None, format=None): """ *rpc_command* specifies rpc command to be dispatched either in plain text or in xml element format (depending on command) *target* name of the configuration datastore being edited *source* name of the configuration datastore being queried *config* is the configuration, which must be rooted in the `config` element. It can be specified either as a string or an :class:`~xml.etree.ElementTree.Element`. *filter* specifies the portion of the configuration to retrieve (by default entire configuration is retrieved) :seealso: :ref:`filter_params` Examples of usage:: m.rpc('rpc_command') or dispatch element like :: rpc_command = new_ele('get-xnm-information') sub_ele(rpc_command, 'type').text = "xml-schema" m.rpc(rpc_command) """ if etree.iselement(rpc_command): node = rpc_command else: node = new_ele(rpc_command) if target is not None: node.append(util.datastore_or_url("target", target, self._assert)) if source is not None: node.append(util.datastore_or_url("source", source, self._assert)) if filter is not None: node.append(util.build_filter(filter)) if config is not None: node.append( validated_element(config, ("config", qualify("config")))) return self._request(node)
def request(self, target): """Delete a configuration datastore. *target* specifies the name or URL of configuration datastore to delete :seealso: :ref:`srctarget_params`""" node = new_ele("delete-config") node.append(util.datastore_or_url("target", target, self._assert)) return self._request(node)
def request(self, format='xml', default_operation=None, target='running', config=None): node = new_ele('edit-config') config_node = new_ele('config') if default_operation is not None: # TODO: check if it is a valid default-operation sub_ele(node, "default-operation").text = default_operation if config is not None: if format == 'xml': node.append(util.datastore_or_url('target', target, self._assert)) config_node.append(config) if format == 'cli': node.append(util.datastore_or_url('target', 'running', self._assert)) sub_ele(config_node, 'config-format-cli-block').text = config node.append(config_node) return self._request(node)
def request(self, config, format='xml', target='candidate', default_operation=None, test_option=None, error_option=None): """Loads all or part of the specified *config* to the *target* configuration datastore. *target* is the name of the configuration datastore being edited *config* is the configuration, which must be rooted in the `config` element. It can be specified either as a string or an :class:`~xml.etree.ElementTree.Element`. *default_operation* if specified must be one of { `"merge"`, `"replace"`, or `"none"` } *test_option* if specified must be one of { `"test-then-set"`, `"set"`, `"test-only"` } *error_option* if specified must be one of { `"stop-on-error"`, `"continue-on-error"`, `"rollback-on-error"` } The `"rollback-on-error"` *error_option* depends on the `:rollback-on-error` capability. """ node = new_ele("edit-config") node.append(util.datastore_or_url("target", target, self._assert)) if (default_operation is not None and util.validate_args('default_operation', default_operation, ["merge", "replace", "none"]) is True): sub_ele(node, "default-operation").text = default_operation if (test_option is not None and util.validate_args( 'test_option', test_option, ["test-then-set", "set", "test-only"]) is True): self._assert(':validate') if test_option == 'test-only': self._assert(':validate:1.1') sub_ele(node, "test-option").text = test_option if (error_option is not None and util.validate_args('error_option', error_option, [ "stop-on-error", "continue-on-error", "rollback-on-error" ]) is True): if error_option == "rollback-on-error": self._assert(":rollback-on-error") sub_ele(node, "error-option").text = error_option if format == 'xml': node.append( validated_element(config, ("config", qualify("config")))) elif format == 'text': config_text = sub_ele(node, "config-text") sub_ele(config_text, "configuration-text").text = config elif format == 'url': if util.url_validator(config): self._assert(':url') sub_ele(node, "url").text = config else: raise OperationError("Invalid URL.") node = self._device_handler.transform_edit_config(node) return self._request(node)
def request(self, source, filter=None): """Retrieve all or part of a specified configuration. *source* name of the configuration datastore being queried *filter* specifies the portion of the configuration to retrieve (by default entire configuration is retrieved) :seealso: :ref:`filter_params`""" node = new_ele("get-bulk-config") node.append(util.datastore_or_url("source", source, self._assert)) if filter is not None: node.append(util.build_filter(filter)) return self._request(node)
def request(self, source, filter=None): """Retrieve all or part of a specified configuration. *source* name of the configuration datastore being queried *filter* specifies the portion of the configuration to retrieve (by default entire configuration is retrieved) :seealso: :ref:`filter_params`""" node = new_ele("get-config") node.append(util.datastore_or_url("source", source, self._assert)) if filter is not None: node.append(util.build_filter(filter)) return self._request(node)
def request(self, source="candidate"): """Validate the contents of the specified configuration. *source* is the name of the configuration datastore being validated or `config` element containing the configuration subtree to be validated :seealso: :ref:`srctarget_params`""" node = new_ele("validate") if type(source) is str: src = util.datastore_or_url("source", source, self._assert) else: validated_element(source, ("config", qualify("config"))) src = new_ele("source") src.append(source) node.append(src) return self._request(node)
def request(self, config, format='xml', target='candidate', default_operation=None, test_option=None, error_option=None): """Loads all or part of the specified *config* to the *target* configuration datastore. *target* is the name of the configuration datastore being edited *config* is the configuration, which must be rooted in the `config` element. It can be specified either as a string or an :class:`~xml.etree.ElementTree.Element`. *default_operation* if specified must be one of { `"merge"`, `"replace"`, or `"none"` } *test_option* if specified must be one of { `"test_then_set"`, `"set"` } *error_option* if specified must be one of { `"stop-on-error"`, `"continue-on-error"`, `"rollback-on-error"` } The `"rollback-on-error"` *error_option* depends on the `:rollback-on-error` capability. """ node = new_ele("edit-config") node.append(util.datastore_or_url("target", target, self._assert)) if default_operation is not None: # TODO: check if it is a valid default-operation sub_ele(node, "default-operation").text = default_operation if test_option is not None: self._assert(':validate') sub_ele(node, "test-option").text = test_option if error_option is not None: if error_option == "rollback-on-error": self._assert(":rollback-on-error") sub_ele(node, "error-option").text = error_option # <<<<<<< HEAD # node.append(validated_element(config, ("config", qualify("config")))) # ======= if format == 'xml': node.append( validated_element(config, ("config", qualify("config")))) if format == 'text': config_text = sub_ele(node, "config-text") sub_ele(config_text, "configuration-text").text = config # >>>>>>> juniper return self._request(node)
def request(self, source, filter=None, with_defaults=None): """Retrieve all or part of a specified configuration. *source* name of the configuration datastore being queried *filter* specifies the portion of the configuration to retrieve (by default entire configuration is retrieved) *with_defaults* defines an explicit method of retrieving default values from the configuration (see RFC 6243) :seealso: :ref:`filter_params`""" node = new_ele("get-config") node.append(util.datastore_or_url("source", source, self._assert)) if filter is not None: node.append(util.build_filter(filter)) if with_defaults is not None: self._assert(":with-defaults") _append_with_defaults(node, with_defaults) return self._request(node)
def request(self, config, format='xml', target='candidate', default_operation=None, test_option=None, error_option=None): """Loads all or part of the specified *config* to the *target* configuration datastore. *target* is the name of the configuration datastore being edited *config* is the configuration, which must be rooted in the `config` element. It can be specified either as a string or an :class:`~xml.etree.ElementTree.Element`. *default_operation* if specified must be one of { `"merge"`, `"replace"`, or `"none"` } *test_option* if specified must be one of { `"test_then_set"`, `"set"` } *error_option* if specified must be one of { `"stop-on-error"`, `"continue-on-error"`, `"rollback-on-error"` } The `"rollback-on-error"` *error_option* depends on the `:rollback-on-error` capability. """ node = new_ele("edit-config") node.append(util.datastore_or_url("target", target, self._assert)) if error_option is not None: if error_option == "rollback-on-error": self._assert(":rollback-on-error") sub_ele(node, "error-option").text = error_option if test_option is not None: self._assert(':validate') sub_ele(node, "test-option").text = test_option if default_operation is not None: # TODO: check if it is a valid default-operation sub_ele(node, "default-operation").text = default_operation # <<<<<<< HEAD # node.append(validated_element(config, ("config", qualify("config")))) # ======= if format == 'xml': node.append(validated_element(config, ("config", qualify("config")))) if format == 'text': config_text = sub_ele(node, "config-text") sub_ele(config_text, "configuration-text").text = config # >>>>>>> juniper return self._request(node)
def request(self, source, filter=None, defaults=None, nsmap={}): node = new_ele("get-config", nsmap=nsmap) node.append(util.datastore_or_url("source", source, self._assert)) return self._request(extend_get_node(self, node, filter, defaults))