<commit_before># vim: tabstop=4 shiftwidth=4 softtabstop=4

# Copyright (c) 2011 University of Southern California
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.
#
"""
A connection to a hypervisor through baremetal.

**Related Flags**

:baremetal_type:  Baremetal domain type.
:baremetal_uri:  Override for the default baremetal URI (baremetal_type).
:rescue_image_id:  Rescue ami image (default: ami-rescue).
:rescue_kernel_id:  Rescue aki image (default: aki-rescue).
:rescue_ramdisk_id:  Rescue ari image (default: ari-rescue).
:injected_network_template:  Template file for injected network
:allow_project_net_traffic:  Whether to allow in project network traffic

"""

import hashlib
import os
import shutil

from nova.compute import instance_types
from nova.compute import power_state
from nova.compute import vm_states
from nova import context as nova_context
from nova import db
from nova import exception
from nova import flags
from nova import notifications
from nova.openstack.common import cfg
from nova.openstack.common import log as logging
from nova import utils
from nova.virt.baremetal import dom
from nova.virt.baremetal import nodes
from nova.virt.disk import api as disk
from nova.virt import driver
from nova.virt.libvirt import utils as libvirt_utils


Template = None

LOG = logging.getLogger(__name__)

FLAGS = flags.FLAGS

baremetal_opts = [
    cfg.StrOpt('baremetal_type',
                default='baremetal',
                help='baremetal domain type'),
    ]

FLAGS.register_opts(baremetal_opts)


def _late_load_cheetah():
    global Template
    if Template is None:
        t = __import__('Cheetah.Template', globals(), locals(),
                       ['Template'], -1)
        Template = t.Template


class BareMetalDriver(driver.ComputeDriver):

    def __init__(self, read_only):
        _late_load_cheetah()
        # Note that baremetal doesn't have a read-only connection
        # mode, so the read_only parameter is ignored
        super(BareMetalDriver, self).__init__()
        self.baremetal_nodes = nodes.get_baremetal_nodes()
        self._wrapped_conn = None
        self._host_state = None

    @property
    def HostState(self):
        if not self._host_state:
            self._host_state = HostState(self)
        return self._host_state

    def init_host(self, host):
        pass

    def _get_connection(self):
        self._wrapped_conn = dom.BareMetalDom()
        return self._wrapped_conn
    _conn = property(_get_connection)

    def get_pty_for_instance(self, instance_name):
        raise NotImplementedError()

    def list_instances(self):
        return self._conn.list_domains()

    def _map_to_instance_info(self, domain_name):
        """Gets info from a virsh domain object into an InstanceInfo"""
        _domain_info = self._conn.get_domain_info(domain_name)
        state, _max_mem, _mem, _num_cpu, _cpu_time = _domain_info
        name = domain_name
        return driver.InstanceInfo(name, state)

    def list_instances_detail(self):
        infos = []
        for domain_name in self._conn.list_domains():
            info = self._map_to_instance_info(domain_name)
            infos.append(info)
        return infos

    def destroy(self, instance, network_info, block_device_info=None,
                cleanup=True):
        while True:
            try:
                self._conn.destroy_domain(instance['name'])
                break
            except Exception as ex:
                LOG.debug(_("Error encountered when destroying instance "
                            "'%(name)s': %(ex)s") %
                          {"name": instance["name"], "ex": ex},
                          instance=instance)
                break
<commit_msg>Remove list_instances_detail from compute drivers.<commit_after># vim: tabstop=4 shiftwidth=4 softtabstop=4

# Copyright (c) 2011 University of Southern California
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.
#
"""
A connection to a hypervisor through baremetal.

**Related Flags**

:baremetal_type:  Baremetal domain type.
:baremetal_uri:  Override for the default baremetal URI (baremetal_type).
:rescue_image_id:  Rescue ami image (default: ami-rescue).
:rescue_kernel_id:  Rescue aki image (default: aki-rescue).
:rescue_ramdisk_id:  Rescue ari image (default: ari-rescue).
:injected_network_template:  Template file for injected network
:allow_project_net_traffic:  Whether to allow in project network traffic

"""

import hashlib
import os
import shutil

from nova.compute import instance_types
from nova.compute import power_state
from nova.compute import vm_states
from nova import context as nova_context
from nova import db
from nova import exception
from nova import flags
from nova import notifications
from nova.openstack.common import cfg
from nova.openstack.common import log as logging
from nova import utils
from nova.virt.baremetal import dom
from nova.virt.baremetal import nodes
from nova.virt.disk import api as disk
from nova.virt import driver
from nova.virt.libvirt import utils as libvirt_utils


Template = None

LOG = logging.getLogger(__name__)

FLAGS = flags.FLAGS

baremetal_opts = [
    cfg.StrOpt('baremetal_type',
                default='baremetal',
                help='baremetal domain type'),
    ]

FLAGS.register_opts(baremetal_opts)


def _late_load_cheetah():
    global Template
    if Template is None:
        t = __import__('Cheetah.Template', globals(), locals(),
                       ['Template'], -1)
        Template = t.Template


class BareMetalDriver(driver.ComputeDriver):

    def __init__(self, read_only):
        _late_load_cheetah()
        # Note that baremetal doesn't have a read-only connection
        # mode, so the read_only parameter is ignored
        super(BareMetalDriver, self).__init__()
        self.baremetal_nodes = nodes.get_baremetal_nodes()
        self._wrapped_conn = None
        self._host_state = None

    @property
    def HostState(self):
        if not self._host_state:
            self._host_state = HostState(self)
        return self._host_state

    def init_host(self, host):
        pass

    def _get_connection(self):
        self._wrapped_conn = dom.BareMetalDom()
        return self._wrapped_conn
    _conn = property(_get_connection)

    def get_pty_for_instance(self, instance_name):
        raise NotImplementedError()

    def list_instances(self):
        return self._conn.list_domains()

    def _map_to_instance_info(self, domain_name):
        """Gets info from a virsh domain object into an InstanceInfo"""
        _domain_info = self._conn.get_domain_info(domain_name)
        state, _max_mem, _mem, _num_cpu, _cpu_time = _domain_info
        name = domain_name
        return driver.InstanceInfo(name, state)

    def destroy(self, instance, network_info, block_device_info=None,
                cleanup=True):
        while True:
            try:
                self._conn.destroy_domain(instance['name'])
                break
            except Exception as ex:
                LOG.debug(_("Error encountered when destroying instance "
                            "'%(name)s': %(ex)s") %
                          {"name": instance["name"], "ex": ex},
                          instance=instance)
                break

{'fraction_non_alphanumeric': 0.07659011662859204, 'fraction_numerical': 0.00288565588553565, 'mean_word_length': 2.957183634633682, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6619872', 'n_tokens_mistral': 2453, 'n_tokens_neox': 2342, 'n_words': 744}