<commit_before>import uuid

from cloudshell.cp.azure.domain.services.virtual_machine_service import VirtualMachineService
from cloudshell.cp.azure.models.deploy_result_model import DeployResult


class DeployAzureVMOperation(object):
    def __init__(self,
                 logger,
                 vm_service):
        """

        :param logger:
        :param VirtualMachineService vm_service:
        :return:
        """

        self.logger = logger
        self.vm_service = vm_service

    def deploy(self, azure_vm_deployment_model, cloud_provider_model, reservation_id):
        """
        :param reservation_id:
        :param cloudshell.cp.azure.models.deploy_azure_vm_resource_model.DeployAzureVMResourceModel azure_vm_deployment_model:
        :param cloudshell.cp.azure.models.azure_cloud_provider_resource_model.AzureCloudProviderResourceModel cloud_provider_model:cloud provider
        :return:
        """

        # inputs from attributes?
        resource_name = self._generate_vm_name(azure_vm_deployment_model)
        group_name = str(reservation_id)
        region = cloud_provider_model.region
        image_publisher = azure_vm_deployment_model.image_publisher
        image_offer = azure_vm_deployment_model.image_offer
        image_sku = azure_vm_deployment_model.image_sku
        image_version = 'latest'

        random_name = 'autogenerated'
        interface_name = random_name
        network_name = random_name
        subnet_name = random_name
        ip_name = random_name
        storage_account_name = random_name
        computer_name = random_name
        admin_username = resource_name
        admin_password = '<PASSWORD>'

        vm_name = resource_name  # will be created in real time?
        storage_name = random_name

        # 1. Crate a resource group
        self.vm_service.create_group(group_name, region)

        # 2. Create a storage account
        self.vm_service.create_storage_account(group_name, region, storage_account_name)

        # 3. Create the network interface
        nic_id = self.vm_service.create_network(group_name, interface_name, ip_name, network_name, region, subnet_name)

        # 4. create Vm
        self.vm_service.create_vm(image_offer, image_publisher, image_sku, image_version, admin_password,
                                  admin_username,
                                  computer_name, group_name, nic_id, region, storage_name, vm_name)

        deployed_app_attributes = {}

        return DeployResult(vm_name=vm_name,
                            vm_uuid=str(uuid.uuid4()),
                            cloud_provider_resource_name=azure_vm_deployment_model.cloud_provider,
                            auto_power_off=True,
                            wait_for_ip=azure_vm_deployment_model.wait_for_ip,
                            auto_delete=True,
                            autoload=azure_vm_deployment_model.autoload,
                            inbound_ports=azure_vm_deployment_model.inbound_ports,
                            outbound_ports=azure_vm_deployment_model.outbound_ports,
                            deployed_app_attributes=deployed_app_attributes,
                            deployed_app_address="10.10.10.10",
                            public_ip="10.10.10.11")

    def _generate_vm_name(self, azure_vm_deployment_model):
        return (azure_vm_deployment_model.app_name.replace(" ", "") + (str(uuid.uuid4())).replace("-", ""))[0:8]
<commit_msg>Changed The calling to the methods to be more strictly.<commit_after>import uuid

from cloudshell.cp.azure.domain.services.virtual_machine_service import VirtualMachineService
from cloudshell.cp.azure.models.deploy_result_model import DeployResult


class DeployAzureVMOperation(object):
    def __init__(self,
                 logger,
                 vm_service):
        """

        :param logger:
        :param VirtualMachineService vm_service:
        :return:
        """

        self.logger = logger
        self.vm_service = vm_service

    def deploy(self, azure_vm_deployment_model, cloud_provider_model, reservation_id):
        """
        :param reservation_id:
        :param cloudshell.cp.azure.models.deploy_azure_vm_resource_model.DeployAzureVMResourceModel azure_vm_deployment_model:
        :param cloudshell.cp.azure.models.azure_cloud_provider_resource_model.AzureCloudProviderResourceModel cloud_provider_model:cloud provider
        :return:
        """
        resource_name = self._generate_vm_name(azure_vm_deployment_model)
        group_name = str(reservation_id)
        random_name = 'autogenerated'
        interface_name = random_name
        network_name = random_name
        subnet_name = random_name
        ip_name = random_name
        storage_account_name = random_name
        computer_name = random_name
        admin_username = resource_name
        storage_name = random_name
        admin_password = '<PASSWORD>'
        vm_name = resource_name

        # 1. Crate a resource group
        self.vm_service.create_group(group_name=group_name, region=cloud_provider_model.region)

        # 2. Create a storage account
        self.vm_service.create_storage_account(group_name=group_name,
                                               region=cloud_provider_model.region,
                                               storage_account_name=storage_account_name)

        # 3. Create the network interface
        nic_id = self.vm_service.create_network(group_name=group_name,
                                                interface_name=interface_name,
                                                ip_name=ip_name,
                                                network_name=network_name,
                                                region=cloud_provider_model.region,
                                                subnet_name=subnet_name)

        # 4. create Vm
        self.vm_service.create_vm(image_offer=azure_vm_deployment_model.image_offer,
                                  image_publisher=azure_vm_deployment_model.image_publisher,
                                  image_sku=azure_vm_deployment_model.image_sku,
                                  image_version='latest',
                                  admin_password=<PASSWORD>,
                                  admin_username=admin_username,
                                  computer_name=computer_name,
                                  group_name=group_name,
                                  nic_id=nic_id,
                                  region=cloud_provider_model.region,
                                  storage_name=storage_name,
                                  vm_name=vm_name)

        deployed_app_attributes = {}

        return DeployResult(vm_name=vm_name,
                            vm_uuid=str(uuid.uuid4()),
                            cloud_provider_resource_name=azure_vm_deployment_model.cloud_provider,
                            auto_power_off=True,
                            wait_for_ip=azure_vm_deployment_model.wait_for_ip,
                            auto_delete=True,
                            autoload=azure_vm_deployment_model.autoload,
                            inbound_ports=azure_vm_deployment_model.inbound_ports,
                            outbound_ports=azure_vm_deployment_model.outbound_ports,
                            deployed_app_attributes=deployed_app_attributes,
                            deployed_app_address="10.10.10.10",
                            public_ip="10.10.10.11")

    def _generate_vm_name(self, azure_vm_deployment_model):
        return (azure_vm_deployment_model.app_name.replace(" ", "") + (str(uuid.uuid4())).replace("-", ""))[0:8]

{'fraction_non_alphanumeric': 0.0628245067497404, 'fraction_numerical': 0.006230529595015576, 'mean_word_length': 1.9385964912280702, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 27, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4630320', 'n_tokens_mistral': 2071, 'n_tokens_neox': 2006, 'n_words': 288}