blob: acb5a3dc68353dabe61857f5ada336fcdc2eb934 [file] [log] [blame]
Jian Lic704b672018-09-04 18:52:53 +09001/*
2 * Copyright 2018-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.openstacknode.api;
18
19import com.google.common.base.MoreObjects;
20
21import java.util.Objects;
22
23import static com.google.common.base.Preconditions.checkArgument;
24
25/**
26 * Implementation class of neutron config.
27 */
28public final class DefaultNeutronConfig implements NeutronConfig {
29
30 private final boolean useMetadataProxy;
31 private final String metadataProxySecret;
32
33 private static final String NOT_NULL_MSG = "% cannot be null";
34
35 private DefaultNeutronConfig(boolean useMetadataProxy, String metadataProxySecret) {
36 this.useMetadataProxy = useMetadataProxy;
37 this.metadataProxySecret = metadataProxySecret;
38 }
39
40 @Override
41 public boolean useMetadataProxy() {
42 return useMetadataProxy;
43 }
44
45 @Override
46 public String metadataProxySecret() {
47 return metadataProxySecret;
48 }
49
50 @Override
51 public boolean equals(Object o) {
52 if (this == o) {
53 return true;
54 }
55
56 if (o instanceof DefaultNeutronConfig) {
57 DefaultNeutronConfig that = (DefaultNeutronConfig) o;
58 return Objects.equals(useMetadataProxy, that.useMetadataProxy) &&
59 Objects.equals(metadataProxySecret, that.metadataProxySecret);
60 }
61 return false;
62 }
63
64 @Override
65 public int hashCode() {
66
67 return Objects.hash(useMetadataProxy, metadataProxySecret);
68 }
69
70 @Override
71 public String toString() {
72 return MoreObjects.toStringHelper(this)
73 .add("useMetadataProxy", useMetadataProxy)
74 .add("metadataProxySecret", metadataProxySecret)
75 .toString();
76 }
77
78 /**
79 * Returns new builder instance.
80 *
81 * @return neutron config instance builder
82 */
83 public static Builder builder() {
84 return new Builder();
85 }
86
87 /**
88 * A builder class for neutron config.
89 */
90 public static final class Builder implements NeutronConfig.Builder {
91
92 private boolean useMetadataProxy;
93 private String metadataProxySecret;
94
95 // private constructor not intended to use from external
96 private Builder() {
97 }
98
99 @Override
100 public NeutronConfig build() {
101 checkArgument(metadataProxySecret != null,
102 NOT_NULL_MSG, "metadataProxySecret");
103
104 return new DefaultNeutronConfig(useMetadataProxy, metadataProxySecret);
105 }
106
107 @Override
108 public NeutronConfig.Builder useMetadataProxy(boolean useMetadataProxy) {
109 this.useMetadataProxy = useMetadataProxy;
110 return this;
111 }
112
113 @Override
114 public NeutronConfig.Builder metadataProxySecret(String metadataProxySecret) {
115 this.metadataProxySecret = metadataProxySecret;
116 return this;
117 }
118 }
119}