You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2011/11/02 15:05:30 UTC

[PATCH core 2/4] Core: Added InstanceAddress model for storing public/private_addresses

From: Michal Fojtik <mf...@redhat.com>


Signed-off-by: Michal fojtik <mf...@redhat.com>
---
 server/lib/deltacloud/models/instance_address.rb |   56 ++++++++++++++++++++++
 1 files changed, 56 insertions(+), 0 deletions(-)
 create mode 100644 server/lib/deltacloud/models/instance_address.rb

diff --git a/server/lib/deltacloud/models/instance_address.rb b/server/lib/deltacloud/models/instance_address.rb
new file mode 100644
index 0000000..f94ef25
--- /dev/null
+++ b/server/lib/deltacloud/models/instance_address.rb
@@ -0,0 +1,56 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.  The
+# ASF licenses this file to you 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.
+
+# Model to store the hardware profile applied to an instance together with
+# any instance-specific overrides
+
+class InstanceAddress
+  attr_accessor :address
+  attr_accessor :port
+  attr_accessor :address_type
+
+  def initialize(address, opts={})
+    self.address = address
+    self.port = opts[:port] if opts[:port]
+    self.address_type = opts[:type] || :ipv6
+    self
+  end
+
+  def address_type
+    (address and !address.strip.empty?) ? @address_type : :unavailable
+  end
+
+  def to_s
+    return ['VNC', address, port].join(':') if is_vnc?
+    address
+  end
+
+  def is_mac?
+    address_type == :mac
+  end
+
+  def is_ipv6?
+    address_type == :ipv6
+  end
+
+  def is_hostname?
+    address_type == :hostname
+  end
+
+  def is_vnc?
+    address_type == :vnc
+  end
+
+end
-- 
1.7.4.4