Exemplo n.º 1
0
    def get_vm_details(self, context, cancellation_context, requests_json):
        """# noqa
        Get vm details for specific deployed app
        :type context: ResourceCommandContext
        :rtype str
        """
        results = []
        vm_details_requests = [
            VmDetailsRequest(item) for item in DeployDataHolder(
                jsonpickle.decode(requests_json)).items
        ]

        for request in vm_details_requests:
            if cancellation_context.is_cancelled:
                break

            try:
                with AwsShellContext(context=context,
                                     aws_session_manager=self.
                                     aws_session_manager) as shell_context:
                    shell_context.logger.info("Get VmDetails")
                    vm_details = self.vm_details_operation.get_vm_details(
                        request.uuid, shell_context.aws_api.ec2_session)
                    vm_details.appName = request.app_name
                    results.append(vm_details)
            except Exception as e:
                result = VmDetailsData()
                result.appName = request.app_name
                result.error = str(e)
                results.append(result)

        return self.command_result_parser.set_command_result(results)
Exemplo n.º 2
0
 def convert_to_deployment_resource_model(deployment_request):
     data = jsonpickle.decode(deployment_request)
     data_holder = DeployDataHolder(data)
     deployment_resource_model = DeployAWSEc2AMIInstanceResourceModel()
     deployment_resource_model.aws_ec2 = data_holder.ami_params.aws_ec2
     deployment_resource_model.aws_ami_id = data_holder.ami_params.aws_ami_id
     deployment_resource_model.storage_size = data_holder.ami_params.storage_size
     deployment_resource_model.storage_iops = data_holder.ami_params.storage_iops
     deployment_resource_model.storage_type = data_holder.ami_params.storage_type
     deployment_resource_model.min_count = int(
         data_holder.ami_params.min_count)
     deployment_resource_model.max_count = int(
         data_holder.ami_params.max_count)
     deployment_resource_model.instance_type = data_holder.ami_params.instance_type
     deployment_resource_model.aws_key = data_holder.ami_params.aws_key
     deployment_resource_model.security_group_ids = data_holder.ami_params.security_group_ids
     deployment_resource_model.private_ip_address = data_holder.ami_params.private_ip_address
     deployment_resource_model.device_name = data_holder.ami_params.device_name
     deployment_resource_model.delete_on_termination = bool(
         data_holder.ami_params.delete_on_termination)
     deployment_resource_model.auto_power_on = bool(
         data_holder.ami_params.auto_power_on)
     deployment_resource_model.auto_power_off = bool(
         data_holder.ami_params.auto_power_off)
     deployment_resource_model.wait_for_ip = bool(
         data_holder.ami_params.wait_for_ip)
     deployment_resource_model.auto_delete = bool(
         data_holder.ami_params.auto_delete)
     deployment_resource_model.autoload = bool(
         data_holder.ami_params.autoload)
     deployment_resource_model.inbound_ports = data_holder.ami_params.inbound_ports
     deployment_resource_model.outbound_ports = data_holder.ami_params.outbound_ports
     return deployment_resource_model, data_holder.app_name
    def test_format_single_outbound(self):
        json_str = '{"vmCustomParams":[{"name": "outbound_ports", "value": "80"}]}'
        dict = jsonpickle.decode(json_str)
        vmdetails = DeployDataHolder(dict)

        result = self.operation.get_formated_deployed_app_ports(
            vmdetails.vmCustomParams)

        self.assertEqual(result, 'Outbound ports:\nPort 80 tcp')
    def test_extracor(self):
        json_str = '{"vmCustomParams":[{"name": "param", "value": "some_value"}]}'
        dict = jsonpickle.decode(json_str)
        vmdetails = DeployDataHolder(dict)

        extracotr = VmCustomParamsExtractor()
        param_value = extracotr.get_custom_param_value(
            vmdetails.vmCustomParams, "param")

        self.assertEqual(param_value, "some_value")
    def test_format_complex_outbound(self):
        json_str = '{"vmCustomParams":[{"name": "Outbound_ports", "value": "80; 1200-2300:udp; 26:tcp"}]}'
        dict = jsonpickle.decode(json_str)
        vmdetails = DeployDataHolder(dict)

        result = self.operation.get_formated_deployed_app_ports(
            vmdetails.vmCustomParams)

        self.assertEqual(
            result,
            'Outbound ports:\nPort 80 tcp\nPorts 1200-2300 udp\nPort 26 tcp')
    def test_no_inbound_or_outbound_ports(self):
        json_str = '{"vmCustomParams":[]}'
        dict = jsonpickle.decode(json_str)
        vmdetails = DeployDataHolder(dict)

        result = self.operation.get_formated_deployed_app_ports(
            vmdetails.vmCustomParams)

        self.assertEquals(
            result,
            "No ports are open for inbound and outbound traffic outside of the Sandbox"
        )
Exemplo n.º 7
0
    def test_power_on(self):
        deployed_model = DeployDataHolder({'vmdetails': {'uid': 'id'}})
        remote_resource = Mock()
        remote_resource.fullname = 'my ami name'
        self.command_context.remote_endpoints = [remote_resource]
        self.aws_shell_api.model_parser.convert_app_resource_to_deployed_app = Mock(
            return_value=deployed_model)
        self.aws_shell_api.power_management_operation.power_on = Mock(
            return_value=True)
        self.aws_shell_api.power_on_ami(self.command_context)

        self.assertTrue(
            self.aws_shell_api.power_management_operation.power_on.called_with(
                self.aws_shell_api.aws_session_manager.get_ec2_session(),
                'id'))
    def test_power_off(self):
        deployed_model = DeployDataHolder({'vmdetails': {'uid': 'id'}})
        remote_resource = Mock()
        remote_resource.fullname = 'my ami name'
        self.command_context.remote_endpoints = [remote_resource]
        self.aws_shell.model_parser.convert_app_resource_to_deployed_app = Mock(return_value=deployed_model)
        self.aws_shell.power_management_operation.power_off = Mock(return_value=True)

        with patch('cloudshell.cp.aws.aws_shell.AwsShellContext') as shell_context:
            shell_context.return_value = self.mock_context

            # act
            self.aws_shell.power_off_ami(self.command_context)

        self.aws_shell.power_management_operation.power_off.assert_called_with(
                ec2_session=self.expected_shell_context.aws_api.ec2_session,
                ami_id=deployed_model.vmdetails.uid)
Exemplo n.º 9
0
    def test_delete_instance(self):
        deployed_model = DeployDataHolder({"vmdetails": {"uid": "id"}})
        remote_resource = Mock()
        remote_resource.fullname = "my ami name"
        self.command_context.remote_endpoints = [remote_resource]
        self.aws_shell.model_parser.convert_app_resource_to_deployed_app = Mock(
            return_value=deployed_model
        )
        self.aws_shell.delete_ami_operation.delete_instance = Mock(return_value=True)

        with patch("cloudshell.cp.aws.aws_shell.AwsShellContext") as shell_context:
            shell_context.return_value = self.mock_context

            # act
            self.aws_shell.delete_instance(self.command_context)

        self.aws_shell.delete_ami_operation.delete_instance.assert_called_with(
            logger=self.expected_shell_context.logger,
            ec2_session=self.expected_shell_context.aws_api.ec2_session,
            instance_id=deployed_model.vmdetails.uid,
        )
Exemplo n.º 10
0
 def _get_deployment_info(self, image_model, name):
     """
     :type image_model: vCenterVMFromImageResourceModel
     """
     return DeployDataHolder({'app_name': name, 'ami_params': image_model})
 def get_app_security_groups_from_request(request):
     json_str = jsonpickle.decode(request)
     data_holder = DeployDataHolder.create_obj_by_type(json_str)
     return data_holder
 def convert_app_resource_to_deployed_app(resource):
     json_str = jsonpickle.decode(resource.app_context.deployed_app_json)
     data_holder = DeployDataHolder(json_str)
     return data_holder
Exemplo n.º 13
0
 def get_app_security_groups_from_request(request):
     json_str = jsonpickle.decode(request)
     data_holder = DeployDataHolder.create_obj_by_type(json_str)
     return data_holder