当前位置: 首页>>代码示例>>Python>>正文


Python misc.sh函数代码示例

本文整理汇总了Python中teuthology.misc.sh函数的典型用法代码示例。如果您正苦于以下问题:Python sh函数的具体用法?Python sh怎么用?Python sh使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了sh函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_ip_neutron

 def get_ip_neutron(instance_id):
     subnets = json.loads(misc.sh("neutron subnet-list -f json -c id -c ip_version"))
     subnet_id = None
     for subnet in subnets:
         if subnet['ip_version'] == 4:
             subnet_id = subnet['id']
             break
     if not subnet_id:
         raise Exception("no subnet with ip_version == 4")
     ports = json.loads(misc.sh("neutron port-list -f json -c fixed_ips -c device_id"))
     fixed_ips = None
     for port in ports:
         if port['device_id'] == instance_id:
             fixed_ips = port['fixed_ips'].split("\n")
             break
     if not fixed_ips:
         raise Exception("no fixed ip record found")
     ip = None
     for fixed_ip in fixed_ips:
         record = json.loads(fixed_ip)
         if record['subnet_id'] == subnet_id:
             ip = record['ip_address']
             break
     if not ip:
         raise Exception("no ip")
     return ip
开发者ID:esnyder,项目名称:teuthology,代码行数:26,代码来源:__init__.py

示例2: push_directory

def push_directory(path, remote, remote_dir):
    """
    local_temp_path=`mktemp`
    tar czf $local_temp_path $path
    ssh remote mkdir -p remote_dir
    remote_temp_path=`mktemp`
    scp $local_temp_path $remote_temp_path
    rm $local_temp_path
    tar xzf $remote_temp_path -C $remote_dir
    ssh remote:$remote_temp_path
    """
    fd, local_temp_path = tempfile.mkstemp(suffix='.tgz',
                                           prefix='rebuild_mondb-')
    os.close(fd)
    cmd = ' '.join(['tar', 'cz',
                    '-f', local_temp_path,
                    '-C', path,
                    '--', '.'])
    teuthology.sh(cmd)
    _, fname = os.path.split(local_temp_path)
    fd, remote_temp_path = tempfile.mkstemp(suffix='.tgz',
                                            prefix='rebuild_mondb-')
    os.close(fd)
    remote.put_file(local_temp_path, remote_temp_path)
    os.remove(local_temp_path)
    remote.run(args=['sudo',
                     'tar', 'xz',
                     '-C', remote_dir,
                     '-f', remote_temp_path])
    remote.run(args=['sudo', 'rm', '-fr', remote_temp_path])
开发者ID:ApusApp,项目名称:ceph,代码行数:30,代码来源:rebuild_mondb.py

示例3: create_security_group

    def create_security_group(self):
        """
        Create a security group that will be used by all teuthology
        created instances. This should not be necessary in most cases
        but some OpenStack providers enforce firewall restrictions even
        among instances created within the same tenant.
        """
        try:
            self.run("security group show teuthology")
            return
        except subprocess.CalledProcessError:
            pass
        # TODO(loic): this leaves the teuthology vm very exposed
        # it would be better to be very liberal for 192.168.0.0/16
        # and 172.16.0.0/12 and 10.0.0.0/8 and only allow 80/8081/22
        # for the rest.
        misc.sh(
            """
openstack security group create teuthology
openstack security group rule create --dst-port 1:65535 teuthology
openstack security group rule create --proto udp --dst-port 53 teuthology # dns
openstack security group rule create --proto udp --dst-port 111 teuthology # for nfs
openstack security group rule create --proto udp --dst-port 2049 teuthology # for nfs
openstack security group rule create --proto udp --dst-port 16000:65535 teuthology # for nfs
        """
        )
开发者ID:ceph,项目名称:teuthology,代码行数:26,代码来源:__init__.py

示例4: begin

 def begin(self):
     misc.sh("""
     set -x
     pip install tox
     tox
     # tox -e py27-integration
     tox -e openstack-integration
     """)
开发者ID:Abhishekvrshny,项目名称:ceph-qa-suite,代码行数:8,代码来源:teuthology_integration.py

示例5: image_create

 def image_create(self, name):
     """
     Upload an image into OpenStack with glance. The image has to be qcow2.
     """
     misc.sh("wget -c -O " + name + ".qcow2 " + self.image2url[name])
     misc.sh("glance image-create --property ownedby=teuthology " +
             " --disk-format=qcow2 --container-format=bare " +
             " --file " + name + ".qcow2 --name " + self.image_name(name))
开发者ID:MrWeird,项目名称:teuthology,代码行数:8,代码来源:__init__.py

示例6: test_floating_ip

    def test_floating_ip(self):
        if not self.can_create_floating_ips:
            pytest.skip('unable to create floating ips')

        expected = TeuthologyOpenStack.create_floating_ip()
        ip = TeuthologyOpenStack.get_unassociated_floating_ip()
        assert expected == ip
        ip_id = TeuthologyOpenStack.get_floating_ip_id(ip)
        misc.sh("openstack -q ip floating delete " + ip_id)
开发者ID:smithfarm,项目名称:teuthology,代码行数:9,代码来源:test_openstack.py

示例7: teardown

 def teardown(self):
     """
     Delete all instances run by the teuthology cluster and delete the
     instance running the teuthology cluster.
     """
     self.ssh("sudo /etc/init.d/teuthology stop || true")
     instance_id = self.get_instance_id(self.args.name)
     self.delete_floating_ip(instance_id)
     misc.sh("openstack server delete --wait " + self.args.name)
开发者ID:esnyder,项目名称:teuthology,代码行数:9,代码来源:__init__.py

示例8: clobber

    def clobber(self):
        misc.sh(
            """
openstack server delete {name} --wait || true
openstack keypair delete {key_name} || true
        """.format(
                key_name=self.key_name, name=self.name
            )
        )
开发者ID:charpty,项目名称:teuthology,代码行数:9,代码来源:test_openstack.py

示例9: associate_floating_ip

 def associate_floating_ip(name_or_id):
     """
     Associate a floating IP to the OpenStack instance
     or do nothing if no floating ip can be created.
     """
     ip = TeuthologyOpenStack.get_unassociated_floating_ip()
     if not ip:
         ip = TeuthologyOpenStack.create_floating_ip()
     if ip:
         misc.sh("openstack ip floating add " + ip + " " + name_or_id)
开发者ID:esnyder,项目名称:teuthology,代码行数:10,代码来源:__init__.py

示例10: delete_floating_ip

 def delete_floating_ip(instance_id):
     """
     Remove the floating ip from instance_id and delete it.
     """
     ip = TeuthologyOpenStack.get_floating_ip(instance_id)
     if not ip:
         return
     misc.sh("openstack ip floating remove " + ip + " " + instance_id)
     ip_id = TeuthologyOpenStack.get_floating_ip_id(ip)
     misc.sh("openstack ip floating delete " + ip_id)
开发者ID:esnyder,项目名称:teuthology,代码行数:10,代码来源:__init__.py

示例11: verify_openstack

 def verify_openstack(self):
     """
     Check there is a working connection to an OpenStack cluster
     and set the provider data member if it is among those we
     know already.
     """
     try:
         misc.sh("openstack server list")
     except subprocess.CalledProcessError:
         log.exception("openstack server list")
         raise Exception("verify openrc.sh has been sourced")
     self.set_provider()
开发者ID:esnyder,项目名称:teuthology,代码行数:12,代码来源:__init__.py

示例12: create_floating_ip

 def create_floating_ip():
     pools = json.loads(misc.sh("openstack ip floating pool list -f json"))
     if not pools:
         return None
     pool = pools[0]['Name']
     try:
         ip = json.loads(misc.sh(
             "openstack ip floating create -f json '" + pool + "'"))
         return TeuthologyOpenStack.get_value(ip, 'ip')
     except subprocess.CalledProcessError:
         log.debug("create_floating_ip: not creating a floating ip")
         pass
     return None
开发者ID:esnyder,项目名称:teuthology,代码行数:13,代码来源:__init__.py

示例13: setup_class

    def setup_class(self):
        if 'OS_AUTH_URL' not in os.environ:
            pytest.skip('no OS_AUTH_URL environment variable')

        teuthology.log.setLevel(logging.DEBUG)
        set_config_attr(argparse.Namespace())

        ip = TeuthologyOpenStack.create_floating_ip()
        if ip:
            ip_id = TeuthologyOpenStack.get_floating_ip_id(ip)
            misc.sh("openstack -q ip floating delete " + ip_id)
            self.can_create_floating_ips = True
        else:
            self.can_create_floating_ips = False
开发者ID:smithfarm,项目名称:teuthology,代码行数:14,代码来源:test_openstack.py

示例14: setup

    def setup(self):
        self.key_filename = tempfile.mktemp()
        self.key_name = 'teuthology-test'
        self.name = 'teuthology-test'
        self.clobber()
        misc.sh("""
openstack keypair create {key_name} > {key_filename}
chmod 600 {key_filename}
        """.format(key_filename=self.key_filename,
                   key_name=self.key_name))
        self.options = ['--key-name', self.key_name,
                        '--key-filename', self.key_filename,
                        '--name', self.name,
                        '--verbose']
开发者ID:smithfarm,项目名称:teuthology,代码行数:14,代码来源:test_openstack.py

示例15: flavor

    def flavor(self, hint, select):
        """
        Return the smallest flavor that satisfies the desired size.
        """
        flavors_string = misc.sh("openstack flavor list -f json")
        flavors = json.loads(flavors_string)
        found = []
        for flavor in flavors:
            if select and not re.match(select, flavor['Name']):
                continue
            if (flavor['RAM'] >= hint['ram'] and
                    flavor['VCPUs'] >= hint['cpus'] and
                    flavor['Disk'] >= hint['disk']):
                found.append(flavor)
        if not found:
            raise Exception("openstack flavor list: " + flavors_string +
                            " does not contain a flavor in which" +
                            " the desired " + str(hint) + " can fit")

        def sort_flavor(a, b):
            return (a['VCPUs'] - b['VCPUs'] or
                    a['RAM'] - b['RAM'] or
                    a['Disk'] - b['Disk'])
        sorted_flavor = sorted(found, cmp=sort_flavor)
        log.debug("sorted flavor = " + str(sorted_flavor))
        return sorted_flavor[0]['Name']
开发者ID:esnyder,项目名称:teuthology,代码行数:26,代码来源:__init__.py


注:本文中的teuthology.misc.sh函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。