-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathEditConfiguration.java
More file actions
62 lines (52 loc) · 1.76 KB
/
Copy pathEditConfiguration.java
File metadata and controls
62 lines (52 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* Copyright (c) 2013 Juniper Networks, Inc.
* All Rights Reserved
*
* Use is subject to license terms.
*
*/
import net.juniper.netconf.CommitException;
import net.juniper.netconf.Device;
import net.juniper.netconf.LoadException;
import net.juniper.netconf.XML;
import net.juniper.netconf.XMLBuilder;
import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
public class EditConfiguration {
public static void main(String[] args) throws IOException,
ParserConfigurationException, SAXException {
/*Build the XML configuration
*The XML configuration required is:
*
* <configuration>
* <system>
* <services>
* <ftp/>
* </services>
* </system>
* </configuration>
*/
XMLBuilder builder = new XMLBuilder();
XML ftp_config = builder.createNewConfig("system", "services", "ftp");
Device device = CreateDevice.createDevice();
device.connect();
//Lock the configuration first
boolean isLocked = device.lockConfig();
if(!isLocked) {
System.out.println("Could not lock configuration. Exit now.");
return;
}
//Load and commit the configuration
try {
device.loadXMLConfiguration(ftp_config.toString(), "merge");
device.commit();
} catch(LoadException | CommitException e) {
System.out.println(e.getMessage());
return;
}
//Unlock the configuration and close the device.
device.unlockConfig();
device.close();
}
}