Package backend :: Package server :: Package rhnServer :: Module server_class
[hide private]
[frames] | no frames]

Source Code for Module backend.server.rhnServer.server_class

  1  # 
  2  # Copyright (c) 2008--2016 Red Hat, Inc. 
  3  # 
  4  # This software is licensed to you under the GNU General Public License, 
  5  # version 2 (GPLv2). There is NO WARRANTY for this software, express or 
  6  # implied, including the implied warranties of MERCHANTABILITY or FITNESS 
  7  # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 
  8  # along with this software; if not, see 
  9  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 
 10  # 
 11  # Red Hat trademarks are not licensed under GPLv2. No permission is 
 12  # granted to use or replicate Red Hat trademarks that are incorporated 
 13  # in this software or its documentation. 
 14  # 
 15  # Stuff for handling Servers 
 16  # 
 17   
 18  # system modules 
 19  import string 
 20  import sys 
 21   
 22  from spacewalk.common.usix import raise_with_tb 
 23  from spacewalk.common import rhnFlags 
 24  from spacewalk.common.rhnConfig import CFG 
 25  from spacewalk.common.rhnLog import log_debug, log_error 
 26  from spacewalk.common.rhnException import rhnFault, rhnException 
 27  from spacewalk.common.rhnTranslate import _ 
 28  from spacewalk.server import rhnChannel, rhnUser, rhnSQL, rhnLib, rhnAction, \ 
 29      rhnVirtualization 
 30  from search_notify import SearchNotify 
 31   
 32  # Local Modules 
 33  import server_kickstart 
 34  import server_lib 
 35  import server_token 
 36  from server_certificate import Certificate, gen_secret 
 37  from server_wrapper import ServerWrapper 
 38   
 39   
40 -class Server(ServerWrapper):
41 42 """ Main Server class """ 43
44 - def __init__(self, user, arch=None, org_id=None):
45 ServerWrapper.__init__(self) 46 self.user = user 47 # Use the handy TableRow 48 self.server = rhnSQL.Row("rhnServer", "id") 49 self.server["release"] = "" 50 self.server["os"] = "Red Hat Linux" 51 self.is_rpm_managed = 0 52 self.set_arch(arch) 53 # We only get this passed in when we create a new 54 # entry. Usually a reload will create a dummy entry first and 55 # then call self.loadcert() 56 if user: 57 self.server["org_id"] = user.customer["id"] 58 elif org_id: 59 self.server["org_id"] = org_id 60 self.cert = None 61 # Also, at this point we know that this is a real server 62 self.type = "REAL" 63 self.default_description() 64 65 # custom info values 66 self.custom_info = None 67 68 # uuid 69 self.uuid = None 70 self.virt_uuid = None 71 self.registration_number = None
72 73 _query_lookup_arch = rhnSQL.Statement(""" 74 select sa.id, 75 case when at.label = 'rpm' then 1 else 0 end is_rpm_managed 76 from rhnServerArch sa, 77 rhnArchType at 78 where sa.label = :archname 79 and sa.arch_type_id = at.id 80 """) 81
82 - def set_arch(self, arch):
83 self.archname = arch 84 # try to detect the archid 85 if arch is None: 86 return 87 88 arch = rhnLib.normalize_server_arch(arch) 89 h = rhnSQL.prepare(self._query_lookup_arch) 90 h.execute(archname=arch) 91 data = h.fetchone_dict() 92 if not data: 93 # Log it to disk, it may show interesting things 94 log_error("Attempt to create server with invalid arch `%s'" % 95 arch) 96 raise rhnFault(24, 97 _("Architecture `%s' is not supported") % arch) 98 self.server["server_arch_id"] = data["id"] 99 self.is_rpm_managed = data['is_rpm_managed']
100 101 # set the default description...
102 - def default_description(self):
103 self.server["description"] = "Initial Registration Parameters:\n"\ 104 "OS: %s\n"\ 105 "Release: %s\n"\ 106 "CPU Arch: %s" % ( 107 self.server["os"], self.server["release"], 108 self.archname)
109
110 - def __repr__(self):
111 # misa: looks like id can return negative numbers, so use %d 112 # instead of %x 113 # For the gory details, 114 # http://mail.python.org/pipermail/python-dev/2005-February/051559.html 115 return "<Server Class at %d: %s>\n" % ( 116 id(self), { 117 "self.cert": self.cert, 118 "self.server": self.server.data, 119 })
120 __str__ = __repr__ 121 122 # Return a Digital Certificate that can be placed in a file on the 123 # client side.
124 - def system_id(self):
125 log_debug(3, self.server, self.cert) 126 if self.cert is None: 127 # need to instantiate it 128 cert = Certificate() 129 cert["system_id"] = self.server["digital_server_id"] 130 cert["os_release"] = self.server["release"] 131 cert["operating_system"] = self.server["os"] 132 cert["architecture"] = self.archname 133 cert["profile_name"] = self.server["name"] 134 cert["description"] = self.server["description"] 135 if self.user: 136 cert["username"] = self.user.contact["login"] 137 cert["type"] = self.type 138 cert.set_secret(self.server["secret"]) 139 self.cert = cert 140 return self.cert.certificate()
141 142 # return the id of this system
143 - def getid(self):
144 if not self.server.has_key("id"): 145 sysid = rhnSQL.Sequence("rhn_server_id_seq")() 146 self.server["digital_server_id"] = "ID-%09d" % sysid 147 # we can't reset the id column, so we need to poke into 148 # internals. kind of illegal, but it works... 149 self.server.data["id"] = (sysid, 0) 150 else: 151 sysid = self.server["id"] 152 return sysid
153 154 # change the base channel of a server
155 - def change_base_channel(self, new_rel):
156 log_debug(3, self.server["id"], new_rel) 157 old_rel = self.server["release"] 158 current_channels = rhnChannel.channels_for_server(self.server["id"]) 159 # Extract the base channel off of 160 old_base = [x for x in current_channels if not x['parent_channel']] 161 162 # Quick sanity check 163 base_channels_count = len(old_base) 164 if base_channels_count == 1: 165 old_base = old_base[0] 166 elif base_channels_count == 0: 167 old_base = None 168 else: 169 raise rhnException("Server %s subscribed to multiple base channels" 170 % (self.server["id"], )) 171 172 # bz 442355 173 # Leave custom base channels alone, don't alter any of the channel subscriptions 174 if not CFG.RESET_BASE_CHANNEL and old_base and rhnChannel.isCustomChannel(old_base["id"]): 175 log_debug(3, 176 "Custom base channel detected, will not alter channel subscriptions") 177 self.server["release"] = new_rel 178 self.server.save() 179 msg = """The Red Hat Satellite Update Agent has detected a 180 change in the base version of the operating system running 181 on your system, additionaly you are subscribed to a custom 182 channel as your base channel. Due to this configuration 183 your channel subscriptions will not be altered. 184 """ 185 self.add_history("Updated system release from %s to %s" % ( 186 old_rel, new_rel), msg) 187 self.save_history_byid(self.server["id"]) 188 return 1 189 190 s = rhnChannel.LiteServer().init_from_server(self) 191 s.release = new_rel 192 s.arch = self.archname 193 # Let get_server_channels deal with the errors and raise rhnFault 194 target_channels = rhnChannel.guess_channels_for_server(s, none_ok=True) 195 if target_channels: 196 target_base = filter(lambda x: not x['parent_channel'], 197 target_channels)[0] 198 else: 199 target_base = None 200 201 channels_to_subscribe = [] 202 channels_to_unsubscribe = [] 203 if old_base and target_base and old_base['id'] == target_base['id']: 204 # Same base channel. Preserve the currently subscribed child 205 # channels, just add the ones that are missing 206 hash = {} 207 for c in current_channels: 208 hash[c['id']] = c 209 210 for c in target_channels: 211 channel_id = c['id'] 212 if channel_id in hash: 213 # Already subscribed to this one 214 del hash[channel_id] 215 continue 216 # Have to subscribe to this one 217 channels_to_subscribe.append(c) 218 219 # We don't want to lose subscriptions to prior channels, so don't 220 # do anything with hash.values() 221 else: 222 # Different base channel 223 channels_to_unsubscribe = current_channels 224 channels_to_subscribe = target_channels 225 226 rhnSQL.transaction("change_base_channel") 227 self.server["release"] = new_rel 228 self.server.save() 229 if not (channels_to_subscribe or channels_to_unsubscribe): 230 # Nothing to do, just add the history entry 231 self.add_history("Updated system release from %s to %s" % ( 232 old_rel, new_rel)) 233 self.save_history_byid(self.server["id"]) 234 return 1 235 236 # XXX: need a way to preserve existing subscriptions to 237 # families so we can restore access to non-public ones. 238 239 rhnChannel.unsubscribe_channels(self.server["id"], 240 channels_to_unsubscribe) 241 rhnChannel.subscribe_channels(self.server["id"], 242 channels_to_subscribe) 243 # now that we changed, recompute the errata cache for this one 244 rhnSQL.Procedure("queue_server")(self.server["id"]) 245 # Make a history note 246 sub_channels = rhnChannel.channels_for_server(self.server["id"]) 247 if sub_channels: 248 channel_list = [a["name"] for a in sub_channels] 249 msg = """The Red Hat Satellite Update Agent has detected a 250 change in the base version of the operating system running 251 on your system and has updated your channel subscriptions 252 to reflect that. 253 Your server has been automatically subscribed to the following 254 channels:\n%s\n""" % (string.join(channel_list, "\n"),) 255 else: 256 msg = """*** ERROR: *** 257 While trying to subscribe this server to software channels: 258 There are no channels serving release %s""" % new_rel 259 self.add_history("Updated system release from %s to %s" % ( 260 old_rel, new_rel), msg) 261 self.save_history_byid(self.server["id"]) 262 return 1
263
264 - def take_snapshot(self, reason):
265 return server_lib.snapshot_server(self.server['id'], reason)
266 267 # returns true iff the base channel assigned to this system 268 # has been end-of-life'd
269 - def base_channel_is_eol(self):
270 h = rhnSQL.prepare(""" 271 select 1 272 from rhnChannel c, rhnServerChannel sc 273 where sc.server_id = :server_id 274 and sc.channel_id = c.id 275 and c.parent_channel IS NULL 276 and sysdate - c.end_of_life > 0 277 """) 278 h.execute(server_id=self.getid()) 279 ret = h.fetchone_dict() 280 if ret: 281 return 1 282 283 return None
284 285 _query_server_custom_info = rhnSQL.Statement(""" 286 select cdk.label, 287 scdv.value 288 from rhnCustomDataKey cdk, 289 rhnServerCustomDataValue scdv 290 where scdv.server_id = :server_id 291 and scdv.key_id = cdk.id 292 """) 293
294 - def load_custom_info(self):
295 self.custom_info = {} 296 297 h = rhnSQL.prepare(self._query_server_custom_info) 298 h.execute(server_id=self.getid()) 299 rows = h.fetchall_dict() 300 301 if not rows: 302 log_debug(4, "no custom info values") 303 return 304 305 for row in rows: 306 self.custom_info[row['label']] = row['value']
307 308 # load additional server information from the token definition
309 - def load_token(self):
310 # Fetch token 311 tokens_obj = rhnFlags.get("registration_token") 312 if not tokens_obj: 313 # No tokens present 314 return 0 315 316 # make sure we have reserved a server_id. most likely if this 317 # is a new server object (just created from 318 # registration.new_system) then we have no associated a 319 # server["id"] yet -- and getid() will reserve that for us. 320 self.getid() 321 # pull in the extra information needed to fill in the 322 # required registration fields using tokens 323 324 user_id = tokens_obj.get_user_id() 325 org_id = tokens_obj.get_org_id() 326 327 self.user = rhnUser.User("", "") 328 if user_id is not None: 329 self.user.reload(user_id) 330 self.server["creator_id"] = user_id 331 self.server["org_id"] = org_id 332 return 0
333 334 # perform the actions required by the token (subscribing to 335 # channels, server groups, etc)
336 - def use_token(self):
337 # Fetch token 338 tokens_obj = rhnFlags.get("registration_token") 339 if not tokens_obj: 340 # No token present 341 return 0 342 343 is_rereg_token = tokens_obj.is_rereg_token 344 345 # We get back a history of what is being done in the 346 # registration process 347 history = server_token.process_token(self.server, self.archname, 348 tokens_obj, self.virt_type) 349 350 if is_rereg_token: 351 event_name = "Reactivation via Token" 352 event_text = "System reactivated" 353 else: 354 event_name = "Subscription via Token" 355 event_text = "System created" 356 357 token_name = tokens_obj.get_names() 358 # now record that history nicely 359 self.add_history(event_name, 360 "%s with token <strong>%s</strong><br />\n%s" % 361 (event_text, token_name, history)) 362 self.save_history_byid(self.server["id"]) 363 364 # 6/23/05 wregglej 157262, use get_kickstart session_id() to see if we're in the middle of a kickstart. 365 ks_id = tokens_obj.get_kickstart_session_id() 366 367 # 4/5/05 wregglej, Added for bugzilla: 149932. Actions need to be flushed on reregistration. 368 # 6/23/05 wregglej 157262, don't call flush_actions() if we're in the middle of a kickstart. 369 # It would cause all of the remaining kickstart actions to get flushed, which is bad. 370 if is_rereg_token and ks_id is None: 371 self.flush_actions() 372 373 # XXX: will need to call self.save() later to commit all that 374 return 0
375
376 - def disable_token(self):
377 tokens_obj = rhnFlags.get('registration_token') 378 if not tokens_obj: 379 # Nothing to do 380 return 381 if not tokens_obj.is_rereg_token: 382 # Not a re-registration token - nothing to do 383 return 384 385 # Re-registration token - we know for sure there is only one 386 token_server_id = tokens_obj.get_server_id() 387 if token_server_id != self.getid(): 388 # Token is not associated with this server (it may actually not be 389 # associated with any server) 390 return 391 server_token.disable_token(tokens_obj)
392 # save() will commit this 393 394 # Auto-entitlement: attempt to entitle this server to the highest 395 # entitlement that is available
396 - def autoentitle(self):
397 entitlement_hierarchy = ['enterprise_entitled'] 398 399 any_base_entitlements = 0 400 401 for entitlement in entitlement_hierarchy: 402 try: 403 self._entitle(entitlement) 404 any_base_entitlements = 1 405 except rhnSQL.SQLSchemaError: 406 e = sys.exc_info()[1] 407 if e.errno == 20287: 408 # ORA-20287: (invalid_entitlement) - The server can not be 409 # entitled to the specified level 410 # 411 # ignore for now, since any_base_entitlements will throw 412 # an error at the end if not set 413 continue 414 415 # Should not normally happen 416 log_error("Failed to entitle", self.server["id"], entitlement, 417 e.errmsg) 418 raise_with_tb(server_lib.rhnSystemEntitlementException("Unable to entitle"), sys.exc_info()[2]) 419 except rhnSQL.SQLError: 420 e = sys.exc_info()[1] 421 log_error("Failed to entitle", self.server["id"], entitlement, 422 str(e)) 423 raise_with_tb(server_lib.rhnSystemEntitlementException("Unable to entitle"), sys.exc_info()[2]) 424 else: 425 if any_base_entitlements: 426 # All is fine 427 return 428 else: 429 raise_with_tb(server_lib.rhnNoSystemEntitlementsException, sys.exc_info()[2])
430
431 - def _entitle(self, entitlement):
432 system_entitlements = server_lib.check_entitlement(self.server["id"]) 433 system_entitlements = list(system_entitlements.keys()) 434 435 if entitlement not in system_entitlements: 436 entitle_server = rhnSQL.Procedure("rhn_entitlements.entitle_server") 437 entitle_server(self.server['id'], entitlement)
438
439 - def create_perm_cache(self):
440 log_debug(4) 441 create_perms = rhnSQL.Procedure("rhn_cache.update_perms_for_server") 442 create_perms(self.server['id'])
443
444 - def gen_secret(self):
445 # Running this invalidates the cert 446 self.cert = None 447 self.server["secret"] = gen_secret()
448 449 _query_update_uuid = rhnSQL.Statement(""" 450 update rhnServerUuid set uuid = :uuid 451 where server_id = :server_id 452 """) 453 _query_insert_uuid = rhnSQL.Statement(""" 454 insert into rhnServerUuid (server_id, uuid) 455 values (:server_id, :uuid) 456 """) 457
458 - def update_uuid(self, uuid, commit=1):
459 log_debug(3, uuid) 460 # XXX Should determine a way to do this dinamically 461 uuid_col_length = 36 462 if uuid is not None: 463 uuid = str(uuid) 464 if not uuid: 465 log_debug('Nothing to do') 466 return 467 468 uuid = uuid[:uuid_col_length] 469 server_id = self.server['id'] 470 log_debug(4, "Trimmed uuid", uuid, server_id) 471 472 # Update this server's UUID (unique client identifier) 473 h = rhnSQL.prepare(self._query_update_uuid) 474 ret = h.execute(server_id=server_id, uuid=uuid) 475 log_debug(4, "execute returned", ret) 476 477 if ret != 1: 478 # Row does not exist, have to create it 479 h = rhnSQL.prepare(self._query_insert_uuid) 480 h.execute(server_id=server_id, uuid=uuid) 481 482 if commit: 483 rhnSQL.commit()
484
485 - def handle_virtual_guest(self):
486 # Handle virtualization specific bits 487 if self.virt_uuid and self.virt_type: 488 rhnVirtualization._notify_guest(self.getid(), 489 self.virt_uuid, self.virt_type)
490 491 # Save this record in the database
492 - def __save(self, channel):
493 tokens_obj = rhnFlags.get("registration_token") 494 495 if self.server.real: 496 server_id = self.server["id"] 497 self.server.save() 498 else: # create new entry 499 self.gen_secret() 500 server_id = self.getid() 501 org_id = self.server["org_id"] 502 503 if self.user: 504 user_id = self.user.getid() 505 else: 506 user_id = None 507 508 # some more default values 509 self.server["auto_update"] = "N" 510 if self.user and not self.server.has_key("creator_id"): 511 # save the link to the user that created it if we have 512 # that information 513 self.server["creator_id"] = self.user.getid() 514 # and create the server entry 515 self.server.create(server_id) 516 server_lib.create_server_setup(server_id, org_id) 517 518 self.handle_virtual_guest() 519 520 # if we're using a token, then the following channel 521 # subscription request can allow no matches since the 522 # token code will fix up or fail miserably later. 523 # subscribe the server to applicable channels 524 525 # bretm 02/17/2007 -- TODO: refactor activation key codepaths 526 # to allow us to not have to pass in none_ok=1 in any case 527 # 528 # This can now throw exceptions which will be caught at a higher level 529 if channel is not None: 530 channel_info = dict(rhnChannel.channel_info(channel)) 531 log_debug(4, "eus channel id %s" % str(channel_info)) 532 rhnChannel.subscribe_sql(server_id, channel_info['id']) 533 else: 534 rhnChannel.subscribe_server_channels(self, 535 none_ok=tokens_obj, 536 user_id=user_id) 537 538 if not tokens_obj: 539 # Attempt to auto-entitle, can throw the following exceptions: 540 # rhnSystemEntitlementException 541 # rhnNoSystemEntitlementsException 542 self.autoentitle() 543 544 # If a new server that was registered by an user (i.e. not 545 # with a registration token), look for this user's default 546 # groups 547 self.join_groups() 548 549 server_lib.join_rhn(org_id) 550 551 # Update virtual guest attributes on re-registration 552 if tokens_obj and tokens_obj.is_rereg_token: 553 self.handle_virtual_guest() 554 555 # Update the uuid - but don't commit yet 556 self.update_uuid(self.uuid, commit=0) 557 558 self.create_perm_cache() 559 # And save the extra profile data... 560 self.save_packages_byid(server_id, schedule=1) 561 self.save_hardware_byid(server_id) 562 self.save_history_byid(server_id) 563 return 0
564 565 # This is a wrapper for the above class that allows us to rollback 566 # any changes in case we don't succeed completely
567 - def save(self, commit=1, channel=None):
568 log_debug(3) 569 # attempt to preserve pending changes before we were called, 570 # so we set up our own transaction checkpoint 571 rhnSQL.transaction("save_server") 572 try: 573 self.__save(channel) 574 except: # roll back to what we have before and raise again 575 rhnSQL.rollback("save_server") 576 # shoot the exception up the chain 577 raise 578 else: # if we want to commit, commit all pending changes 579 if commit: 580 rhnSQL.commit() 581 try: 582 search = SearchNotify() 583 search.notify() 584 except Exception: 585 e = sys.exc_info()[1] 586 log_error("Exception caught from SearchNotify.notify().", e) 587 return 0
588 589 # Reload the current configuration from database using a server id.
590 - def reload(self, server, reload_all=0):
591 log_debug(4, server, "reload_all = %d" % reload_all) 592 593 if not self.server.load(int(server)): 594 log_error("Could not find server record for reload", server) 595 raise rhnFault(29, "Could not find server record in the database") 596 self.cert = None 597 # it is lame that we have to do this 598 h = rhnSQL.prepare(""" 599 select label from rhnServerArch where id = :archid 600 """) 601 h.execute(archid=self.server["server_arch_id"]) 602 data = h.fetchone_dict() 603 if not data: 604 raise rhnException("Found server with invalid numeric " 605 "architecture reference", 606 self.server.data) 607 self.archname = data['label'] 608 # we don't know this one anymore (well, we could look for, but 609 # why would we do that?) 610 self.user = None 611 612 # XXX: Fix me 613 if reload_all: 614 if not self.reload_packages_byid(self.server["id"]) == 0: 615 return -1 616 if not self.reload_hardware_byid(self.server["id"]) == 0: 617 return -1 618 return 0
619 620 # Use the values we find in the cert to cause a reload of this 621 # server from the database.
622 - def loadcert(self, cert, load_user=1):
623 log_debug(4, cert) 624 # certificate is presumed to be already verified 625 if not isinstance(cert, Certificate): 626 return -1 627 # reload the whole thing based on the cert data 628 server = cert["system_id"] 629 row = server_lib.getServerID(server) 630 if row is None: 631 return -1 632 sid = row["id"] 633 # standard reload based on an ID 634 ret = self.reload(sid) 635 if not ret == 0: 636 return ret 637 638 # the reload() will never be able to fill in the username. It 639 # would require from the database standpoint insuring that for 640 # a given server we can have only one owner at any given time. 641 # cert includes it and it's valid because it has been verified 642 # through checksuming before we got here 643 644 self.user = None 645 646 # Load the user if at all possible. If it's not possible, 647 # self.user will be None, which should be a handled case wherever 648 # self.user is used. 649 if load_user: 650 # Load up the username associated with this profile 651 self.user = rhnUser.search(cert["username"]) 652 653 # 4/27/05 wregglej - Commented out this block because it was causing problems 654 # with rhn_check/up2date when the user that registered the system was deleted. 655 # if not self.user: 656 # log_error("Invalid username for server id", 657 # cert["username"], server, cert["profile_name"]) 658 # raise rhnFault(9, "Invalid username '%s' for server id %s" %( 659 # cert["username"], server)) 660 661 # XXX: make sure that the database thinks that the server 662 # registrnt is the same as this certificate thinks. The 663 # certificate passed checksum checks, but it never hurts to be 664 # too careful now with satellites and all. 665 return 0
666 667 # Is this server entitled?
668 - def check_entitlement(self):
669 if not self.server.has_key("id"): 670 return None 671 log_debug(3, self.server["id"]) 672 673 return server_lib.check_entitlement(self.server['id'])
674
675 - def checkin(self, commit=1):
676 """ convenient wrapper for these thing until we clean the code up """ 677 if not self.server.has_key("id"): 678 return 0 # meaningless if rhnFault not raised 679 return server_lib.checkin(self.server["id"], commit)
680
681 - def throttle(self):
682 """ convenient wrapper for these thing until we clean the code up """ 683 if not self.server.has_key("id"): 684 return 1 # meaningless if rhnFault not raised 685 return server_lib.throttle(self.server)
686
687 - def set_qos(self):
688 """ convenient wrapper for these thing until we clean the code up """ 689 if not self.server.has_key("id"): 690 return 1 # meaningless if rhnFault not raised 691 return server_lib.set_qos(self.server["id"])
692
693 - def join_groups(self):
694 """ For a new server, join server groups """ 695 696 # Sanity check - we should always have a user 697 if not self.user: 698 raise rhnException("User not specified") 699 700 server_id = self.getid() 701 user_id = self.user.getid() 702 703 h = rhnSQL.prepare(""" 704 select system_group_id 705 from rhnUserDefaultSystemGroups 706 where user_id = :user_id 707 """) 708 h.execute(user_id=user_id) 709 while 1: 710 row = h.fetchone_dict() 711 if not row: 712 break 713 server_group_id = row['system_group_id'] 714 log_debug(5, "Subscribing server to group %s" % server_group_id) 715 716 server_lib.join_server_group(server_id, server_group_id)
717
719 return rhnChannel.system_reg_message(self)
720
721 - def process_kickstart_info(self):
722 log_debug(4) 723 tokens_obj = rhnFlags.get("registration_token") 724 if not tokens_obj: 725 log_debug(4, "no registration token found") 726 # Nothing to do here 727 return 728 729 # If there are kickstart sessions associated with this system (other 730 # than, possibly, the current one), mark them as failed 731 history = server_kickstart.terminate_kickstart_sessions(self.getid()) 732 for k, v in history: 733 self.add_history(k, v) 734 735 kickstart_session_id = tokens_obj.get_kickstart_session_id() 736 if kickstart_session_id is None: 737 log_debug(4, "No kickstart_session_id associated with token %s (%s)" 738 % (tokens_obj.get_names(), tokens_obj.tokens)) 739 740 # Nothing to do here 741 return 742 743 # Flush server actions 744 self.flush_actions() 745 746 server_id = self.getid() 747 action_id = server_kickstart.schedule_kickstart_sync(server_id, 748 kickstart_session_id) 749 750 server_kickstart.subscribe_to_tools_channel(server_id, 751 kickstart_session_id) 752 753 server_kickstart.schedule_virt_pkg_install(server_id, 754 kickstart_session_id) 755 756 # Update the next action to the newly inserted one 757 server_kickstart.update_ks_session_table(kickstart_session_id, 758 'registered', action_id, server_id)
759
760 - def flush_actions(self):
761 server_id = self.getid() 762 h = rhnSQL.prepare(""" 763 select action_id 764 from rhnServerAction 765 where server_id = :server_id 766 and status in (0, 1) -- Queued or Picked Up 767 """) 768 h.execute(server_id=server_id) 769 while 1: 770 row = h.fetchone_dict() 771 if not row: 772 break 773 action_id = row['action_id'] 774 rhnAction.update_server_action(server_id=server_id, 775 action_id=action_id, status=3, result_code=-100, 776 result_message="Action canceled: system kickstarted or reregistered") # 4/6/05 wregglej, added the "or reregistered" part.
777
778 - def server_locked(self):
779 """ Returns true is the server is locked (for actions that are blocked) """ 780 server_id = self.getid() 781 h = rhnSQL.prepare(""" 782 select 1 783 from rhnServerLock 784 where server_id = :server_id 785 """) 786 h.execute(server_id=server_id) 787 row = h.fetchone_dict() 788 if row: 789 return 1 790 return 0
791
792 - def register_push_client(self):
793 """ insert or update rhnPushClient for this server_id """ 794 server_id = self.getid() 795 ret = server_lib.update_push_client_registration(server_id) 796 return ret
797
798 - def register_push_client_jid(self, jid):
799 """ update the JID in the corresponing entry from rhnPushClient """ 800 server_id = self.getid() 801 ret = server_lib.update_push_client_jid(server_id, jid) 802 return ret
803