示例#1
0
def cloneVM(sourcevm_uuid, host_uuid, sruuid, serverip, serveraccount,
            serverpwd, poolname, operator, guid):
    vm = servers.get(sourcevm_uuid)
    volume_id = vm._info['os-extended-volumes:volumes_attached'][0]['id']
    volume = cinder.volumes.find(id=volume_id)
    volume.reset_state('available')
    volume_name = str(gf.getTime()) + volume_id
    snapshot = cinder.volume_snapshots.create(volume_id, name=volume_name)
    while cinder.volume_snapshots.find(id=snapshot.id).status == 'creating':
        time.sleep(5)
    new_volume = cinder.volumes.create(snapshot.size,
                                       consistencygroup_id=None,
                                       group_id=None,
                                       snapshot_id=snapshot.id,
                                       source_volid=None,
                                       name=volume_name,
                                       description=None)
    while cinder.volumes.find(id=new_volume.id).status == 'creating':
        time.sleep(5)
    #status -> in-use
    volume.reset_state('in-use')
    vol = cinder.volumes.find(id=new_volume.id)
    block_dev_mapping = {'vda': vol}
    server_name = Cvm

    sg_list = []
    for item in vm.security_groups:
        sg_list.append(item['id'])

    keypair_name = vm.key_name
    body_value = {
        "port": {
            "admin_state_up": True,
            "name": "port",
            "network_id": network_uuid,
            "fixed_ips": [{
                "subnet_id": '9950c209-2c27-43c8-9e10-2b331ca9d225'
            }],
            "security_groups": sg_list,
        }
    }
    #nics
    port = neutron.create_port(body=body_value)
    nics = [{'port-id': port['port']['id']}]
    # #keypair find

    server = nova.servers.create(
        name=server_name,
        image=None,
        block_device_mapping=block_dev_mapping,
        flavor=flavor.id,
        nics=nics,
        key_name=keypair_name,
        availability_zone=host_name,
    )
示例#2
0
# vmuuid="cf8f5293-050c-41a8-83ac-85e0beec8df6"
# cpu_num=2
# memory_mb=2048
# addGB=3
# diskctrl = 2
# deviceidx = 0
# sruuid =0
# serverip =  "140.128.101.205"
# serveraccount = "admin"
# serverpwd ="1j6el4nj4su3"
# poolname =""
# operator =""
# guid =""

now = gf.getTime()
nova = client_setting.nova(server_ip, server_account, server_pwd, project_name)
# nova = client_setting.nova(serverip,serveraccount,serverpwd,projectname)
neutron = client_setting.neutron(server_ip, server_account, server_pwd,
                                 project_name)
cinder = client_setting.cinder(server_ip, server_account, server_pwd,
                               project_name)
volumes = nova.volumes
servers = nova.servers
flavors = nova.flavors
networks = nova.networks
hypervisors = nova.hypervisors
images = nova.images
ip = nova.floating_ips
hl = hypervisors.list()
nl = networks.list()
示例#3
0
import io
import os
# from multiprocessing.pool import ThreadPool
import time
from threading import Thread

#python Snapshotvm.py 28b904d6-6c82-4f90-ae9e-9cc392f83a2c 140.128.101.205 admin 1j6el4nj4su3 admin 0 snapshot
vm_uuid = sys.argv[1]
serverip = sys.argv[2]
serveraccount = sys.argv[3]
serverpwd = sys.argv[4]
poolname = sys.argv[5]
operator = sys.argv[6]
guid = sys.argv[7]
projectname = poolname
now = str(gf.getTime())

# vm_uuid = "083cb621-76b8-42ba-9728-651cdc795d06"
# network_uuid = sys.argv[8]
# host_uuid =  sys.argv[9]
# if host_uuid == 'null':
#     host_name = gf.compareHost(serverip,serveraccount,serverpwd,projectname)

# else:
#     host_uuid = sys.argv[9]
#     host_name = hypervisors.get(host_uuid).hypervisor_hostname
# suspend_num = 3
# host_uuid =  "1" # host id
# sruuid = 1
# serverip = "140.128.101.205"
# serveraccount = "admin"