Java SDK
システム API
//Specify the IP address of the appliance and service type
nitro_service nitroservice = new nitro_service ("10.102.31.16", "https");
//Specify the login credentials
nitroservice.login("nsroot", "verysecret");
nitroservice.logout();
設定 API
リソースを作成する
-
対応するプロパティー名を使用して、リソースの必須プロパティーの値を設定します。その結果、リソースに必要な詳細を含むリソースオブジェクトが生成されます。 注:これらの値はクライアント上でローカルに設定されます。オブジェクトがアップロードされるまで、値はアプライアンスに反映されません。
-
static add () メソッドを使用して、リソースオブジェクトをアプライアンスにアップロードします。
ns newns = new ns();
//Set the properties of the NetScaler locally
newns.set_name("ns_instance");
newns.set_ip_address("10.70.136.5");
newns.set_netmask("255.255.255.0");
newns.set_gateway("10.70.136.1");
newns.set_image_name("nsvpx-9.3.45_nc.xva");
newns.set_profile_name("ns_nsroot_profile");
newns.set_vm_memory_total(new Double(2048));
newns.set_throughput(new Double(1000));
newns.set_pps(new Double(1000000));
newns.set_license("Standard");
newns.set_username("admin");
newns.set_password("admin");
int number_of_interfaces = 2;
network_interface[] interface_array = new network_interface[number_of_interfaces];
//Adding 10/1
interface_array[0] = new network_interface();
interface_array[0].set_port_name("10/1");
//Adding 10/2
interface_array[1] = new network_interface();
interface_array[1].set_port_name("10/2");
newns.set_network_interfaces(interface_array);
//Upload the Citrix ADC instance
ns result = ns.add(nitroservice, newns);
リソース詳細の取得
-
get () メソッドを使用して、アプライアンスから設定を取得します。結果はリソースオブジェクトです。
-
対応するプロパティ名を使用して、必要なプロパティをオブジェクトから抽出します。
//Retrieve the resource object from the SDX appliance
ns[] returned_ns = ns.get(nitroservice);
//Extract the properties of the resource from the object
System.out.println(returned_ns[i].get_ip_address());
System.out.println(returned_ns[i].get_netmask());
リソース統計の取得
ns obj = new ns();
obj.set_id("123456a");
ns stats = ns.get(nitroservice, obj);
System.out.println("CPU Usage:" + stats.get_ns_cpu_usage());
System.out.println("Memory Usage:" + stats.get_ns_memory_usage());
System.out.println("Request rate/sec:" +stats.get_http_req());
リソースを更新する
-
id プロパティーを、更新するリソースの ID に設定します。
-
対応するプロパティー名を使用して、リソースの必須プロパティーの値を設定します。結果はリソースオブジェクトです。 注:これらの値はクライアント上でローカルに設定されます。オブジェクトがアップロードされるまで、値はアプライアンスに反映されません。
-
update () メソッドを使用して、リソースオブジェクトをアプライアンスにアップロードします。
ns update_obj = new ns();
//Set the ID of the NetScaler to be updated
update_obj.set_id("123456a");
//Get existing NetScaler details
update_obj = ns.get(nitroservice, update_obj);
//Update the name of the NetScaler to "ns_instance_new" locally
update_obj.set_name("ns_instance_new");
//Upload the updated NetScaler details
ns result = ns.update(nitroservice, update_obj);
リソースを削除する
ns obj = new ns();
obj.set_id("123456a");
ns.delete(nitroservice, obj);
一括操作
-
Exit. 最初のエラーが発生すると、実行は停止します。エラー発生前に実行されたコマンドがコミットされます。
-
**続ける。**一部のコマンドが失敗しても、リスト内のすべてのコマンドが実行されます。
ns[] newns = new ns[2];
//Specify details of first NetScaler
newns[0] = new ns();
newns[0].set_name("ns_instance1");
newns[0].set_ip_address("10.70.136.5");
newns[0].set_netmask("255.255.255.0");
newns[0].set_gateway("10.70.136.1");
...
...
...
//Specify details of second NetScaler
newns[1] = new ns();
newns[1].set_name("ns_instance2");
newns[1].set_ip_address("10.70.136.8");
newns[1].set_netmask("255.255.255.0");
newns[1].set_gateway("10.70.136.1");
...
...
//upload the details of the NetScalers to the NITRO server
ns[] result = ns.add(nitroservice, newns);
例外ハンドリング
-
エラーコード 0 は、操作が成功したことを示します。
-
0 以外のエラーコードは、NITRO 要求の処理中にエラーが発生したことを示します。