Class: Registration::Registration

Inherits:
Object
  • Object
show all
Includes:
Yast::Logger
Defined in:
src/lib/registration/registration.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url = nil) ⇒ Registration


39
40
41
# File 'src/lib/registration/registration.rb', line 39

def initialize(url = nil)
  @url = url
end

Instance Attribute Details

#urlObject

Returns the value of attribute url


37
38
39
# File 'src/lib/registration/registration.rb', line 37

def url
  @url
end

Class Method Details

.is_registered?Boolean


193
194
195
196
# File 'src/lib/registration/registration.rb', line 193

def self.is_registered?
  # just a simple file check without connection to SCC
  File.exist?(SUSE::Connect::YaST::GLOBAL_CREDENTIALS_FILE)
end

Instance Method Details

#activated_productsObject


145
146
147
148
149
150
# File 'src/lib/registration/registration.rb', line 145

def activated_products
  log.info "Reading activated products..."
  activated = SUSE::Connect::YaST.status(connect_params).activated_products || []
  log.info "Activated products: #{activated.map(&:id)}"
  activated
end

#downgrade_product(product) ⇒ Object

downgrade product registration used when restoring the original registration after aborted migration


93
94
95
96
97
98
99
100
101
# File 'src/lib/registration/registration.rb', line 93

def downgrade_product(product)
  service_for_product(product) do |product_ident, params|
    log.info "Downgrading product: #{product}"
    service = SUSE::Connect::YaST.downgrade_product(product_ident, params)
    log.info "Downgrade product result: #{service}"

    service
  end
end

#get_addon_listObject


128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'src/lib/registration/registration.rb', line 128

def get_addon_list
  # extensions for base product
  base_product = ::Registration::SwMgmt.base_product_to_register

  log.info "Reading available addons for product: #{base_product["name"]}"

  remote_product = SwMgmt.remote_product(base_product)
  addons = SUSE::Connect::YaST.show_product(remote_product, connect_params).extensions || []
  addons.each { |a| log.info "Found available addon: #{a.inspect}" }

  renames = collect_renames(addons)
  ::Registration::SwMgmt.update_product_renames(renames)

  # ignore the base product "addon"
  addons.reject { |a| a.identifier == base_product["name"] }
end

#get_updates_list(product = nil) ⇒ Array<String>

Get the list of updates for a given product

See Also:


178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'src/lib/registration/registration.rb', line 178

def get_updates_list(product = nil)
  product ||= SwMgmt.base_product_to_register

  log.info "Reading available updates for product: #{product["name"]}"
  updates = []

  ConnectHelpers.catch_registration_errors do
    remote_product = SwMgmt.remote_product(product)
    updates = SUSE::Connect::YaST.list_installer_updates(remote_product, connect_params)
  end

  log.info "Updates for '#{product["name"]}' are available at '#{updates}'"
  updates
end

#migration_products(installed_products) ⇒ Array<Array<SUSE::Connect::Remote::Product>>

get the list of migration products


156
157
158
159
160
161
162
163
164
165
166
# File 'src/lib/registration/registration.rb', line 156

def migration_products(installed_products)
  log.info "Loading migration products for: #{installed_products}"
  migrations = []

  ConnectHelpers.catch_registration_errors do
    migrations = SUSE::Connect::YaST.system_migrations(installed_products)
  end

  log.info "Received system migrations: #{migrations}"
  migrations
end

#register(email, reg_code, distro_target) ⇒ Object


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'src/lib/registration/registration.rb', line 43

def register(email, reg_code, distro_target)
  settings = connect_params(
    token: reg_code,
    email: email
  )

  , password = SUSE::Connect::YaST.announce_system(settings, distro_target)
  log.info "Global SCC credentials (username): #{login}"

  # ensure the zypp config directories are writable in inst-sys
  ::Registration::SwMgmt.zypp_config_writable!

  # write the global credentials
  SUSE::Connect::YaST.create_credentials_file(, password)
end

#register_product(product, email = nil) ⇒ Object


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'src/lib/registration/registration.rb', line 59

def register_product(product, email = nil)
  service_for_product(product) do |product_ident, params|
    log_product = product.dup
    log_product["reg_code"] = "[FILTERED]" if log_product["reg_code"]
    log.info "Registering product: #{log_product}"

    service = SUSE::Connect::YaST.activate_product(product_ident, params, email)
    log.info "Register product result: #{service}"
    set_registered(product_ident)

    renames = collect_renames([service.product])
    SwMgmt.update_product_renames(renames)

    service
  end
end

#synchronize_products(products) ⇒ Object

synchronize the registered products on the server with the local installed products (removes all registrered products on the server which are not installed in the system)


106
107
108
109
110
111
112
113
114
115
116
117
# File 'src/lib/registration/registration.rb', line 106

def synchronize_products(products)
  remote_products = products.map do |product|
    OpenStruct.new(
      arch:         product["arch"],
      identifier:   product["name"],
      version:      product["version_version"],
      release_type: product["release_type"]
    )
  end
  log.info "Synchronizing products: #{remote_products}"
  SUSE::Connect::YaST.synchronize(remote_products)
end

#update_system(target_distro = nil) ⇒ OpenStruct


121
122
123
124
125
126
# File 'src/lib/registration/registration.rb', line 121

def update_system(target_distro = nil)
  log.info "Updating the system, new target distribution: #{target_distro}"
  ret = SUSE::Connect::YaST.update_system(connect_params, target_distro)
  log.info "Update result: #{ret}"
  ret
end

#upgrade_product(product) ⇒ Object


76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'src/lib/registration/registration.rb', line 76

def upgrade_product(product)
  service_for_product(product) do |product_ident, params|
    log.info "Upgrading product: #{product}"
    service = SUSE::Connect::YaST.upgrade_product(product_ident, params)
    log.info "Upgrade product result: #{service}"
    set_registered(product_ident)

    renames = collect_renames([service.product])
    SwMgmt.update_product_renames(renames)

    service
  end
end