def test_create_composite(self):
        fwrule = FirewallRule(**self.resource['fwrule'])
        nic = NIC(firewall_rules=[fwrule], **self.resource['nic'])
        volume = Volume(image=self.image['id'],
                        image_password='******',
                        ssh_keys=['ssh-rsa AAAAB3NzaC1'],
                        **self.resource['volume'])
        volume.availability_zone = 'ZONE_3'

        server = Server(
            nics=[nic],
            create_volumes=[volume],
            **self.resource['server'])

        composite_server = self.client.create_server(
            datacenter_id=self.datacenter['id'],
            server=server)
        self.client.wait_for_completion(composite_server, timeout=600)

        composite_server = self.client.get_server(
            datacenter_id=self.datacenter['id'],
            server_id=composite_server['id'])

        assertRegex(self, composite_server['id'], self.resource['uuid_match'])
        self.assertEqual(composite_server['properties']['name'], self.resource['server']['name'])
        self.assertEqual(composite_server['properties']['cores'], self.resource['server']['cores'])
        self.assertEqual(composite_server['properties']['ram'], self.resource['server']['ram'])
        self.assertEqual(composite_server['properties']['availabilityZone'], 'ZONE_1')
        self.assertIn(composite_server['properties']['vmState'], self.resource['vm_states'])
        self.assertGreater(len(composite_server['entities']['volumes']['items']), 0)
        self.assertGreater(len(composite_server['entities']['nics']['items']), 0)
    def setUpClass(cls):
        warnings\
            .filterwarnings("ignore", category=ResourceWarning,
                            message="unclosed.*<ssl.SSLSocket.*>")
        cls.resource = resource()
        cls.client = IonosEnterpriseService(username=configuration.USERNAME,
                                            password=configuration.PASSWORD,
                                            headers=configuration.HEADERS)

        # Create test datacenter.
        cls.datacenter = cls.client.create_datacenter(
            Datacenter(**cls.resource['datacenter']))
        cls.client.wait_for_completion(cls.datacenter)

        # Create test server.
        cls.server = cls.client.create_server(cls.datacenter['id'],
                                              Server(**cls.resource['server']))
        cls.client.wait_for_completion(cls.server)

        # Use an image ID for CDROM
        images = cls.client.list_images()['items']
        images = list(
            filter(
                lambda v: v['properties']['location'] == cls.resource[
                    'datacenter']['location'] and v['properties']['imageType']
                != 'HDD', images))
        cls.image_id = images[0]['id']
        cls.attached_cdrom = cls.client.attach_cdrom(cls.datacenter['id'],
                                                     cls.server['id'],
                                                     cls.image_id)
        cls.client.wait_for_completion(cls.attached_cdrom)
Exemple #3
0
def getServerObject(defdict=None):
    if not defdict or not isinstance(defdict, dict):
        raise ValueError("argument 'defdict' must be non-empty dict")
    # AARGH! some of Servers's fields have different names -> need to convert manually
    # so make a copy and let source as is
    props = dict()
    for k, v in defdict['properties'].items():
        if k == 'availabilityZone':
            props['availability_zone'] = v
            continue
        if k == 'bootCdrom':
            props['boot_cdrom'] = v
            continue
        if k == 'cpuFamily':
            props['cpu_family'] = v
            continue
# -- TODO: if volumes entries have an ID -> attach, else create w/ properties of volume
#         if k == 'bootVolume':
#             props['boot_volume_id'] = v
#             continue
#         if k == 'volumes':
#             props['create_volumes'] = v
#             continue
#         if k == 'volumes':
#             props['attach_volumes'] = v
#             continue
# Server() has no kwargs, so we must exactly match the known keywords
        if k in ['name', 'cores', 'ram']:
            props[k] = v
    # end for(defdict)
    apiobj = Server(**props)
    return apiobj
Exemple #4
0
 def test_create_failure(self):
     try:
         server = Server(name=self.resource['server']['name'],
                         ram=self.resource['server']['ram'])
         self.client.create_server(datacenter_id=self.datacenter['id'],
                                   server=server)
     except ICError as e:
         self.assertIn(self.resource['missing_attribute_error'] % 'cores',
                       e.content[0]['message'])
    def setUpClass(cls):
        warnings.filterwarnings("ignore", category=ResourceWarning,
                                message="unclosed.*<ssl.SSLSocket.*>")
        cls.resource = resource()
        cls.client = IonosEnterpriseService(
            username=configuration.USERNAME,
            password=configuration.PASSWORD,
            headers=configuration.HEADERS)

        # Create test datacenter.
        cls.datacenter = cls.client.create_datacenter(
            datacenter=Datacenter(**cls.resource['datacenter']))
        cls.client.wait_for_completion(cls.datacenter)

        # Create test LAN.
        cls.lan = cls.client.create_lan(
            datacenter_id=cls.datacenter['id'],
            lan=LAN(**cls.resource['lan']))
        cls.client.wait_for_completion(cls.lan)

        # Create test server.
        cls.server = cls.client.create_server(
            datacenter_id=cls.datacenter['id'],
            server=Server(**cls.resource['server']))
        cls.client.wait_for_completion(cls.server)

        # Create test NIC1.
        nic1 = NIC(**cls.resource['nic'])
        nic1.lan = cls.lan['id']
        cls.nic1 = cls.client.create_nic(
            datacenter_id=cls.datacenter['id'],
            server_id=cls.server['id'],
            nic=nic1)
        cls.client.wait_for_completion(cls.nic1)

        # Create test Firewall Rule
        fwrule = FirewallRule(**cls.resource['fwrule'])
        cls.fwrule = cls.client.create_firewall_rule(
            datacenter_id=cls.datacenter['id'],
            server_id=cls.server['id'],
            nic_id=cls.nic1['id'],
            firewall_rule=fwrule)
        cls.client.wait_for_completion(cls.fwrule)

        # Create test Firewall Rule 2
        fwrule2 = FirewallRule(**cls.resource['fwrule'])
        fwrule2.port_range_start = 8080
        fwrule2.port_range_end = 8080
        fwrule2.name = "8080"
        cls.fwrule2 = cls.client.create_firewall_rule(
            datacenter_id=cls.datacenter['id'],
            server_id=cls.server['id'],
            nic_id=cls.nic1['id'],
            firewall_rule=fwrule2)
        cls.client.wait_for_completion(cls.fwrule2)
Exemple #6
0
    def test_delete_server(self):
        server = self.client.create_server(
            datacenter_id=self.datacenter['id'],
            server=Server(**self.resource['server']))
        self.client.wait_for_completion(server)

        response = self.client.delete_server(
            datacenter_id=self.datacenter['id'], server_id=server['id'])

        self.assertTrue(response)
        assertRegex(self, response['requestId'], self.resource['uuid_match'])
    def setUpClass(cls):
        warnings.filterwarnings("ignore", category=ResourceWarning,
                                message="unclosed.*<ssl.SSLSocket.*>")
        cls.resource = resource()
        cls.client = IonosEnterpriseService(
            username=configuration.USERNAME,
            password=configuration.PASSWORD,
            headers=configuration.HEADERS)

        # Create test datacenter.
        cls.datacenter = cls.client.create_datacenter(
            datacenter=Datacenter(**cls.resource['datacenter']))
        cls.client.wait_for_completion(cls.datacenter)

        # Create pcc.
        pcc = PrivateCrossConnect(name="TEST NAME - %s" % uuid.uuid1(),
                                  description="TEST DESCRIPTION 1")

        cls.pcc = cls.client.create_pcc(pcc)
        cls.client.wait_for_completion(cls.pcc)

        # Create test LAN.
        lan_properties = cls.resource['lan']
        lan_properties['pcc_id'] = cls.pcc['id']
        cls.lan = cls.client.create_lan(
            datacenter_id=cls.datacenter['id'],
            lan=LAN(**lan_properties))
        cls.client.wait_for_completion(cls.lan)

        # Create test server.
        cls.server = cls.client.create_server(
            datacenter_id=cls.datacenter['id'],
            server=Server(**cls.resource['server']))
        cls.client.wait_for_completion(cls.server)

        # Create test NIC1.
        nic1 = NIC(**cls.resource['nic'])
        nic1.lan = cls.lan['id']
        cls.nic1 = cls.client.create_nic(
            datacenter_id=cls.datacenter['id'],
            server_id=cls.server['id'],
            nic=nic1)
        cls.client.wait_for_completion(cls.nic1)

        # Create test NIC2.
        nic2 = NIC(**cls.resource['nic'])
        nic2.lan = cls.lan['id']
        cls.nic2 = cls.client.create_nic(
            datacenter_id=cls.datacenter['id'],
            server_id=cls.server['id'],
            nic=nic2)
        cls.client.wait_for_completion(cls.nic2)
    def setUpClass(cls):
        warnings.filterwarnings("ignore",
                                category=ResourceWarning,
                                message="unclosed.*<ssl.SSLSocket.*>")
        cls.resource = resource()
        cls.client = IonosEnterpriseService(username=configuration.USERNAME,
                                            password=configuration.PASSWORD,
                                            headers=configuration.HEADERS)

        # Create test datacenter.
        cls.datacenter = cls.client.create_datacenter(datacenter=Datacenter(
            **cls.resource['datacenter']))
        cls.client.wait_for_completion(cls.datacenter)

        # Create test LAN.
        cls.lan = cls.client.create_lan(datacenter_id=cls.datacenter['id'],
                                        lan=LAN(
                                            name=cls.resource['lan']['name'],
                                            public=False))
        cls.client.wait_for_completion(cls.lan)

        # Create test server.
        cls.server = cls.client.create_server(
            datacenter_id=cls.datacenter['id'],
            server=Server(**cls.resource['server']))
        cls.client.wait_for_completion(cls.server)

        # Create test NIC1.
        nic1 = NIC(**cls.resource['nic'])
        nic1.lan = cls.lan['id']
        cls.ips = ['10.0.0.1']
        nic1.ips = cls.ips
        cls.nic1 = cls.client.create_nic(datacenter_id=cls.datacenter['id'],
                                         server_id=cls.server['id'],
                                         nic=nic1)
        cls.client.wait_for_completion(cls.nic1)

        # Create test NIC2.
        nic2 = NIC(**cls.resource['nic'])
        nic2.lan = cls.lan['id']
        cls.nic2 = cls.client.create_nic(datacenter_id=cls.datacenter['id'],
                                         server_id=cls.server['id'],
                                         nic=nic2)
        cls.client.wait_for_completion(cls.nic2)
Exemple #9
0
    def setUpClass(cls):
        cls.resource = resource()
        cls.client = IonosEnterpriseService(
            username=configuration.USERNAME,
            password=configuration.PASSWORD,
            headers=configuration.HEADERS)

        # Create test datacenter.
        cls.datacenter = cls.client.create_datacenter(
            datacenter=Datacenter(**cls.resource['datacenter']))
        cls.client.wait_for_completion(cls.datacenter)

        # Create test LAN.
        cls.lan = cls.client.create_lan(
            datacenter_id=cls.datacenter['id'],
            lan=LAN(**cls.resource['lan']))
        cls.client.wait_for_completion(cls.lan)

        # Create test server.
        cls.server = cls.client.create_server(
            datacenter_id=cls.datacenter['id'],
            server=Server(**cls.resource['server']))
        cls.client.wait_for_completion(cls.server)

        # Create test NIC1.
        nic1 = NIC(**cls.resource['nic'])
        nic1.lan = cls.lan['id']
        cls.nic1 = cls.client.create_nic(
            datacenter_id=cls.datacenter['id'],
            server_id=cls.server['id'],
            nic=nic1)
        cls.client.wait_for_completion(cls.nic1)

        # Create test NIC2.
        nic2 = NIC(**cls.resource['nic'])
        nic2.lan = cls.lan['id']
        cls.nic2 = cls.client.create_nic(
            datacenter_id=cls.datacenter['id'],
            server_id=cls.server['id'],
            nic=nic2)
        cls.client.wait_for_completion(cls.nic2)
    def test_create_composite(self):
        datacenter_resource = Datacenter(
            **self.resource['datacenter_composite'])
        datacenter_resource.servers = [Server(**self.resource['server'])]
        datacenter_resource.volumes = [Volume(**self.resource['volume'])]

        datacenter = self.client.create_datacenter(
            datacenter=datacenter_resource)
        self.client.wait_for_completion(datacenter)

        self.assertEqual(datacenter['type'], 'datacenter')
        self.assertEqual(datacenter['properties']['name'],
                         self.resource['datacenter_composite']['name'])
        self.assertEqual(datacenter['properties']['description'],
                         self.resource['datacenter_composite']['description'])
        self.assertEqual(datacenter['properties']['location'],
                         self.resource['datacenter_composite']['location'])
        self.assertGreater(len(datacenter['entities']['servers']), 0)
        self.assertGreater(len(datacenter['entities']['volumes']), 0)

        response = self.client.delete_datacenter(
            datacenter_id=datacenter['id'])
        self.assertTrue(response)
def main(argv=None):
    '''Command line options.'''

    if argv is None:
        argv = sys.argv
    else:
        sys.argv.extend(argv)

    program_name = os.path.basename(sys.argv[0])
    program_version = "v%s" % __version__
    program_build_date = str(__updated__)
    program_version_message = '%%(prog)s %s (%s)' % (program_version,
                                                     program_build_date)
    program_shortdesc = __import__('__main__').__doc__.split("\n")[1]
    program_license = '''%s

  Created by Jürgen Buchhammer on %s.
  Copyright 2016 IONOS. All rights reserved.

  Licensed under the Apache License 2.0
  http://www.apache.org/licenses/LICENSE-2.0

  Distributed on an "AS IS" basis without warranties
  or conditions of any kind, either express or implied.

USAGE
''' % (program_shortdesc, str(__date__))

    try:
        # Setup argument parser
        parser = ArgumentParser(description=program_license,
                                formatter_class=RawDescriptionHelpFormatter)
        parser.add_argument('-u', '--user', dest='user', help='the login name')
        parser.add_argument('-p',
                            '--password',
                            dest='password',
                            help='the login password')
        parser.add_argument('-L',
                            '--Login',
                            dest='loginfile',
                            default=None,
                            help='the login file to use')
        parser.add_argument('-t',
                            '--type',
                            dest='metatype',
                            default="OVF",
                            help='type of VM meta data')
        parser.add_argument('-m',
                            '--metadata',
                            dest='metafile',
                            required=True,
                            default=None,
                            help='meta data file')
        parser.add_argument('-d',
                            '--datacenterid',
                            dest='datacenterid',
                            default=None,
                            help='datacenter of the new server')
        parser.add_argument('-D',
                            '--DCname',
                            dest='dcname',
                            default=None,
                            help='new datacenter name')
        parser.add_argument('-l',
                            '--location',
                            dest='location',
                            default=None,
                            help='location for new datacenter')
        parser.add_argument('-v',
                            '--verbose',
                            dest="verbose",
                            action="count",
                            default=0,
                            help="set verbosity level [default: %(default)s]")
        parser.add_argument('-V',
                            '--version',
                            action='version',
                            version=program_version_message)

        # Process arguments
        args = parser.parse_args()
        global verbose
        verbose = args.verbose

        if verbose > 0:
            print("Verbose mode on")
            print("start {} with args {}".format(program_name, str(args)))

        (user, password) = getLogin(args.loginfile, args.user, args.password)
        if user is None or password is None:
            raise ValueError("user or password resolved to None")
        pbclient = IonosEnterpriseService(user, password)

        if args.metatype == 'OVF':
            metadata = OFVData(args.metafile)
            metadata.parse()
        else:
            sys.stderr.write("Metadata type '{}' is not supported".format(
                args.metatype))
            return 1

        # we need the DC first to have the location defined
        dc_id = None
        if args.datacenterid is None:
            if args.dcname is None or args.location is None:
                sys.stderr.write(
                    "Either '-d <id>' or '-D <name> -l <loc>'  must be specified"
                )
                return 1
            # else: we will create the DC later after parsing the meta data
        else:
            dc_id = args.datacenterid

        if dc_id is None:
            location = args.location
            dc = Datacenter(name=args.dcname,
                            location=location,
                            description="created by pb_importVM")
            print("create new DC {}".format(str(dc)))
            response = pbclient.create_datacenter(dc)
            dc_id = response['id']
            result = wait_for_request(pbclient, response['requestId'])
            print("wait loop returned {}".format(result))
        else:
            dc = pbclient.get_datacenter(dc_id)
            location = dc['properties']['location']
            print("use existing DC {} in location {}".format(
                dc['properties']['name'], location))

        # check if images exist
        for disk in metadata.disks:
            disk_name = disk['file']
            images = get_disk_image_by_name(pbclient, location, disk_name)
            if not images:
                raise ValueError(
                    "No HDD image with name '{}' found in location {}".format(
                        disk_name, location))
            if len(images) > 1:
                raise ValueError(
                    "Ambigous image name '{}' in location {}".format(
                        disk_name, location))
            disk['image'] = images[0]['id']

        # now we're ready to create the VM
        # Server
        server = Server(name=metadata.name,
                        cores=metadata.cpus,
                        ram=metadata.ram)
        print("create server {}".format(str(Server)))
        response = pbclient.create_server(dc_id, server)
        srv_id = response['id']
        result = wait_for_request(pbclient, response['requestId'])
        print("wait loop returned {}".format(str(result)))
        # NICs (note that createing LANs may be implicit)
        for nic in metadata.nics:
            dcnic = NIC(name=nic['nic'], lan=nic['lanid'])
            print("create NIC {}".format(str(dcnic)))
            response = pbclient.create_nic(dc_id, srv_id, dcnic)
            nic_id = response['id']
            result = wait_for_request(pbclient, response['requestId'])
            print("wait loop returned {}".format(str(result)))
            response = pbclient.get_nic(dc_id, srv_id, nic_id, 2)
            mac = response['properties']['mac']
            print("dcnic has MAC {} for {}".format(mac, nic_id))
        # end for(nics)
        # Volumes (we use the image name as volume name too
        requests = []
        for disk in metadata.disks:
            dcvol = Volume(name=disk['file'],
                           size=disk['capacity'],
                           image=disk['image'],
                           licence_type=metadata.licenseType)
            print("create Volume {}".format(str(dcvol)))
            response = pbclient.create_volume(dc_id, dcvol)
            requests.append(response['requestId'])
            disk['volume_id'] = response['id']
        # end for(disks)
        if requests:
            result = wait_for_requests(pbclient,
                                       requests,
                                       initial_wait=10,
                                       scaleup=15)
            print("wait loop returned {}".format(str(result)))
        for disk in metadata.disks:
            print("attach volume {}".format(disk))
            response = pbclient.attach_volume(dc_id, srv_id, disk['volume_id'])
            result = wait_for_request(pbclient, response['requestId'])
            print("wait loop returned {}".format(str(result)))
        # end for(disks)

        print("import of VM succesfully finished")
        return 0

    except KeyboardInterrupt:
        # handle keyboard interrupt
        return 0
    except Exception:
        traceback.print_exc()
        sys.stderr.write("\n" + program_name + ":  for help use --help\n")
        return 2
Exemple #12
0
    def setUpClass(cls):
        cls.resource = resource()
        cls.client = IonosEnterpriseService(username=configuration.USERNAME,
                                            password=configuration.PASSWORD,
                                            headers=configuration.HEADERS)

        # Create test datacenter.
        cls.datacenter = cls.client.create_datacenter(datacenter=Datacenter(
            **cls.resource['datacenter']))
        cls.client.wait_for_completion(cls.datacenter)

        # Create test volume1.
        cls.volume1 = cls.client.create_volume(
            datacenter_id=cls.datacenter['id'],
            volume=Volume(**cls.resource['volume']))
        cls.client.wait_for_completion(cls.volume1)

        # Create test volume2 (attach volume test).
        cls.volume2 = cls.client.create_volume(
            datacenter_id=cls.datacenter['id'],
            volume=Volume(**cls.resource['volume']))
        cls.client.wait_for_completion(cls.volume2)

        # Create test server.
        server = Server(**cls.resource['server'])
        server.attach_volumes = [cls.volume1['id']]
        cls.server = cls.client.create_server(
            datacenter_id=cls.datacenter['id'], server=server)
        cls.client.wait_for_completion(cls.server)

        # Create test NIC.
        cls.nic = cls.client.create_nic(datacenter_id=cls.datacenter['id'],
                                        server_id=cls.server['id'],
                                        nic=NIC(**cls.resource['nic']))
        cls.client.wait_for_completion(cls.nic)

        # Find an Ubuntu image for testing.
        for item in cls.client.list_images()['items']:
            if (configuration.IMAGE_NAME in item['properties']['name'] and
                    item['properties']['location'] == configuration.LOCATION):
                cls.image = item
        # Find a cdrom image
        images = cls.client.list_images(depth=5)
        usedIndex = 0
        for index, image in enumerate(images['items']):
            if (image['metadata']['state'] == "AVAILABLE"
                    and image['properties']['public'] is True
                    and image['properties']['imageType'] == "CDROM" and
                    image['properties']['location'] == configuration.LOCATION
                    and image['properties']['licenceType'] == "LINUX"):
                if usedIndex == 0:
                    cls.test_image1 = image
                    usedIndex = index
                else:
                    cls.test_image2 = image
                    break
        # Create test cdrom
        cls.cdrom = cls.client.attach_cdrom(datacenter_id=cls.datacenter['id'],
                                            server_id=cls.server['id'],
                                            cdrom_id=cls.test_image1['id'])
        cls.client.wait_for_completion(cls.cdrom)
Exemple #13
0
                 size=56,
                 image=image_id,
                 bus='VIRTIO',
                 image_password="******")

volume2 = Volume(name='volume2',
                 size=56,
                 image=image_id,
                 bus='VIRTIO',
                 image_password="******")

volumes = [volume2]

server1 = Server(name='My New Server1',
                 ram=4096,
                 cores=4,
                 nics=nics,
                 create_volumes=[volume1])

servers = [server1]

lan1 = LAN(name='public Lan 4', public=True)

lan2 = LAN(name='public Lan 5', public=True)

lans = [lan1, lan2]

loadbalancer1 = LoadBalancer(name='LB01', ip='10.2.2.5', dhcp=False)

loadbalancers = [loadbalancer1]
Exemple #14
0
def main(argv=None):
    '''Parse command line options and create a server/volume composite.'''

    if argv is None:
        argv = sys.argv
    else:
        sys.argv.extend(argv)

    program_name = os.path.basename(sys.argv[0])
    program_version = "v%s" % __version__
    program_build_date = str(__updated__)
    program_version_message = '%%(prog)s %s (%s)' % (program_version,
                                                     program_build_date)
    program_shortdesc = __import__('__main__').__doc__.split("\n")[1]
    program_license = '''%s

  Created by J. Buchhammer on %s.
  Copyright 2016 IONOS. All rights reserved.

  Licensed under the Apache License 2.0
  http://www.apache.org/licenses/LICENSE-2.0

  Distributed on an "AS IS" basis without warranties
  or conditions of any kind, either express or implied.

USAGE
''' % (program_shortdesc, str(__date__))

    try:
        # Setup argument parser
        parser = ArgumentParser(description=program_license,
                                formatter_class=RawDescriptionHelpFormatter)
        parser.add_argument('-u', '--user', dest='user', help='the login name')
        parser.add_argument('-p', '--password', dest='password',
                            help='the login password')
        parser.add_argument('-L', '--Login', dest='loginfile', default=None,
                            help='the login file to use')
        parser.add_argument('-d', '--datacenterid', dest='datacenterid',
                            required=True, default=None,
                            help='datacenter of the new server')
        parser.add_argument('-l', '--lanid', dest='lanid', required=True,
                            default=None, help='LAN of the new server')
        parser.add_argument('-n', '--name', dest='servername',
                            default="SRV_"+datetime.now().isoformat(),
                            help='name of the new server')
        parser.add_argument('-c', '--cores', dest='cores', type=int,
                            default=2, help='CPU cores')
        parser.add_argument('-r', '--ram', dest='ram', type=int, default=4,
                            help='RAM in GB')
        parser.add_argument('-s', '--storage', dest='storage', type=int,
                            default=4, help='storage in GB')
        parser.add_argument('-b', '--boot', dest='bootdevice', default="HDD",
                            help='boot device')
        parser.add_argument('-i', '--imageid', dest='imageid', default=None,
                            help='installation image')
        parser.add_argument('-P', '--imagepassword', dest='imgpassword',
                            default=None, help='the image password')
        parser.add_argument('-v', '--verbose', dest="verbose", action="count",
                            help="set verbosity level [default: %(default)s]")
        parser.add_argument('-V', '--version', action='version',
                            version=program_version_message)

        # Process arguments
        args = parser.parse_args()
        global verbose
        verbose = args.verbose
        dc_id = args.datacenterid
        lan_id = args.lanid
        servername = args.servername

        if verbose > 0:
            print("Verbose mode on")
            print("start {} with args {}".format(program_name, str(args)))

        # Test images (location de/fra)
        # CDROM: 7fc885b3-c9a6-11e5-aa10-52540005ab80   # debian-8.3.0-amd64-netinst.iso
        # HDD:   28007a6d-c88a-11e5-aa10-52540005ab80   # CentOS-7-server-2016-02-01
        hdimage = args.imageid
        cdimage = None
        if args.bootdevice == "CDROM":
            hdimage = None
            cdimage = args.imageid
        print("using boot device {} with image {}"
              .format(args.bootdevice, args.imageid))

        (user, password) = getLogin(args.loginfile, args.user, args.password)
        if user is None or password is None:
            raise ValueError("user or password resolved to None")
        pbclient = IonosEnterpriseService(user, password)

        first_nic = NIC(name="local", ips=[], dhcp=True, lan=lan_id)
        volume = Volume(name=servername+"-Disk", size=args.storage,
                        image=hdimage, image_password=args.imgpassword)
        server = Server(name=servername, cores=args.cores, ram=args.ram*1024,
                        create_volumes=[volume], nics=[first_nic],
                        boot_cdrom=cdimage)
        print("creating server..")
        if verbose > 0:
            print("SERVER: {}".format(str(server)))
        response = pbclient.create_server(dc_id, server)
        print("wait for provisioning..")
        wait_for_request(pbclient, response["requestId"])
        server_id = response['id']
        print("Server provisioned with ID {}".format(server_id))
        nics = pbclient.list_nics(dc_id, server_id, 1)
        # server should have exactly one nic, but we only test empty nic list
        if not nics['items']:
            raise CLIError("No NICs found for newly created server {}"
                           .format(server_id))
        nic0 = nics['items'][0]
        if verbose > 0:
            print("NIC0: {}".format(str(nic0)))
        (nic_id, nic_mac) = (nic0['id'], nic0['properties']['mac'])
        print("NIC of new Server has ID {} and MAC {}".format(nic_id, nic_mac))
        print("{} finished w/o errors".format(program_name))
        return 0

    except KeyboardInterrupt:
        # handle keyboard interrupt #
        return 0
    except Exception:
        traceback.print_exc()
        sys.stderr.write("\n" + program_name + ":  for help use --help\n")
        return 2
Exemple #15
0
    def setUpClass(cls):
        cls.resource = resource()
        cls.client = IonosEnterpriseService(
            username=configuration.USERNAME,
            password=configuration.PASSWORD,
            headers=configuration.HEADERS)

        # Create test datacenter.
        cls.datacenter = cls.client.create_datacenter(
            datacenter=Datacenter(**cls.resource['datacenter']))
        cls.client.wait_for_completion(cls.datacenter)

        # Create test LAN.
        cls.lan = cls.client.create_lan(
            datacenter_id=cls.datacenter['id'],
            lan=LAN(**cls.resource['lan']))
        cls.client.wait_for_completion(cls.lan)

        # Create test server.
        cls.server = cls.client.create_server(
            datacenter_id=cls.datacenter['id'],
            server=Server(**cls.resource['server']))
        cls.client.wait_for_completion(cls.server)

        # Create test NIC1.
        nic1 = NIC(**cls.resource['nic'])
        nic1.lan = cls.lan['id']
        cls.nic1 = cls.client.create_nic(
            datacenter_id=cls.datacenter['id'],
            server_id=cls.server['id'],
            nic=nic1)
        cls.client.wait_for_completion(cls.nic1)

        # Create test NIC2.
        # nic2 = NIC(**cls.resource['nic'])
        # nic2.lan = cls.lan['id']
        # cls.nic2 = cls.client.create_nic(
        #     datacenter_id=cls.datacenter['id'],
        #     server_id=cls.server['id'],
        #     nic=nic2)
        # cls.client.wait_for_completion(cls.nic2)

        # Create test LoadBalancer
        loadbalancer = LoadBalancer(**cls.resource['loadbalancer'])
        loadbalancer.balancednics = [cls.nic1['id']]
        cls.loadbalancer = cls.client.create_loadbalancer(
            datacenter_id=cls.datacenter['id'],
            loadbalancer=loadbalancer
        )

        cls.client.wait_for_completion(cls.loadbalancer)

        # Create test LoadBalancer2
        loadbalancer2 = LoadBalancer(**cls.resource['loadbalancer'])
        loadbalancer2.name = "Python SDK Test 2"
        cls.loadbalancer2 = cls.client.create_loadbalancer(
            datacenter_id=cls.datacenter['id'],
            loadbalancer=loadbalancer2
        )

        cls.client.wait_for_completion(cls.loadbalancer2)

        # Create test LoadBalancer3
        loadbalancer3 = LoadBalancer(**cls.resource['loadbalancer'])
        loadbalancer3.balancednics = [cls.nic1['id']]
        loadbalancer3.name = "Python SDK Test 3"
        cls.loadbalancer3 = cls.client.create_loadbalancer(
            datacenter_id=cls.datacenter['id'],
            loadbalancer=loadbalancer3
        )

        cls.client.wait_for_completion(cls.loadbalancer3)
Exemple #16
0
# See the License for the specific language governing permissions and
# limitations under the License.

# pylint: disable=reimported,wrong-import-position
"""Create Simple Server
"""

from ionosenterprise.client import IonosEnterpriseService
from ionosenterprise.client import Server

server_id = '700e1cab-99b2-4c30-ba8c-1d273ddba023'
datacenter_id = '700e1cab-99b2-4c30-ba8c-1d273ddba022'

client = IonosEnterpriseService(username='******', password='******')

i = Server(name='server', ram=4096, cores=4)

response = client.create_server(datacenter_id=datacenter_id, server=i)
"""Create Complex Server
"""

from ionosenterprise.client import IonosEnterpriseService  # noqa
from ionosenterprise.client import Server, NIC, Volume  # noqa

server_id = '700e1cab-99b2-4c30-ba8c-1d273ddba023'
datacenter_id = '700e1cab-99b2-4c30-ba8c-1d273ddba022'
image_id = '226ed8c0-a2fe-11e4-b187-5f1f641608c8'

client = IonosEnterpriseService(username='******', password='******')

nic1 = NIC(