PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/server/lib/deltacloud/models/instance_address.rb

https://github.com/apache/deltacloud
Ruby | 71 lines | 43 code | 12 blank | 16 comment | 9 complexity | fb14275f7408249b360d0ea04aaf58cd MD5 | raw file
Possible License(s): Apache-2.0
  1. # Licensed to the Apache Software Foundation (ASF) under one or more
  2. # contributor license agreements. See the NOTICE file distributed with
  3. # this work for additional information regarding copyright ownership. The
  4. # ASF licenses this file to you under the Apache License, Version 2.0 (the
  5. # "License"); you may not use this file except in compliance with the
  6. # License. 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, WITHOUT
  12. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. # License for the specific language governing permissions and limitations
  14. # under the License.
  15. # Model to store the hardware profile applied to an instance together with
  16. # any instance-specific overrides
  17. module Deltacloud
  18. class InstanceAddress
  19. attr_accessor :address
  20. attr_accessor :port
  21. attr_accessor :address_type
  22. def initialize(address, opts={})
  23. self.address = address
  24. self.port = opts[:port] if opts[:port]
  25. self.address_type = opts[:type] || :ipv4
  26. self
  27. end
  28. def address_type
  29. (address and !address.strip.empty?) ? @address_type : :unavailable
  30. end
  31. def to_s
  32. return ['VNC', address, port].join(':') if is_vnc?
  33. address
  34. end
  35. def to_hash(context)
  36. r = {
  37. :address => address,
  38. :type => address_type
  39. }
  40. r.merge!(:port => port) if !port.nil?
  41. r
  42. end
  43. def is_mac?
  44. address_type == :mac
  45. end
  46. def is_ipv4?
  47. address_type == :ipv4
  48. end
  49. def is_ipv6?
  50. address_type == :ipv6
  51. end
  52. def is_hostname?
  53. address_type == :hostname
  54. end
  55. def is_vnc?
  56. address_type == :vnc
  57. end
  58. end
  59. end