~lamont/maas/bug-1599223-2.0

« back to all changes in this revision

Viewing changes to src/maasserver/models/node.py

  • Committer: LaMont Jones
  • Date: 2016-05-12 19:07:37 UTC
  • mfrom: (5017 maas)
  • mto: This revision was merged to the branch mainline in revision 5021.
  • Revision ID: lamont@canonical.com-20160512190737-00g34satnuo0tk8v
mergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
162
162
from provisioningserver.power import QUERY_POWER_TYPES
163
163
from provisioningserver.rpc.cluster import (
164
164
    AddChassis,
 
165
    DisableAndShutoffRackd,
165
166
    IsImportBootImagesRunning,
166
167
    RefreshRackControllerInfo,
167
168
)
2423
2424
            # No interfaces on the node. Nothing to do.
2424
2425
            return
2425
2426
 
 
2427
        assert \
 
2428
            self.status not in [NODE_STATUS.DEPLOYING, NODE_STATUS.DEPLOYED], \
 
2429
            'Node cannot be in a deploying state when configuring network'
 
2430
 
2426
2431
        # Set AUTO mode on the boot interface.
2427
2432
        auto_set = False
2428
2433
        discovered_addresses = boot_interface.ip_addresses.filter(
3582
3587
        self._register_request_event(
3583
3588
            self.owner, EVENT_TYPES.REQUEST_RACK_CONTROLLER_REFRESH,
3584
3589
            action='starting refresh')
3585
 
        self.status = NODE_STATUS.COMMISSIONING
3586
 
        self.save()
3587
3590
 
3588
3591
        client = getClientFor(self.system_id, timeout=1)
3589
3592
        token = NodeKey.objects.get_token_for_node(self)
3642
3645
 
3643
3646
    def delete(self):
3644
3647
        """Delete this rack controller."""
3645
 
        # Avoid circular dependency.
3646
 
        from maasserver.models import RegionRackRPCConnection
3647
 
        connections = RegionRackRPCConnection.objects.filter(
3648
 
            rack_controller=self)
3649
 
 
3650
 
        if len(connections) != 0:
 
3648
        primary_vlans = VLAN.objects.filter(primary_rack=self)
 
3649
        if len(primary_vlans) != 0:
3651
3650
            raise ValidationError(
3652
 
                "Unable to delete %s as it's currently connected to one or "
3653
 
                "more regions." % self.hostname)
 
3651
                "Unable to delete '%s'; it is currently set as a primary rack"
 
3652
                " controller on VLANs %s" %
 
3653
                (self.hostname,
 
3654
                    ', '.join([str(vlan) for vlan in primary_vlans])))
 
3655
 
 
3656
        try:
 
3657
            client = getClientFor(self.system_id, timeout=1)
 
3658
            call = client(DisableAndShutoffRackd)
 
3659
            call.wait(30)
 
3660
        except NoConnectionsAvailable:
 
3661
            # NoConnectionsAvailable is always thrown. Either because the rack
 
3662
            # is currently disconnected or rackd was killed
 
3663
            pass
 
3664
 
 
3665
        for vlan in VLAN.objects.filter(secondary_rack=self):
 
3666
            vlan.secondary_rack = None
 
3667
            vlan.save()
 
3668
 
3654
3669
        if self.node_type == NODE_TYPE.REGION_AND_RACK_CONTROLLER:
3655
3670
            self.node_type = NODE_TYPE.REGION_CONTROLLER
3656
3671
            self.save()