Example #1
0
    def test_wait_until(self):
        status_obj = fakes.FakeStatusChanger()
        self.assertRaises(exc.NoReloadError, utils.wait_until, status_obj, "status", "available")
        status_obj.manager = fakes.FakeManager()
        status_obj.manager.get = Mock(return_value=status_obj)

        ret = utils.wait_until(status_obj, "status", "ready", interval=0.1)
        self.assertTrue(ret)
        self.assertEqual(status_obj.status, "ready")
        ret = utils.wait_until(status_obj, "status", "fake", interval=0.1, attempts=2)
Example #2
0
 def test_wait_until_fail(self):
     status_obj = fakes.FakeStatusChanger()
     self.assertRaises(exc.NoReloadError, utils.wait_until, status_obj, "status", "available")
     status_obj.manager = fakes.FakeManager()
     status_obj.manager.get = Mock(return_value=status_obj)
     status_obj.get = status_obj.manager.get
     ret = utils.wait_until(status_obj, "status", "fake", interval=0.00001, attempts=2)
     self.assertFalse(ret.status == "fake")
Example #3
0
 def test_wait_until_callback(self):
     cback = Mock()
     status_obj = fakes.FakeStatusChanger()
     status_obj.manager = fakes.FakeManager()
     status_obj.manager.get = Mock(return_value=status_obj)
     thread = utils.wait_until(obj=status_obj, att="status", desired="ready",
             interval=0.1, callback=cback)
     thread.join()
     cback.assert_called_once_with(status_obj)
Example #4
0
 def test_wait_until_callback(self):
     cback = Mock()
     status_obj = fakes.FakeStatusChanger()
     status_obj.manager = fakes.FakeManager()
     status_obj.manager.get = Mock(return_value=status_obj)
     status_obj.get = status_obj.manager.get
     thread = utils.wait_until(obj=status_obj, att="status", desired="ready",
             interval=0.00001, callback=cback)
     thread.join()
     cback.assert_called_once_with(status_obj)
Example #5
0
 def test_wait_until_fail(self):
     status_obj = fakes.FakeStatusChanger()
     self.assertRaises(exc.NoReloadError, utils.wait_until, status_obj,
             "status", "available")
     status_obj.manager = fakes.FakeManager()
     status_obj.manager.get = Mock(return_value=status_obj)
     status_obj.get = status_obj.manager.get
     ret = utils.wait_until(status_obj, "status", "fake", interval=0.00001,
             attempts=2)
     self.assertFalse(ret.status == "fake")
Example #6
0
 def test_wait_until(self):
     status_obj = fakes.FakeStatusChanger()
     self.assertRaises(exc.NoReloadError, utils.wait_until, status_obj,
             "status", "available")
     status_obj.manager = fakes.FakeManager()
     status_obj.manager.get = Mock(return_value=status_obj)
     status_obj.get = status_obj.manager.get
     ret = utils.wait_until(status_obj, "status", "ready", interval=0.1)
     self.assertTrue(isinstance(ret, fakes.FakeStatusChanger))
     self.assertEqual(ret.status, "ready")
Example #7
0
 def log_wait(self, obj, att="status", desired=None, verbose_atts=None):
     start = time.time()
     self.logit("Beginning wait for", obj.name, obj)
     if not desired:
         desired = ["ACTIVE", "ERROR"]
     ret = utils.wait_until(obj, "status", desired=desired, interval=10, verbose=True, verbose_atts="progress")
     end = time.time()
     duration = str(datetime.timedelta(seconds=(end - start)))
     self.logit("Completed wait for", obj.name, obj)
     self.logit("  It took %s to complete" % duration)
     return ret
Example #8
0
 def test_wait_until(self):
     status_obj = fakes.FakeStatusChanger()
     self.assertRaises(exc.NoReloadError, utils.wait_until, status_obj, "status", "available")
     status_obj.manager = fakes.FakeManager()
     status_obj.manager.get = Mock(return_value=status_obj)
     status_obj.get = status_obj.manager.get
     sav_out = sys.stdout
     out = StringIO.StringIO()
     sys.stdout = out
     ret = utils.wait_until(status_obj, "status", "ready", interval=0.00001, verbose=True, verbose_atts="progress")
     self.assertTrue(isinstance(ret, fakes.FakeStatusChanger))
     self.assertEqual(ret.status, "ready")
     self.assertTrue(len(out.getvalue()) > 0)
     sys.stdout = sav_out
Example #9
0
 def test_wait_until(self):
     status_obj = fakes.FakeStatusChanger()
     self.assertRaises(exc.NoReloadError, utils.wait_until, status_obj,
             "status", "available")
     status_obj.manager = fakes.FakeManager()
     status_obj.manager.get = Mock(return_value=status_obj)
     status_obj.get = status_obj.manager.get
     sav_out = sys.stdout
     out = StringIO()
     sys.stdout = out
     ret = utils.wait_until(status_obj, "status", "ready", interval=0.00001,
             verbose=True, verbose_atts="progress")
     self.assertTrue(isinstance(ret, fakes.FakeStatusChanger))
     self.assertEqual(ret.status, "ready")
     self.assertTrue(len(out.getvalue()) > 0)
     sys.stdout = sav_out
Example #10
0
 def log_wait(self, obj, att="status", desired=None, verbose_atts=None):
     start = time.time()
     self.logit("Beginning wait for", obj.name, obj)
     if not desired:
         desired = ["ACTIVE", "ERROR"]
     ret = utils.wait_until(obj,
                            "status",
                            desired=desired,
                            interval=10,
                            verbose=True,
                            verbose_atts="progress")
     end = time.time()
     duration = str(datetime.timedelta(seconds=(end - start)))
     self.logit("Completed wait for", obj.name, obj)
     self.logit("  It took %s to complete" % duration)
     return ret
Example #11
0
     print 'Serving your request, please wait...'
     flavor = getFlavor(args.flavor)
     image = getImage(args.image)
     sname = args.server_prefix if args.server_prefix else randomStr(8)
     lbname = args.lbname if args.lbname else  randomStr(8)
     servers = createServers(args.node_count, sname, image, flavor,
                             nics=net.get_server_networks(public=True,
                                                           private=True))
     nodes = createNodes(servers, args.port_on_nodes)
     lb = createLB(lbname, args.algorithm, args.port, args.protocol, nodes)
     print "LB: %s Public: %s" % (lb.name, lb.virtual_ips[0].address)
     print 'Creating cloud blockstorage and attaching to servers.'
     for server in servers:
          vol_name = randomStr(8)
          vol = cbs.create(name=vol_name, size=vol_size, volume_type=vol_type)
          utils.wait_until(server, "status", "ACTIVE", attempts=0, verbose=True)
          vol.attach_to_instance(server, mountpoint="/dev/xvdd")
          utils.wait_until(vol, "status", "in-use", interval=3, attempts=0, 
                           verbose=True)
     lb_ssl = lb.get_ssl_termination()
     if lb_ssl:
          print "SSL termination currently in place.\n%s" % lb_ssl
     else:
          ssl = createSelfSignedCert(args.fqdn)
          lb.add_ssl_termination(securePort=443, secureTrafficOnly=False,
                                 certificate=ssl['cert'], privatekey=ssl['key'])
     lb_ip = str(lb.virtual_ips[0].address)
     addRecord(args.fqdn, validateIPv4(lb_ip))
     print 'Connect to your LB at: https://%s' % args.fqdn
     sys.exit(0)
Example #12
0
import pyrax
import os 

from pyrax.utils import wait_until
pyrax.set_credential_file(os.path.expanduser('~/.rackspace_cloud_credentials'))
cs = pyrax.cloudservers
ubu = [img for img in cs.images.list() if "Ubuntu 12.04" in img.name][0]
server = cs.servers.create('test', image=ubu, flavor=2)
server = wait_until(server, 'status', ['ACTIVE', 'ERROR'], interval = 15, attempts = 40, verbose = True, verbose_atts = 'progress')
if server.status == 'ACTIVE':
     print server.accessIPv4
else:
     server.delete()
Example #13
0
        print "Admin Password:"******"Networks", server.networks
        print

    return completed

def create_load_balancer(clb, name, port, protocol, nodes, virtual_ips):

    print "Building Load Balancer '{}'...".format(name)
    try:
        lb = clb.create(name, port = port, protocol = protocol, 
            nodes = nodes, virtual_ips = virtual_ips)
    except Exception, e:
        print "Error in load balancer creation: {}".format(e)
        sys.exit(1)
    lb = wait_until(lb, 'status', ['ACTIVE', 'ERROR'], interval = 10, attempts = 30, 
        verbose = True, verbose_atts = 'status')

    return lb

def print_load_balancer(lb):

    print "Name:", lb.name
    print "ID:", lb.id
    print "Status:", lb.status
    print "Nodes:", lb.nodes
    print "Virtual IPs:", lb.virtual_ips
    print "Algorithm:", lb.algorithm
    print "Protocol:", lb.protocol
    print "Port:", lb.port
    print
Example #14
0
        print "Admin Password:"******"Networks", server.networks
        print

    return completed

def create_load_balancer(clb, name, port, protocol, nodes, virtual_ips):

    print "Building Load Balancer '{}'...".format(name)
    try:
        lb = clb.create(name, port = port, protocol = protocol, 
            nodes = nodes, virtual_ips = virtual_ips)
    except Exception, e:
        print "Error in load balancer creation: {}".format(e)
        sys.exit(1)
    lb = wait_until(lb, 'status', ['ACTIVE', 'ERROR'], interval = 10, 
        attempts = 30, verbose = True)

    return lb

def print_load_balancer(lb):

    print "Name:", lb.name
    print "ID:", lb.id
    print "Status:", lb.status
    print "Nodes:", lb.nodes
    print "Virtual IPs:", lb.virtual_ips
    print "Algorithm:", lb.algorithm
    print "Protocol:", lb.protocol
    print "Port:", lb.port
    print
Example #15
0
	choice = raw_input('Proceed? [y/N]: ')
	if choice.capitalize() != 'Y':
		print "Exiting..."
		sys.exit(0)

	if len(servers) > 1:
		new_servers = rscloudlib.create_servers(cs, servers)
		created_servers, errored_servers = rscloudlib.track_servers(cs, 
			new_servers)
	else:
		server = servers[0]
		created_server = cs.servers.create(server['name'], server['image'],
				server['flavor'], files = server['files'], 
				nics = server['nics'])
		admin_pass = created_server.adminPass
		created_server = wait_until(created_server, 'status', 'ACTIVE', 
			interval = 10, verbose = True, verbose_atts = ['progress'])
		created_server.adminPass = admin_pass
		rscloudlib.print_server(created_server)
		print created_server.adminPass
		print
		created_servers = [created_server]

	if args.block_storage is not None:

		print '\nCreating and attaching block storage volumes...'
		cbs = pyrax.connect_to_cloud_blockstorage(region = region)
		for server in created_servers:
			try:
				volume = cbs.create(name = '{}{}'.format(args.volume_base, 
					server.name), size = args.block_storage, volume_type = 
					args.volume_type)