Search in sources :

Example 1 with NicDetails

use of com.cloud.agent.api.GetVmConfigAnswer.NicDetails in project cloudstack by apache.

the class HypervDirectConnectResource method getVmFreeNicIndex.

protected int getVmFreeNicIndex(final String vmName) {
    final GetVmConfigCommand vmConfig = new GetVmConfigCommand(vmName);
    URI agentUri = null;
    int nicposition = -1;
    try {
        final String cmdName = GetVmConfigCommand.class.getName();
        agentUri = new URI("https", null, _agentIp, _port, "/api/HypervResource/" + cmdName, null, null);
    } catch (final URISyntaxException e) {
        final String errMsg = "Could not generate URI for Hyper-V agent";
        s_logger.error(errMsg, e);
    }
    final String ansStr = postHttpRequest(s_gson.toJson(vmConfig), agentUri);
    final Answer[] result = s_gson.fromJson(ansStr, Answer[].class);
    s_logger.debug("GetVmConfigCommand response received " + s_gson.toJson(result));
    if (result.length > 0) {
        final GetVmConfigAnswer ans = (GetVmConfigAnswer) result[0];
        final List<NicDetails> nics = ans.getNics();
        for (final NicDetails nic : nics) {
            if (nic.getState() == false) {
                nicposition = nics.indexOf(nic);
                break;
            }
        }
    }
    return nicposition;
}
Also used : UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.agent.api.CheckS2SVpnConnectionsAnswer) SetPortForwardingRulesAnswer(com.cloud.agent.api.routing.SetPortForwardingRulesAnswer) SetSourceNatAnswer(com.cloud.agent.api.routing.SetSourceNatAnswer) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) GetVmConfigAnswer(com.cloud.agent.api.GetVmConfigAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) SetStaticNatRulesAnswer(com.cloud.agent.api.routing.SetStaticNatRulesAnswer) IpAssocAnswer(com.cloud.agent.api.routing.IpAssocAnswer) SetFirewallRulesAnswer(com.cloud.agent.api.routing.SetFirewallRulesAnswer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) SetStaticRouteAnswer(com.cloud.agent.api.routing.SetStaticRouteAnswer) GetVmConfigCommand(com.cloud.agent.api.GetVmConfigCommand) GetVmConfigAnswer(com.cloud.agent.api.GetVmConfigAnswer) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) NicDetails(com.cloud.agent.api.GetVmConfigAnswer.NicDetails)

Example 2 with NicDetails

use of com.cloud.agent.api.GetVmConfigAnswer.NicDetails in project cloudstack by apache.

the class HypervDirectConnectResource method getVmNics.

protected int getVmNics(final String vmName, String vlanid) {
    final GetVmConfigCommand vmConfig = new GetVmConfigCommand(vmName);
    URI agentUri = null;
    int nicposition = -1;
    if (vlanid.equalsIgnoreCase("untagged")) {
        vlanid = "-1";
    }
    try {
        final String cmdName = GetVmConfigCommand.class.getName();
        agentUri = new URI("https", null, _agentIp, _port, "/api/HypervResource/" + cmdName, null, null);
    } catch (final URISyntaxException e) {
        final String errMsg = "Could not generate URI for Hyper-V agent";
        s_logger.error(errMsg, e);
    }
    final String ansStr = postHttpRequest(s_gson.toJson(vmConfig), agentUri);
    final Answer[] result = s_gson.fromJson(ansStr, Answer[].class);
    s_logger.debug("executeRequest received response " + s_gson.toJson(result));
    if (result.length > 0) {
        final GetVmConfigAnswer ans = (GetVmConfigAnswer) result[0];
        final List<NicDetails> nics = ans.getNics();
        for (final NicDetails nic : nics) {
            nicposition++;
            if (nicposition > 1 && nic.getVlanid().equals(vlanid)) {
                break;
            }
        }
    }
    return nicposition;
}
Also used : UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.agent.api.CheckS2SVpnConnectionsAnswer) SetPortForwardingRulesAnswer(com.cloud.agent.api.routing.SetPortForwardingRulesAnswer) SetSourceNatAnswer(com.cloud.agent.api.routing.SetSourceNatAnswer) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) GetVmConfigAnswer(com.cloud.agent.api.GetVmConfigAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) SetStaticNatRulesAnswer(com.cloud.agent.api.routing.SetStaticNatRulesAnswer) IpAssocAnswer(com.cloud.agent.api.routing.IpAssocAnswer) SetFirewallRulesAnswer(com.cloud.agent.api.routing.SetFirewallRulesAnswer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) SetStaticRouteAnswer(com.cloud.agent.api.routing.SetStaticRouteAnswer) GetVmConfigCommand(com.cloud.agent.api.GetVmConfigCommand) GetVmConfigAnswer(com.cloud.agent.api.GetVmConfigAnswer) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) NicDetails(com.cloud.agent.api.GetVmConfigAnswer.NicDetails)

Aggregations

Answer (com.cloud.agent.api.Answer)2 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)2 CheckS2SVpnConnectionsAnswer (com.cloud.agent.api.CheckS2SVpnConnectionsAnswer)2 GetDomRVersionAnswer (com.cloud.agent.api.GetDomRVersionAnswer)2 GetVmConfigAnswer (com.cloud.agent.api.GetVmConfigAnswer)2 NicDetails (com.cloud.agent.api.GetVmConfigAnswer.NicDetails)2 GetVmConfigCommand (com.cloud.agent.api.GetVmConfigCommand)2 NetworkUsageAnswer (com.cloud.agent.api.NetworkUsageAnswer)2 PlugNicAnswer (com.cloud.agent.api.PlugNicAnswer)2 UnPlugNicAnswer (com.cloud.agent.api.UnPlugNicAnswer)2 UnsupportedAnswer (com.cloud.agent.api.UnsupportedAnswer)2 CheckSshAnswer (com.cloud.agent.api.check.CheckSshAnswer)2 IpAssocAnswer (com.cloud.agent.api.routing.IpAssocAnswer)2 SetFirewallRulesAnswer (com.cloud.agent.api.routing.SetFirewallRulesAnswer)2 SetPortForwardingRulesAnswer (com.cloud.agent.api.routing.SetPortForwardingRulesAnswer)2 SetSourceNatAnswer (com.cloud.agent.api.routing.SetSourceNatAnswer)2 SetStaticNatRulesAnswer (com.cloud.agent.api.routing.SetStaticNatRulesAnswer)2 SetStaticRouteAnswer (com.cloud.agent.api.routing.SetStaticRouteAnswer)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2