Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/harp-runtime/cloud/cloud_mutator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ def destroy(resource_name, resource_def)

destroyed = resource.destroy(service)
#pr = persist_resource(resource_name, resource, resource, "destroy")
#persisted.live_resource = resource
persisted.state = Harp::Resources::AvailableResource::DESTROYED
remember(persisted)
persisted.save
Expand Down
9 changes: 6 additions & 3 deletions lib/harp-runtime/resources/autoscaling/autoscaling_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class AutoScalingGroup < AvailableResource
attribute :tags, :aliases => 'Tags'
attribute :termination_policies, :aliases => 'TerminationPolicies'
attribute :vpc_zone_identifier, :aliases => 'VPCZoneIdentifier'
attribute :description
attribute :state
attribute :type
attribute :live_resource


register_resource :auto_scaling_group, RESOURCES_AUTOSCALE
Expand All @@ -48,9 +52,8 @@ def create(service)
end

def destroy(service)
destroy_attribs = self.attribs
if @id
group = service.groups.destroy(destroy_attribs)
if id
group = service.groups.destroy(id)
else
puts "No ID set, cannot delete."
end
Expand Down
10 changes: 6 additions & 4 deletions lib/harp-runtime/resources/autoscaling/launch_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ class LaunchConfiguration < AvailableResource
attribute :security_groups, :aliases => 'SecurityGroups'
attribute :user_data, :aliases => 'UserData'
attribute :spot_price, :aliases => 'SpotPrice'

attribute :description
attribute :state
attribute :type
attribute :live_resource

register_resource :launch_configuration, RESOURCES_AUTOSCALE

Expand All @@ -45,9 +48,8 @@ def create(service)
end

def destroy(service)
destroy_attribs = self.attribs
if @id
configuration = service.configurations.destroy(destroy_attribs)
if id
configuration = service.configurations.destroy(id)
else
puts "No ID set, cannot delete."
end
Expand Down
9 changes: 6 additions & 3 deletions lib/harp-runtime/resources/autoscaling/scaling_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class ScalingPolicy < AvailableResource
attribute :cooldown, :aliases => 'Cooldown'
attribute :min_adjustment_step, :aliases => 'MinAdjustmentStep'
attribute :scaling_adjustment, :aliases => 'ScalingAdjustment'
attribute :description
attribute :state
attribute :type
attribute :live_resource

register_resource :scaling_policy, RESOURCES_AUTOSCALE

Expand All @@ -36,9 +40,8 @@ def create(service)
end

def destroy(service)
destroy_attribs = self.attribs
if @id
policy = service.policies.destroy(destroy_attribs)
if id
policy = service.delete_policy(auto_scaling_group_name, id)
else
puts "No ID set, cannot delete."
end
Expand Down
9 changes: 6 additions & 3 deletions lib/harp-runtime/resources/beanstalk/elastic_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class ElasticApplication < AvailableResource
attribute :updated_at, :aliases => 'DateUpdated'
attribute :description, :aliases => 'Description'
attribute :version_names, :aliases => 'Versions'
attribute :description
attribute :state
attribute :type
attribute :live_resource

register_resource :elastic_application, RESOURCES_BEANSTALK

Expand All @@ -41,9 +45,8 @@ def create(service)
end

def destroy(service)
destroy_attribs = self.attribs
if @id
application = service.applications.destroy(destroy_attribs)
if id
application = service.applications.destroy(id)
else
puts "No ID set, cannot delete."
end
Expand Down
11 changes: 7 additions & 4 deletions lib/harp-runtime/resources/beanstalk/elastic_environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ class ElasticEnvironment < AvailableResource
attribute :version_label, :aliases => 'VersionLabel'
attribute :option_settings, :aliases => 'OptionSettings'
attribute :options_to_remove, :aliases => 'OptionsToRemove'

attribute :description
attribute :state
attribute :type
attribute :live_resource

register_resource :elastic_environment, RESOURCES_BEANSTALK

# Only keeping a few properties, simplest define keeps.
Expand All @@ -47,9 +51,8 @@ def create(service)
end

def destroy(service)
destroy_attribs = self.attribs
if @id
environment = service.environments.destroy(destroy_attribs)
if id
environment = service.environments.destroy(id)
else
puts "No ID set, cannot delete."
end
Expand Down
11 changes: 8 additions & 3 deletions lib/harp-runtime/resources/compute/elastic_ip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ class ElasticIP < AvailableResource

include Harp::Resources

attribute :id, :aliases => 'allocation_id'
attribute :id
attribute :public_ip_address
attribute :public_ip, :aliases => 'publicIp'
attribute :server_id, :aliases => 'instanceId'
attribute :domain

attribute :description
attribute :type
attribute :live_resource
attribute :state

register_resource :elastic_ip, RESOURCES_COMPUTE

Expand All @@ -24,7 +29,7 @@ class ElasticIP < AvailableResource
# Return persistable attributes with only desired attributes to keep
def keep(attribs)
attribs[:public_ip_address] = attribs[:public_ip]
attribs[:id] = attribs[:allocation_id]
attribs[:id] = attribs[:public_ip]
super
end

Expand All @@ -37,7 +42,7 @@ def self.persistent_type()
def create(service)
create_attribs = self.attribs
address = service.addresses.create(create_attribs)
address.allocation_id = SecureRandom.urlsafe_base64(16)
@id = address.public_ip
return address
end

Expand Down
21 changes: 13 additions & 8 deletions lib/harp-runtime/resources/compute/elastic_ip_association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ class ElasticIPAssociation < AvailableResource
attribute :server_id, :aliases => 'instanceId'
attribute :network_interface_id, :aliases => 'networkInterfaceId'
attribute :network_interface_owner_id, :aliases => 'networkInterfaceOwnerId'
attribute :public_ip

attribute :description
attribute :type
attribute :live_resource
attribute :state


register_resource :elastic_ip_association, RESOURCES_COMPUTE
Expand All @@ -34,17 +40,16 @@ def self.persistent_type()


def create(service)
create_attribs = self.attribs
address = service.addresses.create(create_attribs)
address.association_id = SecureRandom.urlsafe_base64(16)
return address
create_attribs = self.attribs[:attributes]
address = service.associate_address(create_attribs[:server_id],create_attribs[:public_ip],nil,nil)
#id = address.association_id
return self
end

def destroy(service)
destroy_attribs = self.attribs
binding.pry
if @id
address = service.addresses.destroy(destroy_attribs)
public_ip = self.attribs[:attributes][:public_ip]
if public_ip
address = service.disassociate_address(public_ip)
else
puts "No ID set, cannot delete."
end
Expand Down
6 changes: 5 additions & 1 deletion lib/harp-runtime/resources/compute/security_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ class SecurityGroup < AvailableResource
attribute :ip_permissions_egress, :aliases => 'ipPermissionsEgress'
attribute :owner_id, :aliases => 'ownerId'
attribute :vpc_id, :aliases => 'vpcId'

attribute :type
attribute :live_resource
attribute :state

register_resource :security_group, RESOURCES_COMPUTE

Expand Down Expand Up @@ -46,7 +50,7 @@ def create(service)

def destroy(service)
if id
security_groups = service.security_groups.destroy(id)
security_groups = service.security_groups.destroy(name)
else
puts "No ID set, cannot delete."
end
Expand Down
4 changes: 4 additions & 0 deletions lib/harp-runtime/resources/compute/volume.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class Volume < AvailableResource
attribute :state, :aliases => 'status'
attribute :tags, :aliases => 'tagSet'
attribute :type, :aliases => 'volumeType'

attribute :description
attribute :live_resource
attribute :state

register_resource :volume, RESOURCES_COMPUTE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class LoadBalancer < AvailableResource
attribute :scheme, :aliases => 'Scheme'
attribute :vpc_id, :aliases => 'VPCId'
attribute :listeners

attribute :description
attribute :type
attribute :live_resource
attribute :state

register_resource :load_balancer, RESOURCES_ELASTIC_LOAD_BALANCING

Expand All @@ -45,9 +50,9 @@ def create(service)
end

def destroy(service)
destroy_attribs = self.attribs
if @id
load_balancer = service.load_balancers.destroy(destroy_attribs)
id
if id
load_balancer = service.load_balancers.destroy(id)
else
puts "No ID set, cannot delete."
end
Expand Down
9 changes: 6 additions & 3 deletions lib/harp-runtime/resources/rds/db_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class DBInstance < AvailableResource
attribute :publicly_accessible, :aliases => 'PubliclyAccessible'
attribute :vpc_security_groups, :aliases => 'VpcSecurityGroups'
attribute :password

attribute :description
attribute :type
attribute :live_resource

attr_accessor :parameter_group_name, :security_group_names, :port

Expand All @@ -60,9 +64,8 @@ def create(service)
end

def destroy(service)
destroy_attribs = self.attribs
if @id
instance = service.servers.destroy(destroy_attribs)
if id
instance = service.servers.destroy(id)
else
puts "No ID set, cannot delete."
end
Expand Down
9 changes: 6 additions & 3 deletions lib/harp-runtime/resources/rds/db_security_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class DBSecurityGroup < AvailableResource
attribute :ec2_security_groups, :aliases => 'EC2SecurityGroups'
attribute :ip_ranges, :aliases => 'IPRanges'
attribute :owner_id, :aliases => 'OwnerId'

attribute :type
attribute :live_resource
attribute :state

register_resource :db_security_group, RESOURCES_RDS

Expand All @@ -36,9 +40,8 @@ def create(service)
end

def destroy(service)
destroy_attribs = self.attribs
if @id
security_group = service.security_groups.destroy(destroy_attribs)
if id
security_group = service.security_groups.destroy(id)
else
puts "No ID set, cannot delete."
end
Expand Down
29 changes: 28 additions & 1 deletion spec/autoscaling_cloud_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,31 @@
expect(result.class).to eq(ScalingPolicy)
expect(result.name).to eq("test_as_policy1")
end
end
end

describe Harp::Cloud::CloudMutator, "#destroy" do
include_context "when have mutator"
it "destroys launch configuration" do
launch_config_resource["id"] = "testLC2"
created = mutator.create("test_lc2", launch_config_resource)
result = mutator.destroy("test_lc2", launch_config_resource)
expect(result.class).to eq(LaunchConfiguration)
expect(result.name).to eq("test_lc2")
end

it "destroys AS group" do
autoscaling_group_resource["id"] = "testASG2"
created = mutator.create("test_as_group2", autoscaling_group_resource)
result = mutator.destroy("test_as_group2", autoscaling_group_resource)
expect(result.class).to eq(AutoScalingGroup)
expect(result.name).to eq("test_as_group2")
end

it "destroys AutoScaling Policy" do
autoscaling_policy_resource["id"] = "testScalingPolicy2"
created = mutator.create("test_as_policy2", autoscaling_policy_resource)
result = mutator.destroy("test_as_policy2", autoscaling_policy_resource)
expect(result.class).to eq(ScalingPolicy)
expect(result.name).to eq("test_as_policy2")
end
end
Loading