Exemple #1
0
    def create(self):
        if self._exists():
            return

        ci_client = _get_ci_client(self.config)
        ci = AciContainer(self.logger, self.config)
        container = ci.create()

        group = ContainerGroup(
            location=self.config.resource_group_loation,
            containers=[container],
            os_type=OperatingSystemTypes.linux,
            restart_policy=ContainerGroupRestartPolicy.never,
            identity=ContainerGroupIdentity(
                type=ResourceIdentityType.system_assigned))

        try:
            result = ci_client.container_groups.create_or_update(
                self.config.resource_group_name,
                self.config.container_group_name, group)

            _poll_for_complete(result)
        except CloudError as ce:
            if ce.inner_exception.error == "InaccessibleImage":
                self.logger.logger.warning("Did you forget to push the image?")

        self.logger.container_group_created()
Exemple #2
0
    def execute_command(self, command):
        ci_client = _get_ci_client(self.config)
        res: ContainerExecResponse = ci_client.container.execute_command(
            resource_group_name=self.config.resource_group_name,
            container_group_name=self.config.container_group_name,
            container_name=self.config.container_group_name,
            command=command,
            terminal_size=ContainerExecRequestTerminalSize(rows=600, cols=800))

        _start_exec_pipe(res.web_socket_uri, res.password)
Exemple #3
0
    def stop(self):
        if not self._exists():
            return

        ci_client = _get_ci_client(self.config)

        try:
            ci_client.container_groups.stop(self.config.resource_group_name,
                                            self.config.container_group_name)
        except CloudError:
            pass
Exemple #4
0
    def start(self):
        if not self._exists():
            return

        ci_client = _get_ci_client(self.config)

        try:
            result = ci_client.container_groups.start(
                self.config.resource_group_name,
                self.config.container_group_name)

            _poll_for_complete(result)
        except CloudError:
            pass
Exemple #5
0
    def delete(self):
        if not self._exists():
            return

        ci_client = _get_ci_client(self.config)

        try:
            ci_client.container_groups.delete(self.config.resource_group_name,
                                              self.config.container_group_name)
        except CloudError as ce:
            self.logger.logger.warning(
                f'Delete Container Group Error: {ce.message}')

        self.logger.container_group_deleted()
Exemple #6
0
    def _exists(self) -> bool:
        ci_client = _get_ci_client(self.config)

        try:
            c = ci_client.container_groups.get(
                self.config.resource_group_name,
                self.config.container_group_name)

            if c.containers[0].image != self.config.container_image:
                return False

            self.logger.container_group_exist()
            return True
        except CloudError as ce:
            if ce.inner_exception.error == "ResourceGroupNotFound":
                self.logger.logger.warning(
                    "You need to create a resource group")
            if ce.inner_exception.error == "ResourceNotFound":
                self.logger.container_group_not_exist()
                return False