----- Original Message -----
> From: "Tejesh M" <[email protected]>
> To: "Moti Asayag" <[email protected]>
> Cc: "[email protected]" <[email protected]>
> Sent: Tuesday, March 11, 2014 3:18:37 AM
> Subject: Re: Delete & Detach Logical Network
> 
> I tried below code, but still it is not detaching the network
> 
>           HostNICs nicsApi = api.getHosts().get("venus-vdsb").getHostNics();
>           List<HostNIC> nics = nicsApi.list();
>           HostNIC nic =
> api.getHosts().get("rhevhost").getHostNics().get("bond1.1231"); //logical
> network network name is "testLNw"
>           nic.setNetwork(null);
> 
> 
> *Result of executing this line*:
> nicsApi.setupnetworks(createSetupNetworksParams(nics));
> 
> *Result:*
> code  : 400
> reason: Bad Request
> detail: Cannot setup Networks. The following VMs are actively using the
> Logical Network: greyvm, vmLogicalTest1, OmVM1. Please stop the VMs and try
> again., Cannot setup Networks. The following Bonds consist of less than two
> Network Interfaces: bond0., Cannot setup Networks. The following Network
> Interfaces were specified more than once: eth0, eth3, eth1, eth2.
> 
> Can you post the complete code?
> 

See example attached.
You'll have to adjust the parameters to fit yours (hostName and modified nic).

> 
> 
> 
> On Mon, Mar 10, 2014 at 6:54 PM, Moti Asayag <[email protected]> wrote:
> 
> >
> >
> > ----- Original Message -----
> > > From: "Tejesh M" <[email protected]>
> > > To: "Moti Asayag" <[email protected]>, "[email protected]" <
> > [email protected]>
> > > Sent: Monday, March 10, 2014 1:22:08 PM
> > > Subject: Delete & Detach Logical Network
> > >
> > > Hi,
> > >
> > > I'm able to delete the logical network but this logical network after
> > > deletion shows as unmanaged network in "Setup Host Networks" against the
> > > hostnic.
> > >
> > > I tried with this code to detach the logical network.
> > >
> > > *Code 1:*
> > > HostNIC nic = api.getHosts().get("rhevhost").getHostNics().get("eth1");
> > > Action action = new Action();
> > > action.setNetwork(api.getNetworks().get(nw_name));
> > > action.setDetach(true);
> > > action.setCheckConnectivity(false);
> > > nic.detach(action);
> > >
> > > *Returns*:
> > > code  : 409
> > > reason: Conflict
> > > detail: Network Interface is not attached to Logical Network.
> > >
> >
> > I can guess by the error message that the logical network 'rhevhost' is
> > vlan,
> > so the proper interface should be the vlan device.
> >
> >
> > > *Code 2:*
> > > HostNIC nic =
> > api.getHosts().get("rhevhost").getHostNics().get("eth1.1345");
> > > Action action = new Action();
> > > action.setNetwork(api.getNetworks().get(nw_name));
> > > action.setDetach(true);
> > > action.setCheckConnectivity(false);
> > > nic.detach(action);
> > >
> > > *Returns*:
> > > code  : 409
> > > reason: Conflict
> > > detail: Cannot edit Network while Host is Active, change the Host to
> > > Maintenance mode and try again.
> > >
> >
> > This is the 3.0 api which required the host to be in maintenance for
> > network
> > operations on the host. You could use setup networks instead which is the
> > recommended api and doesn't require the host to be in maintenance.
> >
> > you can modify the example from [1] and set null for the network name you
> > wish to detach from the specific interface.
> >
> > Try by replacing only lines 28-41 with:
> > HostNIC nic = nicsByNames.get("eth1.1345");
> > nic.setNetwork(null);
> >
> > [1]
> > https://motiasayag.wordpress.com/2014/02/24/invoke-setup-networks-from-the-java-sdk/
> >
> > >
> > > --
> > > Thanks & Regards
> > > Tejesh
> > >
> >
> 
> 
> 
> --
> Thanks & Regards
> Tejesh
> 
package org.ovirt.test;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.ovirt.engine.sdk.Api;
import org.ovirt.engine.sdk.decorators.Host;
import org.ovirt.engine.sdk.decorators.HostNIC;
import org.ovirt.engine.sdk.decorators.HostNICs;
import org.ovirt.engine.sdk.entities.Action;
import org.ovirt.engine.sdk.entities.BaseResource;
import org.ovirt.engine.sdk.entities.HostNics;

public class SetupNetworksDetachNetworkExample {

    public static void main(String[] args) throws Exception {

        try (Api api = new Api("http://localhost:8080/api";,
                "admin@internal",
                "1",
                null, null, null, null, null, null, true)) {

            String hostName = "venus-vdsb";
            Host hostApi = api.getHosts().get(hostName);
            HostNICs nicsApi = hostApi.getHostNics();
            List<HostNIC> nics = nicsApi.list();

            Map<String, HostNIC> nicsByNames = entitiesByName(nics);
            HostNIC nic = nicsByNames.get("eth4.20");
            nic.setNetwork(null);

            nicsApi.setupnetworks(createSetupNetworksParams(nics));
            hostApi.commitnetconfig(new Action());
        }
    }

    public static Action createSetupNetworksParams(List<HostNIC> nics) {
        Action action = new Action();
        HostNics nicsParams = new HostNics();
        nicsParams.getHostNics().addAll(nics);
        action.setHostNics(nicsParams);
        action.setCheckConnectivity(true);
        return action;
    }

    public static <E extends BaseResource> Map<String, E> entitiesByName(List<E> entityList) {
        if (entityList != null) {
            Map<String, E> map = new HashMap<String, E>();
            for (E e : entityList) {
                map.put(e.getName(), e);
            }
            return map;
        } else {
            return Collections.emptyMap();
        }
    }
}

_______________________________________________
Users mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/users

Reply via email to