Skip to content

Commit ff0d915

Browse files
Sigert Goeminnefmaximus
authored andcommitted
CLOUDSTACK-9806: Nuage domain template selection per VPC
Co-Authored-By: Prashanth Manthena <prashanth.manthena@nuagenetworks.net> Co-Authored-By: Frank Maximus <frank.maximus@nuagenetworks.net> Bug: https://issues.apache.org/jira/browse/CLOUDSTACK-9806 Design Document: https://cwiki.apache.org/confluence/display/CLOUDSTACK/Nuage+domain+template+selection+per+VPC
1 parent d077b3e commit ff0d915

27 files changed

Lines changed: 2105 additions & 305 deletions

plugins/network-elements/nuage-vsp/src/com/cloud/agent/api/guru/DeallocateVmVspCommand.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import com.cloud.agent.api.Command;
3131

32+
3233
public class DeallocateVmVspCommand extends Command {
3334

3435
private final VspNetwork _network;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
20+
package com.cloud.agent.api.manager;
21+
22+
import com.cloud.agent.api.Answer;
23+
import net.nuage.vsp.acs.client.api.model.VspDomainTemplate;
24+
25+
import java.util.List;
26+
27+
28+
public class ListVspDomainTemplatesAnswer extends Answer {
29+
private List<VspDomainTemplate> domainTemplates;
30+
31+
public ListVspDomainTemplatesAnswer(ListVspDomainTemplatesCommand command, List<VspDomainTemplate> domainTemplates) {
32+
super(command);
33+
34+
this.domainTemplates = domainTemplates;
35+
}
36+
37+
public ListVspDomainTemplatesAnswer(ListVspDomainTemplatesCommand command, Exception e) {
38+
super(command, e);
39+
}
40+
41+
public List<VspDomainTemplate> getDomainTemplates() {
42+
return domainTemplates;
43+
}
44+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
20+
package com.cloud.agent.api.manager;
21+
22+
import com.cloud.agent.api.Command;
23+
import net.nuage.vsp.acs.client.api.model.VspDomain;
24+
25+
26+
public class ListVspDomainTemplatesCommand extends Command {
27+
private final VspDomain _domain;
28+
private final String _name;
29+
30+
public ListVspDomainTemplatesCommand(VspDomain domain, String name) {
31+
this._domain = domain;
32+
this._name = name;
33+
}
34+
35+
public VspDomain getDomain() {
36+
return _domain;
37+
}
38+
39+
public String getName() {
40+
return _name;
41+
}
42+
43+
@Override
44+
public boolean executeInSequence() {
45+
return false;
46+
}
47+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
20+
package com.cloud.api.commands;
21+
22+
import com.cloud.exception.ConcurrentOperationException;
23+
import com.cloud.exception.InsufficientCapacityException;
24+
import com.cloud.exception.InvalidParameterValueException;
25+
import com.cloud.exception.ResourceAllocationException;
26+
import com.cloud.exception.ResourceUnavailableException;
27+
import com.cloud.network.manager.NuageVspManager;
28+
import com.cloud.utils.exception.CloudRuntimeException;
29+
30+
import org.apache.cloudstack.acl.RoleType;
31+
import org.apache.cloudstack.api.APICommand;
32+
import org.apache.cloudstack.api.ApiConstants;
33+
import org.apache.cloudstack.api.ApiErrorCode;
34+
import org.apache.cloudstack.api.BaseCmd;
35+
import org.apache.cloudstack.api.Parameter;
36+
import org.apache.cloudstack.api.ServerApiException;
37+
import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
38+
import org.apache.cloudstack.api.response.SuccessResponse;
39+
import org.apache.cloudstack.api.response.VpcResponse;
40+
import org.apache.cloudstack.api.response.ZoneResponse;
41+
import org.apache.cloudstack.context.CallContext;
42+
import org.apache.log4j.Logger;
43+
44+
import javax.inject.Inject;
45+
46+
@APICommand(name = "associateNuageVspDomainTemplate", responseObject = SuccessResponse.class, description = "associate a vpc with a domain template", authorized = {RoleType.Admin, RoleType.DomainAdmin, RoleType.User})
47+
public class AssociateNuageVspDomainTemplateCmd extends BaseCmd {
48+
private static final Logger s_logger = Logger.getLogger(AssociateNuageVspDomainTemplateCmd.class.getName());
49+
private static final String s_name = "associatenuagevspdomaintemplateresponse";
50+
@Inject
51+
NuageVspManager _nuageVspManager;
52+
53+
/////////////////////////////////////////////////////
54+
//////////////// API parameters /////////////////////
55+
/////////////////////////////////////////////////////
56+
57+
@Parameter(name = ApiConstants.VPC_ID, type = CommandType.UUID, entityType = VpcResponse.class, required = true, description = "VPC ID")
58+
private Long vpcId;
59+
60+
61+
@Parameter(name = VspConstants.NUAGE_VSP_API_DOMAIN_TEMPLATE, type = CommandType.STRING, required = true, description = "the name of the domain template")
62+
private String domainTemplate;
63+
64+
@Parameter(name = ApiConstants.PHYSICAL_NETWORK_ID, type = CommandType.UUID, entityType = PhysicalNetworkResponse.class, description = "the physical network ID")
65+
private Long physicalNetworkId;
66+
67+
@Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class, description = "the zone ID")
68+
private Long zoneId;
69+
70+
/////////////////////////////////////////////////////
71+
/////////////////// Accessors ///////////////////////
72+
/////////////////////////////////////////////////////
73+
74+
public Long getVpcId() {
75+
return vpcId;
76+
}
77+
78+
public String getDomainTemplate() { return domainTemplate; }
79+
80+
public Long getZoneId() { return zoneId; }
81+
82+
public Long getPhysicalNetworkId() { return physicalNetworkId; }
83+
84+
/////////////////////////////////////////////////////
85+
/////////////// API Implementation///////////////////
86+
/////////////////////////////////////////////////////
87+
88+
@Override
89+
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
90+
try {
91+
boolean result =_nuageVspManager.associateNuageVspDomainTemplate(this);
92+
SuccessResponse response = new SuccessResponse(getCommandName());
93+
response.setResponseName(getCommandName());
94+
response.setSuccess(result);
95+
this.setResponseObject(response);
96+
} catch (InvalidParameterValueException invalidParamExcp) {
97+
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
98+
} catch (CloudRuntimeException runtimeExcp) {
99+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
100+
}
101+
}
102+
103+
@Override
104+
public String getCommandName() {
105+
return s_name;
106+
}
107+
108+
@Override
109+
public long getEntityOwnerId() {
110+
return CallContext.current().getCallingAccount().getId();
111+
}
112+
113+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
20+
package com.cloud.api.commands;
21+
22+
import com.cloud.api.response.NuageVspDomainTemplateResponse;
23+
import com.cloud.exception.ConcurrentOperationException;
24+
import com.cloud.exception.InsufficientCapacityException;
25+
import com.cloud.exception.InvalidParameterValueException;
26+
import com.cloud.exception.ResourceAllocationException;
27+
import com.cloud.exception.ResourceUnavailableException;
28+
import com.cloud.network.manager.NuageVspManager;
29+
import com.cloud.utils.exception.CloudRuntimeException;
30+
import org.apache.cloudstack.acl.RoleType;
31+
import org.apache.cloudstack.api.APICommand;
32+
import org.apache.cloudstack.api.ApiConstants;
33+
import org.apache.cloudstack.api.ApiErrorCode;
34+
import org.apache.cloudstack.api.BaseListCmd;
35+
import org.apache.cloudstack.api.BaseResponse;
36+
import org.apache.cloudstack.api.Parameter;
37+
import org.apache.cloudstack.api.ServerApiException;
38+
import org.apache.cloudstack.api.response.DomainResponse;
39+
import org.apache.cloudstack.api.response.ListResponse;
40+
import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
41+
import org.apache.cloudstack.api.response.ZoneResponse;
42+
import org.apache.log4j.Logger;
43+
44+
import javax.inject.Inject;
45+
import java.util.List;
46+
47+
@APICommand(name = "listNuageVspDomainTemplates", responseObject = BaseResponse.class, description = "Lists Nuage VSP domain templates", authorized = {RoleType.Admin, RoleType.DomainAdmin, RoleType.User})
48+
public class ListNuageVspDomainTemplatesCmd extends BaseListCmd {
49+
private static final Logger s_logger = Logger.getLogger(ListNuageVspDomainTemplatesCmd.class.getName());
50+
private static final String s_name = "listnuagevspdomaintemplatesresponse";
51+
52+
@Inject
53+
private NuageVspManager _nuageVspManager;
54+
55+
/////////////////////////////////////////////////////
56+
//////////////// API parameters /////////////////////
57+
/////////////////////////////////////////////////////
58+
59+
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class,
60+
description = "the domain ID")
61+
private Long domainId;
62+
63+
@Parameter(name = ApiConstants.PHYSICAL_NETWORK_ID, type = CommandType.UUID, entityType = PhysicalNetworkResponse.class,
64+
description = "the physical network ID")
65+
private Long physicalNetworkId;
66+
67+
@Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class,
68+
description = "the zone ID")
69+
private Long zoneId;
70+
71+
/////////////////////////////////////////////////////
72+
/////////////////// Accessors ///////////////////////
73+
/////////////////////////////////////////////////////
74+
75+
public Long getDomainId() {
76+
return domainId;
77+
}
78+
79+
public Long getPhysicalNetworkId() {
80+
return physicalNetworkId;
81+
}
82+
83+
public Long getZoneId() { return zoneId; }
84+
/////////////////////////////////////////////////////
85+
/////////////// API Implementation///////////////////
86+
/////////////////////////////////////////////////////
87+
88+
@Override
89+
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
90+
try {
91+
List<NuageVspDomainTemplateResponse> responses = _nuageVspManager.listNuageVspDomainTemplates(this);
92+
ListResponse<NuageVspDomainTemplateResponse> response = new ListResponse<>();
93+
response.setResponses(responses);
94+
response.setResponseName(getCommandName());
95+
this.setResponseObject(response);
96+
} catch (InvalidParameterValueException invalidParamExcp) {
97+
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
98+
} catch (CloudRuntimeException e) {
99+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
100+
}
101+
}
102+
103+
@Override
104+
public String getCommandName() {
105+
return s_name;
106+
}
107+
108+
109+
}
110+

0 commit comments

Comments
 (0)