added zone to openstack Host

This commit is contained in:
istolber 2014-10-08 08:46:00 +03:00 committed by Adrian Cole
parent 8122f0b38d
commit f3b3c4c706
3 changed files with 27 additions and 8 deletions

View File

@ -43,6 +43,7 @@ public class Host {
protected String name;
protected String service;
protected String zone;
/**
* @see Host#getName()
@ -60,14 +61,23 @@ public class Host {
return self();
}
/**
* @see Host#getZone()
*/
public T zone(String zone) {
this.zone = zone;
return self();
}
public Host build() {
return new Host(name, service);
return new Host(name, service, zone);
}
public T fromHost(Host in) {
return this
.name(in.getName())
.service(in.getService());
.service(in.getService())
.zone(in.getZone());
}
}
@ -81,13 +91,15 @@ public class Host {
@Named("host_name")
private final String name;
private final String service;
private final String zone;
@ConstructorProperties({
"host_name", "service"
"host_name", "service", "zone"
})
protected Host(@Nullable String name, @Nullable String service) {
protected Host(@Nullable String name, @Nullable String service, @Nullable String zone) {
this.name = name;
this.service = service;
this.zone = zone;
}
@Nullable
@ -100,9 +112,13 @@ public class Host {
return this.service;
}
@Nullable
public String getZone() {
return this.zone;
}
@Override
public int hashCode() {
return Objects.hashCode(name, service);
return Objects.hashCode(name, service, zone);
}
@Override
@ -111,12 +127,13 @@ public class Host {
if (obj == null || getClass() != obj.getClass()) return false;
Host that = Host.class.cast(obj);
return Objects.equal(this.name, that.name)
&& Objects.equal(this.service, that.service);
&& Objects.equal(this.service, that.service)
&& Objects.equal(this.zone, that.zone);
}
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("name", name).add("service", service);
.add("name", name).add("service", service).add("zone", zone);
}
@Override

View File

@ -53,12 +53,13 @@ public class HostAdministrationApiExpectTest extends BaseNovaApiExpectTest {
.endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/hosts_list.json")).build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get();
Host expected = Host.builder().name("ubuntu").service("compute").build();
Host expected = Host.builder().name("ubuntu").service("compute").zone("nova").build();
Set<? extends Host> result = api.list().toSet();
Host host = Iterables.getOnlyElement(result);
assertEquals(host.getName(), "ubuntu");
assertEquals(host.getService(), "compute");
assertEquals(host.getZone(), "nova");
assertEquals(host, expected);
}

View File

@ -1,6 +1,7 @@
{
"hosts": [
{
"zone": "nova",
"host_name": "ubuntu",
"service": "compute"
}