Skip to content

Commit 3eafd0c

Browse files
authored
Merge pull request #1981 from nuagenetworks/feature/nuage_vpc_selectable_domain_template
CLOUDSTACK-9806: Nuage domain template selection per VPC
2 parents 55c059c + 880e475 commit 3eafd0c

28 files changed

Lines changed: 2127 additions & 324 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: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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+
43+
import javax.inject.Inject;
44+
45+
@APICommand(name = AssociateNuageVspDomainTemplateCmd.APINAME, responseObject = SuccessResponse.class, description = "associate a vpc with a domain template", authorized = {RoleType.Admin, RoleType.DomainAdmin, RoleType.User})
46+
public class AssociateNuageVspDomainTemplateCmd extends BaseCmd {
47+
static final String APINAME = "associateNuageVspDomainTemplate";
48+
@Inject
49+
NuageVspManager _nuageVspManager;
50+
51+
/////////////////////////////////////////////////////
52+
//////////////// API parameters /////////////////////
53+
/////////////////////////////////////////////////////
54+
55+
@Parameter(name = ApiConstants.VPC_ID, type = CommandType.UUID, entityType = VpcResponse.class, required = true, description = "VPC ID")
56+
private Long vpcId;
57+
58+
59+
@Parameter(name = VspConstants.NUAGE_VSP_API_DOMAIN_TEMPLATE, type = CommandType.STRING, required = true, description = "the name of the domain template")
60+
private String domainTemplate;
61+
62+
@Parameter(name = ApiConstants.PHYSICAL_NETWORK_ID, type = CommandType.UUID, entityType = PhysicalNetworkResponse.class, description = "the physical network ID")
63+
private Long physicalNetworkId;
64+
65+
@Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class, description = "the zone ID")
66+
private Long zoneId;
67+
68+
/////////////////////////////////////////////////////
69+
/////////////////// Accessors ///////////////////////
70+
/////////////////////////////////////////////////////
71+
72+
public Long getVpcId() {
73+
return vpcId;
74+
}
75+
76+
public String getDomainTemplate() { return domainTemplate; }
77+
78+
public Long getZoneId() { return zoneId; }
79+
80+
public Long getPhysicalNetworkId() { return physicalNetworkId; }
81+
82+
/////////////////////////////////////////////////////
83+
/////////////// API Implementation///////////////////
84+
/////////////////////////////////////////////////////
85+
86+
@Override
87+
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
88+
try {
89+
boolean result =_nuageVspManager.associateNuageVspDomainTemplate(this);
90+
SuccessResponse response = new SuccessResponse(getCommandName());
91+
response.setResponseName(getCommandName());
92+
response.setSuccess(result);
93+
this.setResponseObject(response);
94+
} catch (InvalidParameterValueException invalidParamExcp) {
95+
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
96+
} catch (CloudRuntimeException runtimeExcp) {
97+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
98+
}
99+
}
100+
101+
@Override
102+
public String getCommandName() {
103+
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
104+
}
105+
106+
@Override
107+
public long getEntityOwnerId() {
108+
return CallContext.current().getCallingAccount().getId();
109+
}
110+
111+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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.BaseCmd;
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+
43+
import javax.inject.Inject;
44+
import java.util.List;
45+
46+
@APICommand(name = ListNuageVspDomainTemplatesCmd.APINAME, responseObject = BaseResponse.class, description = "Lists Nuage VSP domain templates", since = "4.11", responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.DomainAdmin, RoleType.User})
47+
public class ListNuageVspDomainTemplatesCmd extends BaseCmd {
48+
static final String APINAME = "listNuageVspDomainTemplates";
49+
50+
@Inject
51+
private NuageVspManager _nuageVspManager;
52+
53+
/////////////////////////////////////////////////////
54+
//////////////// API parameters /////////////////////
55+
/////////////////////////////////////////////////////
56+
57+
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class,
58+
description = "the domain ID")
59+
private Long domainId;
60+
61+
@Parameter(name = ApiConstants.PHYSICAL_NETWORK_ID, type = CommandType.UUID, entityType = PhysicalNetworkResponse.class,
62+
description = "the physical network ID")
63+
private Long physicalNetworkId;
64+
65+
@Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class,
66+
description = "the zone ID")
67+
private Long zoneId;
68+
69+
@Parameter(name = ApiConstants.KEYWORD, type = CommandType.STRING,
70+
description = "filters the domain templates which contain the keyword")
71+
private String keyword;
72+
73+
/////////////////////////////////////////////////////
74+
/////////////////// Accessors ///////////////////////
75+
/////////////////////////////////////////////////////
76+
77+
public String getKeyword() {
78+
return keyword;
79+
}
80+
81+
public Long getDomainId() {
82+
return domainId;
83+
}
84+
85+
public Long getPhysicalNetworkId() {
86+
return physicalNetworkId;
87+
}
88+
89+
public Long getZoneId() { return zoneId; }
90+
91+
/////////////////////////////////////////////////////
92+
/////////////// API Implementation///////////////////
93+
/////////////////////////////////////////////////////
94+
95+
@Override
96+
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
97+
try {
98+
List<NuageVspDomainTemplateResponse> responses = _nuageVspManager.listNuageVspDomainTemplates(this);
99+
ListResponse<NuageVspDomainTemplateResponse> response = new ListResponse<>();
100+
response.setResponses(responses);
101+
response.setResponseName(getCommandName());
102+
this.setResponseObject(response);
103+
} catch (InvalidParameterValueException invalidParamExcp) {
104+
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
105+
} catch (CloudRuntimeException e) {
106+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
107+
}
108+
}
109+
110+
@Override
111+
public String getCommandName() {
112+
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
113+
}
114+
115+
@Override public long getEntityOwnerId() {
116+
return 0; //not owned by anyone
117+
}
118+
119+
}
120+

0 commit comments

Comments
 (0)