当前位置: 首页>>代码示例>>Python>>正文


Python factory.InfrastructureAgentFactory类代码示例

本文整理汇总了Python中agents.factory.InfrastructureAgentFactory的典型用法代码示例。如果您正苦于以下问题:Python InfrastructureAgentFactory类的具体用法?Python InfrastructureAgentFactory怎么用?Python InfrastructureAgentFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了InfrastructureAgentFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_create_agent

    def test_create_agent(self):
        factory = InfrastructureAgentFactory()
        agent = factory.create_agent("ec2")
        self.assertEquals(type(agent), type(EC2Agent()))

        agent = factory.create_agent("euca")
        self.assertEquals(type(agent), type(EucalyptusAgent()))

        try:
            factory.create_agent("bogus")
            self.fail("No exception thrown for invalid infrastructure")
        except NameError:
            pass
        except Exception:
            self.fail("Unexpected exception thrown for invalid infrastructure")
开发者ID:lmandres,项目名称:appscale-raspberry-pi,代码行数:15,代码来源:test_agent_factory.py

示例2: __init__

  def __init__(self, params=None, blocking=False):
    """
    Create a new InfrastructureManager instance. This constructor
    accepts an optional boolean parameter which decides whether the
    InfrastructureManager instance should operate in blocking mode
    or not. A blocking InfrastructureManager does not return until
    each requested run/terminate operation is complete. This mode
    is useful for testing and verification purposes. In a real-world
    deployment it's advisable to instantiate the InfrastructureManager
    in the non-blocking mode as run/terminate operations could take
    a rather long time to complete. By default InfrastructureManager
    instances are created in the non-blocking mode.

    Args
      params    A dictionary of parameters. Optional parameter. If
                specified it must at least include the 'store_type' parameter.
      blocking  Whether to operate in blocking mode or not. Optional
                and defaults to false.
    """
    self.blocking = blocking
    self.secret = utils.get_secret()
    self.agent_factory = InfrastructureAgentFactory()
    if params is not None:
      store_factory = PersistentStoreFactory()
      store = store_factory.create_store(params)
      self.reservations = PersistentDictionary(store)
    else:
      self.reservations = PersistentDictionary()
开发者ID:daxiaxia,项目名称:appscale,代码行数:28,代码来源:infrastructure_manager.py

示例3: terminate_cloud_infrastructure

  def terminate_cloud_infrastructure(cls, keyname, is_verbose):
    """Powers off all machines in the currently running AppScale deployment.

    Args:
      keyname: The name of the SSH keypair used for this AppScale deployment.
      is_verbose: A bool that indicates if we should print the commands executed
        to stdout.
    """
    AppScaleLogger.log("About to terminate instances spawned with keyname {0}"
      .format(keyname))
    # This sleep is here to allow a moment for user to Ctrl-C
    time.sleep(2)

    # get all the instance IDs for machines in our deployment
    agent = InfrastructureAgentFactory.create_agent(
      LocalState.get_infrastructure(keyname))
    params = agent.get_params_from_yaml(keyname)
    params['IS_VERBOSE'] = is_verbose
    _, _, instance_ids = agent.describe_instances(params)

    # terminate all the machines
    params[agent.PARAM_INSTANCE_IDS] = instance_ids
    agent.terminate_instances(params)

    # delete the keyname and group
    agent.cleanup_state(params)
开发者ID:biddyweb,项目名称:appscale-tools,代码行数:26,代码来源:remote_helper.py

示例4: validate_machine_image

  def validate_machine_image(self):
    """Checks with the given cloud (if running in a cloud) to ensure that the
    user-specified ami/emi exists, aborting if it does not.

    Raises:
      BadConfigurationException: If the given machine image does not exist.
    """
    if not self.args.infrastructure:
      return

    cloud_agent = InfrastructureAgentFactory.create_agent(
      self.args.infrastructure)
    params = cloud_agent.get_params_from_args(self.args)
    if not cloud_agent.does_image_exist(params):
      raise BadConfigurationException("Couldn't find the given machine image.")

    if not cloud_agent.does_zone_exist(params):
      raise BadConfigurationException("Couldn't find the given zone.")

    if not self.args.disks:
      return

    for disk in set(self.args.disks.values()):
      if not cloud_agent.does_disk_exist(params, disk):
        raise BadConfigurationException("Couldn't find disk {0}".format(disk))
开发者ID:briandrawert,项目名称:appscale-tools,代码行数:25,代码来源:parse_args.py

示例5: spawn_node_in_cloud

  def spawn_node_in_cloud(cls, options):
    """Starts a single virtual machine in a cloud infrastructure.

    This method also prepares the virual machine for use by the AppScale Tools.
    Specifically, it enables root logins on the machine, enables SSH access,
    and copies the user's SSH key to that machine.

    Args:
      options: A Namespace that specifies the cloud infrastructure to use, as
        well as how to interact with that cloud.
    Returns:
      The instance ID, public IP address, and private IP address of the machine
        that was started.
    """
    agent = InfrastructureAgentFactory.create_agent(options.infrastructure)
    params = agent.get_params_from_args(options)
    agent.configure_instance_security(params)
    instance_ids, public_ips, private_ips = agent.run_instances(count=1,
      parameters=params, security_configured=True)
    AppScaleLogger.log("Please wait for your instance to boot up.")
    cls.sleep_until_port_is_open(public_ips[0], cls.SSH_PORT, options.verbose)
    cls.enable_root_login(public_ips[0], options.keyname,
      options.infrastructure, options.verbose)
    cls.copy_ssh_keys_to_node(public_ips[0], options.keyname, options.verbose)
    return instance_ids[0], public_ips[0], private_ips[0]
开发者ID:biddyweb,项目名称:appscale-tools,代码行数:25,代码来源:remote_helper.py

示例6: validate_credentials

  def validate_credentials(self):
    if not self.args.infrastructure:
      return

    cloud_agent = InfrastructureAgentFactory.create_agent(
      self.args.infrastructure)
    params = cloud_agent.get_params_from_args(self.args)
    cloud_agent.assert_required_parameters(params, BaseAgent.OPERATION_RUN)
开发者ID:altoplano,项目名称:appscale-tools,代码行数:8,代码来源:parse_args.py

示例7: validate_credentials

    def validate_credentials(self):
        """If running over a cloud infrastructure, makes sure that all of the
    necessary credentials have been specified.
    """
        if not self.args.infrastructure:
            return

        cloud_agent = InfrastructureAgentFactory.create_agent(self.args.infrastructure)
        params = cloud_agent.get_params_from_args(self.args)
        cloud_agent.assert_required_parameters(params, BaseAgent.OPERATION_RUN)
开发者ID:TimSoethout,项目名称:appscale-tools,代码行数:10,代码来源:parse_args.py

示例8: terminate_cloud_instance

    def terminate_cloud_instance(cls, instance_id, options):
        """Powers off a single instance in the currently AppScale deployment and
       cleans up secret key from the local filesystem.

    Args:
      instance_id: str containing the instance id.
      options: namespace containing the run parameters.
    """
        AppScaleLogger.log("About to terminate instance {0}".format(instance_id))
        agent = InfrastructureAgentFactory.create_agent(options.infrastructure)
        params = agent.get_params_from_args(options)
        params["IS_VERBOSE"] = options.verbose
        params[agent.PARAM_INSTANCE_IDS] = [instance_id]
        agent.terminate_instances(params)
        agent.cleanup_state(params)
        os.remove(LocalState.get_secret_key_location(options.keyname))
开发者ID:ejmvar,项目名称:appscale-tools,代码行数:16,代码来源:remote_helper.py

示例9: terminate_cloud_infrastructure

  def terminate_cloud_infrastructure(cls, keyname, is_verbose):
    """Powers off all machines in the currently running AppScale deployment.

    Args:
      keyname: The name of the SSH keypair used for this AppScale deployment.
      is_verbose: A bool that indicates if we should print the commands executed
        to stdout.
    """
    AppScaleLogger.log("About to terminate deployment and instances with "
                       "keyname {0}. Press Ctrl-C to stop.".format(keyname))
    # This sleep is here to allow a moment for user to Ctrl-C
    time.sleep(2)

    # get all the instance IDs for machines in our deployment
    agent = InfrastructureAgentFactory.create_agent(
      LocalState.get_infrastructure(keyname))
    params = agent.get_cloud_params(keyname)
    params['IS_VERBOSE'] = is_verbose
    params['autoscale_agent'] = False

    # We want to terminate also the pending instances.
    pending = True
    _, _, instance_ids = agent.describe_instances(params, pending=pending)

    # If using persistent disks, unmount them and detach them before we blow
    # away the instances.
    nodes = LocalState.get_local_nodes_info(keyname)
    for node in nodes:
      if node.get('disk'):
        AppScaleLogger.log("Unmounting persistent disk at {0}".
                           format(node['public_ip']))
        cls.unmount_persistent_disk(node['public_ip'], keyname, is_verbose)
        agent.detach_disk(params, node['disk'], node['instance_id'])

    # terminate all the machines
    AppScaleLogger.log("Terminating instances spawned with keyname {0}"
                       .format(keyname))
    params[agent.PARAM_INSTANCE_IDS] = instance_ids
    agent.terminate_instances(params)

    # Delete the network configuration created for the cloud.
    agent.cleanup_state(params)

    # Cleanup the keyname files created on the local filesystem.
    # For GCE and Azure, the keypairs are created on the filesystem,
    # rather than the cloud. So we have to clean up afterwards.
    LocalState.cleanup_keyname(keyname)
开发者ID:tmarballi,项目名称:appscale-tools,代码行数:47,代码来源:remote_helper.py

示例10: __init__

 def __init__(self, blocking=False):
   """
   Create a new InfrastructureManager instance. This constructor
   accepts an optional boolean parameter which decides whether the
   InfrastructureManager instance should operate in blocking mode
   or not. A blocking InfrastructureManager does not return until
   each requested run/terminate operation is complete. This mode
   is useful for testing and verification purposes. In a real-world
   deployment it's advisable to instantiate the InfrastructureManager
   in the non-blocking mode as run/terminate operations could take
   a rather long time to complete. By default InfrastructureManager
   instances are created in the non-blocking mode.
   """
   self.blocking = blocking
   self.secret = utils.get_secret()
   self.reservations = {}
   self.agent_factory = InfrastructureAgentFactory()
开发者ID:vrbala,项目名称:appscale,代码行数:17,代码来源:infrastructure_manager.py

示例11: spawn_nodes_in_cloud

  def spawn_nodes_in_cloud(cls, options, count=1):
    """Starts a single virtual machine in a cloud infrastructure.

    This method also prepares the virual machine for use by the AppScale Tools.

    Args:
      options: A Namespace that specifies the cloud infrastructure to use, as
        well as how to interact with that cloud.
      count: A int, the number of instances to start.
    Returns:
      The instance ID, public IP address, and private IP address of the machine
        that was started.
    """
    agent = InfrastructureAgentFactory.create_agent(options.infrastructure)
    params = agent.get_params_from_args(options)

    # If we have running instances under the current keyname, we try to
    # re-attach to them. If we have issue finding the locations file or the
    # IP of the head node, we throw an exception.
    login_ip = None
    public_ips, private_ips, instance_ids = agent.describe_instances(params)
    if public_ips:
      try:
        login_ip = LocalState.get_login_host(options.keyname)
      except (IOError, BadConfigurationException):
        raise AppScaleException(
          "Couldn't get login ip for running deployment with keyname"
          " {}.".format(options.keyname))
      if login_ip not in public_ips:
        raise AppScaleException(
          "Couldn't recognize running instances for deployment with"
          " keyname {}.".format(options.keyname))

    if login_ip in public_ips:
      AppScaleLogger.log("Reusing already running instances.")
      return instance_ids, public_ips, private_ips

    agent.configure_instance_security(params)
    instance_ids, public_ips, private_ips = agent.run_instances(count=count,
      parameters=params, security_configured=True)

    if options.static_ip:
      agent.associate_static_ip(params, instance_ids[0], options.static_ip)
      public_ips[0] = options.static_ip
      AppScaleLogger.log("Static IP associated with head node.")
    return instance_ids, public_ips, private_ips
开发者ID:menivaitsi,项目名称:appscale-tools,代码行数:46,代码来源:remote_helper.py

示例12: terminate_cloud_infrastructure

  def terminate_cloud_infrastructure(cls, keyname, is_verbose):
    """Powers off all machines in the currently running AppScale deployment.

    Args:
      keyname: The name of the SSH keypair used for this AppScale deployment.
      is_verbose: A bool that indicates if we should print the commands executed
        to stdout.
    """
    AppScaleLogger.log("About to terminate instances spawned with keyname {0}"
      .format(keyname))
    # This sleep is here to allow a moment for user to Ctrl-C
    time.sleep(2)

    # get all the instance IDs for machines in our deployment
    agent = InfrastructureAgentFactory.create_agent(
      LocalState.get_infrastructure(keyname))
    params = agent.get_params_from_yaml(keyname)
    params['IS_VERBOSE'] = is_verbose

    # We want to terminate also the pending instances.
    pending = True
    _, _, instance_ids = agent.describe_instances(params, pending=pending)

    # If using persistent disks, unmount them and detach them before we blow
    # away the instances.
    cls.terminate_virtualized_cluster(keyname, is_verbose)
    nodes = LocalState.get_local_nodes_info(keyname)
    for node in nodes:
      if node.get('disk'):
        AppScaleLogger.log("Unmounting persistent disk at {0}".format(
          node['public_ip']))
        cls.unmount_persistent_disk(node['public_ip'], keyname, is_verbose)
        agent.detach_disk(params, node['disk'], node['instance_id'])

    # terminate all the machines
    params[agent.PARAM_INSTANCE_IDS] = instance_ids
    agent.terminate_instances(params)

    # delete the keyname and group
    agent.cleanup_state(params)
开发者ID:cdonati,项目名称:appscale-tools,代码行数:40,代码来源:remote_helper.py

示例13: spawn_node_in_cloud

  def spawn_node_in_cloud(cls, options):
    """Starts a single virtual machine in a cloud infrastructure.

    This method also prepares the virual machine for use by the AppScale Tools.
    Specifically, it enables root logins on the machine, enables SSH access,
    and copies the user's SSH key to that machine.

    Args:
      options: A Namespace that specifies the cloud infrastructure to use, as
        well as how to interact with that cloud.
    Returns:
      The instance ID, public IP address, and private IP address of the machine
        that was started.
    """
    agent = InfrastructureAgentFactory.create_agent(options.infrastructure)
    params = agent.get_params_from_args(options)
    agent.configure_instance_security(params)
    instance_ids, public_ips, private_ips = agent.run_instances(count=1,
      parameters=params, security_configured=True)

    if options.static_ip:
      agent.associate_static_ip(params, instance_ids[0], options.static_ip)
      public_ips[0] = options.static_ip

    AppScaleLogger.log("Please wait for your instance to boot up.")
    cls.sleep_until_port_is_open(public_ips[0], cls.SSH_PORT, options.verbose)

    # Since GCE v1beta15, SSH keys don't immediately get injected to newly
    # spawned VMs. It takes around 30 seconds, so sleep a bit longer to be
    # sure.
    if options.infrastructure == 'gce':
      AppScaleLogger.log("Waiting for SSH keys to get injected to your "
        "machine.")
      time.sleep(60)

    cls.enable_root_login(public_ips[0], options.keyname,
      options.infrastructure, options.verbose)
    cls.copy_ssh_keys_to_node(public_ips[0], options.keyname, options.verbose)
    return instance_ids[0], public_ips[0], private_ips[0]
开发者ID:cdonati,项目名称:appscale-tools,代码行数:39,代码来源:remote_helper.py

示例14: cloud

class InfrastructureManager:
  """
  InfrastructureManager class is the main entry point to the AppScale
  Infrastructure Manager implementation. An instance of this class can
  be used to start new virtual machines in a specified cloud environment
  and terminate virtual machines when they are no longer required. Instances
  of this class also keep track of the virtual machines spawned by them
  and hence each InfrastructureManager instance can be queried to obtain
  information about any virtual machines spawned by each of them in the
  past.

  This implementation is completely cloud infrastructure agnostic
  and hence can be used to spawn/terminate instances on a wide range of
  cloud (IaaS) environments. All the cloud environment specific operations
  are delegated to a separate cloud agent and the InfrastructureManager
  initializes cloud agents on demand by looking at the 'infrastructure'
  parameter passed into the methods of this class.
  """

  # Default reasons which might be returned by this module
  REASON_BAD_SECRET = 'bad secret'
  REASON_BAD_VM_COUNT = 'bad vm count'
  REASON_BAD_ARGUMENTS = 'bad arguments'
  REASON_RESERVATION_NOT_FOUND = 'reservation_id not found'
  REASON_NONE = 'none'

  # Parameters required by InfrastructureManager
  PARAM_RESERVATION_ID = 'reservation_id'
  PARAM_INFRASTRUCTURE = 'infrastructure'
  PARAM_NUM_VMS = 'num_vms'

  # States a particular VM deployment could be in
  STATE_PENDING = 'pending'
  STATE_RUNNING = 'running'
  STATE_FAILED  = 'failed'

  # A list of parameters required to query the InfrastructureManager about
  # the state of a run_instances request.
  DESCRIBE_INSTANCES_REQUIRED_PARAMS = ( PARAM_RESERVATION_ID, )

  # A list of parameters required to initiate a VM deployment process
  RUN_INSTANCES_REQUIRED_PARAMS = (
    PARAM_INFRASTRUCTURE,
    PARAM_NUM_VMS
  )

  # A list of parameters required to initiate a VM termination process
  TERMINATE_INSTANCES_REQUIRED_PARAMS = ( PARAM_INFRASTRUCTURE, )

  def __init__(self, params=None, blocking=False):
    """
    Create a new InfrastructureManager instance. This constructor
    accepts an optional boolean parameter which decides whether the
    InfrastructureManager instance should operate in blocking mode
    or not. A blocking InfrastructureManager does not return until
    each requested run/terminate operation is complete. This mode
    is useful for testing and verification purposes. In a real-world
    deployment it's advisable to instantiate the InfrastructureManager
    in the non-blocking mode as run/terminate operations could take
    a rather long time to complete. By default InfrastructureManager
    instances are created in the non-blocking mode.

    Args
      params    A dictionary of parameters. Optional parameter. If
                specified it must at least include the 'store_type' parameter.
      blocking  Whether to operate in blocking mode or not. Optional
                and defaults to false.
    """
    self.blocking = blocking
    self.secret = utils.get_secret()
    self.agent_factory = InfrastructureAgentFactory()
    if params is not None:
      store_factory = PersistentStoreFactory()
      store = store_factory.create_store(params)
      self.reservations = PersistentDictionary(store)
    else:
      self.reservations = PersistentDictionary()

  def describe_instances(self, parameters, secret):
    """
    Query the InfrastructureManager instance for details regarding
    a set of virtual machines spawned in the past. This method accepts
    a dictionary of parameters and a secret for authentication purposes.
    The dictionary of parameters must include a 'reservation_id' parameter
    which is used to reference past virtual machine deployments.

    Args:
      parameters  A dictionary of parameters which contains a valid
                  'reservation_id' parameter. A valid 'reservation_id'
                  is an ID issued by the run_instances method of the
                  same InfrastructureManager object. Alternatively one
                  may provide a valid JSON string instead of a dictionary
                  object.
      secret      A previously established secret

    Returns:
      If the provided secret key is valid and the parameters map contains
      a valid 'reservation_id' parameter, this method will return a
      dictionary containing information regarding the requested past
      virtual machine deployment. This returned map contains several
#.........这里部分代码省略.........
开发者ID:daxiaxia,项目名称:appscale,代码行数:101,代码来源:infrastructure_manager.py

示例15: InfrastructureManager

class InfrastructureManager(object):
    """
    InfrastructureManager class is the main entry point to the AppScale
    Infrastructure Manager implementation. An instance of this class can
    be used to start new virtual machines in a specified cloud environment
    and terminate virtual machines when they are no longer required. Instances
    of this class also keep track of the virtual machines spawned by them
    and hence each InfrastructureManager instance can be queried to obtain
    information about any virtual machines spawned by each of them in the
    past.

    This implementation is completely cloud infrastructure agnostic
    and hence can be used to spawn/terminate instances on a wide range of
    cloud (IaaS) environments. All the cloud environment specific operations
    are delegated to a separate cloud agent and the InfrastructureManager
    initializes cloud agents on demand by looking at the 'infrastructure'
    parameter passed into the methods of this class.
    """

    # URLs
    BACKEND_QUEUE_URL = '/backend/queue'
    PREPARE_VMS_OP = 'prepare_vms'

    # Default reasons which might be returned by this module
    REASON_BAD_SECRET = 'bad secret'
    REASON_BAD_VM_COUNT = 'bad vm count'
    REASON_BAD_ARGUMENTS = 'bad arguments'
    REASON_RESERVATION_NOT_FOUND = 'reservation_id not found'
    REASON_NONE = 'none'

    # Parameters required by InfrastructureManager
    PARAM_RESERVATION_ID = 'reservation_id'
    PARAM_INFRASTRUCTURE = 'infrastructure'
    PARAM_VMS = 'vms'
    PARAM_KEYNAME = 'keyname'

    # States a particular VM deployment could be in
    STATE_PENDING = 'pending'
    STATE_RUNNING = 'running'
    STATE_FAILED = 'failed'

    # A list of parameters required to query the InfrastructureManager about
    # the state of a prepare_instances request.
    DESCRIBE_INSTANCES_REQUIRED_PARAMS = (  )

    # A list of parameters required to initiate a VM deployment process
    PREPARE_INSTANCES_REQUIRED_PARAMS = (
        PARAM_INFRASTRUCTURE,
    )

    # A list of parameters required to initiate a VM termination process
    TERMINATE_INSTANCES_REQUIRED_PARAMS = (PARAM_INFRASTRUCTURE, )

    def __init__(self, params=None, blocking=False):
        """
        Create a new InfrastructureManager instance. This constructor
        accepts an optional boolean parameter which decides whether the
        InfrastructureManager instance should operate in blocking mode
        or not. A blocking InfrastructureManager does not return until
        each requested run/terminate operation is complete. This mode
        is useful for testing and verification purposes. In a real-world
        deployment it's advisable to instantiate the InfrastructureManager
        in the non-blocking mode as run/terminate operations could take
        a rather long time to complete. By default InfrastructureManager
        instances are created in the non-blocking mode.

        Args
          params    A dictionary of parameters. Optional parameter. If
                    specified it must at least include the 'store_type' parameter.
          blocking  Whether to operate in blocking mode or not. Optional
                    and defaults to false.
        """
        self.blocking = blocking
        # self.secret = utils.get_secret()
        self.agent_factory = InfrastructureAgentFactory()
        if params is not None:
            store_factory = PersistentStoreFactory()
            store = store_factory.create_store(params)
            self.reservations = PersistentDictionary(store)
        else:
            self.reservations = PersistentDictionary()

    def describe_instances(self, parameters, secret, prefix=''):
        """
        Query the InfrastructureManager instance for details regarding
        a set of virtual machines spawned in the past. This method accepts
        a dictionary of parameters and a secret for authentication purposes.
        The dictionary of parameters must include a 'reservation_id' parameter
        which is used to reference past virtual machine deployments.

        Args:
          parameters  A dictionary of parameters which contains a valid
                      'reservation_id' parameter. A valid 'reservation_id'
                      is an ID issued by the prepare_instances method of the
                      same InfrastructureManager object. Alternatively one
                      may provide a valid JSON string instead of a dictionary
                      object.
          secret      A previously established secret

        Returns:
#.........这里部分代码省略.........
开发者ID:ahellander,项目名称:stochss,代码行数:101,代码来源:infrastructure_manager.py


注:本文中的agents.factory.InfrastructureAgentFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。