0

Save config

by
Published today

Copy the running configuration to the startup configuration (write memory) with the cisco-ia:save-config RPC.

Script cisco_iosxe Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 2 hours ago
1
//native
2

3
/**
4
 * Save config
5
 * Copy the running configuration to the startup configuration (write memory) by invoking the cisco-ia:save-config RPC.
6
 */
7
export async function main(auth: RT.CiscoIosxe) {
8
  // The RPC has no input, so the request carries no body (RFC 8040 section 3.6.1).
9
  const response = await fetch(
10
    new URL(
11
      `${auth.base_url.replace(/\/+$/, "")}/restconf/operations/cisco-ia:save-config`
12
    ),
13
    {
14
      method: "POST",
15
      headers: {
16
        Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
17
        Accept: "application/yang-data+json",
18
      },
19
    }
20
  )
21

22
  if (!response.ok) {
23
    throw new Error(`${response.status} ${await response.text()}`)
24
  }
25
  if (response.status === 204) return { success: true }
26

27
  return await response.json()
28
}
29