Пример #1
0
    def deploy_from_linked_clone(self, context, deploy_data):
        """
        Deploy Cloned VM From VM Command, will deploy vm from template

        :param models.QualiDriverModels.ResourceCommandContext context: the context of the command
        :param str deploy_data: represent a json of the parameters, example: {"template_resource_model": {"vm_location": "", "vcenter_name": "VMware vCenter", "refresh_ip_timeout": "600", "auto_delete": "True", "vm_storage": "", "auto_power_on": "True", "autoload": "True", "ip_regex": "", "auto_power_off": "True", "vcenter_template": "Alex\\test", "vm_cluster": "", "vm_resource_pool": "", "wait_for_ip": "True"}, "app_name": "Temp"}
        :return str deploy results
        """

        # get command parameters from the environment
        data = jsonpickle.decode(deploy_data)
        data_holder = DeployDataHolder(data)

        if not data_holder.template_resource_model.vcenter_vm:
            raise ValueError('Please insert vm to deploy from')

        data_holder.template_resource_model.vcenter_vm = \
            back_slash_to_front_converter(data_holder.template_resource_model.vcenter_vm)

        if not data_holder.template_resource_model.vcenter_vm_snapshot:
            raise ValueError('Please insert snapshot to deploy from')

        data_holder.template_resource_model.vcenter_vm_snapshot = \
            back_slash_to_front_converter(data_holder.template_resource_model.vcenter_vm_snapshot)

        # execute command
        result = self.command_wrapper.execute_command_with_connection(
            context, self.deploy_command.execute_deploy_from_linked_clone,
            data_holder)

        return set_command_result(result=result, unpicklable=False)
Пример #2
0
    def convert_to_resource_model(self, attributes, resource_model_type):
        """
        Converts an instance of resource with dictionary of attributes
        to a class instance according to family and assigns its properties
        :type attributes: dict
        :param resource_model_type: Resource Model type to create
        :return:
        """
        if resource_model_type:
            if not callable(resource_model_type):
                raise ValueError(
                    'resource_model_type {0} cannot be instantiated'.format(
                        resource_model_type))
            instance = resource_model_type()
        else:
            raise ValueError('resource_model_type must have a value')

        props = ResourceModelParser.get_public_properties(instance)
        for attrib in attributes:
            property_name = ResourceModelParser.get_property_name_from_attribute_name(
                attrib)
            property_name_for_attribute_name = ResourceModelParser.get_property_name_with_attribute_name_postfix(
                attrib)
            if props.__contains__(property_name):
                value = attributes[attrib]
                setattr(instance, property_name, value)
                if hasattr(instance, property_name_for_attribute_name):
                    setattr(instance, property_name_for_attribute_name, attrib)
                    props.remove(property_name_for_attribute_name)
                props.remove(property_name)

        if props:
            raise ValueError(
                'Property(ies) {0} not found on resource with attributes {1}'.
                format(','.join(props), ','.join(attributes)))

        if hasattr(instance, 'vcenter_vm'):
            instance.vcenter_vm = back_slash_to_front_converter(
                instance.vcenter_vm)

        if hasattr(instance, 'vcenter_vm_snapshot'):
            instance.vcenter_vm_snapshot = back_slash_to_front_converter(
                instance.vcenter_vm_snapshot)

        return instance
Пример #3
0
    def _make_attributes_slash_backslash_agnostic(
            attributes_with_slash_or_backslash):
        """
        :param attributes_with_slash_or_backslash: resource attributes from
               cloudshell.cp.vcenter.models.QualiDriverModels.ResourceContextDetails
        :type attributes_with_slash_or_backslash: dict[str,str]
        :return: attributes_with_slash
        :rtype attributes_with_slash: dict[str,str]
        """
        attributes_with_slash = dict()
        for key, value in attributes_with_slash_or_backslash.items():
            if key in ATTRIBUTE_NAMES_THAT_ARE_SLASH_BACKSLASH_AGNOSTIC:
                value = back_slash_to_front_converter(value)
            attributes_with_slash[key] = value

        return attributes_with_slash
Пример #4
0
    def convert_to_vcenter_model(self, resource):
        vcenter_data_model = self.convert_to_resource_model(
            resource_instance=resource,
            resource_model_type=VMwarevCenterResourceModel)

        vcenter_data_model.default_dvswitch = back_slash_to_front_converter(vcenter_data_model.default_dvswitch)
        vcenter_data_model.default_datacenter = back_slash_to_front_converter(vcenter_data_model.default_datacenter)
        vcenter_data_model.reserved_networks = back_slash_to_front_converter(vcenter_data_model.reserved_networks)
        vcenter_data_model.vm_location = back_slash_to_front_converter(vcenter_data_model.vm_location)
        vcenter_data_model.vm_storage = back_slash_to_front_converter(vcenter_data_model.vm_storage)
        vcenter_data_model.vm_resource_pool = back_slash_to_front_converter(vcenter_data_model.vm_resource_pool)
        vcenter_data_model.vm_cluster = back_slash_to_front_converter(vcenter_data_model.vm_cluster)

        return vcenter_data_model
Пример #5
0
    def convert_to_vcenter_model(self, resource):
        vcenter_data_model = self.convert_to_resource_model(
            resource_instance=resource,
            resource_model_type=VMwarevCenterResourceModel)

        vcenter_data_model.default_dvswitch = back_slash_to_front_converter(
            vcenter_data_model.default_dvswitch)
        vcenter_data_model.default_datacenter = back_slash_to_front_converter(
            vcenter_data_model.default_datacenter)
        vcenter_data_model.reserved_networks = back_slash_to_front_converter(
            vcenter_data_model.reserved_networks)
        vcenter_data_model.vm_location = back_slash_to_front_converter(
            vcenter_data_model.vm_location)
        vcenter_data_model.vm_storage = back_slash_to_front_converter(
            vcenter_data_model.vm_storage)
        vcenter_data_model.vm_resource_pool = back_slash_to_front_converter(
            vcenter_data_model.vm_resource_pool)
        vcenter_data_model.vm_cluster = back_slash_to_front_converter(
            vcenter_data_model.vm_cluster)

        return vcenter_data_model
Пример #6
0
    def convert_to_vcenter_model(self, resource):
        vcenter_data_model = self.convert_to_resource_model(
            attributes=ResourceModelParser.get_resource_attributes_as_dict(
                resource),
            resource_model_type=VMwarevCenterResourceModel)

        vcenter_data_model.default_dvswitch = back_slash_to_front_converter(
            vcenter_data_model.default_dvswitch)
        vcenter_data_model.default_datacenter = back_slash_to_front_converter(
            vcenter_data_model.default_datacenter)
        vcenter_data_model.reserved_networks = back_slash_to_front_converter(
            vcenter_data_model.reserved_networks)
        vcenter_data_model.vm_location = back_slash_to_front_converter(
            vcenter_data_model.vm_location)
        vcenter_data_model.vm_storage = back_slash_to_front_converter(
            vcenter_data_model.vm_storage)
        vcenter_data_model.vm_resource_pool = back_slash_to_front_converter(
            vcenter_data_model.vm_resource_pool)
        vcenter_data_model.vm_cluster = back_slash_to_front_converter(
            vcenter_data_model.vm_cluster)

        return vcenter_data_model