Class: Registration::RegistrationUI

Inherits:
Object
  • Object
show all
Extended by:
Yast::I18n
Includes:
Yast::I18n, Yast::Logger, Yast::UIShortcuts
Defined in:
src/lib/registration/registration_ui.rb

Overview

Registration functions with errror handling, progress messages, etc... This is a high level API above Registration::Registration class

Constant Summary collapse

CONTACTING_MESSAGE =

popup message

N_("Contacting the Registration Server")

Instance Method Summary collapse

Constructor Details

#initialize(registration) ⇒ RegistrationUI


42
43
44
45
46
47
48
49
50
# File 'src/lib/registration/registration_ui.rb', line 42

def initialize(registration)
  textdomain "registration"
  @registration = registration

  Yast.import "Mode"
  Yast.import "Popup"
  Yast.import "Wizard"
  Yast.import "Mode"
end

Instance Method Details

#disable_update_repos(product_service) ⇒ Object


186
187
188
189
190
# File 'src/lib/registration/registration_ui.rb', line 186

def disable_update_repos(product_service)
  update_repos = SwMgmt.service_repos(product_service, only_updates: true)
  log.info "Disabling #{update_repos.size} update repositories: #{update_repos}"
  SwMgmt.set_repos_state(update_repos, false)
end

#downgrade_product(product) ⇒ Array<Boolean, OpenStruct>

downgrade product registration registered remote service


143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'src/lib/registration/registration_ui.rb', line 143

def downgrade_product(product)
  product_service = nil
  success = ConnectHelpers.catch_registration_errors do
    product_service = Yast::Popup.Feedback(
      _(CONTACTING_MESSAGE),
      # updating product registration, %s is a product name
      _("Updating to %s ...") % SwMgmt.product_label(product)
    ) do
      registration.downgrade_product(product)
    end
  end

  [success, product_service]
end

#get_available_addonsArray<Registration::Addon>

load available addons from SCC server the result is cached to avoid reloading when going back and forth in the installation workflow


177
178
179
180
181
182
183
184
# File 'src/lib/registration/registration_ui.rb', line 177

def get_available_addons
  Yast::Popup.Feedback(
    _(CONTACTING_MESSAGE),
    _("Loading Available Extensions and Modules...")
  ) do
    Addon.find_all(registration)
  end
end

#install_updates?Boolean


233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'src/lib/registration/registration_ui.rb', line 233

def install_updates?
  # ask only at installation/update
  return true unless Yast::Mode.installation || Yast::Mode.update

  options = Storage::InstallationOptions.instance

  # not set yet?
  if options.install_updates.nil?
    # TRANSLATORS: updates popup question (1/2), multiline, max. ~60 chars/line
    msg = _("The registration server offers update repositories.\n\n")

    if Yast::Mode.installation
      # TRANSLATORS: updates popup question (2/2), multiline, max. ~60 chars/line
      msg += _("Would you like to enable these repositories during installation\n" \
          "in order to receive the latest updates?")
    else # Yast::Mode.update
      # TRANSLATORS: updates popup question (2/2), multiline, max. ~60 chars/line
      msg += _("Would you like to enable these repositories during upgrade\n" \
          "in order to receive the latest updates?")
    end

    options.install_updates = Yast::Popup.YesNo(msg)
  end

  options.install_updates
end

#migration_products(products) ⇒ Object


192
193
194
195
196
197
198
199
# File 'src/lib/registration/registration_ui.rb', line 192

def migration_products(products)
  Yast::Popup.Feedback(
    _(CONTACTING_MESSAGE),
    _("Loading Migration Products...")
  ) do
    registration.migration_products(products)
  end
end

#register_addons(selected_addons, known_reg_codes) ⇒ Symbol

Register the selected addons, asks for reg. codes if required, known_reg_codes


207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'src/lib/registration/registration_ui.rb', line 207

def register_addons(selected_addons, known_reg_codes)
  # if registering only add-ons which do not need a reg. code (like SDK)
  # then simply start the registration
  if selected_addons.all?(&:free)
    Yast::Wizard.SetContents(
      # dialog title
      _("Register Extensions and Modules"),
      # display only the products which need a registration code
      Empty(),
      # help text
      _("<p>Extensions and Modules are being registered.</p>"),
      false,
      false
    )
    # when registration fails go back
    return register_selected_addons(selected_addons, known_reg_codes) ? :next : :back
  else
    loop do
      ret = UI::AddonRegCodesDialog.run(selected_addons, known_reg_codes)
      return ret unless ret == :next

      return :next if register_selected_addons(selected_addons, known_reg_codes)
    end
  end
end

#register_system_and_base_productArray<Boolean, SUSE::Connect::Remote::Service>

register the system and the base product the registration parameters are read from Storage::InstallationOptions


56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'src/lib/registration/registration_ui.rb', line 56

def register_system_and_base_product
  product_service = nil

  success = ConnectHelpers.catch_registration_errors do
    register_system if !Registration.is_registered?

    # then register the product(s)
    product_service = register_base_product
  end

  log.info "Registration suceeded: #{success}"
  [success, product_service]
end

#synchronize_products(products) ⇒ Boolean

synchronize the local products with the registration server


161
162
163
164
165
166
167
168
169
170
171
# File 'src/lib/registration/registration_ui.rb', line 161

def synchronize_products(products)
  ConnectHelpers.catch_registration_errors do
    Yast::Popup.Feedback(
      _(CONTACTING_MESSAGE),
      # TRANSLATORS: progress label
      _("Synchronizing Products...")
    ) do
      registration.synchronize_products(products)
    end
  end
end

#update_addons(addons, enable_updates: true) ⇒ Object


123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'src/lib/registration/registration_ui.rb', line 123

def update_addons(addons, enable_updates: true)
  # find addon updates
  addons_to_update = SwMgmt.find_addon_updates(addons)
  log.info "addons to update: #{addons_to_update.inspect}"

  failed_addons = addons_to_update.reject do |addon_to_update|
    update_addon(addon_to_update, enable_updates)
  end

  # install the new upgraded products
  SwMgmt.select_addon_products

  log.error "Failed addons: #{failed_addons}" unless failed_addons.empty?
  failed_addons
end

#update_base_productBoolean

update base product registration


98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'src/lib/registration/registration_ui.rb', line 98

def update_base_product
  product_service = nil
  upgraded = ConnectHelpers.catch_registration_errors(show_update_hint: true) do
    # then register the product(s)
    base_product = SwMgmt.base_product_to_register
    product_service = Yast::Popup.Feedback(
      _(CONTACTING_MESSAGE),
      # updating base product registration, %s is a new base product name
      _("Updating to %s ...") % SwMgmt.product_label(
        SwMgmt.find_base_product
      )
    ) do
      registration.upgrade_product(base_product)
    end
  end

  if !upgraded
    log.info "Registration upgrade failed, removing the credentials to register from scratch"
    Helpers.reset_registration_status
  end

  [upgraded, product_service]
end

#update_systemBoolean


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'src/lib/registration/registration_ui.rb', line 71

def update_system
  updated = ConnectHelpers.catch_registration_errors(show_update_hint: true) do
    base_product = SwMgmt.find_base_product
    target_distro = base_product["register_target"]

    Yast::Popup.Feedback(
      _(CONTACTING_MESSAGE),
      # FIXME: reused an existing message due to text freeze
      # (later use a better text, it's system update actually...)
      _("Registering the System...")
    ) do
      registration.update_system(target_distro)
    end
  end

  if !updated
    log.info "System update failed, removing the credentials to register from scratch"
    Helpers.reset_registration_status
    UrlHelpers.reset_registration_url
    Storage::Cache.instance.upgrade_failed = true
  end

  updated
end