Пример #1
0
    def _get_maas_client(self, resource_config):
        """

        :param resource_config:
        :return:
        """
        self._logger.info("Initializing MAAS API client...")

        return login(
            f"{resource_config.api_scheme}://{resource_config.address}:{resource_config.api_port}/MAAS/",
            username=resource_config.api_user,
            password=resource_config.api_password,
            insecure=True,
        )
Пример #2
0
    def __init__(self, conf):
        self.conf = self._read_conf(conf)
        # kvm xml template tree root
        self.ktree = self._read_kvm_xml_template(MaaS.KVM_XML_TEMPLATE_PATH)
        self.ktree_root = self.ktree.getroot()
        self.kptree = self._read_kvm_xml_template(MaaS.KVM_POOL_XML_PATH)
        self.kptree_root = self.kptree.getroot()
        self.kvtree = self._read_kvm_xml_template(MaaS.KVM_VOL_XML_TEMP_PATH)
        self.kvtree_root = self.kvtree.getroot()
        self.client = login(self.conf.api,
                            username=self.conf.username,
                            password=self.conf.password)

        conn = libvirt.open(self.conf.qemu)
        if conn is None:
            print("CRITICAL: Failed to connect to the hypervizor")

        self.conn = conn
        self.pool = None
        self.mac_suffix = 0
    for attr, value in [
        ("User", user),
        ("Password", password),
        ("Scheme", "http"),
            # ("Managed Allocation", "True"),
        ("Port", port)
    ]:

        context.resource.attributes["{}.{}".format(MaasDriver.SHELL_NAME,
                                                   attr)] = value
        context.connectivity = mock.MagicMock()
        context.connectivity.server_address = "192.168.85.27"

    dr = MaasDriver()
    dr.initialize(context)

    from maas.client import login

    client = login(
        f"http://192.168.26.24:5240/MAAS/",
        username="******",
        password="******",
        insecure=True,
    )

    for res in dr.get_inventory(context).resources:
        print(res.__dict__)

    dr.Deploy(context, mock.MagicMock())
Пример #4
0
import yaml

from maas.client import login
from maas.client.enum import InterfaceType, LinkMode

with open("maas-lci.yaml", 'r') as stream:
    try:
        nodes = (yaml.safe_load(stream))
    except yaml.YAMLError as exc:
        print(exc)

for node in nodes["nodes_list"]:
    print("%s : %s" % (node["mac"], node["name"]))

client = login("http://localhost:5240/MAAS",
               username="******",
               password="******")
subnet = client.subnets.get('192.168.0.0/24')

for node in nodes["nodes_list"]:
    try:
        machine = client.machines.create(
            architecture="amd64",
            mac_addresses=[node["mac"]],
            power_type="manual",
            hostname=node["name"],
            domain="int.carrefour.io").mark_broken()
        bridge = machine.interfaces.create(
            InterfaceType.BRIDGE,
            name='br-maas',
            parent=machine.interfaces.get_by_name('eth0'))
from maas.client import login

client = login(
    "http://192.168.26.24:5240/MAAS/",
    username="******",
    password="******",
)

# todo: Deploy
# 0. Create resorce to parse the context
# 1. Choose free machine from the pool (by given settings (cores, RAm, disks, storage) )
#   a. If no such machine - raise an Exception
# 2. Get needed OS from the Deployed App "Operation System" field
# 3. Triger "deploy" method. Check in loop while status is not OK
# 4. Implement Power On/Power Off commands
Пример #6
0
#!/usr/bin/python3

from __future__ import print_function
from maas.client import login
from maas.client.enum import NodeStatus
from maas.client.utils.async import asynchronous
import MySQLdb as my
import time


client = login(
    "http://194.47.151.120:5240/MAAS/",
     username = "******", password="******",
)
db = my.connect(host='127.0.0.1', port=3306, db='anm', user='******',passwd='root', charset='utf8mb4')
cursor = db.cursor()

a=[]; b=[]; c=[]; 
for machine in client.machines.list():
        if machine.status==NodeStatus.DEPLOYED:
           t = time.ctime()
        a.append(machine.system_id)
        b.append(machine.hostname)
        c.append(machine.status)

for i in range(0,len(c)):
    if c[i]==NodeStatus.NEW:
      print(time.ctime(),"--", a[i],"--", b[i],"--", "NEW")
    elif c[i]==NodeStatus.READY:
      print(time.ctime(),"--", a[i],"--", b[i], "--", "READY")
    elif c[i]==NodeStatus.DEPLOYED: