lib/security.rb in forj-0.0.35 vs lib/security.rb in forj-0.0.36
- old
+ new
@@ -14,15 +14,17 @@
# 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 'rubygems'
-require 'require_relative'
+require 'highline/import'
#
# SecurityGroup module
#
+
+# TODO: Introduce most of HPCloud task in an hpcloud object.
module SecurityGroup
def get_or_create_security_group(oFC, name)
Logging.state("Searching for security group '%s'..." % [name])
security_group = get_security_group(oFC, name)
@@ -133,10 +135,22 @@
rule = create_security_group_rule(oFC, security_group_id, protocol, port_min, port_max)
end
rule
end
- def upload_existing_key(key_name, key_path)
- command = 'hpcloud keypairs:import %s %s' % [key_name, key_path]
+ def hpc_import_pubkey(oConfig, account)
+
+ key_name = oConfig.get('keypair_name')
+ key_path = oConfig.get('keypair_path')
+
+ Logging.fatal(1, "'keypair_path' undefined. check your config.yaml file.") if not key_path
+ Logging.fatal(1, "'keypair_name' undefined. check your config.yaml file.") if not key_name
+
+ pubkey_path = key_path + '.pub'
+ Logging.fatal(1, "keypair '%s' are missing. Please call 'forj setup %s' to create the missing key pair required." % [pubkey_path, account]) if not File.exists?(pubkey_path)
+
+ Logging.info("Importing your forj keypair '%s' to hpcloud." % pubkey_path)
+ command = 'hpcloud keypairs:import %s %s -a %s' % [key_name, pubkey_path, account]
+ Logging.debug("Executing command '%s'" % command)
Kernel.system(command)
end
end