diff --git a/.pryrc b/.pryrc new file mode 100644 index 0000000..63d35d4 --- /dev/null +++ b/.pryrc @@ -0,0 +1,6 @@ +if defined?(PryDebugger) + Pry.commands.alias_command 'c', 'continue' + Pry.commands.alias_command 's', 'step' + Pry.commands.alias_command 'n', 'next' + Pry.commands.alias_command 'f', 'finish' +end \ No newline at end of file diff --git a/lib/harp-runtime/resources/compute/security_group.rb b/lib/harp-runtime/resources/compute/security_group.rb index e2b585a..bcbb2a1 100644 --- a/lib/harp-runtime/resources/compute/security_group.rb +++ b/lib/harp-runtime/resources/compute/security_group.rb @@ -9,9 +9,9 @@ class SecurityGroup < AvailableResource include Harp::Resources - identity :name, :aliases => 'groupName' + attribute :id, :aliases => 'groupId' + attribute :name, :aliases => 'groupName' attribute :description, :aliases => 'groupDescription' - attribute :group_id, :aliases => 'groupId' attribute :ip_permissions, :aliases => 'ipPermissions' attribute :ip_permissions_egress, :aliases => 'ipPermissionsEgress' attribute :owner_id, :aliases => 'ownerId' @@ -20,14 +20,38 @@ class SecurityGroup < AvailableResource register_resource :security_group, RESOURCES_COMPUTE # Only keeping a few properties, simplest define keeps. - @keeps = /name|description/ + @keeps = /^id$|name|description/ + + # Return persistable attributes with only desired attributes to keep + def keep(persist_attribs) + persist_attribs[:id] = persist_attribs[:group_id] + super + end + + @output = false def self.persistent_type() ::SecurityGroup end def create(service) - service.security_groups.new(self.attribs) + create_attribs = self.attribs + #security_group = service.security_groups.new(self.attribs) + tags = {"Name" => @name} + create_attribs[:tags] = tags + security_group = service.security_groups.create(create_attribs[:attributes]) + @id = security_group.group_id + return security_group + end + + def destroy(service) + destroy_attribs = self.attribs + if @id + security_group = service.security_groups.destroy(destroy_attribs) + else + puts "No ID set, cannot delete." + end + return security_group end end diff --git a/spec/compute_cloud_spec.rb b/spec/compute_cloud_spec.rb index 707981c..005ec4d 100644 --- a/spec/compute_cloud_spec.rb +++ b/spec/compute_cloud_spec.rb @@ -12,8 +12,7 @@ security_group_resource = { "type" => "Std::SecurityGroup", "name" => "web-security-group", - "description" => "A web security group", - "ip_permissions" => "" + "description" => "A web security group" } describe Harp::Cloud::CloudMutator, "#create" do @@ -43,6 +42,8 @@ result = mutator.create("test_sg1", security_group_resource) expect(result.class).to eq(SecurityGroup) expect(result.name).to eq("test_sg1") + + expect(result.description).to eq("A web security group") end end \ No newline at end of file