Ejemplo n.º 1
0
def Producer_Action():
    db = order_db_handle.DBStore()
    while True:
        rebuild_groups = db.get_action('rebuild')
        if rebuild_groups:
            for rebuild_group in rebuild_groups:
                op = Openstack.UserOpenstack(
                    project_id=rebuild_group.project_id)
                servers_id_list = op.list_server_id()
                for server_id in servers_id_list:
                    data = {
                        "rebuild": {
                            "OS-DCF:diskConfig": "AUTO",
                            "imageRef": rebuild_group.image_id,
                            "name": rebuild_group.name,
                        },
                        'project_id': rebuild_group.project_id,
                        'server_id': server_id
                    }
                    action_q.put(data)
        start_groups = db.get_action('start')
        if start_groups:
            for start_group in start_groups:
                op = Openstack.UserOpenstack(project_id=start_group.project_id)
                servers_id_list = op.list_server_id()
                for server_id in servers_id_list:
                    data = {
                        "os-start": 'null',
                        'project_id': start_group.project_id,
                        'server_id': server_id
                    }
                    action_q.put(data)
        stop_groups = db.get_action('stop')
        if stop_groups:
            for stop_group in stop_groups:
                op = Openstack.UserOpenstack(project_id=stop_group.project_id)
                servers_id_list = op.list_server_id()
                for server_id in servers_id_list:
                    data = {
                        "os-stop": 'null',
                        'project_id': stop_group.project_id,
                        'server_id': server_id
                    }
                    action_q.put(data)
        reboot_groups = db.get_action('reboot')
        if reboot_groups:
            for reboot_group in reboot_groups:
                op = Openstack.UserOpenstack(
                    project_id=reboot_group.project_id)
                servers_id_list = op.list_server_id()
                for server_id in servers_id_list:
                    data = {
                        "reboot": {
                            "type": "HARD"
                        },
                        'project_id': reboot_group.project_id,
                        'server_id': server_id
                    }
                    action_q.put(data)
Ejemplo n.º 2
0
def Consumer_Action():
    while True:
        db_dict = action_q.get()
        op = Openstack.UserOpenstack(
            project_id=db_dict.get('project_id', None))
        server_id = db_dict.get('server_id', None)
        del db_dict['project_id']
        del db_dict['server_id']
        op.server_action(server_id, db_dict)
Ejemplo n.º 3
0
def Consumer_Delete():
    while True:
        db_dict = stop_q.get()
        if db_dict:
            op = Openstack.UserOpenstack(
                project_id=db_dict.get('project_id', None))
            op.get_token()
            id_list = op.list_server_id()
            op.delete_server(id_list)
            op.delete_float_all()
Ejemplo n.º 4
0
def Consumer_Create():
    while True:
        db_dict = start_q.get()
        if db_dict:
            data = {}
            data['server'] = db_dict.get('server', None)
            op = Openstack.UserOpenstack(
                project_id=db_dict.get('project_id', None))
            op.get_token()
            res_data = op.create_server(data)
            time.sleep(10)
            if res_data:
                bind_network = db_dict.get('bind_network', None)
                if bind_network:
                    for network in bind_network:
                        ports_id = op.list_port_id(
                            network_id=network.get('in_network', None))
                        for port_id in ports_id:
                            op.float_create(float_network_id=network.get(
                                'ext_network', None),
                                            band_port_id=port_id)
Ejemplo n.º 5
0
from api import Openstack
from api import connect
conn = connect.Conn()
op = Openstack.Openstack(conn)
data = op.list_flavor()
flavor_dict = {}
print(data)
Ejemplo n.º 6
0
#-*- coding: utf-8 -*-
from api import Openstack
import json
from conf import openstack_setting
from api import connect
conn = connect.Conn()
op = Openstack.Openstack(project='alt_demo', conn=conn)
# name='test'
# image_id= 'd7b418b0-9828-4664-85b3-62571f05d3a1'
# flavor_id='1'
# networks=[{'uuid': '7a47d9f7-f47a-4321-99c4-8fdb7e48567a'}]
# count='10'
# op.create_server(name=name,image_id=image_id,flavor_id=flavor_id,networks=networks,count=count)
op.get_token()

res = op.create_project('xiandian')
# res=op.identity_request('users',method='GET',headers=headers)
# print(json.loads(res.read()))
# print(json.loads(res.read()))
Ejemplo n.º 7
0
from api import connect
from api import Openstack
import json
op = Openstack.Openstack(connect.Conn())


def get_extnetworks():
    extnetworks_list = []
    res = op.network_request(
        'networks?router:external=True&fields=id&fields=name', 'GET')
    networks = json.loads(res.read())
    for network in networks.get('networks', []):
        extnetworks_dict = {}
        extnetworks_dict['id'] = network.get('id', None)
        extnetworks_dict['name'] = network.get('name', None)
        extnetworks_list.append(extnetworks_dict)
    return extnetworks_list


def get_port_device(network_id, is_extnetwork=False):
    ports_id_list = []
    if is_extnetwork:
        res = op.network_request(
            'ports?network_id=%s&device_owner=network:router_gateway&fields=device_id'
            % network_id, 'GET')
    else:
        res = op.network_request(
            'ports?network_id=%s&device_owner=network:router_interface&fields=device_id'
            % network_id, 'GET')
    data = json.loads(res.read())
    for port in data.get('ports', []):
Ejemplo n.º 8
0
from api import Openstack
op = Openstack.UserOpenstack(project_id='dd92a1fe25614b03bb221facc351acd4')
# data={
#     "server": {
#         "name": 'test',
#         "imageRef": '9c9f397a-86a6-4548-8e38-3b45a27ef63b',
#         "flavorRef": '42',
#         "networks": [{"uuid": 'f9c6febf-2ac9-4439-b460-5ae6f7f37723'}],
#         'min_count': '2',
#         'max_count': '2',
#     },
# }
# data=op.create_server(data)
servers = op.list_server()
for server in servers:
    print(servers)
Ejemplo n.º 9
0
from api import Openstack
op=Openstack.UserOpenstack(project_id='1e9fa526dc8141c1b5809fe820dc703e')
# servers=op.list_server_id()
# print(servers)
data=op.float_create(float_network_id='efbe5cc2-f8a3-48a3-beba-32ce2490f091',band_port_id='f284bded-5ce9-4cf8-8973-d2ad04a33fdd')
print(data)