Search in sources :

Example 1 with ClusterNetworksService

use of org.ovirt.engine.sdk4.services.ClusterNetworksService in project ovirt-engine-sdk-java by oVirt.

the class AssignNetworkToCluster method main.

public static void main(String[] args) throws Exception {
    // Create the connection to the server:
    Connection connection = connection().url("https://engine40.example.com/ovirt-engine/api").user("admin@internal").password("redhat123").trustStoreFile("truststore.jks").build();
    // Locate the networks service and use it to find the network:
    NetworksService networksService = connection.systemService().networksService();
    Network network = networksService.list().search("name=mynetwork and datacenter=mydatacenter").send().networks().get(0);
    // Locate the clusters service and use it to find the cluster:
    ClustersService clustersService = connection.systemService().clustersService();
    Cluster cluster = clustersService.list().search("name=mycluster").send().clusters().get(0);
    // Locate the service that manages the networks of the cluster:
    ClusterService clusterService = clustersService.clusterService(cluster.id());
    ClusterNetworksService assignedNetworksService = clusterService.networksService();
    // Use the "add" method to assign network to cluster:
    assignedNetworksService.add().network(network().id(network.id()).required(true)).send();
    // Close the connection to the server:
    connection.close();
}
Also used : ClusterService(org.ovirt.engine.sdk4.services.ClusterService) ClusterNetworksService(org.ovirt.engine.sdk4.services.ClusterNetworksService) Network(org.ovirt.engine.sdk4.types.Network) Connection(org.ovirt.engine.sdk4.Connection) ClustersService(org.ovirt.engine.sdk4.services.ClustersService) NetworksService(org.ovirt.engine.sdk4.services.NetworksService) ClusterNetworksService(org.ovirt.engine.sdk4.services.ClusterNetworksService) Cluster(org.ovirt.engine.sdk4.types.Cluster)

Aggregations

Connection (org.ovirt.engine.sdk4.Connection)1 ClusterNetworksService (org.ovirt.engine.sdk4.services.ClusterNetworksService)1 ClusterService (org.ovirt.engine.sdk4.services.ClusterService)1 ClustersService (org.ovirt.engine.sdk4.services.ClustersService)1 NetworksService (org.ovirt.engine.sdk4.services.NetworksService)1 Cluster (org.ovirt.engine.sdk4.types.Cluster)1 Network (org.ovirt.engine.sdk4.types.Network)1