Skip to content

Commit

Permalink
Partial single product deactivation implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Shaidurov committed Apr 11, 2017
1 parent 5150db9 commit 0c9c64d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
18 changes: 18 additions & 0 deletions lib/suse/connect/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,24 @@ def activate_product(auth, product, email = nil)
@connection.post('/connect/systems/products', auth: auth, params: payload)
end

# Deactivate a product, freeing a slot for another activation. Returns the service
# associated to the product.
#
# @param auth [String] authorization string which will be injected in 'Authorization' header in request.
# In this case we expect Base64 encoded string with login and password
# @param product [SUSE::Connect::Remote::Product] product to be deactivated
#
# @return [OpenStruct] responding to body(response from SCC) and code(natural HTTP response code).
def deactivate_product(auth, product)
payload = {
identifier: product.identifier,
version: product.version,
arch: product.arch,
release_type: product.release_type
}
@connection.delete('/connect/systems/products', auth: auth, params: payload)
end

# Upgrade a product and receive the updated service for the system.
#
# @param auth [String] authorization string which will be injected in 'Authorization' header in request.
Expand Down
23 changes: 16 additions & 7 deletions lib/suse/connect/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ def register!
# @returns: Empty body and 204 status code
def deregister!
if registered?
# if @config.product
# service = deactivate_product @config.product
# System.remove_service service
# Zypper.remove_release_package product.identifier
# print_success_message product, action: 'Deregistered'
# else
if @config.product
service = deactivate_product @config.product
System.remove_service service
Zypper.remove_release_package product.identifier
print_success_message product, action: 'Deregistered'
else
@api.deregister(system_auth)
System.cleanup!
log.info 'Successfully deregistered system.'
# end
end
else
log.fatal 'Deregistration failed. Check if the system has been '\
'registered using the -s option or use the --regcode parameter to '\
Expand Down Expand Up @@ -82,6 +82,15 @@ def activate_product(product, email = nil)
Remote::Service.new(result)
end

# Deactivate a product
#
# @param product [SUSE::Connect::Remote::Product]
# @returns: Service for this product
def deactivate_product(product)
result = @api.deactivate_product(system_auth, product).body
Remote::Service.new(result)
end

# Upgrade a product
# System upgrade (eg SLES11 -> SLES12) without regcode
#
Expand Down
6 changes: 6 additions & 0 deletions lib/suse/connect/system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ def add_service(service)
service
end

def remove_service(service)
raise ArgumentError, 'only Remote::Service accepted' unless service.is_a? Remote::Service
Zypper.remove_service service.name
service
end

def hostname
hostname = Socket.gethostname
if hostname && hostname != '(none)'
Expand Down

0 comments on commit 0c9c64d

Please sign in to comment.