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


Python datacenter.Datacenter类代码示例

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


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

示例1: list

    def list(cls, datacenter=None, flavor=None, match='', exact_match=False):
        """ List available kernels for datacenter."""
        if not datacenter:
            dc_ids = [dc['id'] for dc in Datacenter.filtered_list()]
            kmap = {}
            for dc_id in dc_ids:
                vals = cls.safe_call('hosting.disk.list_kernels', dc_id)
                for key in vals:
                    kmap.setdefault(key, []).extend(vals.get(key, []))
            # remove duplicates
            for key in kmap:
                kmap[key] = list(set(kmap[key]))
        else:
            dc_id = Datacenter.usable_id(datacenter)
            kmap = cls.safe_call('hosting.disk.list_kernels', dc_id)

        if match:
            for flav in kmap:
                if exact_match:
                    kmap[flav] = [x for x in kmap[flav] if match == x]
                else:
                    kmap[flav] = [x for x in kmap[flav] if match in x]
        if flavor:
            if flavor not in kmap:
                cls.error('flavor %s not supported here' % flavor)
            return dict([(flavor, kmap[flavor])])

        return kmap
开发者ID:Gandi,项目名称:gandi.cli,代码行数:28,代码来源:iaas.py

示例2: create

    def create(cls, name, datacenter, subnet=None, gateway=None,
               background=False):
        """Create a new vlan."""
        if not background and not cls.intty():
            background = True

        datacenter_id_ = int(Datacenter.usable_id(datacenter))

        vlan_params = {
            'name': name,
            'datacenter_id': datacenter_id_,
        }

        if subnet:
            vlan_params['subnet'] = subnet
        if gateway:
            vlan_params['gateway'] = gateway

        result = cls.call('hosting.vlan.create', vlan_params)

        if not background:
            # interactive mode, run a progress bar
            cls.echo('Creating your vlan.')
            cls.display_progress(result)
            cls.echo('Your vlan %s has been created.' % name)

        return result
开发者ID:Gandi,项目名称:gandi.cli,代码行数:27,代码来源:network.py

示例3: migrate

    def migrate(cls, resource, background=False, finalize=False):
        """ Migrate a virtual machine to another datacenter. """
        vm_id = cls.usable_id(resource)
        if finalize:
            verb = 'Finalizing'
            result = cls.call('hosting.vm.migrate', vm_id, True)
        else:
            verb = 'Starting'
            result = cls.call('hosting.vm.migrate', vm_id, False)

        dcs = {}
        for dc in Datacenter.list():
            dcs[dc['id']] = dc['dc_code']

        oper = cls.call('operation.info', result['id'])
        dc_from = dcs[oper['params']['from_dc_id']]
        dc_to = dcs[oper['params']['to_dc_id']]
        migration_msg = ('* %s the migration of VM %s '
                         'from datacenter %s to %s'
                         % (verb, resource, dc_from, dc_to))
        cls.echo(migration_msg)

        if background:
            return result

        cls.echo('VM migration in progress.')
        cls.display_progress(result)
        cls.echo('Your VM %s has been migrated.' % resource)
        return result
开发者ID:Gandi,项目名称:gandi.cli,代码行数:29,代码来源:iaas.py

示例4: list

    def list(cls, datacenter=None):
        """List virtual machine vlan

        (in the future it should also handle PaaS vlan)."""
        options = {}
        if datacenter:
            datacenter_id = int(Datacenter.usable_id(datacenter))
            options['datacenter_id'] = datacenter_id

        return cls.call('hosting.vlan.list', options)
开发者ID:Gandi,项目名称:gandi.cli,代码行数:10,代码来源:network.py

示例5: list

    def list(cls, datacenter=None, label=None):
        """List available images for vm creation."""
        options = {}
        if datacenter:
            datacenter_id = int(Datacenter.usable_id(datacenter))
            options['datacenter_id'] = datacenter_id

        # implement a filter by label as API doesn't handle it
        images = cls.safe_call('hosting.image.list', options)
        if not label:
            return images
        return [img for img in images
                if label.lower() in img['label'].lower()]
开发者ID:andronux,项目名称:gandi.cli,代码行数:13,代码来源:iaas.py

示例6: create

    def create(cls, name, datacenter, backends, vhosts, algorithm,
               ssl_enable, zone_alter):
        """ Create a webaccelerator """
        datacenter_id_ = int(Datacenter.usable_id(datacenter))
        params = {
            'datacenter_id': datacenter_id_,
            'name': name,
            'lb': {'algorithm': algorithm},
            'override': True,
            'ssl_enable': ssl_enable,
            'zone_alter': zone_alter
        }
        if vhosts:
            params['vhosts'] = vhosts
        if backends:
            params['servers'] = backends
        try:
            result = cls.call('hosting.rproxy.create', params)
            cls.echo('Creating your webaccelerator %s' % params['name'])
            cls.display_progress(result)
            cls.echo('Your webaccelerator have been created')
            return result
        except Exception as err:
            if err.code == 580142:
                for vhost in params['vhosts']:
                    dns_entry = cls.call(
                        'hosting.rproxy.vhost.get_dns_entries',
                        {'datacenter': datacenter_id_, 'vhost': vhost})
                    txt_record = "@ 3600 IN TXT \"%s=%s\"" % (dns_entry['key'],
                                                              dns_entry['txt'])

                    cname_record = "%s 3600 IN CNAME %s" % (dns_entry['key'],
                                                            dns_entry['cname'])

                    cls.echo('The domain %s don\'t use Gandi DNS or you have'
                             ' not sufficient right to alter the zone file. '
                             'Edit your zone file adding this TXT and CNAME '
                             'record and try again :' % vhost)
                    cls.echo(txt_record)
                    cls.echo(cname_record)
                    cls.echo('\nOr add a file containing %s at :\n'
                             'http://%s/%s.txt\n' % (dns_entry['txt'],
                                                     dns_entry['domain'],
                                                     dns_entry['txt']))
                    cls.separator_line('-', 4)
            else:
                cls.echo(err)
开发者ID:Gandi,项目名称:gandi.cli,代码行数:47,代码来源:webacc.py

示例7: create

    def create(cls, name, size, type, quantity, duration, datacenter, vhosts,
               password, snapshot_profile, background, sshkey):
        """Create a new PaaS instance."""
        if not background and not cls.intty():
            background = True

        datacenter_id_ = int(Datacenter.usable_id(datacenter))

        paas_params = {
            'name': name,
            'size': size,
            'type': type,
            'duration': duration,
            'datacenter_id': datacenter_id_,
        }

        if password:
            paas_params['password'] = password

        if quantity:
            paas_params['quantity'] = quantity

        paas_params.update(cls.convert_sshkey(sshkey))

        if snapshot_profile:
            paas_params['snapshot_profile'] = snapshot_profile

        result = cls.call('paas.create', paas_params)

        if not background:
            # interactive mode, run a progress bar
            cls.echo('Creating your PaaS instance.')
            cls.display_progress(result)
            cls.echo('Your PaaS instance %s has been created.' % name)


        if vhosts:
            paas_info = cls.info(name)
            Vhost.create(paas_info, vhosts, True, background)

        return result
开发者ID:ziir,项目名称:gandi.cli,代码行数:41,代码来源:paas.py

示例8: create

    def create(cls, datacenter, memory, cores, ip_version, bandwidth,
               login, password, hostname, image, run, background, sshkey,
               size):
        """Create a new virtual machine."""
        if not background and not cls.intty():
            background = True

        datacenter_id_ = int(Datacenter.usable_id(datacenter))

        if not hostname:
            hostname = randomstring()
            disk_name = 'sys_%s' % hostname[4:]
        else:
            disk_name = 'sys_%s' % hostname.replace('.', '')

        vm_params = {
            'hostname': hostname,
            'datacenter_id': datacenter_id_,
            'memory': memory,
            'cores': cores,
            'ip_version': ip_version,
            'bandwidth': bandwidth,
        }

        if login:
            vm_params['login'] = login

        if run:
            vm_params['run'] = run

        if password:
            vm_params['password'] = password

        vm_params.update(cls.convert_sshkey(sshkey))

        # XXX: name of disk is limited to 15 chars in ext2fs, ext3fs
        # but api allow 255, so we limit to 15 for now
        disk_params = {'datacenter_id': vm_params['datacenter_id'],
                       'name': disk_name[:15]}

        if size:
            disk_params['size'] = size

        sys_disk_id_ = int(Image.usable_id(image, datacenter_id_))

        result = cls.call('hosting.vm.create_from', vm_params, disk_params,
                          sys_disk_id_)

        if ip_version == 4:
            ip_summary = 'ip v4+v6'
        else:
            ip_summary = 'ip v6'
        cls.echo('* Configuration used: %d cores, %dMb memory, %s, '
                 'image %s, hostname: %s' % (cores, memory, ip_summary, image,
                                             hostname))
        if background:
            return result

        # interactive mode, run a progress bar
        cls.echo('Creating your Virtual Machine %s.' % hostname)
        cls.display_progress(result)
        cls.echo('Your Virtual Machine %s has been created.' % hostname)

        if 'ssh_key' not in vm_params and 'keys' not in vm_params:
            return

        vm_id = None
        for oper in result:
            if oper.get('vm_id'):
                vm_id = oper.get('vm_id')
                break

        if vm_id:
            time.sleep(5)
            cls.ssh(oper['vm_id'], login='root', identity=None, wipe_key=True)
开发者ID:andronux,项目名称:gandi.cli,代码行数:75,代码来源:iaas.py

示例9: create

    def create(cls, datacenter, memory, cores, ip_version, bandwidth,
               login, password, hostname, image, run, background, sshkey,
               size, script):
        """Create a new virtual machine."""
        if not background and not cls.intty():
            background = True

        datacenter_id_ = int(Datacenter.usable_id(datacenter))

        if not hostname:
            hostname = randomstring()
            disk_name = 'sys_%s' % hostname[4:]
        else:
            disk_name = 'sys_%s' % hostname.replace('.', '')

        vm_params = {
            'hostname': hostname,
            'datacenter_id': datacenter_id_,
            'memory': memory,
            'cores': cores,
            'ip_version': ip_version,
            'bandwidth': bandwidth,
        }

        if login:
            vm_params['login'] = login

        if run:
            vm_params['run'] = run

        if password:
            vm_params['password'] = password

        vm_params.update(cls.convert_sshkey(sshkey))

        # XXX: name of disk is limited to 15 chars in ext2fs, ext3fs
        # but api allow 255, so we limit to 15 for now
        disk_params = {'datacenter_id': vm_params['datacenter_id'],
                       'name': disk_name[:15]}

        if size:
            disk_params['size'] = size

        sys_disk_id_ = int(Image.usable_id(image, datacenter_id_))

        result = cls.call('hosting.vm.create_from', vm_params, disk_params,
                          sys_disk_id_)

        ip_summary = 'ip v4+v6'
        if ip_version == 6:
            ip_summary = 'ip v6'
        cls.echo('* Configuration used: %d cores, %dMb memory, %s, '
                 'image %s, hostname: %s' % (cores, memory, ip_summary, image,
                                             hostname))

        # background mode, bail out now (skip interactive part)
        if background:
            return result

        # interactive mode, run a progress bar
        cls.echo('Creating your Virtual Machine %s.' % hostname)
        cls.display_progress(result)
        cls.echo('Your Virtual Machine %s has been created.' % hostname)

        if 'ssh_key' not in vm_params and 'keys' not in vm_params:
            return

        vm_id = None
        for oper in result:
            if oper.get('vm_id'):
                vm_id = oper.get('vm_id')
                break

        if vm_id:
            cls.wait_for_sshd(vm_id)
            cls.ssh_keyscan(vm_id)
            if script:
                ret = cls.scp(vm_id, 'root', None, script, '/var/tmp/gscript')
                if not ret:
                    cls.error('Failed to scp script %s to VM %s (id: %s)' %
                              (script, hostname, vm_id))

            ret = cls.ssh(vm_id, 'root', None, script and ['/var/tmp/gscript'])
            if not ret and (script and ['/var/tmp/gscript']):
                cls.error('Failed to execute script %s on VM %s (id: %s)' %
                          ('/var/tmp/gscript', hostname, vm_id))
开发者ID:webcracy,项目名称:gandi.cli,代码行数:86,代码来源:iaas.py

示例10: create

    def create(cls, datacenter, memory, cores, ip_version, bandwidth,
               login, password, hostname, image, run, background, sshkey,
               size, vlan, ip, script, script_args, ssh):
        """Create a new virtual machine."""
        from gandi.cli.modules.network import Ip, Iface
        if not background and not cls.intty():
            background = True

        datacenter_id_ = int(Datacenter.usable_id(datacenter))

        if not hostname:
            hostname = randomstring('vm')
            disk_name = 'sys_%s' % hostname[2:]
        else:
            disk_name = 'sys_%s' % hostname.replace('.', '')

        vm_params = {
            'hostname': hostname,
            'datacenter_id': datacenter_id_,
            'memory': memory,
            'cores': cores,
        }

        if login:
            vm_params['login'] = login

        if run:
            vm_params['run'] = run

        if password:
            vm_params['password'] = password

        if ip_version:
            vm_params['ip_version'] = ip_version
            vm_params['bandwidth'] = bandwidth

        if script:
            with open(script) as fd:
                vm_params['script'] = fd.read()
            if script_args:
                vm_params['script_args'] = script_args

        vm_params.update(cls.convert_sshkey(sshkey))

        # XXX: name of disk is limited to 15 chars in ext2fs, ext3fs
        # but api allow 255, so we limit to 15 for now
        disk_params = {'datacenter_id': vm_params['datacenter_id'],
                       'name': disk_name[:15]}

        if size:
            if isinstance(size, tuple):
                prefix, size = size
            disk_params['size'] = size

        sys_disk_id_ = int(Image.usable_id(image, datacenter_id_))

        ip_summary = []
        if ip_version == 4:
            ip_summary = ['v4', 'v6']
        elif ip_version == 6:
            ip_summary = ['v6']

        if vlan:
            ip_ = None
            ip_summary.append('private')
            if ip:
                try:
                    ip_ = Ip.info(ip)
                except Exception:
                    pass
                else:
                    if not Ip.check_and_detach(ip_, None, force=False):
                        return
            if ip_:
                iface_id = ip_['iface_id']
            else:
                ip_create = Ip.create(4,
                                      vm_params['datacenter_id'],
                                      bandwidth,
                                      None,
                                      vlan,
                                      ip)

                iface_id = ip_create['iface_id']

            # if there is a public ip, will attach this one later, else give
            # the iface to vm.create
            if not ip_version:
                vm_params['iface_id'] = iface_id

        result = cls.call('hosting.vm.create_from', vm_params, disk_params,
                          sys_disk_id_)

        cls.echo('* Configuration used: %d cores, %dMb memory, ip %s, '
                 'image %s, hostname: %s, datacenter: %s' %
                 (cores, memory, '+'.join(ip_summary), image, hostname,
                  datacenter))

        # background mode, bail out now (skip interactive part)
        if background and (not vlan or not ip_version):
#.........这里部分代码省略.........
开发者ID:ziir,项目名称:gandi.cli,代码行数:101,代码来源:iaas.py


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