
com.abiquo.apiclient.ConfigApi Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of api-java-client Show documentation
Show all versions of api-java-client Show documentation
Abiquo REST API Java client
The newest version!
/**
* Copyright (C) 2008 Abiquo Holdings S.L.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.abiquo.apiclient;
import static com.abiquo.apiclient.domain.ApiPath.COSTCODES_URL;
import static com.abiquo.apiclient.domain.ApiPath.CURRENCIES_URL;
import static com.abiquo.apiclient.domain.ApiPath.DEVICETYPES_URL;
import static com.abiquo.apiclient.domain.ApiPath.HARDWARE_PROFILE_FAMILIES_URL;
import static com.abiquo.apiclient.domain.ApiPath.HYPERVISORTYPES_URL;
import static com.abiquo.apiclient.domain.ApiPath.PRICINGTEMPLATES_URL;
import static com.abiquo.apiclient.domain.ApiPath.PRIVILEGES_URL;
import static java.util.Objects.requireNonNull;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Stream;
import com.abiquo.apiclient.domain.LinkRel;
import com.abiquo.apiclient.domain.options.ListOptions;
import com.abiquo.server.core.cloud.DeviceTypeDto;
import com.abiquo.server.core.cloud.DeviceTypesDto;
import com.abiquo.server.core.cloud.HardwareProfileFamilyDto;
import com.abiquo.server.core.cloud.HardwareProfileTypeDto;
import com.abiquo.server.core.cloud.HypervisorTypeDto;
import com.abiquo.server.core.cloud.HypervisorTypesDto;
import com.abiquo.server.core.cloud.RegionDto;
import com.abiquo.server.core.cloud.RegionsDto;
import com.abiquo.server.core.enterprise.PrivilegeDto;
import com.abiquo.server.core.enterprise.PrivilegesDto;
import com.abiquo.server.core.infrastructure.LocationDto;
import com.abiquo.server.core.pricing.CostCodeDto;
import com.abiquo.server.core.pricing.CostCodesDto;
import com.abiquo.server.core.pricing.CurrenciesDto;
import com.abiquo.server.core.pricing.CurrencyDto;
import com.abiquo.server.core.pricing.PricingTemplateDto;
import com.abiquo.server.core.pricing.PricingTemplatesDto;
public class ConfigApi
{
private final RestClient client;
// Package private constructor to be used only by the ApiClient
ConfigApi(final RestClient client)
{
this.client = requireNonNull(client, "client cannot be null");
}
public HypervisorTypeDto getHypervisorType(final String type)
{
return client.get(String.format("%s/%s", HYPERVISORTYPES_URL, type),
HypervisorTypeDto.MEDIA_TYPE, HypervisorTypeDto.class);
}
public HypervisorTypeDto getHypervisorType(final LocationDto location)
{
return client.get(location.searchLink(LinkRel.HYPERVISORTYPE).getHref(),
HypervisorTypeDto.MEDIA_TYPE, HypervisorTypeDto.class);
}
public Stream getHypervisorTypes()
{
return client.list(HYPERVISORTYPES_URL, HypervisorTypesDto.MEDIA_TYPE,
HypervisorTypesDto.class);
}
public DeviceTypeDto getDeviceType(final String type)
{
return client.get(String.format("%s/%s", DEVICETYPES_URL, type), DeviceTypeDto.MEDIA_TYPE,
DeviceTypeDto.class);
}
public Stream getDeviceTypes()
{
return client.list(DEVICETYPES_URL, DeviceTypesDto.MEDIA_TYPE, DeviceTypesDto.class);
}
public Stream getRegions(final String hypervisorType)
{
return client.list(getHypervisorType(hypervisorType).searchLink("regions").getHref(),
RegionsDto.MEDIA_TYPE, RegionsDto.class);
}
public Optional getRegion(final String hypervisorType, final String region)
{
return getRegions(hypervisorType).filter(r -> r.getProviderId().equals(region)).findFirst();
}
public Stream getDynamicRegions(final String hypervisorType, final String identity,
final String credential, final String endpoint)
{
Map headers = new HashMap<>();
headers.put("X-Abiquo-PCR-Identity", identity);
headers.put("X-Abiquo-PCR-Credential", credential);
headers.put("X-Abiquo-PCR-Endpoint", endpoint);
return client.list(getHypervisorType(hypervisorType).searchLink("regions").getHref(),
RegionsDto.MEDIA_TYPE, RegionsDto.class, headers);
}
public Optional getDynamicRegion(final String hypervisorType, final String region,
final String identity, final String credential, final String endpoint)
{
return getDynamicRegions(hypervisorType, identity, credential, endpoint)
.filter(r -> r.getName().equals(region)).findFirst();
}
public CostCodeDto createCostcode(final CostCodeDto costCode)
{
return client.post(COSTCODES_URL, CostCodeDto.MEDIA_TYPE_JSON, CostCodeDto.MEDIA_TYPE_JSON,
costCode, CostCodeDto.class);
}
public Stream listCostcodes(final ListOptions options)
{
return client.list(COSTCODES_URL, options.queryParams(), CostCodesDto.MEDIA_TYPE,
CostCodesDto.class);
}
public Stream listPrivileges()
{
return client.list(PRIVILEGES_URL, PrivilegesDto.MEDIA_TYPE, PrivilegesDto.class);
}
public PricingTemplateDto createPricingTemplate(final PricingTemplateDto pricingTemplate)
{
return client.post(PRICINGTEMPLATES_URL, PricingTemplateDto.MEDIA_TYPE,
PricingTemplateDto.MEDIA_TYPE, pricingTemplate, PricingTemplateDto.class);
}
public Stream listPricingTemplates()
{
return client.list(PRICINGTEMPLATES_URL, PricingTemplatesDto.MEDIA_TYPE,
PricingTemplatesDto.class);
}
public Stream listCurrencies()
{
return client.list(CURRENCIES_URL, CurrenciesDto.MEDIA_TYPE, CurrenciesDto.class);
}
public HardwareProfileFamilyDto createHardwareProfileFamily(final String name,
final String description)
{
HardwareProfileFamilyDto hardwareProfileFamilyDto = new HardwareProfileFamilyDto();
hardwareProfileFamilyDto.setName(name);
hardwareProfileFamilyDto.setDescription(description);
return client.post(HARDWARE_PROFILE_FAMILIES_URL, HardwareProfileFamilyDto.MEDIA_TYPE,
HardwareProfileFamilyDto.MEDIA_TYPE, hardwareProfileFamilyDto,
HardwareProfileFamilyDto.class);
}
public HardwareProfileTypeDto createHardwareProfileType(
final HardwareProfileFamilyDto hardwareProfileFamilyDto, final String name,
final String description)
{
HardwareProfileTypeDto dto = new HardwareProfileTypeDto();
dto.setName(name);
dto.setDescription(description);
return client.post(
hardwareProfileFamilyDto.searchLink(LinkRel.HARDWARE_PROFILE_TYPES).getHref(),
HardwareProfileTypeDto.MEDIA_TYPE, HardwareProfileTypeDto.MEDIA_TYPE, dto,
HardwareProfileTypeDto.class);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy