Ejemplo n.º 1
0
    def get_boot_device(self):
        service_profile = get_mo_by_dn(self.__handle,
                                       self.__service_profile_dn)

        operation = "get_boot_device"
        if not service_profile:
            raise exception.UcsOperationError(operation=operation,
                                              error="Invalid Service Profile")

        if not service_profile.BootPolicyName:
            boot_dn = UcsUtils.MakeDn(
                [self.__service_profile_dn, "boot-policy"])
            class_id = "LsbootDef"
        else:
            boot_dn = UcsUtils.MakeDn([
                self.__org_dn,
                "boot-policy-%s" % service_profile.BootPolicyName
            ])
            class_id = "LsbootPolicy"

        operation = "get_boot_device"
        try:
            boot_device = None
            boot_devices = get_children_by_dn(self.__handle, boot_dn)
            if boot_devices:
                for boot_device_mo in boot_devices:
                    if int(boot_device_mo.Order) == 1:
                        boot_device = boot_device_rn[boot_device_mo.Rn]
                        break
            return {'boot_device': boot_device, 'persistent': None}
        except UcsException as ex:
            print "Cisco client exception: %ss." % (ex)
            raise exception.UcsOperationError(operation=operation, error=ex)
Ejemplo n.º 2
0
    def get_boot_device(self):
        """Get the current boot device for the node.

            Provides the current boot device of the node. Be aware that not
            all drivers support this.

            :raises: InvalidParameterValue if any connection parameters are
                incorrect.
            :raises: MissingParameterValue if a required parameter is missing
            :returns: a dictionary containing:

            :boot_device: the boot device, one of
            :mod:`ironic.common.boot_devices` or None if it is unknown.
            :persistent: Whether the boot device will persist to all
                future boots or not, None if it is unknown.
            """
        operation = 'get_boot_device'
        try:
            boot_device = None
            boot_devices = get_children_by_dn(self.__handle,
                                              self.__boot_policy_dn)
            if boot_devices:
                for boot_device_mo in boot_devices:
                    if boot_device_mo.Order == 1:
                        boot_device = boot_device_rn[boot_device_mo.Rn]
                        break

            return {'boot_device': boot_device, 'persistent': None}
        except UcsException as ex:
            print "Cisco client exception: %ss." % (ex)
            raise exception.UcsOperationError(operation=operation, error=ex)
Ejemplo n.º 3
0
 def create(self):
     operation = "create_boot_policy"
     try:
         self.__boot_policy_obj = add_mo_by_dn_overwrite(
             self.__handle, LsbootPolicy.ClassId(), self.__boot_policy_dn,
             **self.__boot_policy_cfg)
     except UcsException as ex:
         raise exception.UcsOperationError(operation=operation, error=ex)
Ejemplo n.º 4
0
 def detach_boot_policy(self):
     service_profile = get_mo_by_dn(self.__handle, self.__service_profile_dn)
     operation = ""
     if not service_profile:
         raise exception.UcsOperationError(operation=operation,
                                           error="Invalid Service Profile")
     service_profile = modify_mo(self.__handle, [service_profile],
                                 BootPolicyName="")
Ejemplo n.º 5
0
    def set_boot_device(self, device, persistent=False):
        """Set the boot device for the node.

            Set the boot device to use on next reboot of the node.
            :param device: the boot device, one of
            :mod:`ironic.common.boot_devices`.
            :param persistent: Boolean value. True if the boot device will
                persist to all future boots, False if not.
                Default: False. Ignored by this driver.
            :raises: UcsOperationError if it UCS Manager reports any error.
            """

        operation = "set_boot_device"
        try:
            self.sp_manager.create_boot_policy()
            self.sp_manager.set_boot_device(device)

        except UcsException as ex:
            raise exception.UcsOperationError(operation=operation, error=ex)
Ejemplo n.º 6
0
    def __config_boot_device(self, parent_dn, boot_device_meta, order):
        child_class_id = boot_device_meta.class_id
        child_dn = UcsUtils.MakeDn([parent_dn, boot_device_meta.rn])
        child_config = boot_device_meta.config
        if child_config.has_key("Order"):
            child_config["Order"] = order

        operation = "create %s" % (child_dn)
        try:
            device_obj = add_mo_by_dn_overwrite(self.__handle, child_class_id,
                                                child_dn, **child_config)
        except UcsException as ex:
            raise exception.UcsOperationError(operation=operation, error=ex)

        if boot_device_meta.child:
            child_device_name = boot_device_meta.child[0]
            child_device_meta = BootDeviceMeta(
                *boot_device_meta_dict[child_device_name])
            self.__config_boot_device(device_obj.Dn, child_device_meta, order)
Ejemplo n.º 7
0
    def get_boot_device(self):
        """Get the current boot device for the node.

            Provides the current boot device of the node. Be aware that not
            all drivers support this.

            :raises: InvalidParameterValue if any connection parameters are
                incorrect.
            :raises: MissingParameterValue if a required parameter is missing
            :returns: a dictionary containing:

            :boot_device: the boot device, one of
            :mod:`ironic.common.boot_devices` or None if it is unknown.
            :persistent: Whether the boot device will persist to all
                future boots or not, None if it is unknown.
            """
        operation = 'get_boot_device'
        try:
            boot_device = self.sp_manager.get_boot_device()
            return boot_device
        except UcsException as ex:
            print(_("Cisco client exception: %(msg)s."), {'msg': ex})
            raise exception.UcsOperationError(operation=operation, error=ex)
Ejemplo n.º 8
0
    def add_boot_device(self, boot_device_name, order=None):
        operation = "add_boot_device"
        boot_device_meta = BootDeviceMeta(
            *boot_device_meta_dict[boot_device_name])
        boot_device_dn = UcsUtils.MakeDn(
            [self.__boot_policy_dn, boot_device_meta.rn])

        try:
            boot_policy = get_mo_by_dn(self.__handle, self.__boot_policy_dn)
            if not boot_policy:
                raise exception.UcsOperationError(
                    operation=operation,
                    error="Unknown BootPolicy %s" % (self.__boot_policy_dn))
            existing_boot_devices = get_children_by_dn(self.__handle,
                                                       self.__boot_policy_dn)
            if existing_boot_devices:
                boot_order_dict = {}
                boot_device_present = False
                boot_device_order = None
                for existing_boot_device in existing_boot_devices:
                    boot_order_dict[int(
                        existing_boot_device.Order)] = existing_boot_device
                    if boot_device_dn == existing_boot_device.Dn:
                        boot_device_present = True
                        boot_device_order = int(existing_boot_device.Order)
                        if order and boot_device_order != order:
                            continue
                        return

                max_boot_order = max(boot_order_dict)

                if boot_device_present:
                    my_boot_device = boot_order_dict[boot_device_order]
                    other_boot_device = boot_order_dict[order]
                    self.__handle.StartTransaction()
                    self.__modify_boot_device(my_boot_device, order)
                    self.__modify_boot_device(other_boot_device,
                                              boot_device_order)

                    #                     modify_mo(self.__handle, input_mo=my_boot_device,
                    #                                                             Order=order)
                    #                     modify_mo(self.__handle, input_mo=other_boot_device,
                    #                                                 Order=boot_device_order)
                    self.__handle.CompleteTransaction()
                else:
                    if not order:
                        self.__config_boot_device(self.__boot_policy_dn,
                                                  boot_device_meta,
                                                  max_boot_order + 1)
                    elif order and order in boot_order_dict:
                        other_boot_device = boot_order_dict[order]
                        self.__handle.StartTransaction()
                        self.__config_boot_device(self.__boot_policy_dn,
                                                  boot_device_meta, order)
                        self.__modify_boot_device(other_boot_device,
                                                  max_boot_order + 1)

                        #                         modify_mo(self.__handle, input_mo=other_boot_device,
                        #                                                 Order=max_boot_order + 1)
                        self.__handle.CompleteTransaction()
                    else:
                        self.__config_boot_device(self.__boot_policy_dn,
                                                  boot_device_meta, order)
            else:
                if not order:
                    self.__config_boot_device(self.__boot_policy_dn,
                                              boot_device_meta, 1)
                else:
                    self.__config_boot_device(self.__boot_policy_dn,
                                              boot_device_meta, order)

        except UcsException as ex:
            raise exception.UcsOperationError(operation=operation, error=ex)