Esempio n. 1
0
  def testCommandSucceedsNoOutput(self):
    with mock.patch(vm_util.__name__ + '.IssueCommand',
                    return_value=('', '', 0)):
      response, retval = util.DoctlAndParse(['foo', 'bar', 'baz'])

      self.assertEqual(response, None)
      self.assertEqual(retval, 0)
Esempio n. 2
0
  def _Exists(self):
    """Returns true if the VM exists."""

    response, retcode = util.DoctlAndParse(
        ['compute', 'droplet', 'get', self.droplet_id])

    return retcode == 0
Esempio n. 3
0
  def testCommandFailsWithoutNull(self):
    with mock.patch(vm_util.__name__ + '.IssueCommand',
                    return_value=('{"errors": [{"detail": "foo"}]}', '', 1)):
      response, retval = util.DoctlAndParse(['foo', 'bar', 'baz'])

      self.assertEqual(response, {'errors': [{'detail': 'foo'}]})
      self.assertEqual(retval, 1)
Esempio n. 4
0
  def testCommandSucceeds(self):
    with mock.patch(vm_util.__name__ + '.IssueCommand',
                    return_value=('{"a": 1, "b": 2}', '', 0)):
      response, retval = util.DoctlAndParse(['foo', 'bar', 'baz'])

      self.assertEqual(response, {'a': 1, 'b': 2})
      self.assertEqual(retval, 0)
Esempio n. 5
0
 def _Delete(self):
     response, retcode = util.DoctlAndParse(
         ['compute', 'volume', 'delete',
          self.volume_id, '--force'])
     if retcode:
         raise errors.Resource.RetryableDeletionError(
             'Error deleting disk: %s' % (response,))
Esempio n. 6
0
 def _PostCreate(self):
   """Get the instance's data."""
   response, retcode = util.DoctlAndParse(
       ['compute', 'droplet', 'get', self.droplet_id])
   for interface in response[0]['networks']['v4']:
     if interface['type'] == 'public':
       self.ip_address = interface['ip_address']
     else:
       self.internal_ip = interface['ip_address']
Esempio n. 7
0
    def Detach(self):
        response, retcode = util.DoctlAndParse(
            ['compute', 'volume-action', 'detach', self.volume_id])
        if retcode:
            raise errors.VmUtil.CalledProcessException(
                'Error detaching disk: %s' % (response, ))

        action_id = response[0]['id']
        util.WaitForAction(action_id)
Esempio n. 8
0
  def _Delete(self):
    """Delete a DigitalOcean VM instance."""

    response, retcode = util.DoctlAndParse(
        ['compute', 'droplet', 'delete', self.droplet_id, '--force'])
    # The command doesn't return the HTTP status code, and the error
    # format is very difficult to parse, so we string
    # search. TODO(user): parse the error message.
    if retcode and '404' in response['errors'][0]['detail']:
      return
    elif retcode:
      raise errors.Resource.RetryableDeletionError('Deletion failed: %s' %
                                                   (response,))
Esempio n. 9
0
    def _Create(self):
        self.volume_name = 'pkb-%s-%s' % (FLAGS.run_uri, self.disk_number)

        response, retcode = util.DoctlAndParse([
            'compute', 'volume', 'create', self.volume_name, '--region',
            self.zone, '--size',
            str(self.disk_size) + 'gb'
        ])
        if retcode:
            raise errors.Resource.RetryableCreationError(
                'Error creating disk: %s' % (response, ))

        self.volume_id = response[0]['id']
    def _Create(self):
        """Create a DigitalOcean VM instance (droplet)."""
        with open(self.ssh_public_key) as f:
            public_key = f.read().rstrip('\n')

        response, retcode = util.DoctlAndParse([
            'compute', 'droplet', 'create', self.name, '--region', self.zone,
            '--size', self.machine_type, '--image', self.image, '--user-data',
            CLOUD_CONFIG_TEMPLATE.format(self.user_name, public_key),
            '--enable-private-networking', '--wait'
        ])
        if retcode:
            raise errors.Resource.RetryableCreationError(
                'Creation failed: %s' % (response, ))
        self.droplet_id = response[0]['id']