lib/azure/core/utility.rb in gitlab-fog-azure-rm-2.0.1 vs lib/azure/core/utility.rb in gitlab-fog-azure-rm-2.1.0
- old
+ new
@@ -11,12 +11,10 @@
# 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.
#--------------------------------------------------------------------------
-require 'ipaddr'
-
if RUBY_VERSION.to_f < 2.0
begin
require 'Win32/Console/ANSI' if RUBY_PLATFORM =~ /win32|mingw32/
rescue LoadError
puts 'WARNING: Output will look weird on Windows unless'\
@@ -186,58 +184,9 @@
cyan: 36,
white: 37,
}.each do |key, value|
define_method key do
"\e[#{value}m" + self + "\e[0m"
- end
- end
-end
-
-# Code validate private/public IP acceptable ranges.
-class IPAddr
- PRIVATE_RANGES = [
- IPAddr.new('10.0.0.0/8'),
- IPAddr.new('172.16.0.0/12'),
- IPAddr.new('192.168.0.0/16')
- ]
-
- def private?
- return false unless self.ipv4?
- PRIVATE_RANGES.each do |ipr|
- return true if ipr.include?(self)
- end
- false
- end
-
- def public?
- !private?
- end
-
- class << self
- def validate_ip_and_prefix(ip, cidr)
- if cidr.to_s.empty?
- raise "Cidr is missing for IP '#{ip}'."
- elsif valid?(ip)
- raise "Ip address '#{ip}' is invalid."
- elsif !IPAddr.new(ip).private?
- raise "Ip Address #{ip} must be private."
- end
- end
-
- def validate_address_space(ip)
- if ip.split('/').size != 2
- raise "Cidr is invalid for IP #{ip}."
- elsif valid?(ip)
- raise "Address space '#{ip}' is invalid."
- end
- end
-
- def address_prefix(ip, cidr)
- ip + '/' + cidr.to_s
- end
-
- def valid?(ip)
- (IPAddr.new(ip) rescue nil).nil?
end
end
end
Azure::Loggerx = Azure::Core::Logger